#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll mul(ll a, ll b, ll mod) {
    return a * b % mod;
}
ll add(ll a, ll b, ll mod) {
    return (a + b) % mod;
}
ll sub(ll a, ll b, ll mod) {
    return (a - b + mod) % mod;
}
ll power(ll x, ll n, ll mod) {
    ll res = 1;
    for (ll i = 1; i <= n; i <<= 1) {
        if (i & n) res = mul(res, x, mod);
        x = mul(x, x, mod);
    }
    return res;
}
ll inv(ll n, ll mod) {
    return power(n, mod-2, mod);
}

class RollingHash {
private:
    const ll A, mod;
    const string str;
    vector<ll> hash;
    vector<ll> make_hash(const string& s, const ll A, const ll mod) {
        vector<ll> res(s.size()+1, 0);
        ll coe = 1;
        REP(i, s.size()) {
            hash[i+1] = add(hash[i], mul(coe, s[i], mod), mod);
            coe = mul(coe, A, mod);
        }
        return res;
    }
public:
    RollingHash(const string& s, const ll A, const ll mod) : str(s), A(A), mod(mod), hash(make_hash(s, A, mod)) {}
    ll get(ll l, ll r) {
        return mul(sub(hash[r], hash[l], mod), inv(power(A, l, mod), mod), mod);
    }
    bool iseq(ll s1, ll s2, ll len) {
        return get(s1, s1+len) == get(s2, s2+len);
    }
};
const ll A1 = 1007, mod1 = 1e9+9;
ll get_hash(const string& s, ll dx) {
    const ll n = s.size();
    string str = "";
    rep(i, n) str += s[(i-dx+n)%n];
    return RollingHash(str, A1, mod1).get(0, n);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<string> m(n); cin >> m;
    vector<vector<ll>> hash(n, vector<ll>(n));
    rep(i, n) rep(j, n) {
        hash[i][j] = get_hash(m[i], j);
    }
    vector<string> rm = m;
    rep(i, n) rep(j, n) rm[i][j] = m[j][i];
    vector<vector<ll>> rhash(n, vector<ll>(n));
    rep(i, n) rep(j, n) {
        rhash[i][j] = get_hash(rm[i], j);
    }
    vector<ll> tgt(n);
    rep(i, n) tgt[i] = get_hash(rm[i], 0);
    ll ans = 0;
    rep(dx, n) rep(dy, n) {
        bool f = true;
        rep(i, n) if (hash[(i-dy+n)%n][dx] != rhash[(i-dx+n)%n][dy]) {
            f = false;
            break;
        }
        if (f) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920