Skip to main content
2 of 3
added 39 characters in body
ovs
  • 60.6k
  • 3
  • 47
  • 161

Python 3, 57 56 bytes

-1 byfe thanks to @notjagan

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

Try it online!

ovs
  • 60.6k
  • 3
  • 47
  • 161