#include <bits/stdc++.h>
using namespace std;
long long a[505][505];
long long solve() {
  long long n;
  cin >> n;
  long long x, y, ax, ay;
  for (long long i = 1; i <= n; i++) {
    long long sum = 0, f = 0;
    for (long long j = 1; j <= n; j++) {
      cin >> a[i][j];
      sum += a[i][j];
      if (a[i][j] == 0) f = 1, ax = i, ay = j;
    }
    if (f)
      x = sum;
    else
      y = sum;
  }
  if (n == 1) return 1;
  if (y <= x) return -1;
  a[ax][ay] = y - x;
  long long da = 0, db = 0;
  for (long long i = 1; i <= n; i++) {
    long long sa = 0, sb = 0;
    for (long long j = 1; j <= n; j++) {
      sa += a[i][j], sb += a[j][i];
    }
    if (sa != y || sb != y) return -1;
    da += a[i][i], db += a[i][n - i + 1];
  }
  if (da != y || db != y) return -1;
  return y - x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cout << solve() << "\n";
  return 0;
}
