#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int long long n;
  cin >> n;
  int long long x = 0, y = 0;
  vector<vector<int long long> > a(n, vector<int long long>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) x = i, y = j;
    }
  int long long sum = 0;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (x == 0)
    for (int i = 0; i < n; i++) sum += a[1][i];
  else
    for (int i = 0; i < n; i++) sum += a[0][i];
  int long long sum2 = 0;
  for (int i = 0; i < n; i++) sum2 += a[x][i];
  int long long ans = sum - sum2;
  if (ans <= 0)
    cout << -1 << endl;
  else {
    a[x][y] = ans;
    sum = 0;
    sum2 = 0;
    for (int i = 0; i < n; i++) sum += a[0][i];
    for (long long i = 1; i <= n - 1; i++) {
      sum2 = sum;
      sum = 0;
      for (int j = 0; j < n; j++) sum += a[i][j];
      if (sum != sum2) {
        cout << -1 << endl;
        return 0;
      }
    }
    for (int i = 0; i < n; i++) {
      sum2 = sum;
      sum = 0;
      for (int j = 0; j < n; j++) sum += a[j][i];
      if (sum != sum2) {
        cout << -1 << endl;
        return 0;
      }
    }
    sum2 = sum;
    sum = 0;
    for (int i = 0; i < n; i++) sum += a[i][i];
    if (sum != sum2) {
      cout << -1 << endl;
      return 0;
    }
    sum2 = sum;
    sum = 0;
    for (int i = 0; i < n; i++) sum += a[i][n - 1 - i];
    if (sum != sum2) {
      cout << -1 << endl;
      return 0;
    }
    cout << ans << endl;
  }
}
