$T=<>;<>;@c=glob<>; for$v(glob<>){ for($c=shift@c;$v;$v>>=1){ for$t(reverse$c..$T){ $\+=$-=($d[$t]+=$-=$d[$t-$c]+$v-$d[$t])-$\ } } } print