#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 100005;
const double epsilon = 1e-12;
template <class T>
string toStr(const T &x) {
  stringstream s;
  s << x;
  return s.str();
}
template <class T>
int toInt(const T &x) {
  stringstream s;
  s << x;
  int r;
  s >> r;
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, indexi, indexj, sum1 = 0, sum2 = 0, sum = 0, a1 = 0;
  set<long long> s;
  bool flag = false;
  cin >> n;
  if (n == 1) {
    cout << "1";
    return 0;
  } else {
    long long arr[n + 1][n + 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> arr[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (arr[i][j] == 0) {
          indexi = i;
          indexj = j;
          flag = true;
        }
        if (flag == true) {
          break;
        }
      }
      if (flag == true) {
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      sum1 = sum1 + arr[indexi][i];
    }
    for (int i = 0; i < n; i++) {
      if (indexi == 0) {
        sum2 = sum2 + arr[indexi + 1][i];
      } else if (indexi == n - 1) {
        sum2 = sum2 + arr[indexi - 1][i];
      } else {
        sum2 = sum2 + arr[indexi + 1][i];
      }
    }
    long long sum3 = sum2 - sum1;
    if (sum3 <= 0) {
      cout << "-1";
      return 0;
    } else {
      arr[indexi][indexj] = sum3;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          sum = sum + arr[i][j];
        }
        s.insert(sum);
        sum = 0;
      }
      sum = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          sum = sum + arr[j][i];
        }
        s.insert(sum);
        sum = 0;
      }
      sum = 0;
      for (int i = 0; i < n; ++i) {
        sum = sum + arr[i][i];
        a1 = a1 + arr[i][n - i - 1];
      }
      s.insert(sum);
      s.insert(a1);
      if (s.size() == 1) {
        cout << sum3 << "\n";
      } else {
        cout << "-1"
             << "\n";
      }
    }
  }
  return 0;
}
