def f(S): temp=[] cnt=0 for c in S[::-1]: if c=='0': cnt+=1 else: temp.append(cnt) cnt=0 ans=[] for n in temp[::-1]: while len(ans) and ans[-1]