#include <bits/stdc++.h>
using namespace std;
const int N = 505;
long long a[N][N], h[N], c[N];
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      scanf("%I64d", &a[i][j]);
      if (a[i][j] == 0) {
        x = i;
        y = j;
      }
      h[i] += a[i][j];
      c[j] += a[i][j];
    }
  if (n == 1) {
    puts("1");
    return 0;
  }
  long long de = 0;
  for (int i = 0; i < n; i++)
    if (i != x) {
      de = h[i];
      break;
    }
  if (h[x] != c[y]) {
    puts("-1");
    return 0;
  }
  long long to = de - h[x];
  if (to <= 0) {
    puts("-1");
    return 0;
  }
  a[x][y] = to;
  h[x] += to;
  c[y] += to;
  for (int i = 0; i < n; i++) {
    if (h[i] != de || c[i] != de) {
      puts("-1");
      return 0;
    }
  }
  long long zh = 0, fu = 0;
  for (int i = 0; i < n; i++) {
    zh += a[i][i];
    fu += a[i][n - 1 - i];
  }
  if (zh != de || fu != de) {
    puts("-1");
    return 0;
  }
  printf("%I64d", to);
  return 0;
}
