# 人工智能

## 样例输入

5
0 0 0 0 0
0 1 0 1 0
0 0 2 0 0
0 1 0 1 0
0 0 0 0 0


4


20%的数据，保证棋盘上只有车
50%的数据，n<=50
80%的数据，n<=200
100%的数据，n<=1000，车的数量<=n*n，后的数量<=n

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int n, a[1005][1005], vis[1005][1005], ans;

struct node
{
int x, y;
};

vector<node> vechou, vecche;

void solvehou(int x, int y){
int t1 = x - y, t2 = x + y;
for (int i = x + 1; i <= n; i++){ //主对角线往下
if(i - t1 < 1 || i - t1 > n || vis[i][i - t1] == 2) break;
if(!vis[i][i - t1]) ans++;
vis[i][i - t1] = 1;
}
for (int i = x - 1; i >= 1; i--){//主对角线往上
if(i - t1 < 1 || i - t1 > n || vis[i][i - t1] == 2) break;
if(!vis[i][i - t1]) ans++;
vis[i][i - t1] = 1;
}
for (int i = x + 1; i <= n; i++){//次对角线往下
if(t2 - i < 1 || t2 - i > n || vis[i][t2 - i] == 2) break;
if(!vis[i][t2 - i]) ans++;
vis[i][t2 - i] = 1;
}
for (int i = x - 1; i >= 1; i--){//次对角线往上
if(t2 - i < 1 || t2 - i > n || vis[i][t2 - i] == 2) break;
if(!vis[i][t2 - i]) ans++;
vis[i][t2 - i] = 1;
}
}

void solveche(int x, int y){
for (int i = y + 1; i <= n; i++){
if(vis[x][i] == 2) break;
else if(!vis[x][i]) vis[x][i] = 1, ans++;
}
for (int i = y - 1; i >= 1; i--){
if(vis[x][i] == 2) break;
else if(!vis[x][i]) vis[x][i] = 1, ans++;
}
for (int i = x + 1; i <= n; i++){
if(vis[i][y] == 2) break;
else if(!vis[i][y]) vis[i][y] = 1, ans++;
}
for (int i = x - 1; i >= 1; i--){
if(vis[i][y] == 2) break;
else if(!vis[i][y]) vis[i][y] = 1, ans++;
}
}

int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);

scanf("%d", &n);

for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
scanf("%d", &a[i][j]);
if(a[i][j] == 2) vechou.push_back(node{i, j}), vis[i][j] = 2;
else if(a[i][j] == 1) vecche.push_back(node{i, j}), vis[i][j] = 2;
}
}
int hou = vechou.size(), che = vecche.size();
for (int i = 0; i < hou; i++){
int x = vechou[i].x, y = vechou[i].y;
solvehou(x, y);
solveche(x, y);

}
for (int i = 0; i < che; i++){
int x = vecche[i].x, y = vecche[i].y;
solveche(x, y);
}
printf("%d\n", n *n - ans - hou - che);

return 0;
}
/**/