ll@n,@x,@y,d[x+=y]{},s=0;rep(i,n){ll@p;char@c;d[i%x]+=c&1?s+=p,p:-p;}sortA(x,d);wt(s-sum(d(y)));