#include <bits/stdc++.h>
using namespace std;
long long a[1000][1000];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int sx = 0, sy = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        scanf("%I64d", &a[i][j]);
        if (a[i][j] == 0ll) {
          sx = i;
          sy = j;
        }
      }
    }
    if (n == 1) {
      printf("1\n");
      continue;
    }
    int ii = 1;
    while (ii == sx) {
      ii++;
    }
    long long sum = 0;
    for (int j = 1; j <= n; j++) {
      sum += a[ii][j];
    }
    long long tmp = 0;
    for (int j = 1; j <= n; j++) {
      tmp += a[sx][j];
    }
    int judge = 0;
    if (sum - tmp >= 1) {
      a[sx][sy] = sum - tmp;
      for (int i = 1; i <= n; i++) {
        long long w = 0;
        for (int j = 1; j <= n; j++) {
          w += a[i][j];
        }
        if (w != sum) {
          goto loop1;
        }
      }
      for (int j = 1; j <= n; j++) {
        long long w = 0;
        for (int i = 1; i <= n; i++) {
          w += a[i][j];
        }
        if (w != sum) {
          goto loop1;
        }
      }
      long long w1 = 0;
      for (int i = 1; i <= n; i++) {
        w1 += a[i][i];
      }
      if (w1 != sum) {
        goto loop1;
      }
      long long w2 = 0;
      for (int i = 1; i <= n; i++) {
        w2 += a[i][n - i + 1];
      }
      if (w2 != sum) {
        goto loop1;
      }
      judge = 1;
      printf("%I64d\n", sum - tmp);
    } else {
      printf("-1\n");
      judge = 1;
    }
  loop1:
    if (judge == 0) {
      printf("-1\n");
    }
  }
  return 0;
}
