#include <bits/stdc++.h>
using namespace std;
const int M = 100000;
long long a[505][505];
long long solo(int n) {
  int ll, rr;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%I64d", &a[i][j]);
      if (a[i][j] == 0) {
        ll = i;
        rr = j;
      }
    }
  }
  long long sum = 0;
  long long ssum = 0;
  int flag = 0;
  int flagg = 0;
  for (int i = 1; i <= n; i++) {
    if (i == ll) {
      for (int j = 1; j <= n; j++) ssum += a[i][j];
      flagg = 1;
    }
    if (flagg) break;
  }
  for (int i = 1; i <= n; i++) {
    if (i != ll) {
      for (int j = 1; j <= n; j++) sum += a[i][j];
      flag = 1;
    }
    if (flag) break;
  }
  long long ja = sum - ssum;
  if (ja < 1) return -1;
  a[ll][rr] = ja;
  for (int i = 1; i <= n; i++) {
    ssum = 0;
    for (int j = 1; j <= n; j++) {
      ssum += a[i][j];
    }
    if (ssum != sum) return -1;
  }
  for (int j = 1; j <= n; j++) {
    ssum = 0;
    for (int i = 1; i <= n; i++) ssum += a[i][j];
    if (ssum != sum) return -1;
  }
  long long q, w;
  q = w = 0;
  for (int i = 1; i <= n; i++) {
    q += a[i][i];
    w += a[i][n - i + 1];
  }
  if (q != sum || w != sum) return -1;
  return ja;
}
int main() {
  int n, ll, rr;
  scanf("%d", &n);
  if (n == 1) {
    printf("1\n");
    return 0;
  }
  printf("%I64d\n", solo(n));
}
