#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

const int MAX_LHM = 1;
const ll MUL[2] = {72727, 51419};
const ll RHMOD[2] = {765876961, 727272727};
struct RollingHash{
  vector<ll> h[MAX_LHM];
  vector<ll> e[MAX_LHM];
  int n;
  void init(const string &s){
    n = s.length();
    for(int i = 0; i < MAX_LHM; i++){
      h[i] = vector<ll>(n+1 , 0);
      e[i] = vector<ll>(n+1 , 1);
      for(int j = 0; j < n; j++){
        h[i][j+1] = (h[i][j]*MUL[i] + s[j]) % RHMOD[i];
        e[i][j+1] = e[i][j]*MUL[i]%RHMOD[i];
      }
    }
  }
  RollingHash(){}
  RollingHash(const string &s){
    init(s);
  }
  ll get(int s, int t){
    s = min(s, n);
    s = max(s, 0);
    t = min(t, n);
    t = max(t, 0);
    ll res = (h[0][t] - h[0][s]*e[0][t-s]%RHMOD[0] + RHMOD[0]) % RHMOD[0];
    // res += ((h[1][t] - h[1][s]*e[1][t-s]%RHMOD[1] + RHMOD[1]) % RHMOD[1]) * RHMOD[0];
    return res;
  }
};

template<ll p, ll b>
struct FastRollingHash{
  vector<ll> h;
  vector<ll> e;
  ll n, m;
  inline ll mod(ll x){
    x = (x & m) + (x >> p);
    return (x >= m) ? (x - m) : x;
  }
  void init(const string &s){
    n = s.length();
    m = (1LL << p) - 1;
    h = vector<ll>(n+1, 0);
    e = vector<ll>(n+1, 1);
    for(int i = 0; i < n; i++){
      h[i+1] = mod(mod(h[i]*b)+s[i]);
      e[i+1] = mod(e[i]*b);
    }
  }
  FastRollingHash(){}
  FastRollingHash(const string &s){
    init(s);
  }
  ll get(int s, int t){
    ll res = h[t] - mod(h[s]*e[t-s]);
    return (res < 0) ? (res + m) : res;
  }
};

int n;
string s[310];
string t[610];

FastRollingHash<31, 31> rhs[310];
FastRollingHash<31, 31> rht[310];

// RollingHash rhs[310];
// RollingHash rht[310];

int main(){

  n = in();
  REP(i, n){
    s[i] = stin();
    t[i] = s[i];
    s[i] += s[i];
  }

  REP(i, n){
    REP(j, n){
      if(i < j){
        swap(t[i][j], t[j][i]);
      }
    }
  }
  REP(i, n){
    t[i] += t[i];
  }
  
  REP(i, n){
    rhs[i].init(s[i]);
    rht[i].init(t[i]);
  }

  ll ans = 0;
  REP(i, n){
    REP(j, n){
      bool ok = true;
      int si = i;
      int tj = j;
      REP(k, n){
        if(rhs[si].get(j, j+n) != rht[tj].get(i, i+n)){
          ok = false;
          break;
        }
        si = (si + 1 == n) ? 0 : (si + 1);
        tj = (tj + 1 == n) ? 0 : (tj + 1);
      }
      if(ok){
        ans++;
      }
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 8448