#include <bits/stdc++.h>
using namespace std;
long long int ma = -1, mi = 1000000000000000;
inline long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
inline long long int lcm(long long int a, long long int b, long long int MOD) {
  return a / gcd(a, b) * b % MOD;
}
int main() {
  long long int i, j, n, ans = 0, a[509][509] = {0}, b, d = 0, sum = 0, x, y,
                         h[509] = {0}, v[509] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        x = i;
        y = j;
      }
      v[j] += a[i][j];
      h[i] += a[i][j];
    }
  }
  if (x != n - 1) {
    d = h[x + 1] - h[x];
  } else {
    d = h[x - 1] - h[x];
  }
  if (h[x] != v[y] || d <= 0) {
    cout << -1 << endl;
    return 0;
  }
  a[x][y] = d;
  h[x] += d;
  v[y] += d;
  for (i = 0; i < n - 1; i++) {
    if (h[i] != h[i + 1]) break;
  }
  if (i != n - 1) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 0; i < n - 1; i++) {
    if (v[i] != v[i + 1]) break;
  }
  if (i != n - 1) {
    cout << -1 << endl;
    return 0;
  }
  sum = 0;
  b = 0;
  for (i = 0; i < n; i++) {
    sum += a[i][i];
    b += a[i][n - 1 - i];
  }
  if (sum != b || sum != h[0] || b != h[0]) {
    cout << -1 << endl;
    return 0;
  }
  cout << d << endl;
  return 0;
}
