import Foundation public struct Queue { fileprivate var array = [T?]() fileprivate var head = 0 public var isEmpty: Bool { return count == 0 } public var count: Int { return array.count - head } public mutating func enqueue(_ element: T) { array.append(element) } public mutating func dequeue() -> T? { guard head < array.count, let element = array[head] else { return nil } array[head] = nil head += 1 let percentage = Double(head)/Double(array.count) if array.count > 50 && percentage > 0.25 { array.removeFirst(head) head = 0 } return element } public var front: T? { if isEmpty { return nil } else { return array[head] } } } let n = Int(readLine()!)! struct Point { let x: Int let y: Int } var b: [[Int]] = [] for i in 0..() var position = Point(x: n-1, y: n-1) var notFound = false while position.x != 0 || position.y != 0 { let newpositions = [Point(x: position.x - i, y: position.y - j), Point(x: position.x - i, y: position.y + j), Point(x: position.x + i, y: position.y - j), Point(x: position.x + i, y: position.y + j), Point(x: position.x - j, y: position.y - i), Point(x: position.x - j, y: position.y + i), Point(x: position.x + j, y: position.y - i), Point(x: position.x + j, y: position.y + i),] let corretPositions = newpositions.filter({ point -> Bool in if point.x < 0 || point.y < 0 { return false } if point.x >= n || point.y >= n { return false } if board[point.x][point.y] > 0 { return false } return true }) corretPositions.forEach({ (pp) in toCheck.enqueue(pp) board[pp.x][pp.y] = board[position.x][position.y] + 1 }) if let newPosition = toCheck.dequeue() { position = newPosition } else { resultsBoard[i][j] = -1 notFound = true break } } if !notFound { resultsBoard[i][j] = board[0][0]-1 } } } for j in 1..