import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;

void main()
{
immutable n = readln.chomp.to!size_t;
ubyte[][] b;
foreach (i; 0..n)
    b ~= cast(ubyte[])readln.chomp;
size_t ret;
foreach (i; 0..n)
{
    ret += b.sym * n;
    b = b[1..$] ~ b[0];
}
ret.writeln;
}

bool sym(T)(T[][] b)
{
    foreach (i; 0..b.length)
        foreach (j; 0..i)
            if (b[i][j]!=b[j][i]) return false;
    return true;
}