eval q{$N=<>-1;@S=map/ .* /?&`=`&=$':$_,<>;for$k(@@=0..$N){/^/,map'_-=$-=('_||=$\=9e9)-k'-k_,@@for@@}/^/,map$'==$_||($\-=$-=$\-$S[$']-$S[$_]-k'-'_-_N),@@for@@=1..$N-1;print}=~s/([&'_`k])([&'N_`])/\$%[\$$1][\$$2]/gr