read h w read {a..d} mapfile s for((Q[N=n=1]=c+d*64-65;!r*N;r=z[a+b*64-65])){ for((p=Q[N--];z[c=p]++<4;t=u<2|v?u*u<2:2,Q[++N]=p+n*t,n=n/64-n%2*64)){ eval {t=,{u,v}=t-}'1${s[c&63]:c>>6:c+=n,1}' } } NO echo ${_[r]-YES}