#include <bits/stdc++.h>
using namespace std;
set<long long int> myset;
set<long long int> myset1;
long long int ara[500][5000];
bool flag = false;
int main() {
  long long int n, sum = 0, a, b, ans, count = 0, maxs = 0,
                   mins = 5799999999999;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> ara[i][j];
      sum += ara[i][j];
      if (ara[i][j] == 0) {
        a = i;
        b = j;
        flag = true;
      }
    }
    myset.insert(sum);
    sum = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) sum += ara[i][j];
    }
  }
  myset.insert(sum);
  sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + j == n + 1 - 2) sum += ara[i][j];
    }
  }
  myset.insert(sum);
  sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      sum += ara[j][i];
    }
    myset.insert(sum);
    sum = 0;
  }
  set<long long int>::iterator it;
  for (it = myset.begin(); it != myset.end(); it++) {
    ans = *it;
    if (ans > maxs) maxs = ans;
    if (ans < mins) mins = ans;
    count++;
  }
  if (count >= 3) {
    cout << -1 << endl;
    return 0;
  }
  if (count == 1 && flag == true) {
    cout << -1 << endl;
    return 0;
  }
  ara[a][b] = (maxs - mins);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      sum += ara[i][j];
    }
    myset1.insert(sum);
    sum = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) sum += ara[i][j];
    }
  }
  myset1.insert(sum);
  sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + j == n + 1 - 2) sum += ara[i][j];
    }
  }
  myset1.insert(sum);
  sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      sum += ara[j][i];
    }
    myset1.insert(sum);
    sum = 0;
  }
  if (myset1.size() > 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << (maxs - mins) << endl;
  return 0;
}
