#include <bits/stdc++.h>
using namespace std;
const int N = 40003, dir[2][2] = {{1, 0}, {0, 1}};
const int inf = 803;
int n, cnode, a[203][203], id[203][203];
long long ans, mincost, dis[N];
int S, T, vis[N], inq[N], head[N], cur[N], ce = 1;
struct edge {
  int to, nxt, cap, flow, w;
} e[2000003];
void lnk(int a, int b, int c, int w) {
  e[++ce] = (edge){b, head[a], c, 0, w}, head[a] = ce;
  e[++ce] = (edge){a, head[b], 0, 0, -w}, head[b] = ce;
}
void add(int a, int b, int c, int w) {
  e[++ce] = (edge){b, head[a], c, 0, w}, head[a] = ce;
  e[++ce] = (edge){a, head[b], c, 0, -w}, head[b] = ce;
}
queue<int> q;
bool bfs() {
  for (int i = 1; i <= T; ++i) dis[i] = 1e18, inq[i] = 0;
  q.push(T), dis[T] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (dis[v] > dis[u] + e[i ^ 1].w && e[i ^ 1].cap > e[i ^ 1].flow) {
        dis[v] = dis[u] + e[i ^ 1].w;
        if (!inq[v]) inq[v] = 1, q.push(v);
      }
    }
  }
  return dis[S] < 0;
}
int relabel() {
  long long delt = 1e18;
  for (int i = 1; i <= T; ++i)
    if (vis[i])
      for (int j = head[i]; j; j = e[j].nxt)
        if (e[j].cap > e[j].flow && !vis[e[j].to])
          delt = min(delt, dis[e[j].to] + e[j].w - dis[i]);
  if (dis[S] + delt >= 0) return 0;
  for (int i = 1; i <= T; ++i)
    if (vis[i]) dis[i] += delt;
  return 1;
}
int dfs(int u, int lim) {
  vis[u] = 1;
  if (u == T) return lim;
  int tag = 0;
  for (int &i = cur[u]; i; i = e[i].nxt)
    if (e[i].cap > e[i].flow && dis[e[i].to] + e[i].w == dis[u] &&
        !vis[e[i].to]) {
      int d = dfs(e[i].to, min(lim - tag, e[i].cap - e[i].flow));
      tag += d, e[i].flow += d, e[i ^ 1].flow -= d;
      if (tag == lim) return tag;
    }
  return tag;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      cin >> a[i][j];
      if (~a[i][j]) id[i][j] = ++cnode;
    }
  S = ++cnode, T = ++cnode;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (a[i][j] > 0)
        lnk(S, id[i][j], inf, -a[i][j]), lnk(id[i][j], T, inf, a[i][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (id[i][j])
        for (int t = 0; t < 2; ++t) {
          int x = i + dir[t][0], y = j + dir[t][1];
          if (id[x][y]) add(id[i][j], id[x][y], 1, 0);
        }
  int flow = 0;
  if (!bfs()) {
    puts("0");
    return 0;
  }
  do {
    do {
      memset(vis, 0, T + 1 << 2), memcpy(cur, head, T + 1 << 2);
      flow = dfs(S, inf), mincost -= dis[S] * flow;
    } while (flow);
  } while (relabel());
  cout << mincost << endl;
  return 0;
}
