import std.stdio;

void main()
{
	int n;
	scanf("%d", &n);

	long[500][500] m;
	int r, c;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%lld", &m[i][j]);

			if (m[i][j] == 0) {
				r = i;
				c = j;
			}
		}
	}

	long sum = 0;
	long s = 1;
	if (n > 1) {
		int g = 0;
		if (r == 0) {
			g++;
		}
	
		for (int i = 0; i < n; i++) {
			sum += m[g][i];
		}

		s = sum;
		for (int i = 0; i < n; i++) {
			s -= m[r][i];
		}
	}
	else {
		sum = 1;
	}

	m[r][c] = s;

	long sumDiagL = 0;
	long sumDiagR = 0;
	for (int i = 0; i < n; i++) {
		long sumRow = 0;
		long sumCol = 0;
		
		for (int j = 0; j < n; j++) {
			sumRow += m[i][j];
			sumCol += m[j][i];
		}

		sumDiagL += m[i][i];
		sumDiagR += m[n - 1 - i][i];
		if (sumRow != sum || sumCol != sum) {
			s = -1;
		}
	}
	if (sumDiagL != sum || sumDiagR != sum) {
		s = -1;
	}

	if (s <= 0) {
		printf("-1\n");
	}
	else {
		printf("%lld\n", s);
	}
}