#include <bits/stdc++.h>
long long ss[510][510];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int x, y;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        scanf("%d", &ss[i][j]);
        if (ss[i][j] == 0) x = i, y = j;
      }
    if (n == 1) {
      printf("1\n");
      continue;
    }
    long long sum = 0, ans = -1;
    if (x && y) {
      for (int j = 0; j < n; j++) sum += ss[0][j];
      for (int j = 0; j < n; j++) sum -= ss[x][j];
    } else if (x != n - 1) {
      for (int j = 0; j < n; j++) sum += ss[n - 1][j];
      for (int j = 0; j < n; j++) sum -= ss[x][j];
    } else {
      for (int j = 0; j < n; j++) sum += ss[j][n - 1];
      for (int j = 0; j < n; j++) sum -= ss[x][j];
    }
    if (sum <= 0) {
      printf("-1\n");
      continue;
    }
    ss[x][y] = sum;
    bool fg = true;
    long long r[510], c[510];
    memset(r, 0, sizeof(r));
    memset(c, 0, sizeof(c));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        r[i] += ss[i][j];
        c[j] += ss[i][j];
      }
    for (int i = 0; i < n; i++) {
      r[n] += ss[i][i];
      c[n] += ss[i][n - i - 1];
    }
    for (int i = 0; i < n + 1; i++) {
      if (r[i] != r[0]) {
        fg = false;
        break;
      }
      if (c[i] != r[0]) {
        fg = false;
        break;
      }
    }
    if (fg) ans = sum;
    printf("%I64d\n", ans);
  }
  return 0;
}
