import sequtils,deques 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 let h = scan() let w = scan() var isWater : array[3001,array[3001,bool]] for y in 0.. 0: let x = X.popFirst() let y = Y.popFirst() for i in 0..<4: let nx = x+dxdy4[i].x let ny = y+dxdy4[i].y if nx < 0 or nx >= w : continue if ny < 0 or ny >= h : continue if not isWater[nx][ny] : continue X.addLast(nx) Y.addLast(ny) isWater[nx][ny] = false var ans = 0 for x in 0.int32..