sub f{my($c,$x,$y)=@_;$$c[$x][$y]//=(sort{$b-$a}map f($c>>1,$x,$_)+f($c+1>>1,$_,$y),@m)[0]}$n=<>-1;@m=0..<>-1;@1=map[glob],<>;map{//;$%+=$-=f($n,$_,$')-$%for@m}@m;print$%