ll@n,w=0,z=0; string@s; rrep(i,n){ if(s[i]&1){ z>?=n-i+w; ++w; }else{ --w; w>?=0; } } wt(z);