#include <bits/stdc++.h>
using namespace std;
const int maxn = 501;
long long matrix[maxn][maxn];
long long sum_col[maxn];
long long sum_row[maxn];
long long sum_d1 = 0;
long long sum_d2 = 0;
int pos_col = 0;
int pos_row = 0;
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int tmp;
      cin >> tmp;
      if (tmp == 0) {
        pos_col = j;
        pos_row = i;
      }
      if (i == j) sum_d1 += tmp;
      if (i == n - j - 1) sum_d2 += tmp;
      sum_row[i] += tmp;
      sum_col[j] += tmp;
    }
  }
  if (n == 1) {
    cout << 1;
    return 0;
  }
  bool ans = true;
  int cor = 0;
  if (pos_col == cor) cor = 1;
  long long num = sum_col[cor] - sum_col[pos_col];
  if (num <= 0) ans = false;
  sum_col[pos_col] += num;
  sum_row[pos_row] += num;
  if (pos_col == pos_row) sum_d1 += num;
  if (pos_row == n - pos_col - 1) sum_d2 += num;
  for (int i = 0; i < n; i++) {
    if (sum_col[i] != sum_col[cor]) ans = false;
    if (sum_row[i] != sum_col[cor]) ans = false;
  }
  if (sum_d1 != sum_col[cor]) ans = false;
  if (sum_d2 != sum_col[cor]) ans = false;
  if (ans)
    cout << num;
  else
    cout << -1;
}
