#include <bits/stdc++.h>
using namespace std;
int n;
long long a[555][555];
long long diag1() {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i][i] == 0)
      return -1;
    else
      sum += a[i][i];
  }
  return sum;
}
long long diag2() {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i][n - i + 1] == 0)
      return -1;
    else
      sum += a[i][n - i + 1];
  }
  return sum;
}
long long col(int j) {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i][j] == 0)
      return -1;
    else
      sum += a[i][j];
  }
  return sum;
}
long long row(int j) {
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[j][i] == 0)
      return -1;
    else
      sum += a[j][i];
  }
  return sum;
}
int main() {
  int x = 0, y = 0;
  scanf("%d", &n);
  if (n == 1) return puts("1"), 0;
  long long target = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%I64d", a[i] + j);
      if (a[i][j] == 0) x = j, y = i;
    }
  }
  if (target == -1) target = diag1();
  if (target == -1) target = diag2();
  for (int i = 1; i <= n; i++) {
    if (target == -1) target = col(i);
    if (target == -1) target = row(i);
  }
  a[y][x] = 1;
  long long t = row(y) - 1;
  a[y][x] = target - t;
  if (a[y][x] <= 0) return puts("-1"), 0;
  for (int i = 1; i <= n; i++) {
    if (col(i) != target) return puts("-1"), 0;
    if (row(i) != target) return puts("-1"), 0;
  }
  if (diag1() != target) return puts("-1"), 0;
  if (diag2() != target) return puts("-1"), 0;
  printf("%I64d\n", a[y][x]);
  return 0;
}
