#include <bits/stdc++.h>
long long int powermod(long long int _a, long long int _b) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
using namespace std;
void scan(long long int &x);
int main(void) {
  int n;
  cin >> n;
  long long int a[n][n];
  int ex, ey;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        ex = i;
        ey = j;
      }
    }
  }
  long long int esum = 0;
  if (ex == 0) {
    for (int j = 0; j < n; j++) esum += a[1][j];
  } else {
    for (int j = 0; j < n; j++) esum += a[0][j];
  }
  long long int psum = 0;
  for (int j = 0; j < n; j++) {
    psum += a[ex][j];
  }
  a[ex][ey] = esum - psum;
  if (a[ex][ey] <= 0) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    long long int tsum = 0;
    for (int j = 0; j < n; j++) {
      tsum += a[i][j];
    }
    if (tsum != esum) {
      cout << "-1";
      return 0;
    }
  }
  for (int j = 0; j < n; j++) {
    long long int tsum = 0;
    for (int i = 0; i < n; i++) {
      tsum += a[i][j];
    }
    if (tsum != esum) {
      cout << "-1";
      return 0;
    }
  }
  long long int tsum = 0;
  for (int i = 0; i < n; i++) {
    tsum += a[i][i];
  }
  if (tsum != esum) {
    cout << "-1";
    return 0;
  }
  tsum = 0;
  for (int i = 0, j = n - 1; i < n; i++, j--) {
    tsum += a[i][j];
  }
  if (tsum != esum) {
    cout << "-1";
    return 0;
  }
  cout << a[ex][ey];
  return 0;
}
void scan(long long int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
