local n = io.read("*n", "*l")
local rowmap = {}
for i = 1, n do
  rowmap[i] = io.read()
end

local colmap = {}
for i = 1, n do
  local tmps = ""
  for j = 1, n do
    tmps = tmps .. rowmap[j]:sub(i, i)
  end
  colmap[i] = {}
  tmps = tmps .. tmps
  for j = 1, n do
    colmap[i][j] = tmps:sub(n + 2 - j, n + 2 - j + n - 1)
  end
end

local function check(r)
  for k = 1, n do
    local row_tgt = k + n - r
    if n < row_tgt then row_tgt = row_tgt - n end
    local col_ofst = 1 + r
    if rowmap[row_tgt] ~= colmap[k][col_ofst] then return 0 end
  end
  return n
end
local ret = 0
for i = 0, n - 1 do
  ret = ret + check(i)
end
print(ret)
