//#define print_board for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cout << (board[i][j]) << ' '; } std::cout << '\n'; } std::cout << std::endl
//#define print_flowers(flowers) for (int i = 0; i < 26; i++) { std::cout << ((flowers & (1<<i)) >> i); } std::cout << '\n' << "abcdefghijklmnopqrstuvwxyz" << std::endl
//#define print_rect(r) std::cout << r.left << ' ' << r.right << ' ' << r.top << ' ' << r.bottom << std::endl
#define to_bit(c) (1<<(c - 'A'))
//#define MAX_RECT ((rect) { .left = 0, .right = (int16_t) (n-1), .top = 0, .bottom = (int16_t) (n-1) })
//#define rect_size(r) ((1 + r.right - r.left) * (1 + r.bottom - r.top))
#define bitmap uint32_t
#include <stdio.h>
//#include <stdlib.h>
#include <stdint.h>
// note: int16_t only needed for last part!
// other parts can do with int8_t
/*typedef struct {
int16_t left;
int16_t right;
int16_t top;
int16_t bottom;
} rect;*/
int n;
bitmap found_flowers = 0;
bitmap **board = new bitmap*[500];
/*inline bool valid_rect(int16_t left, int16_t right, int16_t top, int16_t bottom) {
bitmap flowers_in_rect = 0;
for (uint16_t x = left; x <= right; x++) {
for (uint16_t y = top; y <= bottom; y++) {
flowers_in_rect = flowers_in_rect | board[x][y];
if (found_flowers == flowers_in_rect) { return true; }
}
}
return false;
}*/
int main() {
//std::ios_base::sync_with_stdio(false);
//std::cin.tie(NULL);
scanf("%d", &n);
//board = (bitmap**) malloc((n) * sizeof(bitmap*));
char *buf = new char[501];
for (int i = 0; i < n; i++) {
bitmap *row = new bitmap[500];
scanf("%s", buf);
for (int j = 0; j < n; j++) {
found_flowers = found_flowers | to_bit(buf[j]);
row[j] = to_bit(buf[j]);
}
board[i] = row;
}
//print_board;
//print_flowers(found_flowers);
long solutions = 0;
bitmap *columns = new bitmap[500];
bitmap cols_bwise_ored;
int right;
int bottom;
// brute force everything smaller than that
for (int left = 0; left < n; left++) {
for (int top = 0; top < n; top++) {
right = n-1;
bottom = top;
for (int c_col = left; c_col <= right; c_col++) {
columns[c_col] = board[c_col][top];
}
begin:
cols_bwise_ored = 0;
for (int c_col = left; c_col <= right; c_col++) {
cols_bwise_ored |= columns[c_col];
if (cols_bwise_ored == found_flowers) {
goto valid;
}
}
goto invalid;
valid:
//std::cout << "valid!\n";
solutions += (n - bottom);
right--; // last column is no longer used at all
if (right < left) {
goto next;
}
goto begin;
invalid:
//std::cout << "invalid...\n";
bottom++;
if (bottom >= n) {
goto next;
}
for (int c_col = left; c_col <= right; c_col++) {
columns[c_col] |= board[c_col][bottom];
}
goto begin;
//std::cout << std::endl;
next:
continue;
}
} // */
printf("%ld", solutions);
/*
for (unsigned int i = 0; i < n; i++) {
free(board[i]);
}
free(board);
*/
return 0;
}