#include <bits/stdc++.h>
using namespace std;
long long a[505][505];
long long sumx[505];
long long sumy[505];
int main() {
  int n;
  cin >> n;
  int x, y;
  memset(sumx, 0, sizeof(sumx));
  memset(sumy, 0, sizeof(sumy));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      sumx[i] += a[i][j];
      sumy[j] += a[i][j];
      if (a[i][j] == 0) {
        x = i;
        y = j;
      }
    }
  }
  if (n == 1) {
    cout << "1" << endl;
    return 0;
  }
  long long res;
  if (x != 1) {
    res = sumx[1] - sumx[x];
  } else {
    res = sumx[2] - sumx[x];
  }
  sumx[x] += res;
  sumy[y] += res;
  a[x][y] = res;
  long long sums = 0, sumt = 0;
  for (int i = 1; i <= n; i++) {
    sums += a[i][i];
    sumt += a[i][n - i + 1];
  }
  sort(sumx + 1, sumx + n + 1);
  sort(sumy + 1, sumy + n + 1);
  if (sumx[1] == sumx[n] && sumy[1] == sumy[n] && sumx[1] == sumy[n] &&
      sums == sumt && sums == sumx[1] && res > 0) {
    cout << res << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
