# [Python 3], 57 bytes <!-- language-all: lang-python --> f=lambda a,*s,m=1:m*a+(s>()and f(*s,m=(a==s[0])*m*2or 1)) [Try it online!][TIO-j5h9ggs5] [Python 3]: https://docs.python.org/3/ [TIO-j5h9ggs5]: https://tio.run/##dY/BCsIwDIbve4rcltYqm@KlWF9k7hAZxYHtxtpDZezZaxVlTBwkBP58f8jfP/yts4eoQcElanUnc20ISHAnjCql4bRBd0ZGtgGNbxVJKVcVNeOG77sBSsYiJX@VAVSlgNWqxX9i@9MLfCnO2OfYF5rhmV8fia6zTKfnA7QWSCZzP7TWYz7K07GYYJzyXdob8uj8gIGJV/zAUtYn "Python 3 – Try It Online"