#include <bits/stdc++.h>
using namespace std;
long long int mag[501][501];
long long int sumrow[501];
long long int sumcol[501];
int main() {
  long long int N, i, j, k;
  long long int sum;
  cin >> N;
  for (i = 0; i < N; i++) {
    sumrow[i] = 0;
    sumcol[i] = 0;
  }
  long long int row = -1;
  long long int col = -1;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      cin >> mag[i][j];
      if (mag[i][j] == 0) {
        row = i;
        col = j;
      }
    }
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) sumrow[i] += mag[i][j];
  }
  for (j = 0; j < N; j++) {
    for (i = 0; i < N; i++) {
      sumcol[j] += mag[i][j];
    }
  }
  if (N == 1) {
    cout << "1" << endl;
    return 0;
  }
  if (row == 0)
    sum = sumrow[1];
  else
    sum = sumrow[0];
  int status = 0;
  for (i = 0; i < N; i++) {
    if (i == row) continue;
    if (sumrow[i] != sum) status = 1;
  }
  for (i = 0; i < N; i++) {
    if (i == col) continue;
    if (sumcol[i] != sum) status = 1;
  }
  if (status == 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (sumrow[row] != sumcol[col]) {
    cout << "-1" << endl;
    return 0;
  }
  long long int num;
  num = sum - sumcol[col];
  if (num <= 0) {
    cout << "-1" << endl;
    return 0;
  }
  mag[row][col] = num;
  long long int temp = 0;
  for (i = 0; i < N; i++) temp += mag[i][i];
  long long int temp1 = 0;
  for (i = 0; i < N; i++) temp1 += mag[i][N - i - 1];
  if (temp1 != temp) {
    cout << "-1" << endl;
    return 0;
  }
  if (temp1 != sum) {
    cout << "-1" << endl;
    return 0;
  }
  cout << num << endl;
  return 0;
}
