You have to paint with shades of grey the tiles of an n× n wall. The wall has n rows of tiles, each with n tiles.

The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of the tiles are broken, you shall not paint those tiles. It is guaranteed that the tiles on the boundary are not broken.

You shall paint all the non-broken tiles that are not already painted. When you paint a tile you can choose from 10^9 shades of grey, indexed from 1 to 10^9. You can paint multiple tiles with the same shade. Formally, painting the wall is equivalent to assigning a shade (an integer between 1 and 10^9) to each non-broken tile that is not already painted.

The contrast between two tiles is the absolute value of the difference between the shades of the two tiles. The total contrast of the wall is the sum of the contrast of all the pairs of adjacent non-broken tiles (two tiles are adjacent if they share a side).

Compute the minimum possible total contrast of the wall.

Input

The first line contains n (3≤ n≤ 200) – the number of rows and columns.

Then n lines, each containing n integers, follow. The i-th of these lines describe the i-th row of tiles. It contains the n integers a_{ij} (-1≤ a_{ij} ≤ 10^9). The value of a_{ij} described the tile on the i-th row and j-th column: 

  * If a_{ij}=0, then the tile is not painted and shall be painted. 
  * If a_{ij}=-1, then the tile is broken and shall not be painted. 
  * If 1≤ a_{ij}≤ 10^9, then the tile is already painted with the shade a_{ij}. 

It is guaranteed that the tiles on the boundary are already painted, the tiles not on the boundary are not already painted, and the tiles on the boundary are not broken.

Output

Print a single integer – the minimum possible total contrast of the wall.

Examples

Input


3
1 7 6
4 0 6
1 1 1


Output


26


Input


3
10 100 1
1 -1 100
10 10 10


Output


396


Input


5
6 6 5 4 4
6 0 0 0 4
7 0 0 0 3
8 0 0 0 2
8 8 1 2 2


Output


34


Input


7
315055237 841510063 581663979 148389224 405375301 243686840 882512379
683199716 -1 -1 0 0 0 346177625
496442279 0 0 0 0 0 815993623
223938231 0 0 -1 0 0 16170511
44132173 0 -1 0 0 0 130735659
212201259 0 0 -1 0 0 166102576
123213235 506794677 467013743 410119347 791447348 80193382 142887538


Output


10129482893

Note

Explanation of the first testcase: The initial configuration of the tiles is (tiles to paint are denoted by ?): 
    
    
      
    1 7 6  
    4 ? 6  
    1 1 1  
    

A possible way to paint the tile achieving the minimum possible contrast of 26 is: 
    
    
      
    1 7 6  
    4 5 6  
    1 1 1  
    

Explanation of the second testcase: Since all tiles are either painted or broken, there is nothing to do. The total contrast is 396.

Explanation of the third testcase: The initial configuration of the tiles is (tiles to paint are denoted by ?): 
    
    
      
    6 6 5 4 4  
    6 ? ? ? 4  
    7 ? ? ? 3  
    8 ? ? ? 2  
    8 8 1 2 2  
    

A possible way to paint the tiles achieving the minimum possible contrast of 34 is: 
    
    
      
    6 6 5 4 4  
    6 6 5 4 4  
    7 7 5 3 3  
    8 8 2 2 2  
    8 8 1 2 2  
    
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MAX_N = 1e5 + 5;
struct Graph {
  int to, cap, cost, next;
} e[MAX_N * 50];
int fir[MAX_N], e_cnt;
void clearGraph() {
  memset(fir, -1, sizeof(fir));
  e_cnt = 0;
}
void Add_Edge(int u, int v, int c, int w) {
  e[e_cnt] = (Graph){v, c, w, fir[u]}, fir[u] = e_cnt++;
  e[e_cnt] = (Graph){u, 0, -w, fir[v]}, fir[v] = e_cnt++;
}
void AddEdge(int u, int v, int c, int w) {
  e[e_cnt] = (Graph){v, c, w, fir[u]}, fir[u] = e_cnt++;
  e[e_cnt] = (Graph){u, c, -w, fir[v]}, fir[v] = e_cnt++;
}
const LL INF = 1e18;
int S, T;
LL dis[MAX_N];
bool inq[MAX_N];
bool spfa() {
  queue<int> que;
  for (int i = 0; i <= T; i++) dis[i] = INF;
  dis[T] = 0, inq[T] = 1, que.push(T);
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (int i = fir[x]; ~i; i = e[i].next) {
      int v = e[i].to, w = e[i ^ 1].cost;
      if (e[i ^ 1].cap && dis[v] > dis[x] + w) {
        dis[v] = dis[x] + w;
        if (!inq[v]) que.push(v), inq[v] = 1;
      }
    }
    inq[x] = 0;
  }
  return dis[S] != INF;
}
int tim, vis[MAX_N];
bool relabel() {
  LL res = INF;
  for (int x = 0; x <= T; x++) {
    if (vis[x] != tim) continue;
    for (int i = fir[x]; ~i; i = e[i].next) {
      int v = e[i].to;
      if (e[i].cap && vis[v] != tim)
        res = min(res, dis[v] + e[i].cost - dis[x]);
    }
  }
  if (res == INF) return 0;
  for (int i = 0; i <= T; i++)
    if (vis[i] == tim) dis[i] += res;
  return 1;
}
int dfs(int x, int f) {
  if (x == T || !f) return f;
  vis[x] = tim;
  int res = 0;
  for (int i = fir[x]; ~i; i = e[i].next) {
    int v = e[i].to, w = e[i].cost;
    if (e[i].cap && dis[x] == dis[v] + w && vis[v] != tim) {
      int d = dfs(v, min(f, e[i].cap));
      res += d, f -= d;
      e[i].cap -= d, e[i ^ 1].cap += d;
      if (!f) break;
    }
  }
  return res;
}
LL zkw() {
  spfa();
  LL res = 0, f = 0;
  do do {
      ++tim, f = dfs(S, 1e9);
      if (dis[S] >= 0) return res;
      res += dis[S] * f;
    } while (f);
  while (relabel());
  return res;
}
int N, a[205][205], Id[205][205], cnt;
int main() {
  clearGraph();
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) scanf("%d", a[i] + j), Id[i][j] = ++cnt;
  S = 0, T = cnt + 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      if (i != N && a[i][j] != -1 && a[i + 1][j] != -1)
        AddEdge(Id[i][j], Id[i + 1][j], 1, 0);
      if (j != N && a[i][j] != -1 && a[i][j + 1] != -1)
        AddEdge(Id[i][j], Id[i][j + 1], 1, 0);
      if (a[i][j] > 0)
        Add_Edge(S, Id[i][j], 1e9, -a[i][j]),
            Add_Edge(Id[i][j], T, 1e9, a[i][j]);
    }
  printf("%lld\n", -zkw());
  return 0;
}
