#include <bits/stdc++.h>
using namespace std;
long long a[555][555];
int n;
long long srow(int i) {
  long long res = 0;
  for (int j = 0; j < n; j++) {
    res += a[i][j];
  }
  return res;
}
long long scol(int j) {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    res += a[i][j];
  }
  return res;
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    cout << 31;
    return 0;
  }
  int i0 = -1, j0 = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      scanf("%d", &x);
      a[i][j] = x;
      if (a[i][j] == 0) {
        i0 = i;
        j0 = j;
      }
    }
  }
  long long s = -1;
  for (int i = 0; s == -1; i++) {
    if (i == i0) {
      continue;
    }
    s = srow(i);
  }
  long long s0 = srow(i0);
  if (s0 >= s) {
    cout << -1;
    return 0;
  }
  a[i0][j0] = s - s0;
  bool ok = true;
  long long sd1 = 0, sd2 = 0;
  for (int i = 0; i < n; i++) {
    if (srow(i) != s || scol(i) != s) {
      ok = false;
    }
    sd1 += a[i][i];
    sd2 += a[n - 1 - i][i];
  }
  if (sd1 != s || sd2 != s) {
    ok = false;
  }
  if (!ok) {
    cout << -1;
  } else {
    cout << a[i0][j0];
  }
  return 0;
}
