#include <bits/stdc++.h>
using namespace std;
long long a[500][500];
long long getSum(int n) {
  for (int i = 0; i < n; i++) {
    long long s = 0;
    for (int j = 0; j < n; j++) {
      s += a[i][j];
      if (a[i][j] == 0) {
        s = -1;
        break;
      }
    }
    if (s > 0) return s;
  }
  return -1;
}
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      if (!a[i][j]) {
        x = i;
        y = j;
      }
    }
  if (n == 1) {
    cout << 1;
    return 0;
  }
  long long sum = getSum(n);
  long long s = 0;
  for (int j = 0; j < n; j++) s += a[x][j];
  a[x][y] = sum - s;
  bool pos = 1;
  for (int i = 0; i < n; i++) {
    s = 0;
    for (int j = 0; j < n; j++) s += a[i][j];
    if (s != sum) pos = 0;
  }
  for (int j = 0; j < n; j++) {
    s = 0;
    for (int i = 0; i < n; i++) s += a[i][j];
    if (s != sum) pos = 0;
  }
  s = 0;
  for (int i = 0, j = 0; i < n; i++, j++) s += a[i][j];
  if (s != sum) pos = 0;
  s = 0;
  for (int i = 0, j = n - 1; i < n; i++, j--) s += a[i][j];
  if (s != sum) pos = 0;
  if (pos && a[x][y] > 0)
    cout << a[x][y];
  else
    cout << -1;
}
