local n = io.read("*n", "*l")
local row = {}
for i = 1, n do
  row[i] = io.read()
end
local col = {}
for i = 1, n do col[i] = "" end
for i = 1, n do
  for j = 1, n do
    col[i] = col[i] .. row[j]:sub(i, i)
  end
end

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

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

local ret = 0
for i = 0, n - 1 do
  for j = 0, n - 1 do
    ret = ret + check(i, j)
  end
end
print(ret)
