#include <bits/stdc++.h>
using namespace std;
long long int a[505][505];
int main() {
  int n;
  cin >> n;
  int x, y;
  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;
      }
    }
  }
  if (n == 1)
    cout << 1 << endl;
  else {
    int koji = 0;
    if (x == 0) koji = 1;
    long long int sum = 0;
    for (int i = 0; i < n; i++) sum += a[koji][i];
    long long int sumr = 0;
    for (int i = 0; i < n; i++) sumr += a[x][i];
    long long int rj = sum - sumr;
    a[x][y] = rj;
    long long int sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        sum1 += a[i][j];
        sum2 += a[j][i];
      }
      if (sum1 != sum || sum2 != sum) {
        cout << -1 << endl;
        return 0;
      }
      sum1 = 0;
      sum2 = 0;
    }
    sum1 = 0;
    for (int i = 0; i < n; i++) sum1 += a[i][i];
    sum2 = 0;
    for (int i = 0; i < n; i++) sum2 += a[i][n - i - 1];
    if (sum1 != sum || sum2 != sum || rj < 1) {
      cout << -1 << endl;
      return 0;
    }
    cout << rj << endl;
  }
  return 0;
}
