import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;


void main() {
    int n; scan(n);
    char[][] ban = new char[][](n, n);
    iota(n).each!(i => ban[i] = readln.chomp.to!(char[]));

    long ans;

    foreach (i ; 0 .. n) {
        if (isSym(n, ban, 0, i)) {
            ans += n;
        }
    }

    writeln(ans);
}

bool isSym(int n, char[][] ban, int a, int b) {
    auto cop = new char[][](n, n);

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            cop[i][j] = ban[(i + a) % n][(j + b) % n];
        }
    }

    debug {
        writefln("(a, b) = (%d, %d)", a, b);
        writefln("%-(%s\n%)", cop);
    }

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            if (cop[i][j] != cop[j][i]) {
                return false;
            }
        }
    }

    return true;
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
