#include #include #include #include #include using namespace std; int n, bbi = 0; string p[50]; bool s[50][50]{}; bool f[50][50]{}; int b[50][50]{}; bool isValid(int y, int x) { return y < n && y >= 0 && x < n && x >= 0; } bool isBird(int y, int x) { return p[y][x] == 'v' || p[y][x] == 'D'; } bool isAnimal(int y, int x) { return p[y][x] == '!' || isBird(y, x); } void goSuns(int y, int x, int dy, int dx) { y += dy; x += dx; while (isValid(y, x)) { if (p[y][x] != ' ') { if (p[y][x] != '*') s[y][x] = true; return; } y += dy; x += dx; } } void goBirds(int y, int x) { if (!isValid(y, x)) return; if (b[y][x] != 0) return; if (!isBird(y, x)) return; b[y][x] = bbi; goBirds(y + 1, x); goBirds(y, x + 1); goBirds(y - 1, x); goBirds(y, x - 1); } void goFreedom(int y, int x) { if (!isValid(y, x)) return; if (f[y][x]) return; f[y][x] = true; if (p[y][x] != ' ') return; goFreedom(y + 1, x); goFreedom(y, x + 1); goFreedom(y - 1, x); goFreedom(y, x - 1); } int main() { vector> peaks; map freq; set blocks; uint64_t worth = 0; long x, y, i, j; cin >> n; getline(cin, p[0]); // Clear line for (y = 0; y < n; ++y) getline(cin, p[y]); for (y = 0; y < n; ++y) for (x = 0; x < n; ++x) { // Frequencies freq[p[y][x]]++; if (p[y][x] == '*') // Suns { goSuns(y, x, 1, 0); goSuns(y, x, 1, 1); goSuns(y, x, 0, 1); goSuns(y, x, -1, 1); goSuns(y, x, -1, 0); goSuns(y, x, -1, -1); goSuns(y, x, 0, -1); goSuns(y, x, 1, -1); } if (isBird(y, x)) // Bird flocks { if (b[y][x] == 0) { ++bbi; goBirds(y, x); } } if (p[y][x] == '^') // House view up / down { for (i = y - 1; i >= 0; --i) if (p[i][x] != ' ') break; worth += (y - i - 1) * 10; for (i = y + 1; i < n; ++i) if (p[i][x] != ' ') break; worth += (i - y - 1) * 5; } if (isValid(y + 2, x + 2)) // 3x3 blocks { blocks.emplace(p[y].substr(x, 3) + p[y + 1].substr(x, 3) + p[y + 2].substr(x, 3)); } if (isAnimal(y, x)) // Animals 1 { if (y + 1 < n && p[y + 1][x] == ' ') worth += 15; if (x + 1 < n && p[y][x + 1] == ' ') worth += 15; if (y - 1 >= 0 && p[y - 1][x] == ' ') worth += 15; if (x - 1 >= 0 && p[y][x - 1] == ' ') worth += 15; } if (y == 0 || x == 0 || y == n - 1 || x == n - 1) // Freedom { goFreedom(y, x); } if (p[y][x] == '!') // Chupacabra { if (isValid(y - 2, x + 1) && isBird(y - 2, x + 1)) worth += 200; if (isValid(y - 1, x + 2) && isBird(y - 1, x + 2)) worth += 200; if (isValid(y + 1, x + 2) && isBird(y + 1, x + 2)) worth += 200; if (isValid(y + 2, x + 1) && isBird(y + 2, x + 1)) worth += 200; if (isValid(y + 2, x - 1) && isBird(y + 2, x - 1)) worth += 200; if (isValid(y + 1, x - 2) && isBird(y + 1, x - 2)) worth += 200; if (isValid(y - 1, x - 2) && isBird(y - 1, x - 2)) worth += 200; if (isValid(y - 2, x - 1) && isBird(y - 2, x - 1)) worth += 200; } if (p[y][x] == '/' && x + 1 < n && p[y][x + 1] == '\\') // Peaks { peaks.emplace_back(make_pair(y, x)); } if (p[y][x] == 'D') // Drake/grill { if ( (y + 1 < n && p[y + 1][x] == 'G') || (x + 1 < n && p[y][x + 1] == 'G') || (y - 1 >= 0 && p[y - 1][x] == 'G') || (x - 1 >= 0 && p[y][x - 1] == 'G')) worth += 500; } if (p[y][x] == 'G') // Grill/drake { if ( (y + 1 < n && p[y + 1][x] == 'D') || (x + 1 < n && p[y][x + 1] == 'D') || (y - 1 >= 0 && p[y - 1][x] == 'D') || (x - 1 >= 0 && p[y][x - 1] == 'D')) worth += 50; } } for (y = 0; y < n; ++y) for (x = 0; x < n; ++x) { if (s[y][x]) // Suns worth worth += 100; if (f[y][x] && p[y][x] != ' ') // Freedom worth worth += 7; } if (peaks.size() > 1) // Peaks worth { for (i = 0; i < peaks.size(); ++i) { int md = 0; for (j = 0; j < peaks.size(); ++j) { md = max(md, abs(peaks[i].first - peaks[j].first) + abs(peaks[i].second - peaks[j].second)); } worth += 50 * md; } } int minc = n * n; int minCount = 0; for (auto fr : freq) // Minimum frequency { if (fr.first == ' ') continue; if (fr.second > minc) continue; if (fr.second == minc) minCount += fr.second; else { minCount = fr.second; minc = fr.second; } } worth += 10 * minCount; // Empty fields worth += freq[' ']; // Aniamls 2 worth += freq['!'] * freq['v'] * freq['D']; // Houses and grills worth += 3 * min(freq['^'], freq['G']); // Biggest bird worth & Flock perimeter map flockw; map flockp; for (y = 0; y < n; ++y) { for (x = 0; x < n; ++x) { if (b[y][x] != 0) { // Perimeter if (!isValid(y + 1, x) || b[y + 1][x] == 0) flockp[b[y][x]]++; if (!isValid(y, x + 1) || b[y][x + 1] == 0) flockp[b[y][x]]++; if (!isValid(y - 1, x) || b[y - 1][x] == 0) flockp[b[y][x]]++; if (!isValid(y, x - 1) || b[y][x - 1] == 0) flockp[b[y][x]]++; // Width for (i = 0; x + i < n; ++i) { if (b[y][x + i] == 0) break; } flockw[b[y][x]] = max(flockw[b[y][x]], i); } } } for (auto wi : flockw) worth += 500 * wi.second; for (auto per : flockp) worth += 60 * per.second; worth += blocks.size(); cout << worth << '\n'; return 0; }