import scala.io.StdIn object Main { def rec(idx: Int, n: Int, s: Array[Array[Char]]): Int = { if (idx == n * n) { val winCount = s.map { (ss) => ss.filter(_ == 'o').size } var rank = 1 for (i <- (0 to n).reverse) { if (winCount(0) == i) return rank if (winCount.filter(_ == i).size != 0) rank += 1 } } val x = idx % n val y = idx / n if (s(y)(x) == '-') { s(y)(x) = 'o' s(x)(y) = 'x' val res1 = rec(idx + 1, n, s) s(y)(x) = 'x' s(x)(y) = 'o' val res2 = rec(idx + 1, n, s) return Math.min(res1, res2) } else { return rec(idx + 1, n, s) } } def main(args: Array[String]): Unit = { val n = StdIn.readInt val s = Array.fill(n)(StdIn.readLine.toArray) println(rec(0, n, s)) } }