#include <bits/stdc++.h>
using namespace std;
long long int a[550][550];
int main() {
  long long int i, j, x = 0, n, loci = 0, locj = 0, cnt[1000] = {0}, check = 0,
                      y = 0, p = 0, q = 0, mcount = 0, x1 = 0, x2 = 0,
                      scount = 0, count;
  long long int row[550] = {0}, col[550] = {0};
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        loci = i;
        locj = j;
      }
    }
  }
  if (n == 1)
    cout << 1;
  else {
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) cnt[i] = cnt[i] + a[i][j];
    }
    if (loci == 1) {
      if (cnt[loci] <= cnt[loci + 1]) {
        p = cnt[loci + 1] - cnt[loci];
        y = 1;
      } else {
        check = 0;
        p = 0;
      }
    } else {
      if ((cnt[loci] <= cnt[loci - 1])) {
        p = cnt[loci - 1] - cnt[loci];
        y = 1;
      } else {
        check = 0;
        p = 0;
      }
    }
    if (y == 1) {
      a[loci][locj] = p;
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
          row[i] = row[i] + a[i][j];
          col[i] = col[i] + a[j][i];
        }
      }
      for (i = 1, j = n; i <= n; i++, j--) {
        x1 = x1 + a[i][i];
        x2 = x2 + a[j][i];
      }
      if (x1 == x2) {
        for (i = 1, j; i <= n; i++) {
          if (x1 == row[i] && x1 == col[i] && col[i] == row[i]) {
            for (j = 1; j <= n - 1; j++) {
              if (row[j] == row[j + 1] && col[j] == col[j + 1])
                check = 1;
              else {
                check = 0;
                p = 0;
              }
            }
          } else {
            check = 0;
            p = 0;
          }
        }
      } else {
        check = 0;
        p = 0;
      }
    } else {
      check = 0;
      p = 0;
    }
    if (check == 0 || p == 0)
      cout << "-1";
    else {
      cout << p;
    }
  }
}
