def f(ar,dx,dy,h,w,c) arr= Marshal.load(Marshal.dump(ar)) return false if c==0 h.times{|y| w.times{|x| y1=y+dy x1=x+dx if arr[y][x]==1 return false if x1<0 || x1>=w || y1<0 || y1>=h arr[y1][x1]-=1 c-=2 end next if x1<0 || x1>=w || y1<0 || y1>=h return false if arr[y1][x1]<0 } } return c==0 end h,w=gets.split.map{|e| e.to_i} m=[] h.times{ m<