import Foundation func readInt() -> Int { return Int(readLine()!)! } func make(size: Int, value: Int = 0) -> [[Int]] { let rows = (0..(repeating: value, count: size) }) return Array<[Int]>(rows) } func show(_ s: [[Int]]) -> String { return s.map({ row in row.map({ x in x.description }).joined(separator: " ") }).joined(separator: "\n") } // input let n = readInt() // solution var results = make(size: n - 1) func add(_ a: (Int, Int), _ b: (Int, Int)) -> (Int, Int) { return (a.0 + b.0, a.1 + b.1) } func inside(_ x: Int) -> Bool { return 0 <= x && x < n } func count(_ sx: Int, _ sy: Int) -> Int { let offsets: [(Int, Int)] = [ (+sx,+sy), (+sx,-sy), (-sx,+sy), (-sx,-sy), (+sy,+sx), (+sy,-sx), (-sy,+sx), (-sy,-sx), ] var state = make(size: n, value: -1) var queue = [(Int, Int)]() state[0][0] = 0 queue.append((0, 0)) func enqueue(from: (Int, Int)) { let x = from.0 let y = from.1 let c = state[x][y] let ps = offsets .map({ offest in add(from, offest) }) .filter({ p in inside(p.0) && inside(p.1) }) for p in ps { if state[p.0][p.1] == -1 { state[p.0][p.1] = c + 1 queue.append(p) } } } while !queue.isEmpty && state[n-1][n-1] == -1 { let next = queue.remove(at: 0) enqueue(from: next) } return state[n-1][n-1] } for i in 1..