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