#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
long long A[555][555];
int N;
long long R[555], C[555], D[2];
int Si, Sj;
int main() {
  scanf("%d", &N);
  for (int i = 0, i_len = (N); i < i_len; ++i)
    for (int j = 0, j_len = (N); j < j_len; ++j) scanf("%lld", A[i] + j);
  if (N == 1) {
    puts("1");
    return 0;
  }
  bool yes = true;
  for (int i = 0, i_len = (N); i < i_len; ++i)
    for (int j = 0, j_len = (N); j < j_len; ++j) {
      if (A[i][j] == 0) {
        Si = i;
        Sj = j;
      }
      R[i] += A[i][j];
      C[j] += A[i][j];
    }
  long long sum = *max_element(R, R + N);
  long long ans = sum - R[Si];
  A[Si][Sj] = sum - R[Si];
  memset(R, 0, sizeof R);
  memset(C, 0, sizeof C);
  for (int i = 0, i_len = (N); i < i_len; ++i)
    for (int j = 0, j_len = (N); j < j_len; ++j) {
      R[i] += A[i][j];
      C[j] += A[i][j];
    }
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    if (R[i] != sum) yes = false;
    if (C[i] != sum) yes = false;
    D[0] += A[i][i];
    D[1] += A[i][N - 1 - i];
  }
  if (sum != D[0] || sum != D[1]) yes = false;
  if (yes && ans > 0)
    printf("%lld\n", ans);
  else
    puts("-1");
  return 0;
}
