#include <bits/stdc++.h>
using namespace std;
int cas, cass;
int n, m, lll, ans;
long long a[504][504];
long long sum[504], tot[504];
int sx, sy;
bool judge() {
  int i, j;
  long long ll, c;
  if (sx == 1)
    a[sx][sy] = sum[2] - sum[sx];
  else
    a[sx][sy] = sum[1] - sum[sx];
  sum[sx] += a[sx][sy], tot[sy] += a[sx][sy];
  c = sum[1];
  for (i = 1; i <= n; i++)
    if (sum[i] != c) return 0;
  for (j = 1; j <= n; j++)
    if (tot[j] != c) return 0;
  for (i = 1, ll = 0; i <= n; i++) ll += a[i][i];
  if (ll != c) return 0;
  for (i = 1, ll = 0; i <= n; i++) ll += a[i][n + 1 - i];
  if (ll != c) return 0;
  return 1;
}
int main() {
  int i, j, k;
  while (~scanf("%d", &n)) {
    memset(sum, 0, sizeof(sum));
    memset(tot, 0, sizeof(tot));
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        scanf("%I64d", &a[i][j]);
        if (a[i][j] == 0) sx = i, sy = j;
        sum[i] += a[i][j];
        tot[j] += a[i][j];
      }
    }
    if (n == 1) {
      puts("1");
      continue;
    }
    if (judge() && a[sx][sy] > 0)
      printf("%I64d\n", a[sx][sy]);
    else
      puts("-1");
  }
  return 0;
}
