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

bool checkgood(char[][] a, int shift) {
    size_t n(size_t x) {
        return x % a.length;
    }

    for (size_t i = 0; i < a.length; ++i) {
        for (size_t j = i+1; j < a[0].length; ++j) {
            if(a[n(i + shift)][n(j)] != a[n(j + shift)][n(i)]) {
                return false;
            }
        }
    }
    return true;
}

void main(){
    auto buf = readln().strip().split().map!(to!int)();
    immutable N = buf[0];

    char[][] a;
    a.length = N;

    int ans;

    foreach(immutable int i; 0 .. N) {
        a[i] = readln().strip().map!(to!(char))().array;
    }

    for (int i = 0; i < N; ++i) {
        if (checkgood(a, i)) {
            ans ++;
        }
    }

    writeln(ans * N);
}
