#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <fstream>
#include <queue>
#include <iterator>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
using namespace std;
//Utilities
#define sqr(x) ((x)*(x))
#define cbr(x) ((x)*(x)*(x))
#define rep(c, i, n) for((i)=(c); (i)<(n); (i)++)
//Geometry
/**
struct pt { long long x, y; };
double vecmul(pt a, pt b) { //Векторное умножение А*В
return (a.x*b.y - b.x*a.y);
}
//скалярное умножение a*b = |a|*|b|*cos(a,b)
double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); }
*/
//DBG
//template<typename T, typename T2>void printarr(T a[], T2 sz, T2 beg = 0) { for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
#define DBG(a) cout<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBG3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
//Files
#define FILE_MODE(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
//Constants
#define PI 3.1415926535897932
#define INF 1011111111
#define LLINF 1000111000111000111LL
#define eps 1e-14
#define mod 1000000007
#define ll long long
#define ull unsigned long long
//-------------------------------------------------
#define N 40
int n;
char lab[N][N];
int paint=0;
void dfs(int x, int y);
int main() {
cin >> n;
int i, j;
rep(0, i, n+2) {
lab[0][i] = '#';
lab[n + 1][i] = '#';
lab[i][0] = '#';
lab[i][n + 1] = '#';
}
rep(0, i, n) {
rep(0, j, n) {
cin >> lab[i+1][j+1];
}
}
rep(0, i, n+2) {
rep(0, j, n+2) {
cout << lab[i][j];
}
cout << endl;
}
dfs(1, 1);
dfs(n - 1, n - 1);
cout << paint*9-36;
return 0;
}
void dfs(int y, int x)
{
lab[y][x] = '$';
if (lab[y][x + 1] == '#') { paint++; };
DBG3(y, x, paint);
if (lab[y][x - 1] == '#') { paint++; };
DBG3(y, x, paint);
if (lab[y + 1][x] == '#') { paint++; };
DBG3(y, x, paint);
if (lab[y - 1][x] == '#') { paint++; };
DBG3(y, x, paint);
cout << endl;
if (lab[y][x + 1] == '.') { dfs(y, x + 1); };
if (lab[y][x - 1] == '.') { dfs(y, x - 1); };
if (lab[y + 1][x] == '.') { dfs(y + 1, x); };
if (lab[y - 1][x] == '.') { dfs(y - 1, x); };
}
Comments