// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;

// Rolling Hash
// Verified: AOJ 2444 (Substring)

ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2, mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}

struct RollingHash {
public:
    long long base_1, base_2, mod_1, mod_2;
    vector<long long> hash1, hash2, pow_hash;
    long long pow;

    // init (constructor)
    RollingHash() {}
    RollingHash(string s, int N) : base_1(1013), base_2(1007),
        mod_1(1000000007), mod_2(1000000009),
        hash1(s.length()+1,0), hash2(s.length()+1,0),
        pow_hash(s.length()+1,0), pow(1) {
            pow = mod_pow(base_1, N, mod_1);
            for(int i=0; i<s.length(); i++) {
                hash1[i+1] = (hash1[i]+s[i]) * base_1 % mod_1;
                // hash2[i+1] = (hash2[i]+s[i]) * base_2 % mod_2;
                // pow1[i+1] = pow1[i] * base_1 % mod_1;
                // pow2[i+1] = pow2[i] * base_2 % mod_2;
            }

            for(int i=0; i<=s.length(); i++) {
                pow_hash[i] = (hash1[i] * pow) % mod_1;
            }
        }

    // calc str[l,r) hash (0-indexed)
    // if get(i1,j1) == get(i2,j2) -> identical string
    pair<long long, long long> get(int l, int r) {
        long long t1 = (hash1[r] - pow_hash[l] + mod_1) % mod_1;
        // long long t2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod_2 + mod_2) % mod_2;
        long long t2 = 1;
        return make_pair(t1, t2);
    }
};

using pll = pair<long long, long long>;
 
signed main() {
    int N; cin >> N;
    vector<string> vs(N);
    rep(i,0,N) cin >> vs[i];

    vector<string> pat(2*N-1, ""), inv(2*N-1, "");
    rep(i,0,2*N-1) {
        int idx = (i % N);
        pat[i] = vs[idx] + vs[idx].substr(0, N-1);
        // cerr << "pat: " << pat[i] << endl;
    }

    rep(j,0,2*N-1) rep(i,0,2*N-1) {
        inv[j] += pat[i][j];
    }

    /*
    // cout << "Pattern generate end" << endl;
    rep(i,0,2*N-1) {
        // cerr << "inv: " << inv[i] << endl;
    }
    */

    vector<RollingHash> rh_pat(2*N-1), rh_inv(2*N-1);
    rep(i,0,2*N-1) {
        rh_pat[i] = RollingHash(pat[i], N);
        rh_inv[i] = RollingHash(inv[i], N);
    }

    // cout << "Rolling Hash end" << endl;

    int ans = 0;
    rep(i,0,N) rep(j,0,N) {
        bool ok = true;
        // printf("i = %lld, j = %lld\n", i, j);
        rep(k,0,N) {
            int row_l = i+k, col_l = j;
            int row_r = j+k, col_r = i;

            pll vl = rh_pat[row_l].get(col_l, col_l+N);
            pll vr = rh_inv[row_r].get(col_r, col_r+N);

            if(vl != vr) {
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20480