#include <bits/stdc++.h>
const long long mod = 1000000007;
int Inf = (int)2e9;
using namespace std;
bool check(vector<vector<long long>> a) {
  bool f = true;
  vector<long long> sums;
  for (int(i) = 0; (i) < a.size(); (i)++) {
    long long s = 0;
    for (int(j) = 0; (j) < a[i].size(); (j)++) {
      s += a[i][j];
    }
    sums.push_back(s);
  }
  for (int(i) = 0; (i) < a.size(); (i)++) {
    long long s = 0;
    for (int(j) = 0; (j) < a.size(); (j)++) {
      s += a[j][i];
    }
    sums.push_back(s);
  }
  long long s = 0;
  for (int(i) = 0; (i) < a.size(); (i)++) {
    s += a[i][i];
  }
  sums.push_back(s);
  s = 0;
  for (int(i) = 0; (i) < a.size(); (i)++) {
    s += a[i][a.size() - i - 1];
  }
  sums.push_back(s);
  sort((sums).begin(), (sums).end());
  if (sums[0] == sums[sums.size() - 1])
    return true;
  else
    return false;
}
int main() {
  int n;
  scanf("%d", &(n));
  vector<vector<long long>> pole(n, vector<long long>(n));
  pair<int, int> tmp;
  for (int(i) = 0; (i) < n; (i)++) {
    for (int(j) = 0; (j) < n; (j)++) {
      scanf("%I64d", &pole[i][j]);
      if (pole[i][j] == 0) {
        tmp.first = i;
        tmp.second = j;
      }
    }
  }
  vector<long long> sums;
  for (int(i) = 0; (i) < n; (i)++) {
    long long s = 0;
    for (int(j) = 0; (j) < n; (j)++) {
      s += pole[i][j];
    }
    sums.push_back(s);
  }
  for (int(i) = 0; (i) < n; (i)++) {
    long long s = 0;
    for (int(j) = 0; (j) < n; (j)++) {
      s += pole[j][i];
    }
    sums.push_back(s);
  }
  long long s1 = 0, s2 = 0;
  for (int(i) = 0; (i) < n; (i)++) {
    s1 += pole[i][i];
    s2 += pole[i][n - i - 1];
  }
  sums.push_back(s1);
  sums.push_back(s2);
  sort((sums).begin(), (sums).end());
  int k = sums.size();
  long long need = sums[k - 1] - sums[0];
  pole[tmp.first][tmp.second] = need;
  bool f = check(pole);
  if (n == 1) {
    cout << 1;
    return 0;
  }
  if (f && need > 0)
    cout << need;
  else
    cout << -1;
  return 0;
}
