#include <iostream>
#include <vector>
#include <map>
#include <string>
#include<cmath>
#include <bitset>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<string>> string_rows(n, vector<string>(n, ""));
for(int i=0; i<n; i++){
string row;
cin >> row;
for(int j=0; j<n; j++){
string_rows[i][j] = row[j];
}
}
map<string, int> species_to_number;
vector<vector<int>> rows (n, vector<int>(n, 0));
for(int y=0; y<n; y++){
for(int x=0; x<n; x++){
if(species_to_number.find(string_rows[y][x]) == species_to_number.end()){
species_to_number[string_rows[y][x]] = species_to_number.size()+1;
}
rows[y][x] = species_to_number[string_rows[y][x]];
}
}
int existing_species_mask = 0;
for(int i=0; i<species_to_number.size(); i++){
existing_species_mask += pow(2, i);
}
uint64_t fitting_fences = 0;
for(int y1=0; y1<n; y1++){
vector<int> found_species_per_column (n, 0);
for(int y2=y1; y2<n; y2++){
vector<int> column = rows[y2];
for (int i=0; i < column.size(); i++){
found_species_per_column[i] = found_species_per_column[i] | (int)pow(2, column[i])>>1;
}
for(int x1=0; x1<n; x1++){
int mask = 0;
for(int x2=x1; x2<n; x2++){
mask = mask | found_species_per_column[x2];
if(mask == existing_species_mask){
fitting_fences += n-x2;
break;
}
}
}
}
}
}
cout << fitting_fences;
return 0;
}