#include using namespace std; int Suns(char** a, int N) { bool** i = new bool* [N]; for (int p = 0; p < N; p++) { i[p] = new bool[N + 1]; } for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { i[y][x] = false; } } for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (a[y][x] == '*') { for (int tx = x + 1; tx < N; tx++) { if (a[y][tx] != ' ') { i[y][tx] = true; break; } } for (int tx = x - 1; tx >= 0; tx--) { if (a[y][tx] != ' ') { i[y][tx] = true; break; } } for (int ty = y + 1; ty < N; ty++) { if (a[ty][x] != ' ') { i[ty][x] = true; break; } } for (int ty = y - 1; ty >= 0; ty--) { if (a[ty][x] != ' ') { i[ty][x] = true; break; } } for (int ty = y + 1, tx = x + 1; ty < N && tx < N; ty++, tx++) { if (a[ty][tx] != ' ') { i[ty][tx] = true; break; } } for (int ty = y - 1, tx = x + 1; ty >= 0 && tx < N; ty--, tx++) { if (a[ty][tx] != ' ') { i[ty][tx] = true; break; } } for (int ty = y + 1, tx = x - 1; ty < N && tx >= 0; ty++, tx--) { if (a[ty][tx] != ' ') { i[ty][tx] = true; break; } } for (int ty = y - 1, tx = x - 1; ty >= 0 && tx >= 0; ty--, tx--) { if (a[ty][tx] != ' ') { i[ty][tx] = true; break; } } } } } int cnt = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (i[y][x] == true) { cnt++; } } } return cnt * 100; } int discover(char** a, bool** i, bool** current, int N, int x, int y) { if (a[y][x] == 'v' || a[y][x] == 'D') { i[y][x] = 1; current[y][x] = 1; int sum = 0; if (x - 1 >= 0 && i[y][x - 1] == 0) { sum += discover(a, i, current, N, x - 1, y); } if (x + 1 < N && i[y][x + 1] == 0) { sum += discover(a, i, current, N, x + 1, y); } if (y + 1 < N && i[y + 1][x] == 0) { sum += discover(a, i, current, N, x, y + 1); } if (y - 1 >= 0 && i[y - 1][x] == 0) { sum += discover(a, i, current, N, x, y - 1); } return sum + 1; } return 0; } int BiggestBird(char** a, int N) { bool** i = new bool* [N]; bool** current = new bool* [N]; for (int p = 0; p < N; p++) { i[p] = new bool[N + 1]; current[p] = new bool[N + 1]; } for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { i[y][x] = false; current[y][x] = false; } } int sum = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if ((a[y][x] == 'v' || a[y][x] == 'D') && i[y][x] == 0) { discover(a, i, current, N, x, y); int tmpMax = 0; for (int p = 0; p < N; p++) { int num = 0; for (int x1 = 0; x1 < N; x1++) { if (current[p][x1]) { num++; if (tmpMax < num) { tmpMax = num; } } else { num = 0; } } num = 0; for (int y1 = 0; y1 < N; y1++) { if (current[y1][p]) { num++; if (tmpMax < num) { tmpMax = num; } } else { num = 0; } } } sum += tmpMax * 500; for (int y1 = 0; y1 < N; y1++) { for (int x1 = 0; x1 < N; x1++) { current[y1][x1] = false; } } } } } return sum; } int AnimalsI(char** a, int N) { int cnt = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (a[y][x] == '!' || a[y][x] == 'v' || a[y][x] == 'D') { if (x + 1 < N && a[y][x + 1] == ' ') { cnt++; } if (y + 1 < N && a[y + 1][x] == ' ') { cnt++; } if (x - 1 >= 0 && a[y][x - 1] == ' ') { cnt++; } if (y - 1 >= 0 && a[y - 1][x] == ' ') { cnt++; } } } } return cnt * 15; } bool freedomHelper(char** a, char** i, int N, int x, int y) { if (a[y][x] == ' ') { if (i[y][x] == 2) { return false; } if (y == 0 || x == 0 || y == N - 1 || x == N - 1 || i[y][x] == 1) { i[y][x] = 1; return true; } else { i[y][x] = 2; if (freedomHelper(a, i, N, x + 1, y) || freedomHelper(a, i, N, x - 1, y) || freedomHelper(a, i, N, x, y + 1) || freedomHelper(a, i, N, x, y - 1)) { i[y][x] = 1; return true; } return false; i[y][x] = 0; } } return false; } int Freedom(char** a, int N) { char** i = new char* [N]; for (int p = 0; p < N; p++) { i[p] = new char[N + 1]; } for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { i[y][x] = 0; } } int cnt = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (a[y][x] != ' ') { if (y == 0 || x == 0 || y == N - 1 || x == N - 1) { cnt++; } else { if (freedomHelper(a, i, N, x + 1, y) || freedomHelper(a, i, N, x, y - 1) || freedomHelper(a, i, N, x, y + 1) || freedomHelper(a, i, N, x - 1, y)) { cnt++; } } } } } return cnt * 7; } int Chupacabra(char** a, int N) { int cnt = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (a[y][x] == 'v' || a[y][x] == 'D') { if (x - 1 >= 0 && y - 1 >= 0 && a[y - 1][x - 1] == '!') { cnt++; continue; } if (x - 1 >= 0 && a[y][x - 1] == '!') { cnt++; continue; } if (x - 1 >= 0 && y + 1 < N && a[y + 1][x - 1] == '!') { cnt++; continue; } if (y - 1 >= 0 && a[y - 1][x] == '!') { cnt++; continue; } if (x + 1 < N && y - 1 >= 0 && a[y - 1][x + 1] == '!') { cnt++; continue; } if (y + 1 < N && a[y + 1][x] == '!') { cnt++; continue; } if (x + 1 < N && a[y][x + 1] == '!') { cnt++; continue; } if (x + 1 < N && y + 1 < N && a[y + 1][x + 1] == '!') { cnt++; continue; } } } } return cnt * 200; } int Peaks(char** a, int N) { bool** i = new bool* [N + 1]; for (int p = 0; p <= N; p++) { i[p] = new bool[N + 1]; } for (int y = 0; y <= N; y++) { for (int x = 0; x <= N; x++) { i[y][x] = false; } } for (int y = 0; y < N; y++) { for (int x = 0; x < N - 1; x++) { if (a[y][x] == '/' && a[y][x + 1] == '\\') { i[y][x + 1] = 1; } } } int sum = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { int max = 0; if (i[y][x]) { for (int y1 = 0; y1 < N; y1++) { for (int x1 = 0; x1 < N; x1++) { if ((y1 != y || x1 != x) && i[y1][x1]) { if (max < abs(x - x1) + abs(y - y1)) { max = abs(x - x1) + abs(y - y1); } } } } } sum += max * 50; } } return sum; } int DG(char** a, int N) { int cnt = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (a[y][x] == 'D') { if (y + 1 < N && a[y + 1][x] == 'G') { cnt++; continue; } if (x + 1 < N && a[y][x + 1] == 'G') { cnt++; continue; } if (y - 1 >= 0 && a[y - 1][x] == 'G') { cnt++; continue; } if (x - 1 >= 0 && a[y - 1][x] == 'G') { cnt++; continue; } } } } return cnt * 500; } int FrequencyEmptyAnimalsII(char** a, int N) { int e = 0, s = 0, h = 0, c = 0, l = 0, r = 0, b = 0, d = 0, g = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { if (a[y][x] == ' ') e++; if (a[y][x] == '*') s++; if (a[y][x] == '^') h++; if (a[y][x] == '!') c++; if (a[y][x] == '/') l++; if (a[y][x] == '\\') r++; if (a[y][x] == 'v') b++; if (a[y][x] == 'D') d++; if (a[y][x] == 'G') g++; } } int sum = 0; sum += e * 1; sum += b * c * d; if (s < h && s < c && s < l && s < r && s < b && s < d && s < g && s > 0) { sum += s * 10; }else if (h < s && h < c && h < l && h < r && h < b && h < d && h < g && h > 0) { sum += h * 10; } else if (c < h && c < s && c < l && c < r && c < b && c < d && c < g && c > 0) { sum += c * 10; } else if (l < h && l < c && l < s && l < r && l < b && l < d && l < g && l > 0) { sum += l * 10; } else if (r < h && r < c && r < l && r < s && r < b && r < d && r < g && r > 0) { sum += r * 10; } else if (b < h && b < c && b < l && b < r && b < s && b < d && b < g && b > 0) { sum += b * 10; } else if (d < h && d < c && d < l && d < r && d < b && d < s && d < g && d > 0) { sum += d * 10; } else { sum += g * 10; } return sum; } bool same(int i, int q, char** arr, char thr[][3]) { bool iden = true; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (thr[y][x] != arr[i + y][q + x]) iden = false; } } return iden; } int threebythree(char** arr, int arrSize) { int cnt = 0; char thr[3][3]; if (arrSize > 2) { for (int y = 0; y < arrSize - 2; y++) { for (int x = 0; x < arrSize - 2; x++) { bool unique = true; for (int i = y; i < y + 3; i++) for (int q = x; q < x + 3; q++) thr[i - y][q - x] = arr[i][q]; for (int i = 0; i < arrSize - 2; i++) { for (int q = 0; q < arrSize - 2; q++) { if (i != y || q != x) { if (same(i, q, arr, thr)) { unique = false; } } } } if (unique) cnt++; } } } return cnt; } int house_view_up(char** arr, int arrSize) { int house = 0; for (int y = 0; y < arrSize; y++) { for (int x = 0; x < arrSize; x++) { if (arr[y][x] == '^') { bool t = true; for (int i = y - 1; i >= 0 && t; i--) { if (arr[i][x] == ' ') house++; else t = false; } } } } return house * 10; } int house_view_down(char** arr, int arrSize) { int house = 0; for (int y = 0; y < arrSize; y++) { for (int x = 0; x < arrSize; x++) { if (arr[y][x] == '^') { bool t = true; for (int i = y - 1; i >= 0 && t; i--) { if (arr[i][x] == ' ') house++; else t = false; } } } } return house * 5; } int housegrill(char** arr, int arrSize) { int grills = 0; int houses = 0; for (int y = 0; y < arrSize; y++) { for (int x = 0; x < arrSize; x++) { if (arr[y][x] == '^') { houses++; } if (arr[y][x] == 'G') { grills++; } } } return 3 * min(houses, grills); } int grilldrake(char** arr, int arrSize) { int grill = 0; for (int y = 0; y < arrSize; y++) { for (int x = 0; x < arrSize; x++) { if (arr[y][x] == 'G') { bool isgrill = false; if (y > 0) { if (arr[y - 1][x] == 'D') { isgrill = true; } } if (x > 0) { if (arr[y][x - 1] == 'D') { isgrill = true; } } if (y < arrSize - 1) { if (arr[y + 1][x] == 'D') { isgrill = true; } } if (x < arrSize - 1) { if (arr[y][x + 1] == 'D') { isgrill = true; } } if (isgrill) grill++; } } } return grill * 50; } int flock_perim(char** arr, int arrSize) { int perim = 0; for (int y = 0; y < arrSize; y++) { for (int x = 0; x < arrSize; x++) { if (arr[y][x] == 'v') { if (y > 0) { if (arr[y - 1][x] != 'v') { perim++; } } else if (y == 0) { perim++; } if (x > 0) { if (arr[y][x - 1] != 'v') { perim++; } } else if (x == 0) { perim++; } if (y < arrSize - 1) { if (arr[y + 1][x] != 'v') { perim++; } } else if (y == arrSize - 1) { perim++; } if (x < arrSize - 1) { if (arr[y][x + 1] != 'v') { perim++; } } else if (x == arrSize - 1) { perim++; } } } } return perim * 60; } int main() { int arrSize; std::cin >> arrSize; char** arr = new char*[arrSize]; for (int p = 0; p < arrSize; p++) { arr[p] = new char[arrSize+1]; } char c; cin >> noskipws >> c; for (int y = 0; y < arrSize; y++) { std::cin.getline(arr[y], (uint64_t)arrSize+1); } int sum = Suns(arr, arrSize) + BiggestBird(arr, arrSize) + AnimalsI(arr, arrSize) + Freedom(arr, arrSize) + Chupacabra(arr, arrSize) + Peaks(arr, arrSize) + DG(arr, arrSize) + +FrequencyEmptyAnimalsII(arr, arrSize) + threebythree(arr, arrSize) + housegrill(arr, arrSize) + house_view_up(arr, arrSize) + house_view_down(arr, arrSize) + +grilldrake(arr, arrSize) + flock_perim(arr, arrSize); cout << sum; }