program main implicit none integer::h,w,sx,sy,gx,gy character*50::input integer,allocatable::height(:,:) integer,allocatable::reach(:,:) integer::i,j,itr,nexti,nextj read *, h,w read *, sx,sy,gx,gy allocate(height(-1:h+2,-1:w+2),reach(h,w)) do i=1,h read *,input do j=1,LEN_TRIM(input) height(i,j) = ICHAR(input(j:j))-ICHAR('0') end do end do height(-1:0 ,:) = 100 height(h+1:h+2,:) = 100 height(: ,-1:0) = 100 height(: ,w+1:w+2) = 100 reach = 0 reach(sx,sy) = 1 do itr=1,h*w do i=1,h do j=1,w if(reach(i,j).ne.1) cycle if(abs(height(i,j)-height(i,j+1)).le.1) reach(i,j+1) = 1 if(abs(height(i,j)-height(i,j-1)).le.1) reach(i,j-1) = 1 if(abs(height(i,j)-height(i+1,j)).le.1) reach(i+1,j) = 1 if(abs(height(i,j)-height(i-1,j)).le.1) reach(i-1,j) = 1 if(height(i,j).eq.height(i,j+2).and.height(i,j).gt.height(i,j+1)) reach(i,j+2) = 1 if(height(i,j).eq.height(i,j-2).and.height(i,j).gt.height(i,j-1)) reach(i,j-2) = 1 if(height(i,j).eq.height(i+2,j).and.height(i,j).gt.height(i+1,j)) reach(i+2,j) = 1 if(height(i,j).eq.height(i-2,j).and.height(i,j).gt.height(i-1,j)) reach(i-2,j) = 1 end do end do if(reach(gx,gy).eq.1) then print '(a)',"YES" return end if end do print '(a)',"NO" end program main