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

local function check(j)
  for i = 1, n do
    if row[i] ~= colmap[i][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(j)
    local tmp = row[1]
    for k = 2, n do
      row[k - 1] = row[k]
    end
    row[n] = tmp
  end
  local tmp2 = colmap[1]
  for k = 2, n do
    colmap[k - 1] = colmap[k]
  end
  colmap[n] = tmp2
  for k = 1, n do
    row[k] = row[k]:sub(n, n) .. row[k]:sub(1, n - 1)
  end
end
print(ret)
