#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef double lf; typedef long double Lf; typedef pair pii; typedef pair pll; #define TRACE(x) cerr << #x << " " << x << endl #define FOR(i, a, b) for (int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) #define all(x) (x).begin(), (x).end() #define _ << " " << #define fi first #define sec second #define mp make_pair #define pb push_back const int MAXN = 55; char s[MAXN][MAXN]; int n; const int smjerx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int smjery[] = {-1, 0, 1, -1, 1, -1, 0, 1}; bool valid(int x, int y) { if (x < 0 || y < 0 || x >= n || y >= n) return 0; return 1; } ll suns() { vector> bio; bio.resize(n); for (auto &x : bio) x.resize(n); REP(i, n) { REP(j, n) { if (s[i][j] != '*') continue; REP(k, 8) { int x = i + smjerx[k]; int y = j + smjery[k]; while (valid(x, y)) { if (s[x][y] != ' ') { if (s[x][y] != '*') bio[x][y] = 1; break; } x += smjerx[k]; y += smjery[k]; } } } } ll ret = 0; REP(i, n) REP(j, n) ret += bio[i][j] * 100; return ret; } vector> floke; const int Smjerx[] = {0, 0, 1, -1}; const int Smjery[] = {-1, 1, 0, 0}; void dfs(int x, int y, int mark) { floke[x][y] = mark; REP(i, 4) { int nx = x + Smjerx[i]; int ny = y + Smjery[i]; if (!valid(nx, ny)) continue; if (floke[nx][ny]) continue; if (s[nx][ny] != 'v' && s[nx][ny] != 'D') continue; dfs(nx, ny, mark); } } long long big_bird() { floke.resize(n); for (auto &x : floke) x.resize(n); int CNT = 1; REP(i, n) { REP(j, n) { if ((s[i][j] == 'D' || s[i][j] == 'v') && floke[i][j] == 0) { dfs(i, j, CNT++); } } } vector wid; wid.resize(CNT + 100); REP(i, n) { REP(j, n) { if (!floke[i][j]) continue; int k = j; for (; k < n && floke[i][k] == floke[i][j]; k++) ; wid[floke[i][j]] = max(wid[floke[i][j]], k - j); j = k - 1; } } ll ret = 0; for (auto x : wid) ret += 500 * x; return ret; } ll floke_perim() { ll ret = 0; REP(i, n) { REP(j, n) { if (!floke[i][j]) continue; REP(k, 4) { int nx = i + Smjerx[k]; int ny = j + Smjery[k]; if (!valid(nx, ny) || !floke[nx][ny]) ret++; } } } return ret * 60; } ll house_view_up() { ll ret = 0; REP(i, n) { REP(j, n) { if (s[i][j] != '^') continue; for (int x = i - 1; x >= 0; x--) { int y = j; if (s[x][y] == ' ') ret++; else break; } } } return ret * 10; } ll triXtri() { set S; REP(i, n - 2) { REP(j, n - 2) { string tmp = ""; FOR(x, i, i + 3) { FOR(y, j, j + 3) { tmp += s[x][y]; } } S.insert(tmp); } } return S.size() * 1; } ll animalsJedan() { ll ret = 0; REP(i, n) { REP(j, n) { REP(k, 4) { int x = Smjerx[k] + i; int y = j + Smjery[k]; if (s[i][j] == ' ' && valid(x, y) && (s[x][y] == 'D' || s[x][y] == 'v' || s[x][y] == '!')) { ret++; } } } } return ret * 15; } void start(int x, int y, vector> &bio) { bio[x][y] = 1; if (s[x][y] != ' ') return; REP(i, 4) { int nx = Smjerx[i] + x; int ny = Smjery[i] + y; if (!valid(nx, ny)) continue; if (bio[nx][ny]) continue; start(nx, ny, bio); } } ll freedom() { vector> bio; bio.resize(n); for (auto &x : bio) x.resize(n); REP(i, n) { start(i, 0, bio); start(0, i, bio); start(n - 1, i, bio); start(i, n - 1, bio); } ll ret = 0; REP(i, n) REP(j, n) if (s[i][j] != ' ') ret += bio[i][j]; return ret * 7; } int chupax[] = {-1, -2, -2, -1, 1, 2, 2, 1}; int chupay[] = {-2, -1, 1, 2, -2, -1, 1, 2}; void oznaci(int x, int y, vector> &bio, int d) { if (s[x][y] == 'D' || s[x][y] == 'v') bio[x][y] = 1; if (d) return; REP(i, 8) { int nx = x + chupax[i]; int ny = y + chupay[i]; if (!valid(nx, ny)) continue; oznaci(nx, ny, bio, d + 1); } } ll chupa() { vector> bio; bio.resize(n); for (auto &x : bio) x.resize(n); REP(i, n) REP(j, n) { if (s[i][j] == '!') { oznaci(i, j, bio, 0); } } ll ret = 0; REP(i, n) REP(j, n) ret += bio[i][j]; return ret * 200; } ll peaks() { vector> peak; peak.resize(n); for (auto &x : peak) x.resize(n); REP(i, n) { REP(j, n - 1) { if (s[i][j] == '/' && s[i][j + 1] == '\\') { peak[i][j] = 1; } } } ll ret = 0; REP(i, n) { REP(j, n) { if (!peak[i][j]) continue; ll maks = 0; REP(a, n) { REP(b, n) { if (peak[a][b]) { maks = max(maks, (ll)abs(a - i) + abs(j - b)); } } } ret += maks; } } return ret * 50; } ll drake_grill() { ll ret = 0; REP(i, n) REP(j, n) { if (s[i][j] != 'D') continue; bool ima = 0; REP(k, 4) { int x = i + Smjerx[k]; int y = j + Smjery[k]; if (!valid(x, y)) continue; if (s[x][y] == 'G') ima = 1; } ret += ima; } return ret * 500; } ll min_freq() { map m; REP(i, n) { REP(j, n) { m[s[i][j]]++; } } int mini = INT_MAX; for (auto t : m) mini = min(mini, t.second); ll ret = 0; for (auto t : m) { if (t.first != ' ' && t.second == mini) { ret += t.second; } } return ret * 10; } ll empty() { ll ret = 0; REP(i, n) REP(j, n) if (s[i][j] == ' ') ret++; return ret * 1; } ll animalsDva() { ll ret = 0; map m; REP(i, n) REP(j, n) { if (s[i][j] == '!' || s[i][j] == 'v' || s[i][j] == 'D') m[s[i][j]]++; } ret = (ll)m['D'] * m['v'] * m['!']; return ret; } ll grill_drake() { ll ret = 0; REP(i, n) REP(j, n) { if (s[i][j] != 'G') continue; bool ima = 0; REP(k, 4) { int x = i + Smjerx[k]; int y = j + Smjery[k]; if (!valid(x, y)) continue; if (s[x][y] == 'D') ima = 1; } ret += ima; } return ret * 50; } ll houses_grills() { ll ret = 0; map m; REP(i, n) REP(j, n) m[s[i][j]]++; ret = min(m['G'], m['^']); return ret * 3; } ll house_view_down() { ll ret = 0; REP(i, n) { REP(j, n) { if (s[i][j] != '^') continue; for (int x = i - 0; x >= 0; x--) { int y = j; if (s[x][y] == ' ') ret++; else break; } } } return ret * 5; } int main() { cin >> n; char c; REP(i, n) { scanf("%c", &c); REP(j, n) scanf("%c", &s[i][j]); } long long sol = 0; sol += suns(); sol += big_bird(); sol += floke_perim(); // OK sol += house_view_up(); sol += house_view_down(); sol += triXtri(); // OK sol += animalsJedan(); sol += freedom(); // OK sol += chupa(); // OK sol += peaks(); sol += drake_grill(); // OK sol += empty(); // OK sol += grill_drake(); // OK sol += animalsDva(); // OK sol += houses_grills(); // OK sol += min_freq(); cout << sol << endl; return 0; }