#include <iostream>
#define MAX_WIDTH 499
using namespace std;
int map[MAX_WIDTH][MAX_WIDTH];
bool visit[MAX_WIDTH][MAX_WIDTH];
int width, amountOfSand = 0;
int ten, seven, five, two, one, rest;
int getLostAmountSand();
void setNum(int row, int col) {
ten = (float)map[row][col] * 0.1;
seven = (float)map[row][col] * 0.07;
five = (float)map[row][col] * 0.05;
two = (float)map[row][col] * 0.02;
one = (float)map[row][col] * 0.01;
rest = map[row][col] - (2 * ten + 2 * seven + five + 2 * two + 2 * one);
}
void spreadLeftSand(int row, int col);
void spreadRightSand(int row, int col);
void spreadUpSand(int row, int col);
void spreadDownSand(int row, int col);
int main() {
cin >> width;
for (int i = 0; i < width; i++) {
for (int j = 0; j < width; j++) {
cin >> map[i][j];
if (map[i][j] != 0)
amountOfSand += map[i][j];
}
}
cout << getLostAmountSand();
}
int getLostAmountSand() {
visit[width / 2][width / 2] = true;
bool left = true, down = false, right = false, up = false;
int row = width / 2, col = width / 2;
for (int i = 1; i < width * width; i++) {
cout << row << " " << col << endl;
if (left) {
col--;
spreadLeftSand(row, col);
}
else if (down) {
row++;
spreadDownSand(row, col);
}
else if (right) {
col++;
spreadRightSand(row, col);
}
else if (up) {
row--;
spreadUpSand(row, col);
}
visit[row][col] = true;
if (left && !visit[row + 1][col]) {
left = false;
down = true;
}
else if (down && !visit[row][col + 1]) {
down = false;
right = true;
}
else if (right && !visit[row - 1][col]) {
right = false;
up = true;
}
else if (up && !visit[row][col - 1]) {
up = false;
left = true;
}
for (int j = 0; j < width; j++) {
for (int k = 0; k < width; k++) {
cout << map[j][k] << " ";
}
cout << endl;
}
cout << endl;
}
int sand = 0;
for (int i = 0; i < width; i++)
for (int j = 0; j < width; j++)
sand += map[i][j];
return amountOfSand - sand;
}
void spreadLeftSand(int row, int col) {
setNum(row, col);
if (row > 1)
map[row - 2][col] += two;
if (row > 0) {
map[row - 1][col] += seven;
map[row - 1][col + 1] += one;
}
if (row > 0 && col > 0)
map[row - 1][col - 1] += ten;
if (col > 1)
map[row][col - 2] += five;
if (row < width - 1 && col > 0)
map[row + 1][col - 1] += ten;
if (row < width - 1) {
map[row + 1][col] += seven;
map[row + 1][col + 1] += one;
}
if (row < width - 2)
map[row + 2][col] += two;
if (col > 0)
map[row][col - 1] += rest;
map[row][col] = 0;
}
void spreadRightSand(int row, int col) {
setNum(row, col);
if (row > 1)
map[row - 2][col] += two;
if (row > 0) {
map[row - 1][col] += seven;
map[row - 1][col - 1] += one;
}
if (row > 0 && col < width -1)
map[row - 1][col + 1] += ten;
if (col < width - 2)
map[row][col + 2] += five;
if (row < width - 1 && col < width-1)
map[row + 1][col + 1] += ten;
if (row < width - 1) {
map[row + 1][col] += seven;
map[row + 1][col - 1] += one;
}
if (row < width - 2)
map[row + 2][col] += two;
if (col < width - 1)
map[row][col + 1] += rest;
map[row][col] = 0;
}
void spreadUpSand(int row, int col) {
setNum(row, col);
if (col > 1)
map[row][col - 2] += two;
if (col > 0) {
map[row][col - 1] += seven;
map[row + 1][col - 1] += one;
}
if (row > 0 && col > 0)
map[row - 1][col - 1] += ten;
if (row > 1)
map[row - 2][col] += five;
if (row > 0 && col < width-1)
map[row - 1][col + 1] += ten;
if (col < width - 1) {
map[row][col + 1] += seven;
map[row + 1][col + 1] += one;
}
if (col < width - 2)
map[row][col + 2] += two;
if (row > 0)
map[row - 1][col] += rest;
map[row][col] = 0;
}
void spreadDownSand(int row, int col) {
setNum(row, col);
if (col > 1)
map[row][col - 2] += two;
if (col > 0) {
map[row][col - 1] += seven;
map[row - 1][col - 1] += one;
}
if (row < width - 1 && col < width - 1)
map[row + 1][col + 1] += ten;
if (row < width - 2)
map[row + 2][col] += five;
if (row < width - 1 && col > 0)
map[row + 1][col - 1] += ten;
if (col < width - 1) {
map[row][col + 1] += seven;
map[row - 1][col + 1] += one;
}
if (col < width - 2)
map[row][col + 2] += two;
if (row < width - 1)
map[row + 1][col] += rest;
map[row][col] = 0;
}