def insort(t,c): global head p=head if t<d[head][0]: head=c __________ else: while __________: p=d[p][1] d[c][1]=d[p][1] d[p][1]=c return d s=list(map(int,input().split(','))) d=[] head=0 d.append([s[0],-1]) for i in range(1,len(s)): d.append([s[i],i]) d=insort(s[i],i) w=0 k=head while k!=-1: d[k][0]+=d[d[k][1]][0] w+=d[k][0] head=__________ if head!=-1: d=insort(d[k][0],k) __________ print(w)