#include <bits/stdc++.h>
using namespace std;
#define IC(c) (int)(c-'A')
#define sum(x1,y1,x2,y2,id) pre[x2][y2][id]-pre[x1-1][y2][id]-pre[x2][y1-1][id]+pre[x1-1][y1-1][id]
const int N=509;
const int F=26;
int n,C;
int pre[N][N][F+1];
//pre[i][j][c] : prefix sum
//compact[j][c] for every array[top,btm]
//the compacted prefix sum
int idx[F+1];//char-int list
bool check(int x1,int y1,int x2,int y2){
bool T=1;
for(int i=1;i<=C;i++)T=T&&sum(x1,y1,x2,y2,i);
return T;
}
int ans;
//sum up answer
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
char c;
cin>>c;
int id=IC(c);
if(!idx[id]){
C++;
idx[id]=C;
}
for(int k=1;k<=C;k++){
if(k==idx[id])
pre[i][j][k]=pre[i-1][j][k]+pre[i][j-1][k]-pre[i-1][j-1][k]+1;
else
pre[i][j][k]=pre[i-1][j][k]+pre[i][j-1][k]-pre[i-1][j-1][k];
}
}
//input ends here
//for every [top,btm] in [1,n]
for(int top=1;top<=n;top++){
for(int btm=top;btm<=n;btm++){//O(n^2)
if(!check(top,1,btm,n)){
if(btm==n){
cout<<ans<<endl;
return 0;
}
else continue;
}
int l=1,r=1;
//scan the array
while(r<=n){//O(n)
while(check(top,l+1,btm,r)&&l<r){
l++;
}
if(!tag)if(check(top,l,btm,r))tag=true;
if(tag)ans+=l;
r++;
}
}
}
printf("%d\n",ans);
return 0;
}