#include <bits/stdc++.h>
using namespace std;
int dX[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dY[] = {0, 1, 0, -1, 1, 1, -1, -1};
inline void Refresh() {}
int main() {
  int n;
  int row = -1;
  int column = -1;
  long long int a[505][505];
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 0) {
        row = i;
        column = j;
      }
    }
  }
  if (n == 1)
    printf("1\n");
  else {
    long long int presentSum = 0;
    long long int futureSum = 0;
    if (row != 1) {
      for (int i = 1; i <= n; ++i) {
        futureSum += a[1][i];
      }
    } else {
      for (int i = 1; i <= n; ++i) {
        futureSum += a[2][i];
      }
    }
    for (int i = 1; i <= n; ++i) {
      presentSum += a[row][i];
    }
    if (futureSum - presentSum <= 0) {
      printf("-1\n");
      return 0;
    }
    a[row][column] = futureSum - presentSum;
    bool isMagic = true;
    for (int i = 1; i <= n; ++i) {
      long long int rowSum = 0;
      for (int j = 1; j <= n; ++j) {
        rowSum += a[i][j];
      }
      if (rowSum != futureSum) isMagic = false;
    }
    for (int j = 1; j <= n; ++j) {
      long long int columnSum = 0;
      for (int i = 1; i <= n; ++i) {
        columnSum += a[i][j];
      }
      if (columnSum != futureSum) isMagic = false;
    }
    long long int diagSum = 0;
    for (int i = 1; i <= n; ++i) {
      diagSum += a[i][i];
    }
    if (diagSum != futureSum) isMagic = false;
    diagSum = 0;
    for (int i = 1; i <= n; ++i) {
      diagSum += a[i][n - i + 1];
    }
    if (diagSum != futureSum) isMagic = false;
    if (isMagic)
      cout << a[row][column] << endl;
    else
      printf("-1\n");
  }
  return 0;
}
