#include <bits/stdc++.h>
using namespace std;
void solve() {
  set<long long int> withzero, nonzero;
  int N;
  cin >> N;
  long long int x[N][N];
  for (__typeof((N)) i = (0); i < (N); i += 1) {
    for (__typeof((N)) j = (0); j < (N); j += 1) cin >> x[i][j];
  }
  if (N == 1) {
    cout << 2;
    return;
  }
  for (__typeof((N)) i = (0); i < (N); i += 1) {
    long long int suma = 0;
    bool zero = false;
    for (__typeof((N)) j = (0); j < (N); j += 1) {
      suma += x[i][j];
      if (x[i][j] == 0) zero = true;
    }
    if (zero)
      withzero.insert(suma);
    else
      nonzero.insert(suma);
  }
  for (__typeof((N)) i = (0); i < (N); i += 1) {
    long long int suma = 0;
    bool zero = false;
    for (__typeof((N)) j = (0); j < (N); j += 1) {
      suma += x[j][i];
      if (x[j][i] == 0) zero = true;
    }
    if (zero)
      withzero.insert(suma);
    else
      nonzero.insert(suma);
  }
  long long int suma1 = 0, suma2 = 0;
  bool zero1 = 0, zero2 = 0;
  for (__typeof((N)) i = (0); i < (N); i += 1) {
    suma1 += x[i][i];
    zero1 = zero1 | (x[i][i] == 0);
    suma2 += x[N - i - 1][i];
    zero2 = zero2 | (x[N - i - 1][i] == 0);
  }
  if (zero1)
    withzero.insert(suma1);
  else
    nonzero.insert(suma1);
  if (zero2)
    withzero.insert(suma2);
  else
    nonzero.insert(suma2);
  if ((int)nonzero.size() > 1 || (int)withzero.size() > 1)
    cout << -1;
  else if (*nonzero.begin() - *withzero.begin() > 0)
    cout << *nonzero.begin() - *withzero.begin();
  else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
