#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, row, col;
  cin >> n;
  vector<long long int> a[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int temp;
      cin >> temp;
      a[i].push_back(temp);
      if (temp == 0) {
        row = i;
        col = j;
      }
    }
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    if (row == 0)
      sum += a[1][i];
    else
      sum += a[0][i];
  }
  int i, j;
  for (i = 0; i < n; i++) {
    long long int row_sum = 0, col_sum = 0;
    for (j = 0; j < n; j++) {
      row_sum += a[i][j];
      col_sum += a[j][i];
    }
    if ((i != row && row_sum != sum) || (i != col && col_sum != sum)) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long int ele1 = sum, ele2 = sum;
  for (int i = 0; i < n; i++) {
    ele1 -= a[row][i];
    ele2 -= a[i][col];
  }
  if (ele1 != ele2) {
    cout << -1 << endl;
    return 0;
  } else if (ele1 <= 0) {
    cout << -1 << endl;
    return 0;
  } else
    a[row][col] = ele1;
  long long int dia1 = 0, dia2 = 0;
  for (int i = 0; i < n; i++) {
    dia1 += a[i][i];
    dia2 += a[i][n - i - 1];
  }
  if (dia1 != sum || dia2 != sum)
    cout << -1 << endl;
  else
    cout << ele1 << endl;
  return 0;
}
