def g(a,s,n=1):
for c in s:
b,n=((n,1),(-n,2*n))[c<'W']
if a<-b:break
a+=b
print(a)
return a
print(g(15,'LLLWLLLL'))
ZGVmIGcoYSxzLG49MSk6CiBmb3IgYyBpbiBzOgogICAgYixuPSgobiwxKSwoLW4sMipuKSlbYzwnVyddCiAgICBpZiBhPC1iOmJyZWFrCiAgICBhKz1iCiAgICBwcmludChhKQogcmV0dXJuIGEKIApwcmludChnKDE1LCdMTExXTExMTCcpKQo=