#include <bits/stdc++.h>
using namespace std;
const int MaxN = 500;
long long m, n, a[MaxN + 5][MaxN + 5];
int main() {
  scanf("%I64d", &n);
  int locx, locy;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%I64d", &a[i][j]);
      if (a[i][j] == 0) {
        locx = i;
        locy = j;
      }
    }
  }
  if (n == 1)
    printf("1\n");
  else {
    long long sumx = 0, sumy = 0;
    for (int i = 1; i <= n; i++) {
      if (i != locx) {
        for (int j = 1; j <= n; j++) sumx += a[i][j];
        break;
      }
    }
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      if (i == locx) {
        for (int j = 1; j <= n; j++) sum += a[i][j];
        break;
      }
    }
    long long ans = sumx - sum;
    if (ans <= 0)
      printf("-1\n");
    else {
      a[locx][locy] = ans;
      int flag = 0;
      for (int i = 1; i <= n; i++) {
        sum = 0;
        for (int j = 1; j <= n; j++) sum += a[i][j];
        if (sum != sumx) {
          flag = 1;
          break;
        }
        sum = 0;
        for (int j = 1; j <= n; j++) sum += a[j][i];
        if (sum != sumx) {
          flag = 1;
          break;
        }
      }
      sum = 0;
      for (int i = 1; i <= n; i++) sum += a[i][i];
      if (sum != sumx) flag = 1;
      sum = 0;
      for (int i = 1; i <= n; i++) sum += a[i][n + 1 - i];
      if (sum != sumx) flag = 1;
      if (flag == 1)
        printf("-1\n");
      else
        printf("%I64d\n", ans);
    }
  }
}
