import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val t = Array(n) { Array(n) { nextInt() } } for (i in 0 until n) { for (j in 0 until n) { for (k in 0 until n) { if (t[t[i][j]][k] != t[i][t[j][k]]) { println("No") return } } } } var e = -1 loop@for (i in 0 until n) { for (j in 0 until n) { if (t[i][j] != j) { continue@loop } } e = i break } if (e == -1) { println("No") return } for (i in 0 until n) { var ok = false for (j in 0 until n) { if (t[j][i] == e) { ok = true break } } if (!ok) { println("No") return } } println("Yes") } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", abs(1L.shl(26))) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion