#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long **a = new long long *[n];
  for (int z = 0; z < n; z++) {
    a[z] = new long long[n];
  }
  int x = -1, y = -1;
  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;
    return 0;
  }
  long long sz = 0, s = 0, p = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == x) {
        sz += a[i][j];
      }
      if (i != x && p) {
        s += a[i][j];
      }
    }
    if (s != 0) p = 0;
  }
  bool g = 0;
  if (x >= 0 && y >= 0) {
    a[x][y] = s - sz;
    if (a[x][y] <= 0) g = 1;
  }
  long long sr = 0, sc = 0, d1 = 0, d2 = 0;
  for (int i = 0; i < n; i++) {
    sr = 0, sc = 0;
    for (int j = 0; j < n; j++) {
      if (i == j) d1 += a[i][j];
      if (i + j == n - 1) d2 += a[i][j];
      sc += a[i][j];
      sr += a[j][i];
    }
    if (sc != s || sr != s) g = 1;
  }
  if (d1 != s || d2 != s) g = 1;
  if (g)
    cout << -1;
  else
    cout << a[x][y];
}
