#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
long long g[N][N];
int n;
inline set<long long> go() {
  vector<long long> r(n + 1), c(n + 1);
  long long x = 0, y = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      r[i] += g[i][j];
      c[j] += g[i][j];
      if (i == j) x += g[i][j];
      if (i + j == n + 1) y += g[i][j];
    }
  }
  set<long long> s;
  s.insert(x);
  s.insert(y);
  for (int i = 1; i <= n; i++) {
    s.insert(r[i]);
    s.insert(c[i]);
  }
  return s;
}
int main() {
  cin >> n;
  int zi = 0, zj = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%lld", &g[i][j]);
      if (g[i][j] == 0) zi = i, zj = j;
    }
  }
  set<long long> s = go();
  g[zi][zj] = *(++s.begin()) - *s.begin();
  s = go();
  if (n == 1)
    cout << 1;
  else if (s.size() == 1)
    cout << g[zi][zj];
  else
    cout << -1;
}
