# [Python 3], <s>57</s> 56 bytes

*-1 byfe thanks to @notjagan*

<!-- language-all: lang-python -->

    f=lambda a,*s,m=1:m*a+(s>()and f(*s,m=(m*2)**(a==s[0])))

[Try it online!][TIO-j5hoe7os]

[Python 3]: https://docs.python.org/3/
[TIO-j5hoe7os]: https://tio.run/##dY/BCoMwEETvfsXe3KRp0ZZexPRHbA5bJFRoopgcLOK321hagqXCLguzbwame/p7a0@zBgnXWcsHmVtNQII7YWReGE47dBdkZGvQ@FbR8CPjHElKV2WKMTZTsFcJQJUL2Bwl/hP7n13hazFin7AvFOHIb59AqyTRbQ8DNBaoCOaub6zHdCzKczbBOKWH8Dfk0fkeByaW9sPS9QU "Python 3 – Try It Online"