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(2, n) .. tmps:sub(1, 1)
    colmap[i][j] = tmps
  end
end

local function check(i, j)
  for k = 1, n do
    local kcol = k + i - 1
    if n < kcol then kcol = kcol - n end
    if row[k] ~= colmap[kcol][j] then return 0 end
  end
  return 1
end

local ret = 0
for i = 1, n do
  for j = 1, n do
    ret = ret + check(i, j)
    local tmp = row[1]
    for k = 2, n do
      row[k - 1] = row[k]
    end
    row[n] = tmp
  end
  if 1 < n then
    for k = 1, n do
      row[k] = row[k]:sub(n, n) .. row[k]:sub(1, n - 1)
    end
  end
end
print(ret)
