#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
typedef v(string) vs;
typedef v(vp) vvp;

// rolling hash
const int p1 = 999901571;
const int p2 = 999900301;
const int m1 = 1000000097;
const int m2 = 1000000663;
struct H {
  int n, q1, q2;
  H(){}
  H(int n):n(n) {
    q1 = q2 = 1;
    rep(i,n) q1 = (ll)q1*p1%m1;
    rep(i,n) q2 = (ll)q2*p2%m2;
  }
  P f(P a, int x, int y=0) {
    P r;
    r.fi = ((ll)a.fi*p1 - (ll)y*q1 + m1 + x)%m1;
    r.se = ((ll)a.se*p2 - (ll)y*q2 + m2 + x)%m2;
    return r;
  }
} h;
//

vp get(string& s) {
  int n = sz(s);
  vp p(n);
  P x;
  rep(i,n) x = h.f(x,s[i]);
  rep(i,n) {
    p[i] = x;
    x = h.f(x,s[i],s[i]);
  }
  return p;
}

int solve(vs s) {
  int n = sz(s);
  int res = 0;
  vvp ps(n);
  rep(i,n) {
    string t;
    rep(j,n) t += s[j][(i+j)%n];
    ps[i] = get(t);
  }
  rep(d,n) {
    bool ok = true;
    rep(i,n) {
      int ni = (i+d)%n;
      int nj = (n-i+d)%n;
      if (ps[ni][0] != ps[nj][i]) {
        ok = false;
        break;
      }
    }
    if (ok) res++;
  }
  return res;
}

int main() {
  int n;
  scanf("%d",&n);
  h = H(n);
  vs s(n);
  cin>>s;
  int ans = 0;
  rep(i,n) {
    ans += solve(s);
    rotate(s.begin(),s.begin()+1,s.end());
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 1280