#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, x, y, sum = 0;
  cin >> n;
  long long int a[n + 1][n + 1];
  for (long long int i = 1; i <= n; i++)
    for (long long int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        y = j;
        x = i;
      }
    }
  set<long long int> s;
  if (n == 1) {
    cout << "1";
    exit(0);
  }
  if (x != y) {
    for (long long int i = 1; i <= n; i++) sum += a[i][i];
    s.insert(sum);
  }
  if (x != n - y + 1) {
    sum = 0;
    for (long long int i = 1; i <= n; i++) sum += a[i][n - i + 1];
    s.insert(sum);
  }
  for (long long int i = 1; i <= n; i++) {
    if (i == x) continue;
    sum = 0;
    for (long long int j = 1; j <= n; j++) sum += a[i][j];
    s.insert(sum);
  }
  for (long long int j = 1; j <= n; j++) {
    if (j == y) continue;
    sum = 0;
    for (long long int i = 1; i <= n; i++) sum += a[i][j];
    s.insert(sum);
  }
  long long int val = *(s.begin());
  sum = 0;
  for (long long int i = 1; i <= n; i++) sum += a[i][y];
  long long int t = val - sum;
  if ((long long int)s.size() > 1 || t <= 0) {
    cout << "-1";
    exit(0);
  }
  a[x][y] = t;
  sum = 0;
  long long int sum1 = 0, sum2 = 0;
  for (long long int i = 1; i <= n; i++) sum += a[x][i];
  for (long long int i = 1; i <= n; i++) sum1 += a[i][i];
  for (long long int i = 1; i <= n; i++) sum2 += a[i][n - i + 1];
  if (sum != val || sum1 != val || sum2 != val) {
    cout << "-1";
    exit(0);
  }
  cout << t;
}
