#include <bits/stdc++.h>
using namespace std;
long long a[505][505], r[505], c[505];
bool check(int n) {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      r[i] += a[i][j];
      c[j] += a[i][j];
    }
  }
  long long sum1 = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) {
    sum1 += a[i][i];
    sum2 += a[i][n + 1 - i];
  }
  if (sum1 != sum2) return false;
  for (int i = 1; i <= n; i++) {
    if (sum1 != r[i]) return false;
    if (sum1 != c[i]) return false;
  }
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%lld", &a[i][j]);
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      r[i] += a[i][j];
      c[j] += a[i][j];
    }
  }
  long long MAX = 0;
  for (int i = 1; i <= n; i++) MAX = max(r[i], MAX);
  long long ans;
  for (int i = 1; i <= n; i++) {
    bool bb = false;
    for (int j = 1; j <= n; j++)
      if (a[i][j] == 0) {
        a[i][j] = MAX - r[i];
        ans = a[i][j];
        break;
      }
    if (bb) break;
  }
  if (check(n)) {
    if (ans > 0)
      cout << ans << endl;
    else
      cout << -1 << endl;
  } else
    cout << -1 << endl;
  return 0;
}
