#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

int upd (int x, int N)
{
    return N + x%N;
}

vector<int> d1(string s)
{
    int n = s.size();
    vector<int> d1(n);
    for (int i = 0, l = 0, r = -1; i < n; i++) {
        int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1);
        while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) {
            k++;
        }
        d1[i] = k--;
        if (i + k > r) {
            l = i - k;
            r = i + k;
        }
    }
    return d1;
}

vector<int> d2(string s)
{
    int n = s.size();
    vector<int> d2(n);
    for (int i = 0, l = 0, r = -1; i < n; i++) {
        int k = (i > r) ? 0 : min(d2[l + r - i + 1], r - i + 1);
        while (0 <= i - k - 1 && i + k < n && s[i - k - 1] == s[i + k]) {
            k++;
        }
        d2[i] = k--;
        if (i + k > r) {
            l = i - k - 1;
            r = i + k ;
        }
    }
    return d2;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int N;
    cin>>N;

    vector<string> s(N);
    for (int i = 0; i<N; i++) cin>>s[i];

    vector<string> diags(N);
    for (int i = 0; i<N; i++)
        for (int j = 0; j<N; j++)
        {
            diags[(i+j+N)%N]+=s[i][j];
        }

    //for (auto it: diags) cout<<it<<endl;



    vector<vector<int>> D1(N), D2(N);

    for (int it = 0; it<N; it++)
    {
        diags[it] = diags[it] + diags[it] + diags[it];
        D1[it] = d1(diags[it]);
        D2[it] = d2(diags[it]);
    }

    /*for (auto it: diags) cout<<it<<endl;

    for (auto it: D1)
    {
        for (auto x: it) cout<<x<<' ';
        cout<<endl;
    }
    cout<<endl;
    for (auto it: D2)
    {
        for (auto x: it) cout<<x<<' ';
        cout<<endl;
    }*/

    int cnt = 0;
    vector<vector<bool>> ans(N, vector<bool>(N, true));
    for (int diag = 0; diag<N; diag++)
    {
        //cout<<endl<<diag<<":\n";
        for (int l = 0; l<N; l++)
            for (int r = l; r<=l+N-1; r++) {
                int l1 = r + 1;
                int r1 = l + N - 1;
                int len = r - l + 1;

                int x = l;
                int y = (diag - x + N)%N;



                int a = x;
                int b = (y - (len - 1) + N) % N;

                if (a == 0 && b == 0)
                {
                    //cout<<diag<<' '<<l<<' '<<r<<endl;
                }

                //cout<<l<<' '<<r<<' '<<a<<' '<<b<<endl;

                if (len % 2) {
                    if (D1[diag][upd(l + len / 2, N)] <= len / 2) ans[a][b] = false;
                }
                else
                {
                    if (D2[diag][upd(l + len/2, N)]<len/2) ans[a][b] = false;
                }
                int len1 = r1 - l1 + 1;
                if (len1==0) continue;

                if (len1 % 2) {
                    if (D1[diag][upd(l1 + len1 / 2, N)] <= len1 / 2) ans[a][b] = false;
                }
                else
                {
                    if (D2[diag][upd(l1 + len1/2, N)]<len1/2) ans[a][b] = false;
                }
            }
    }
    for (int a = 0; a<N; a++)
        for (int b = 0; b<N; b++) if (ans[a][b]) cnt++;
    cout<<cnt;

}

/*
3
abc
bde
cef
 */

Measured memory_bytes: 2816