f=h*h+w%2\>N*N read while read h w N do echo ${_[f&(t=h,h=w,w=t,f)]-S} done