fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val table = Array(n, { readLine()!! })
  fun isValid(d: Int): Boolean {
    for (y in 0 until n) {
      for (x in 0 until n) {
        val x2 = (y + n - d) % n
        val y2 = (x + n + d) % n
        if (table[y][x] != table[y2][x2]) {
          return false
        }
      }
    }
    return true
  }

  var ans = 0
  for (d in (-n + 1)..(n - 1)) {
    if (isValid(d)) {
      val count = n - java.lang.Math.abs(d)
      ans += count
    }
  }

  println(ans)
}