#include <bits/stdc++.h>
using namespace std;
long long a[505][505];
long long sumr[505];
long long suml[505];
long long sumx, sumy;
int main() {
  int n;
  int x, y;
  cin >> n;
  sumy = sumx = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        x = i;
        y = j;
      }
    }
  }
  if (n == 1) {
    cout << "1" << endl;
    return 0;
  }
  int flag = 1;
  memset(suml, 0, sizeof(suml));
  memset(sumr, 0, sizeof(sumr));
  for (int i = 1; i <= n; i++) {
    sumx += a[i][i];
    sumy += a[i][n + 1 - i];
  }
  long long ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      sumr[i] += a[i][j];
      suml[i] += a[j][i];
    }
    if (i >= 2 && suml[i] != suml[i - 1]) {
      ans = abs(suml[i] - suml[i - 1]);
    }
    if (i >= 2 && sumr[i] != sumr[i - 1]) {
      ans = abs(sumr[i] - sumr[i - 1]);
    }
  }
  sumr[x] += ans;
  suml[y] += ans;
  if (x == y) sumx += ans;
  if (x + y == (n + 1)) sumy += ans;
  for (int i = 1; i <= n; i++) {
    if (sumr[i] != sumx || suml[i] != sumx || sumx != sumy) {
      flag = 0;
      break;
    }
    for (int j = i - 1; j > 0; j--) {
      if (sumr[j] != sumr[i] || suml[j] != suml[i] || sumr[i] != suml[i]) {
        flag = 0;
        i = n + 1;
        j = -1;
      }
    }
  }
  if (flag)
    cout << ans << endl;
  else
    cout << "-1" << endl;
}
