#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n][n];
  int r, c, l;
  long long int sum = 0, rsum = 0, csum = 0, dsum = 0, rdsum = 0, sum2 = 0,
                sum3 = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        r = i;
        c = j;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    dsum += a[i][i];
    rdsum += a[i][n - 1 - i];
  }
  if (r != c)
    sum = dsum;
  else if (r != n - c - 1)
    sum = rdsum;
  else {
    if (r == 0)
      l = r + 1;
    else
      l = r - 1;
    for (int i = 0; i < n; i++) sum += a[l][i];
  }
  for (int i = 0; i < n; i++) {
    rsum = 0;
    csum = 0;
    for (int j = 0; j < n; j++) {
      rsum += a[i][j];
      csum += a[j][i];
    }
    if (i == r)
      sum2 = rsum;
    else if (rsum != sum) {
      cout << -1 << endl;
      return 0;
    }
    if (i == c)
      sum3 = csum;
    else if (csum != sum) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (sum2 == sum3 && (r != c || sum2 == dsum) &&
      (r != n - c - 1 || sum2 == rdsum) && sum > sum2) {
    cout << sum - sum2 << endl;
  } else {
    cout << -1 << endl;
  }
}
