import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	char[][] field;
	field.length = n;
	foreach(i; 0 .. n){
		field[i] = readln.chomp.to!(char[]);
		field[i] ~= field[i];
		}
	debug field.writeln;
	
	char[][] trans;
	trans.length = n;
	foreach(j; 0 .. n){
		trans[j].length = n * 2;
		foreach(i; 0 .. n){
			trans[j][i] = field[i][j];
			trans[j][n + i] = field[i][j];
			}
		}
	debug trans.writeln;
	
	long[string] xcount;
	foreach(j; 0 .. n){
		string q = "";
		foreach(i; 0 .. n) q ~= field[i][j .. n + j];
		foreach(i; 0 .. n) q ~= field[i][j .. n + j];
		foreach(i; 0 .. n){
			string k = q[i * n .. n * n + i * n]; // this line is heavy
			if(k in xcount) xcount[k] += 1;
			else xcount[k] = 1;
			}
		}
	debug xcount.writeln;
	
	long[string] ycount;
	foreach(j; 0 .. n){
		string q = "";
		foreach(i; 0 .. n) q ~= trans[i][j .. n + j];
		foreach(i; 0 .. n) q ~= trans[i][j .. n + j];
		foreach(i; 0 .. n){
			ycount[q[i * n .. n * n + i * n]] += 1;
			}
		}
	debug ycount.writeln;
	
	string x = xcount.keys[0];
	
	if(x in ycount) writeln(ycount[x]);
	else writeln(0);
	}