#include <bits/stdc++.h>
using namespace std;
const int MaxN = int(2e4) + 256;
const int INF = int(1e9);
const int mod = (int)(1e9) + 7;
const double pi = 3.1415926535897932384626433832795;
long long n, m, t, ans, a[555][555], b[MaxN], sum[MaxN], second[MaxN], d, D;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int id, id1;
  bool ok = 0, ok1 = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      sum[i] = sum[i] + a[i][j];
      second[j] = second[j] += a[i][j];
      if (a[i][j] == 0) {
        id = i;
        id1 = j;
        if (i == j) ok = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    d += a[i][i];
    D += a[i][n - i + 1];
    if (a[i][n - i + 1] == 0) ok1 = 1;
  }
  if (n == 1) {
    cout << 1 << "\n";
    return 0;
  }
  long long x = 0;
  if (id != 1)
    x = sum[1] - sum[id];
  else
    x = sum[n] - sum[id];
  if (x <= 0) {
    cout << -1;
    return 0;
  }
  if (ok) d += x;
  if (ok1) D += x;
  sum[id] += x;
  second[id1] += x;
  cerr << d << " " << D << "\n";
  sort(second + 1, second + 1 + n);
  sort(sum + 1, sum + 1 + n);
  if (d != D || d != sum[1] || sum[1] != D || sum[1] != sum[n] ||
      second[1] != second[n] || second[1] != sum[1])
    cout << -1;
  else
    cout << x;
  return 0;
}
