#include <bits/stdc++.h>
using namespace std;
long long m[501][501];
int main() {
  long long n, sum = 0, row = 0, col = 0, p = 0;
  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 >> m[i][j];
      if (m[i][j] == 0) {
        row = i;
        col = j;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i == row) continue;
    sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += m[i][j];
    }
    if (sum != 0) break;
  }
  for (int j = 0; j < n; ++j) p += m[row][j];
  long long t = sum - p;
  if (t <= 0 || t > 1e18) {
    cout << -1 << endl;
    return 0;
  }
  m[row][col] = t;
  for (int i = 0; i < n; ++i) {
    p = 0;
    for (int j = 0; j < n; ++j) p += m[i][j];
    if (p != sum) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int j = 0; j < n; ++j) {
    p = 0;
    for (int i = 0; i < n; ++i) p += m[i][j];
    if (p != sum) {
      cout << -1 << endl;
      return 0;
    }
  }
  p = 0;
  for (int i = 0; i < n; ++i) p += m[i][i];
  if (p != sum) {
    cout << -1 << endl;
    return 0;
  }
  p = 0;
  for (int i = 0, j = n - 1; i < n; ++i, --j) p += m[i][j];
  if (p != sum) {
    cout << -1 << endl;
    return 0;
  }
  cout << t << endl;
  return 0;
}
