#include <bits/stdc++.h>
using namespace std;
long long mat[501][501];
bool flag = false;
int x, y;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<long long> r(n, 0);
  vector<long long> c(n, 0);
  vector<long long> d(2, 0);
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = 0; j < (long long)n; j++) {
      cin >> mat[i][j];
      r[i] += mat[i][j];
      c[j] += mat[i][j];
      if (i == j) d[0] += mat[i][j];
      if (n - j - 1 == i) d[1] += mat[i][j];
      if (mat[i][j] == 0) {
        x = i;
        y = j;
      }
    }
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)n; i++) {
    if (i != x) {
      ans = r[i];
      break;
    }
  }
  for (long long i = 0; i < (long long)n; i++) {
    if (i != x) {
      if (ans != r[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 0; i < (long long)n; i++) {
    if (i != y) {
      if (ans != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (x != y)
    if (ans != d[0]) {
      cout << -1 << endl;
      return 0;
    }
  if (n - 1 - y != x) {
    if (ans != d[1]) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long change = 0;
  change = ans - r[x];
  if (change != (ans - c[y])) {
    cout << -1 << endl;
    return 0;
  }
  if (x == y)
    if (change != (ans - d[0])) {
      cout << -1 << endl;
      return 0;
    }
  if (n - 1 - y == x)
    if (change != (ans - d[1])) {
      cout << -1 << endl;
      return 0;
    }
  if (change > 0)
    cout << change << endl;
  else
    cout << -1 << endl;
  return 0;
}
