#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 510;
long long a[N][N], hang[N], lie[N], he = -1;
int n, sx, sy;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  if (n == 1) return cout << 1 << endl, 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (!a[i][j]) sx = i, sy = j;
    }
  for (int i = 1; i <= n; i++) {
    long long temp = 0;
    for (int j = 1; j <= n; j++) temp += a[i][j];
    hang[i] = temp;
    if (sx == i) continue;
    if (he == -1)
      he = temp;
    else if (he != temp)
      return cout << -1 << endl, 0;
  }
  for (int j = 1; j <= n; j++) {
    long long temp = 0;
    for (int i = 1; i <= n; i++) temp += a[i][j];
    lie[j] = temp;
    if (sy == j) continue;
    if (he != temp) return cout << -1 << endl, 0;
  }
  bool in1 = false;
  long long he1 = 0;
  for (int i = 1; i <= n; i++) {
    if (i == sx && i == sy) in1 = true;
    he1 += a[i][i];
  }
  if (!in1 && he1 != he) return cout << -1 << endl, 0;
  if (in1 && he1 != hang[sx]) return cout << -1 << endl, 0;
  bool in2 = false;
  long long he2 = 0;
  for (int i = 1; i <= n; i++) {
    if (i == sx && n - i + 1 == sy) in2 = true;
    he2 += a[i][n - i + 1];
  }
  if (!in2 && he2 != he) return cout << -1 << endl, 0;
  if (in2 && he2 != hang[sx]) return cout << -1 << endl, 0;
  if (hang[sx] < he) {
    cout << he - hang[sx];
  } else
    cout << -1 << endl;
  return 0;
}
