#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  if (n == 1) {
    cout << "1";
    return 0;
  }
  long long a[n + 1][n + 1], indx, indy, tmp, sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    a[i][n] = 0;
    a[n][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      a[i][n] += a[i][j];
      a[n][j] += a[i][j];
      if (a[i][j] == 0) {
        indx = i;
        indy = j;
      }
    }
  }
  if (indx == 0) {
    tmp = a[1][n] - a[0][n];
  } else {
    tmp = a[0][n] - a[indx][n];
  }
  a[indx][indy] = tmp;
  a[indx][n] += tmp;
  a[n][indy] += tmp;
  for (int i = 0; i < n; i++) {
    sum1 += a[i][i];
    sum2 += a[i][n - i - 1];
    if (a[i][n] != a[0][n] || a[n][i] != a[0][n]) {
      cout << "-1";
      return 0;
    }
  }
  if (sum1 != a[0][n] || sum2 != a[0][n] || tmp <= 0) {
    cout << "-1";
  } else {
    cout << tmp;
  }
}
