#include <bits/stdc++.h>
using namespace std;
long long int a[505][505];
int main() {
  long long int n;
  long long int ci, cj;
  scanf("%lld", &n);
  if (n == 1) {
    printf("1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%lld", &a[i][j]);
      if (a[i][j] == 0) {
        ci = i;
        cj = j;
      }
    }
  }
  long long int rows = 0, cols = 0, req = 0, sums = 0;
  for (int i = 0; i < n; i++) {
    sums = 0;
    for (int j = 0; j < n; j++) {
      sums += a[i][j];
    }
    if (i != ci) break;
  }
  for (int i = 0; i < n; i++) {
    rows += a[ci][i];
  }
  if (sums <= rows) {
    printf("-1\n");
    return 0;
  }
  a[ci][cj] = sums - rows;
  long long int flag = 0, d1 = 0, d2 = 0;
  for (int i = 0; i < n; i++) {
    long long int r = 0, c = 0;
    for (int j = 0; j < n; j++) {
      r += a[i][j];
      c += a[j][i];
      if (i == j) d1 += a[i][j];
      if (i + j == n - 1) d2 += a[i][j];
    }
    if (r != sums || c != sums) {
      flag = 1;
      break;
    }
  }
  if (d1 != sums || d2 != sums) flag = 1;
  if (flag == 1) {
    printf("-1\n");
  } else
    printf("%lld\n", sums - rows);
  return 0;
}
