{.checks:off.} import sequtils,strutils,algorithm,heapqueue proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord template times*(n:int,body) = (for _ in 0.. y.v) proc twoFactorDijkestra(sx,sy,sv:int,checkOasis:bool = true) = var closed = newSeq[seq[bool]](N) for x in 0.. 0: let (x,y,v) = opens.pop() if closed[x][y] : continue closed[x][y] = true if checkOasis and x == ox and y == oy: twoFactorDijkestra(x,y,v * 2,false) continue for d in dxdy4: let (nx,ny) = (d.x + x,d.y + y) if nx < 0 or ny < 0 or nx >= N or ny >= N : continue var n_v = v - L[ny][nx] if n_v <= 0 : continue if not closed[nx][ny]: opens.push((nx,ny,n_v)) if nx == N-1 and ny == N-1: echo "YES" quit() twoFactorDijkestra(0,0,V) echo "NO"