#include <bits/stdc++.h>
using namespace std;
struct IO {
  IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
} _;
long long n, m, len, k, t, a, b;
long long arr[501][501];
int main() {
  cin >> n;
  long long y, x;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 0) {
        y = i;
        x = j;
      }
    }
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    if (i == y) continue;
    long long sum = 0;
    for (long long j = 0; j < n; j++) {
      sum += arr[i][j];
    }
    s.insert(sum);
  }
  for (long long j = 0; j < n; j++) {
    if (j == x) continue;
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      sum += arr[i][j];
    }
    s.insert(sum);
  }
  long long sum = 0;
  if (y != x) {
    sum = 0;
    for (long long i = 0; i < n; i++) {
      sum += arr[i][i];
    }
    s.insert(sum);
  }
  if (x + y != n - 1) {
    sum = 0;
    for (long long i = 0; i < n; i++) {
      sum += arr[i][n - 1 - i];
    }
    s.insert(sum);
  }
  if (((long long)s.size()) > 1)
    return cout << "-1"
                << "\n",
           0;
  else if (((long long)s.size()) == 0)
    return cout << 1 << "\n", 0;
  set<long long> s2;
  sum = 0;
  for (long long i = 0; i < n; i++) sum += arr[i][x];
  s2.insert(sum);
  sum = 0;
  for (long long j = 0; j < n; j++) sum += arr[y][j];
  s2.insert(sum);
  sum = 0;
  if (y == x) {
    for (long long i = 0; i < n; i++) sum += arr[i][i];
    s2.insert(sum);
  }
  sum = 0;
  if (x + y == n - 1) {
    for (long long i = 0; i < n; i++) sum += arr[i][n - 1 - i];
    s2.insert(sum);
  }
  long long ans = *s.begin() - *s2.begin();
  if (((long long)s2.size()) == 1) {
    if (ans > 0)
      cout << ans << "\n";
    else
      cout << -1 << "\n";
  } else
    cout << -1 << "\n";
}
