#include <iostream>
#include <bits.h>
#include <vector>
using namespace std;
bool are_all_flowers(vector<int> botr, vector<int> topr, vector<int> botl, vector<int> topl, int uniq) {
int cnt = 0;
for (int i = 0; i < botr.size(); i++) {
if (botr[i] - topr[i] - botl[i] + topl[i] > 0) {
cnt++;
}
}
return cnt == uniq;
}
bool contains(vector<char> v, char x) {
for (int i = 0; i < v.size(); i++) {
if (v[i] == x) {
return true;
}
}
return false;
}
int solve(vector<vector<char>> v, int n, int uniq) {
vector<vector<vector<int>>> prefix(n+1, vector<vector<int>> (n+1, vector<int>(26, 0)));
for (int i = 1; i < n+1; i++) {
for (int j = 1; j < n+1; j++) {
for (int k = 0; k < 26; k++) {
prefix[i][j][k] = prefix[i-1][j][k] + prefix[i][j-1][k] - prefix[i-1][j-1][k];
}
prefix[i][j][(int) v[i-1][j-1] - 65] += 1;
}
}
int ans = 0;
for (int i = 1; i < n+1; i++) {
for (int j = 1; j < n+1; j++) {
for (int d = 0; d < n+1-i; d++) {
for (int r = 0; r < n+1-j; r++) {
bool are_all_flower = are_all_flowers(prefix[i+d][j+r], prefix[i+d][j-1], prefix[i-1][j+r] ,prefix[i-1][j-1], uniq);
if (are_all_flower) {
ans++;
}
}
}
}
}
cout << ans << endl;
return 0;
}
int main() {
int n;
cin >> n;
vector<char> uniq;
int cnt=0;
vector<vector<char>> v(n);
for (int i = 0; i < n; i++) {
vector<char> temp(n);
for (int j = 0; j < n; j++) {
char ch;
cin >> ch;
temp[j] = ch;
if (!contains(uniq, ch)) {
cnt++;
uniq.push_back(ch);
}
}
v[i] = temp;
}
solve(v, n, cnt);
return 0;
}