#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int a[n][n];
  int r, c;
  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;
      }
    }
  }
  long long int sum = -2;
  for (int i = 0; i < n; i++) {
    long long int flag = 0;
    if (i == r) continue;
    for (int j = 0; j < n; j++) {
      flag += a[i][j];
    }
    if (sum == -2)
      sum = flag;
    else {
      if (flag != sum) {
        sum = -1;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    long long int flag = 0;
    if (i != r) continue;
    for (int j = 0; j < n; j++) {
      flag += a[i][j];
    }
    a[r][c] = sum - flag;
  }
  for (int i = 0; i < n; i++) {
    if (sum == -1) break;
    long long int flag = 0;
    for (int j = 0; j < n; j++) {
      flag += a[j][i];
    }
    if (sum == -2)
      sum = flag;
    else {
      if (flag != sum) {
        sum = -1;
        break;
      }
    }
  }
  long long int flag = 0;
  for (int i = 0; i < n; i++) {
    flag += a[i][i];
  }
  if (flag != sum) sum = -1;
  flag = 0;
  for (int i = 0; i < n; i++) {
    flag += a[i][n - i - 1];
  }
  if (flag != sum) sum = -1;
  if (sum == -2)
    cout << 1 << endl;
  else if (sum == -1 || a[r][c] < 1)
    cout << -1 << endl;
  else
    cout << a[r][c] << endl;
  return 0;
}
