using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;

        if (n == 1)
        {
            wln(1);
            return;
        }

        var a = new long[n, n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                a[i, j] = rl;
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            long cursum = 0;
            bool flag = false;
            for (int j = 0; j < n; j++)
            {
                if (a[i, j] == 0)
                {
                    flag = true;
                }
                else
                {
                    cursum += a[i, j];
                }
            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }
        }

        for (int j = 0; j < n; j++)
        {
            long cursum = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i, j] == 0)
                {
                    flag = true;
                }
                else
                {
                    cursum += a[i, j];
                }
            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }
        }

        {
            long cursum = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                {
                    if (a[i, i] == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        cursum += a[i, i];
                    }
                }

            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }

            cursum = 0;
            flag = false;
            for (int i = 0; i < n; i++)
            {

                {
                    if (a[i, n - 1 - i] == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        cursum += a[i, n - 1 - i];
                    }
                }

            }

            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }

            long res = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (a[i, j] == 0)
                    {
                        cursum = 0;
                        for (int k = 0; k < n; k++)
                        {
                            cursum += a[i, k];
                        }
                        res = sum - cursum;

                        cursum = 0;
                        for (int k = 0; k < n; k++)
                        {
                            cursum += a[k, j];
                        }
                        if (res != sum - cursum)
                        {
                            wln(-1);
                            return;
                        }
                        if (i == j)
                        {
                            cursum = 0;
                            for (int k = 0; k < n; k++)
                            {
                                cursum += a[k, k];
                            }
                            if (res != sum - cursum)
                            {
                                wln(-1);
                                return;
                            }
                        }

                        if (i == n - i - 1)
                        {
                            cursum = 0;
                            for (int k = 0; k < n; k++)
                            {
                                cursum += a[k, n - 1 - k];
                            }
                            if (res != sum - cursum)
                            {
                                wln(-1);
                                return;
                            }
                        }
                        wln(res);
                        return;
                    }
                }
            }
        }
    }
    //////////////////////////////////////////////////

    static void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }

    static void wln() { Console.WriteLine(); }
    static void wln<T>(T o) { Console.WriteLine(o); }
    static void wsp<T>(T o) { Console.Write(o + " "); }
    static void wrt<T>(T o) { Console.Write(o); }

    static void wln(double o) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    static void wsp(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    static void wrt(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;

        if (n == 1)
        {
            wln(1);
            return;
        }

        var a = new long[n, n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                a[i, j] = rl;
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            long cursum = 0;
            bool flag = false;
            for (int j = 0; j < n; j++)
            {
                if (a[i, j] == 0)
                {
                    flag = true;
                }
                else
                {
                    cursum += a[i, j];
                }
            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }
        }

        for (int j = 0; j < n; j++)
        {
            long cursum = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i, j] == 0)
                {
                    flag = true;
                }
                else
                {
                    cursum += a[i, j];
                }
            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }
        }

        {
            long cursum = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                {
                    if (a[i, i] == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        cursum += a[i, i];
                    }
                }

            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }

            cursum = 0;
            flag = false;
            for (int i = 0; i < n; i++)
            {

                {
                    if (a[i, n - 1 - i] == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        cursum += a[i, n - 1 - i];
                    }
                }

            }

            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }

            long res = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (a[i, j] == 0)
                    {
                        cursum = 0;
                        for (int k = 0; k < n; k++)
                        {
                            cursum += a[i, k];
                        }
                        res = sum - cursum;

                        cursum = 0;
                        for (int k = 0; k < n; k++)
                        {
                            cursum += a[k, j];
                        }
                        if (res != sum - cursum)
                        {
                            wln(-1);
                            return;
                        }
                        if (i == j)
                        {
                            cursum = 0;
                            for (int k = 0; k < n; k++)
                            {
                                cursum += a[k, k];
                            }
                            if (res != sum - cursum)
                            {
                                wln(-1);
                                return;
                            }
                        }

                        if (i == n - j - 1)
                        {
                            cursum = 0;
                            for (int k = 0; k < n; k++)
                            {
                                cursum += a[k, n - 1 - k];
                            }
                            if (res != sum - cursum)
                            {
                                wln(-1);
                                return;
                            }
                        }
                        if (res <= 0)
                        {
                            wln(-1);
                            return;
                        }
                        wln(res);
                        return;
                    }
                }
            }
        }
    }
    //////////////////////////////////////////////////

    static void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }

    static void wln() { Console.WriteLine(); }
    static void wln<T>(T o) { Console.WriteLine(o); }
    static void wsp<T>(T o) { Console.Write(o + " "); }
    static void wrt<T>(T o) { Console.Write(o); }

    static void wln(double o) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    static void wsp(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    static void wrt(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;

        if (n == 1)
        {
            wln(1);
            return;
        }

        var a = new long[n, n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                a[i, j] = rl;
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            long cursum = 0;
            bool flag = false;
            for (int j = 0; j < n; j++)
            {
                if (a[i, j] == 0)
                {
                    flag = true;
                }
                else
                {
                    cursum += a[i, j];
                }
            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }
        }

        for (int j = 0; j < n; j++)
        {
            long cursum = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i, j] == 0)
                {
                    flag = true;
                }
                else
                {
                    cursum += a[i, j];
                }
            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }
        }

        {
            long cursum = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                {
                    if (a[i, i] == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        cursum += a[i, i];
                    }
                }

            }
            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }

            cursum = 0;
            flag = false;
            for (int i = 0; i < n; i++)
            {

                {
                    if (a[i, n - 1 - i] == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        cursum += a[i, n - 1 - i];
                    }
                }

            }

            if (flag == false)
            {
                if (cursum != sum)
                {
                    if (sum == 0)
                        sum = cursum;
                    else
                    {
                        wln(-1);
                        return;
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (a[i, j] == 0)
                    {
                        cursum = 0;
                        for (int k = 0; k < n; k++)
                        {
                            cursum += a[i, k];
                        }
                        wln(sum - cursum);
                        return;
                    }
                }
            }
        }
    }
    //////////////////////////////////////////////////

    static void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }

    static void wln() { Console.WriteLine(); }
    static void wln<T>(T o) { Console.WriteLine(o); }
    static void wsp<T>(T o) { Console.Write(o + " "); }
    static void wrt<T>(T o) { Console.Write(o); }

    static void wln(double o) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    static void wsp(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    static void wrt(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Globalization;

class Program
{
    static void Main(string[] args)
    {
        var n = RI();
        long[,] map = new long[n, n];

        long[] row = new long[n];
        int x = -1;
        int y = -1;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                map[i, j] = RI();
                row[i] += map[i, j];

                if (map[i, j] == 0)
                {
                    x = i;
                    y = j;
                }
            }

        if (n == 1)
        {
            Console.WriteLine(1);
            return;
        }

        long expected = row[1];
        if (x > 0) expected = row[0];

        long delta = expected - row[x];
        if (delta <= 0)
        {
            Console.WriteLine(-1);
            return;
        }

        map[x, y] = delta;

        row = new long[n];
        long[] col = new long[n];

        long d1 = 0;
        long d2 = 0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                row[i] += map[i, j];
                col[j] += map[i, j];
            }

            d1 += map[i, i];
            d2 += map[n - 1 - i, i];
        }

        List<long> all = new List<long>();
        all.AddRange(col);
        all.AddRange(row);
        all.Add(d1);
        all.Add(d2);

        if (all.Distinct().Count() > 1)
        {
            Console.WriteLine(-1);
            return;
        }

        Console.WriteLine(delta);
    }

    #region Data Read
    private static char ReadSign()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == '+' || ans == '-')
                return (char)ans;
        }
    }

    private static long GCD(long a, long b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static int Mod = 1000000007;
    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    val n = readInt()
    if (n == 1) {
        print(1)
        return
    }

    var empty = -1 to -1
    val rows = LongArray(n)
    val cols = LongArray(n)
    var d1 = 0L
    var d2 = 0L

    for (numRow in 0 until n) {
        val row = readLongs()
        for (numColumn in 0 until n) {
            rows[numRow] += row[numColumn]
            cols[numColumn] += row[numColumn]
            if (numRow == numColumn) d1 += row[numColumn]
            if (numColumn == n - 1 - numRow) d2 += row[numColumn]
            if (row[numColumn] == 0L) empty = numRow to numColumn
        }
    }

    val sum = if (empty.first == 0) rows[1] else rows[0]
    var rowRequires = 0L
    for ((index, rowSum) in rows.withIndex()) {
        if (index == empty.first) rowRequires = sum - rowSum else if (sum != rowSum) {
            print(-1)
            return
        }
    }
    var columnRequires = 0L
    for ((index, columnSum) in cols.withIndex()) {
        if (index == empty.second) columnRequires = sum - columnSum else if (sum != columnSum) {
            print(-1)
            return
        }
    }

    if (rowRequires != columnRequires || rowRequires == 0L) {
        print(-1)
        return
    }

    if (empty.first == empty.second)
        d1 += rowRequires
    if (d1 != sum) {
        print(-1)
        return
    }

    if (empty.second == n - 1 - empty.first)
        d2 += rowRequires
    if (d2 != sum) {
        print(-1)
        return
    }

    print(rowRequires)
}


fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    val n = readInt()
    if (n == 1) {
        print(1)
        return
    }

    var empty = -1 to -1
    val rows = LongArray(n)
    val cols = LongArray(n)
    var d1 = 0L
    var d2 = 0L

    for (numRow in 0 until n) {
        val row = readLongs()
        for (numColumn in 0 until n) {
            rows[numRow] += row[numColumn]
            cols[numColumn] += row[numColumn]
            if (numRow == numColumn) d1 += row[numColumn]
            if (numColumn == n - 1 - numRow) d2 += row[numColumn]
            if (row[numColumn] == 0L) empty = numRow to numColumn
        }
    }

    val sum = if (empty.first == 0) rows[1] else rows[0]
    var rowRequires = 0L
    for ((index, rowSum) in rows.withIndex()) {
        if (index == empty.first) rowRequires = sum - rowSum else if (sum != rowSum) {
            print(-1)
            return
        }
    }
    var columnRequires = 0L
    for ((index, columnSum) in cols.withIndex()) {
        if (index == empty.second) columnRequires = sum - columnSum else if (sum != columnSum) {
            print(-1)
            return
        }
    }

    if (rowRequires != columnRequires) {
        print(-1)
        return
    }

    if (empty.first == empty.second)
        d1 += rowRequires
    if (d1 != sum) {
        print(-1)
        return
    }

    if (empty.second == n - 1 - empty.first)
        d2 += rowRequires
    if (d2 != sum) {
        print(-1)
        return
    }

    print(rowRequires)
}


fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    val n = readInt()
    if (n == 1) {
        print(1)
        return
    }

    var empty = -1 to -1
    val rows = LongArray(n)
    val cols = LongArray(n)
    var d1 = 0L
    var d2 = 0L

    for (numRow in 0 until n) {
        val row = readLongs()
        for (numColumn in 0 until n) {
            rows[numRow] += row[numColumn]
            cols[numColumn] += row[numColumn]
            if (numRow == numColumn) d1 += row[numColumn]
            if (numColumn == n - 1 - numRow) d2 += row[numColumn]
            if (row[numColumn] == 0L) empty = numRow to numColumn
        }
    }

    val sum = if (empty.first == 0) rows[1] else rows[0]
    var rowRequires = 0L
    for ((index, rowSum) in rows.withIndex()) {
        if (index == empty.first) rowRequires = sum - rowSum else if (sum != rowSum) {
            print(-1)
            return
        }
    }
    var columnRequires = 0L
    for ((index, columnSum) in cols.withIndex()) {
        if (index == empty.second) columnRequires = sum - columnSum else if (sum != columnSum) {
            print(-1)
            return
        }
    }

    if (rowRequires != columnRequires || rowRequires <= 0L) {
        print(-1)
        return
    }

    if (empty.first == empty.second)
        d1 += rowRequires
    if (d1 != sum) {
        print(-1)
        return
    }

    if (empty.second == n - 1 - empty.first)
        d2 += rowRequires
    if (d2 != sum) {
        print(-1)
        return
    }

    print(rowRequires)
}


#include <stdio.h>

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

  int r = -1, c = -1;
  long long sum_row[n];
  long long sum_col[n];
  long long sum_main_diag = 0;
  long long sum_add_diag = 0;
  for (int i = 0; i != n; ++i)
  {
    sum_row[i] = 0;
    for (int k = 0; k != n; ++k)
    {
      long value = 0;
      scanf("%li", &value);
      sum_row[i] += value;

      if (i == 0)
      {
        sum_col[k] = 0;
      }
      sum_col[k] += value;

      if (i == k)
      {
        sum_main_diag += value;
      }

      if (i == n - k - 1)
      {
        sum_add_diag += value;
      }

      if (value == 0)
      {
        r = i;
        c = k;
      }
    }
  }

  //sanity check
  int sane = 1;
  for (int i = 1; i < n && sane; ++i)
  {
    if (i != r && i != r + 1 && sum_row[i] != sum_row[i - 1])
    {
      sane = 0;
    }
    else if (i == r + 1 && i - 2 > -1 && sum_row[i] != sum_row[i - 2])
    {
      sane = 0;
    }
  }

  if (!sane)
  {
    printf("-1");
    return 0;
  }

  for (int i = 1; i < n && sane; ++i)
  {
    if (i != c && i != c + 1 && sum_col[i] != sum_col[i - 1])
    {
      sane = 0;
    }
    else if (i == c + 1 && i - 2 > -1 && sum_col[i] != sum_col[i - 2])
    {
      sane = 0;
    }
  }

  if (!sane)
  {
    printf("-1");
    return 0;
  }

  int sum_row_i = 0;
  if (r - 1 > -1)
  {
    sum_row_i = r - 1;
  }
  else if (r + 1 < n)
  {
    sum_row_i = r + 1;
  }
  else
  {
    printf("1");
    return 0;
  }

  int sum_col_i = 0;
  if (c - 1 > -1)
  {
    sum_col_i = c - 1;
  }
  else if (c + 1 < n)
  {
    sum_col_i = c + 1;
  }
  else
  {
    printf("1");
    return 0;
  }

  if (sum_col[sum_col_i] != sum_row[sum_row_i])
  {
    printf("-1");
    return 0;
  }

  if (r != c && sum_col[sum_col_i] != sum_main_diag)
  {
    printf("-1");
    return 0;
  }

  if (r != n - c - 1 && sum_col[sum_col_i] != sum_add_diag)
  {
    printf("-1");
    return 0;
  }

  long long res = sum_col[sum_col_i] - sum_col[c];
  if (sum_row[sum_row_i] - sum_row[r] != res)
  {
    printf("-1");
    return 0;
  }

  if (r == c && sum_main_diag + res != sum_col[sum_col_i])
  {
    printf("-1");
    return 0;
  }

  if (r == n - c - 1 && sum_add_diag + res != sum_col[sum_col_i])
  {
    printf("-1");
    return 0;
  }

  printf("%lli", res);

  return 0;
}


#include <stdio.h>

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

  int r = -1, c = -1;
  long long sum_row[n];
  long long sum_col[n];
  long long sum_main_diag = 0;
  long long sum_add_diag = 0;
  for (int i = 0; i != n; ++i)
  {
    sum_row[i] = 0;
    for (int k = 0; k != n; ++k)
    {
      long value = 0;
      scanf("%li", &value);
      sum_row[i] += value;

      if (i == 0)
      {
        sum_col[k] = 0;
      }
      sum_col[k] += value;

      if (i == k)
      {
        sum_main_diag += value;
      }

      if (i == n - k - 1)
      {
        sum_add_diag += value;
      }

      if (value == 0)
      {
        r = i;
        c = k;
      }
    }
  }

  //sanity check
  int sane = 1;
  for (int i = 1; i < n && sane; ++i)
  {
    if (i != r && i != r + 1 && sum_row[i] != sum_row[i - 1])
    {
      sane = 0;
    }
    else if (i == r + 1 && i - 2 > -1 && sum_row[i] != sum_row[i - 2])
    {
      sane = 0;
    }
  }

  if (!sane)
  {
    printf("-1");
    return 0;
  }

  for (int i = 1; i < n && sane; ++i)
  {
    if (i != c && i != c + 1 && sum_col[i] != sum_col[i - 1])
    {
      sane = 0;
    }
    else if (i == c + 1 && i - 2 > -1 && sum_col[i] != sum_col[i - 2])
    {
      sane = 0;
    }
  }

  if (!sane)
  {
    printf("-1");
    return 0;
  }

  int sum_row_i = 0;
  if (r - 1 > -1)
  {
    sum_row_i = r - 1;
  }
  else if (r + 1 < n)
  {
    sum_row_i = r + 1;
  }
  else
  {
    printf("1");
    return 0;
  }

  int sum_col_i = 0;
  if (c - 1 > -1)
  {
    sum_col_i = c - 1;
  }
  else if (c + 1 < n)
  {
    sum_col_i = c + 1;
  }
  else
  {
    printf("1");
    return 0;
  }

  if (sum_col[sum_col_i] != sum_row[sum_row_i])
  {
    printf("-1");
    return 0;
  }

  if (r != c && sum_col[sum_col_i] != sum_main_diag)
  {
    printf("-1");
    return 0;
  }

  if (r != n - c - 1 && sum_col[sum_col_i] != sum_add_diag)
  {
    printf("-1");
    return 0;
  }

  long long res = sum_col[sum_col_i] - sum_col[c];
  if (sum_row[sum_row_i] - sum_row[r] != res)
  {
    printf("-1");
    return 0;
  }

  if (r == c && sum_main_diag + res != sum_col[sum_col_i])
  {
    printf("-1");
    return 0;
  }

  if (r == n - c - 1 && sum_add_diag + res != sum_col[sum_col_i])
  {
    printf("-1");
    return 0;
  }

  if (res > 0)
  {
    printf("%lli", res);
  }
  else
  {
    printf("-1");
  }

  return 0;
}


#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 1500
ll arr[N][N];
int check(ll n){
	ll x=0;
	for(int i=0;i<n;i++){
		x+=arr[0][i];
	}
	for(int i=0;i<n;i++){
		ll s=0;
		for(int w=0;w<n;w++){
			s+=arr[i][w];
		}
		if(s!=x){
			return 1;
		}
	}
	for(int i=0;i<n;i++){
		ll s=0;
		for(int w=0;w<n;w++){
			s+=arr[w][i];
		}
		if(s!=x){

			return 1;
		}
	}
	ll s=0;
	for(int i=0;i<n;i++){
		s+=arr[i][i];
	}
	if(s!=x)
	return 1;
	s=0;
	for(int i=0;i<n;i++){
		for(int w=0;w<n;w++){
			if(i+w==n-1)
			s+=arr[i][w];
		}
	}
	if(s!=x)
	return 1;
	return 0;
}
int main(){
	int a,b,c,d;
	scanf("%d",&a);
	if(a==1){
		printf("1");
		return 0;
	}
	int f,f1; int k=0;
	for(int i=0;i<a;i++){
		for(int w=0;w<a;w++){
			scanf("%lld",&arr[i][w]);
			if(arr[i][w]==0){
				f=i;f1=w;
			}
		}
	}
	ll go,go1;
	go=go1=-1;
	for(int i=0;i<a;i++){
		ll s=0;
		for(int w=0;w<a;w++){
			s+=arr[i][w];
		}
		if(go==-1){
			go=s;
		}
		else if(go!=-1 && s!=go && go1==-1){
			go1=s;
		}
	}
	if(go1>go)
	arr[f][f1]=go1-go;
	else arr[f][f1]=go-go1;
	if(check(a))
	printf("-1");
	else if(go-go1==0)
	printf("-1");
	else if(go1>go)
	printf("%d",go1-go);
	else printf("%d",go-go1);
}


#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 1500
int arr[N][N];
int check(int x,int n){
for(int i=0;i<n;i++){
	ll s=0;
	for(int w=0;w<n;w++){
	s+=arr[i][w];
	}
	if(s!=x){
		return 1;
	}
}
for(int i=0;i<n;i++){
	ll s=0;
	for(int w=0;w<n;w++){
		s+=arr[w][i];
	}
	if(s!=x){
		return 1;
	}
}
ll s=0;
for(int i=0;i<n;i++){
	s+=arr[i][i];
}
if(s!=x)
	return 1;
s=0;
for(int i=0;i<n;i++){
	for(int w=0;w<n;w++){
		if(i+w==n-1)
			s+=arr[i][w];
	}
}
if(s!=x)
	return 1;
return 0;
}
int main(){
	int a,b,c,d;
	scanf("%d",&a);
	if(a==1){
		printf("1");
	return 0;
	}
	int f,f1;
	for(int i=0;i<a;i++){
		for(int w=0;w<a;w++){
			scanf("%d",&arr[i][w]);
			if(arr[i][w]==0){
				f=i;f1=w;
			}
		}
	}
	if(f==f1 && f+f1==a-1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			n2+=arr[i][i];
		}
		for(int i=0;i<a;i++){
			for(int w=0;w<a;w++){
				if((i+w)==a-1){
					n3+=arr[i][w];
				}
			}
		}
		arr[f][f1]=m-n;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",m-n);
	}
	else if((f+f1)==a-1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			for(int w=0;w<a;w++){
				if((i+w)==a-1){
					n3+=arr[i][w];
				}
			}
		}
		arr[f][f1]=m-n;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",m-n);
	}
	else if(f==f1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			n2+=arr[i][i];
		}
		arr[f][f1]=m-n;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",m-n);
	}
	else{
		ll n,n1;n=n1=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		arr[f][f1]=m-n;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",m-n);
	}
}


#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 1500
ll arr[N][N];
int check(ll x,ll n){
	for(int i=0;i<n;i++){
		ll s=0;
		for(int w=0;w<n;w++){
			s+=arr[i][w];
		}
		if(s!=x){
			return 1;
		}
	}
	for(int i=0;i<n;i++){
		ll s=0;
		for(int w=0;w<n;w++){
			s+=arr[w][i];
		}
		if(s!=x){

			return 1;
		}
	}
	ll s=0;
	for(int i=0;i<n;i++){
		s+=arr[i][i];
	}
	if(s!=x)
	return 1;
	s=0;
	for(int i=0;i<n;i++){
		for(int w=0;w<n;w++){
			if(i+w==n-1)
			s+=arr[i][w];
		}
	}
	if(s!=x)
	return 1;
	return 0;
}
int main(){
	int a,b,c,d;
	scanf("%d",&a);
	if(a==1){
		printf("1");
		return 0;
	}
	int f,f1;
	for(int i=0;i<a;i++){
		for(int w=0;w<a;w++){
			scanf("%lld",&arr[i][w]);
			if(arr[i][w]==0){
				f=i;f1=w;
			}
		}
	}
	if(f==f1 && f+f1==a-1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			n2+=arr[i][i];
		}
		for(int i=0;i<a;i++){
			for(int w=0;w<a;w++){
				if((i+w)==a-1){
					n3+=arr[i][w];
				}
			}
		}
		if(m>n)
		arr[f][f1]=m-n;
		else arr[f][f1]=n-m;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",arr[f][f1]);
	}
	else if((f+f1)==a-1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			for(int w=0;w<a;w++){
				if((i+w)==a-1){
					n3+=arr[i][w];
				}
			}
		}
		if(m>n)
		arr[f][f1]=m-n;
		else arr[f][f1]=n-m;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",arr[f][f1]);
	}
	else if(f==f1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			n2+=arr[i][i];
		}
		if(m>n)
		arr[f][f1]=m-n;
		else arr[f][f1]=n-m;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		else printf("%d",arr[f][f1]);
	}
	else{
		ll n,n1;n=n1=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		if(m>n)
		arr[f][f1]=m-n;
		else arr[f][f1]=n-m;
		for(int w=0;w<a;w++){
			s=0;
			for(int i=0;i<a;i++){
				s+=arr[i][w];
			}
			break;
		}
		if(check(s,a)){
			printf("-1");
		}
		if(m-n == 0){
			printf("-1");
		}
		else printf("%d",arr[f][f1]);
	}
}


#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 1500
ll arr[N][N];
int check(ll n){
	ll x=0;
	for(int i=0;i<n;i++){
		x+=arr[0][i];
	}
	for(int i=0;i<n;i++){
		ll s=0;
		for(int w=0;w<n;w++){
			s+=arr[i][w];
		}
		if(s!=x){
			return 1;
		}
	}
	for(int i=0;i<n;i++){
		ll s=0;
		for(int w=0;w<n;w++){
			s+=arr[w][i];
		}
		if(s!=x){

			return 1;
		}
	}
	ll s=0;
	for(int i=0;i<n;i++){
		s+=arr[i][i];
	}
	if(s!=x)
	return 1;
	s=0;
	for(int i=0;i<n;i++){
		for(int w=0;w<n;w++){
			if(i+w==n-1)
			s+=arr[i][w];
		}
	}
	if(s!=x)
	return 1;
	return 0;
}
int main(){
	int a,b,c,d;
	scanf("%d",&a);
	if(a==1){
		printf("1");
		return 0;
	}
	int f,f1; int k=0;
	for(int i=0;i<a;i++){
		for(int w=0;w<a;w++){
			scanf("%lld",&arr[i][w]);
			if(arr[i][w]==0){
				f=i;f1=w;
			}
		}
	}
	ll go,go1;
	go=go1=-1;
	for(int i=0;i<a;i++){
		ll s=0;
		for(int w=0;w<a;w++){
			s+=arr[i][w];
		}
		if(go==-1){
			go=s;
		}
		else if(go!=-1 && s!=go && go1==-1){
			go1=s;
		}
	}
	if(go1>go)
	arr[f][f1]=go1-go;
	else arr[f][f1]=go-go1;
	if(check(a))
	printf("-1");
	else if(go-go1==0)
	printf("-1");
	else if(go1>go)
	printf("%lld",go1-go);
	else printf("%lld",go-go1);
}


#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 1500
int arr[N][N];
int main(){
	int a,b,c,d;
	scanf("%d",&a);
	int f,f1;
	for(int i=0;i<a;i++){
		for(int w=0;w<a;w++){
			scanf("%d",&arr[i][w]);
			if(arr[i][w]==0){
				f=i;f1=w;
			}
		}
	}
	if(f==f1 && f+f1==a-1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			n2+=arr[i][i];
		}
		for(int i=0;i<a;i++){
			for(int w=0;w<a;w++){
				if((i+w)==a-1){
					n3+=arr[i][w];
				}
			}
		}
		ll x = n+n1+n2+n3;
		if(x!=4*n){
			printf("-1");
		}
		else printf("%lld",m-n);
	}
	else if(f==f1){
		ll n,n1,n2,n3;n=n1=n2=n3=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		for(int i=0;i<a;i++){
			n2+=arr[i][i];
		}
		ll x = n+n1+n2;
		if(x!=3*n){
			printf("-1");
		}
		else printf("%lld",m-n);
	}
	else{
		ll n,n1;n=n1=0; ll m=0; ll s=0;
		for(int i=0;i<a;i++){
			s=0;
			for(int w=0;w<a;w++){
				s+=arr[i][w];
			}
			if(s>m)
			m=s;
		}
		for(int i=f;i>=0;i--){
			n+=arr[i][f1];
		}
		for(int i=f;i<a;i++){
			n+=arr[i][f1];
		}

		for(int i=f1;i>=0;i--){
			n1+=arr[f][i];
		}
		for(int i=f1;i<a;i++){
			n1+=arr[f][i];
		}
		if(n!=n1){
			printf("-1");
		}
		else printf("%lld",m-n);
	}
}


#include <stdio.h>

int main(){

	int kvadrat[500][500], n, i, j, test_sum, sum1, sum2, glavna, sporedna;
	int nulin_red = -1, nulin_stupac = -1, nulin_sum;

	scanf("%d", &n);

	if (n == 1) {
		printf("1");
		return 0;
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &kvadrat[i][j]);
			if (kvadrat[i][j] == 0) {
				nulin_red = i;
				nulin_stupac = j;
			}
		}
	}

	nulin_sum = test_sum = 0;
	if (nulin_red == 0) {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[0][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[1][j];
	}

	else {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[nulin_red][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[0][j];
	}

	kvadrat[nulin_red][nulin_stupac] = test_sum - nulin_sum;

	/*testiranje magicnosti*/
	glavna = sporedna = 0;
	for (i = 0; i < n; i++) {
		sum1 = sum2 = 0;

		for (j = 0; j < n; j++) {
			sum1 += kvadrat[i][j];
			sum2 += kvadrat[j][i];

			if (i == j) glavna += kvadrat[i][j];
			if (i == n-j-1) sporedna += kvadrat[i][j];

		}

		if (sum1 != test_sum || sum2 != test_sum) {
			printf("-1");
			return 0;
		}

	}

	if (glavna != test_sum || sporedna != test_sum) {
		printf("-1");
		return 0;
	}

	printf("%d", test_sum - nulin_sum);

	return 0;

}


#include <stdio.h>

int main(){

	int kvadrat[500][500], n, i, j, nulin_red, nulin_stupac;
	double test_sum, sum1, sum2, glavna, sporedna, nulin_sum;

	scanf("%d", &n);

	if (n == 1) {
		printf("1");
		return 0;
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &kvadrat[i][j]);
			if (kvadrat[i][j] == 0) {
				nulin_red = i;
				nulin_stupac = j;
			}
		}
	}

	nulin_sum = test_sum = 0;
	if (nulin_red == 0) {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[0][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[1][j];
	}

	else {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[nulin_red][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[0][j];
	}

	kvadrat[nulin_red][nulin_stupac] = test_sum - nulin_sum;

	/*testiranje magicnosti*/
	glavna = sporedna = 0;
	for (i = 0; i < n; i++) {
		sum1 = sum2 = 0;

		for (j = 0; j < n; j++) {
			sum1 += kvadrat[i][j];
			sum2 += kvadrat[j][i];

			if (i == j) glavna += kvadrat[i][j];
			if (i == n-j-1) sporedna += kvadrat[i][j];

		}

		/*printf("%.0f %.0f\n", sum1, sum2);*/

		if (sum1 != test_sum || sum2 != test_sum) {
			printf("-1");
			return 0;
		}

	}

	/*printf("%.0f %.0f\n", glavna, sporedna);*/

	if (glavna != test_sum || sporedna != test_sum || test_sum - nulin_sum == 0) {
		printf("-1");
		return 0;
	}

	printf("%.0f", test_sum - nulin_sum);

	return 0;

}


#include <stdio.h>

int main(){

	int  n, i, j, nulin_red, nulin_stupac;
	double kvadrat[500][500], test_sum, sum1, sum2, glavna, sporedna, nulin_sum;

	scanf("%d", &n);

	if (n == 1) {
		printf("1");
		return 0;
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%lf", &kvadrat[i][j]);
			if (kvadrat[i][j] == 0) {
				nulin_red = i;
				nulin_stupac = j;
			}
		}
	}

	nulin_sum = test_sum = 0;
	if (nulin_red == 0) {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[0][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[1][j];
	}

	else {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[nulin_red][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[0][j];
	}

	kvadrat[nulin_red][nulin_stupac] = test_sum - nulin_sum;

	/*testiranje magicnosti*/
	glavna = sporedna = 0;
	for (i = 0; i < n; i++) {
		sum1 = sum2 = 0;

		for (j = 0; j < n; j++) {
			sum1 += kvadrat[i][j];
			sum2 += kvadrat[j][i];

			if (i == j) glavna += kvadrat[i][j];
			if (i == n-j-1) sporedna += kvadrat[i][j];

		}

		/*printf("%.0f %.0f\n", sum1, sum2);*/

		if (sum1 != test_sum || sum2 != test_sum) {
			printf("-1");
			return 0;
		}

	}

	/*printf("%.0f %.0f\n", glavna, sporedna);*/

	if (glavna != test_sum || sporedna != test_sum || test_sum - nulin_sum <= 0) {
		printf("-1");
		return 0;
	}

	printf("%.0f", test_sum - nulin_sum);

	return 0;

}


#include <stdio.h>

int main(){

	int kvadrat[500][500], n, i, j, nulin_red, nulin_stupac;
	double test_sum, sum1, sum2, glavna, sporedna, nulin_sum;

	scanf("%d", &n);

	if (n == 1) {
		printf("1");
		return 0;
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &kvadrat[i][j]);
			if (kvadrat[i][j] == 0) {
				nulin_red = i;
				nulin_stupac = j;
			}
		}
	}

	nulin_sum = test_sum = 0;
	if (nulin_red == 0) {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[0][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[1][j];
	}

	else {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[nulin_red][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[0][j];
	}

	kvadrat[nulin_red][nulin_stupac] = test_sum - nulin_sum;

	/*testiranje magicnosti*/
	glavna = sporedna = 0;
	for (i = 0; i < n; i++) {
		sum1 = sum2 = 0;

		for (j = 0; j < n; j++) {
			sum1 += kvadrat[i][j];
			sum2 += kvadrat[j][i];

			if (i == j) glavna += kvadrat[i][j];
			if (i == n-j-1) sporedna += kvadrat[i][j];

		}

		/*printf("%.0f %.0f\n", sum1, sum2);*/

		if (sum1 != test_sum || sum2 != test_sum) {
			printf("-1");
			return 0;
		}

	}

	/*printf("%.0f %.0f\n", glavna, sporedna);*/

	if (glavna != test_sum || sporedna != test_sum || test_sum - nulin_sum <= 0) {
		printf("-1");
		return 0;
	}

	printf("%.0f", test_sum - nulin_sum);

	return 0;

}


#include <stdio.h>

int main(){

	int kvadrat[500][500], n, i, j, nulin_red, nulin_stupac;
	double test_sum, sum1, sum2, glavna, sporedna, nulin_sum;

	scanf("%d", &n);

	if (n == 1) {
		printf("1");
		return 0;
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &kvadrat[i][j]);
			if (kvadrat[i][j] == 0) {
				nulin_red = i;
				nulin_stupac = j;
			}
		}
	}

	nulin_sum = test_sum = 0;
	if (nulin_red == 0) {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[0][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[1][j];
	}

	else {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[nulin_red][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[0][j];
	}

	kvadrat[nulin_red][nulin_stupac] = test_sum - nulin_sum;

	/*testiranje magicnosti*/
	glavna = sporedna = 0;
	for (i = 0; i < n; i++) {
		sum1 = sum2 = 0;

		for (j = 0; j < n; j++) {
			sum1 += kvadrat[i][j];
			sum2 += kvadrat[j][i];

			if (i == j) glavna += kvadrat[i][j];
			if (i == n-j-1) sporedna += kvadrat[i][j];

		}

		printf("%.0f %.0f\n", sum1, sum2);

		if (sum1 != test_sum || sum2 != test_sum) {
			printf("-1");
			return 0;
		}

	}

	printf("%.0f %.0f\n", glavna, sporedna);

	if (glavna != test_sum || sporedna != test_sum || test_sum - nulin_sum == 0) {
		printf("-1");
		return 0;
	}

	printf("%.0f", test_sum - nulin_sum);

	return 0;

}


#include <stdio.h>

int main(){

	int kvadrat[500][500], n, i, j, nulin_red, nulin_stupac;
	double test_sum, sum1, sum2, glavna, sporedna, nulin_sum;

	scanf("%d", &n);

	if (n == 1) {
		printf("1");
		return 0;
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &kvadrat[i][j]);
			if (kvadrat[i][j] == 0) {
				nulin_red = i;
				nulin_stupac = j;
			}
		}
	}

	nulin_sum = test_sum = 0;
	if (nulin_red == 0) {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[0][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[1][j];
	}

	else {
		for (j = 0; j < n; j++) nulin_sum += kvadrat[nulin_red][j];
		for (j = 0; j < n; j++) test_sum += kvadrat[0][j];
	}

	kvadrat[nulin_red][nulin_stupac] = test_sum - nulin_sum;

	/*testiranje magicnosti*/
	glavna = sporedna = 0;
	for (i = 0; i < n; i++) {
		sum1 = sum2 = 0;

		for (j = 0; j < n; j++) {
			sum1 += kvadrat[i][j];
			sum2 += kvadrat[j][i];

			if (i == j) glavna += kvadrat[i][j];
			if (i == n-j-1) sporedna += kvadrat[i][j];

		}

		if (sum1 != test_sum || sum2 != test_sum) {
			printf("-1");
			return 0;
		}

	}

	if (glavna != test_sum || sporedna != test_sum) {
		printf("-1");
		return 0;
	}

	printf("%.0f", test_sum - nulin_sum);

	return 0;

}


#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    long long data[n][n];
    int zero_i, zero_j;
    long long result;
    long long sum = 0;
    long long sum_zero = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%I64d", &data[i][j]);
            if (data[i][j] == 0) {
                zero_i = i;
                zero_j = j;
            }
        }
    }
    if (n==1) {
        result = 1;
        goto print;
    }
    if (zero_i == 0) {
        for (int i = 0; i < n; ++i) {
            sum += data[1][i];
        }
    } else {
        for (int i = 0; i < n; ++i) {
            sum += data[0][i];
        }
    }
    for (int i = 0; i < n; ++i) {
        sum_zero += data[zero_i][i];
    }
    result = data[zero_i][zero_j] = sum - sum_zero;
    if (result <= 0) {
        result = -1;
        goto print;
    }
    for (int i = 0; i < n; ++i) {
        long long sum_i = 0;
        for (int j = 0; j < n; ++j) {
            sum_i += data[i][j];
        }
        if (sum_i != sum) {
            result = -1;
            goto print;
        }
    }
    for (int j = 0; j < n; ++j) {
        long long sum_j = 0;
        for (int i = 0; i < n; ++i) {
            sum_j += data[i][j];
        }
        if (sum_j != sum) {
            result = -1;
            goto print;
        }
    }
    long long sum_x1 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x1 += data[i][i];
    }
    if (sum_x1 != sum) {
        result = -1;
        goto print;
    }
    long long sum_x2 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x2 += data[i][n-1-i];
    }
    if (sum_x2 != sum) {
        result = -1;
        goto print;
    }

    print: printf("%I64d\n", result);
    return 0;
}


#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    long long data[n][n];
    int zero_i, zero_j;
    long long result;
    long long sum = 0;
    long long sum_zero = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%I64d", &data[i][j]);
            if (data[i][j] == 0) {
                zero_i = i;
                zero_j = j;
            }
        }
    }
    if (zero_i == 0) {
        for (int i = 0; i < n; ++i) {
            sum += data[1][i];
        }
    } else {
        for (int i = 0; i < n; ++i) {
            sum += data[0][i];
        }
    }
    for (int i = 0; i < n; ++i) {
        sum_zero += data[zero_i][i];
    }
    result = data[zero_i][zero_j] = sum - sum_zero;
    if (result <= 0) {
        result = -1;
        goto print;
    }
    for (int i = 0; i < n; ++i) {
        int sum_i = 0;
        for (int j = 0; j < n; ++j) {
            sum_i += data[i][j];
        }
        if (sum_i != sum) {
            result = -1;
            goto print;
        }
    }
    for (int j = 0; j < n; ++j) {
        int sum_j = 0;
        for (int i = 0; i < n; ++i) {
            sum_j += data[i][j];
        }
        if (sum_j != sum) {
            result = -1;
            goto print;
        }
    }
    int sum_x1 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x1 += data[i][i];
    }
    if (sum_x1 != sum) {
        result = -1;
        goto print;
    }
    int sum_x2 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x2 += data[i][n-1-i];
    }
    if (sum_x2 != sum) {
        result = -1;
        goto print;
    }

    print: printf("%I64d\n", result);
    return 0;
}


#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    long long data[n][n];
    int zero_i, zero_j;
    long long result;
    long long sum = 0;
    long long sum_zero = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%I64d", &data[i][j]);
            if (data[i][j] == 0) {
                zero_i = i;
                zero_j = j;
            }
        }
    }
    if (zero_i == 0) {
        for (int i = 0; i < n; ++i) {
            sum += data[1][i];
        }
    } else {
        for (int i = 0; i < n; ++i) {
            sum += data[0][i];
        }
    }
    for (int i = 0; i < n; ++i) {
        sum_zero += data[zero_i][i];
    }
    result = data[zero_i][zero_j] = sum - sum_zero;
    if (result <= 0) {
        result = -1;
        goto print;
    }
    for (int i = 0; i < n; ++i) {
        long long sum_i = 0;
        for (int j = 0; j < n; ++j) {
            sum_i += data[i][j];
        }
        if (sum_i != sum) {
            result = -1;
            goto print;
        }
    }
    for (int j = 0; j < n; ++j) {
        long long sum_j = 0;
        for (int i = 0; i < n; ++i) {
            sum_j += data[i][j];
        }
        if (sum_j != sum) {
            result = -1;
            goto print;
        }
    }
    long long sum_x1 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x1 += data[i][i];
    }
    if (sum_x1 != sum) {
        result = -1;
        goto print;
    }
    long long sum_x2 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x2 += data[i][n-1-i];
    }
    if (sum_x2 != sum) {
        result = -1;
        goto print;
    }

    print: printf("%I64d\n", result);
    return 0;
}


#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    int data[n][n];
    int zero_i, zero_j;
    int result;
    int sum = 0;
    int sum_zero = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%d", &data[i][j]);
            if (data[i][j] == 0) {
                zero_i = i;
                zero_j = j;
            }
        }
    }
    if (zero_i == 0) {
        for (int i = 0; i < n; ++i) {
            sum += data[1][i];
        }
    } else {
        for (int i = 0; i < n; ++i) {
            sum += data[0][i];
        }
    }
    for (int i = 0; i < n; ++i) {
        sum_zero += data[zero_i][i];
    }
    result = data[zero_i][zero_j] = sum - sum_zero;
    if (result <= 0) {
        result = -1;
        goto print;
    }
    for (int i = 0; i < n; ++i) {
        int sum_i = 0;
        for (int j = 0; j < n; ++j) {
            sum_i += data[i][j];
        }
        if (sum_i != sum) {
            result = -1;
            goto print;
        }
    }
    for (int j = 0; j < n; ++j) {
        int sum_j = 0;
        for (int i = 0; i < n; ++i) {
            sum_j += data[i][j];
        }
        if (sum_j != sum) {
            result = -1;
            goto print;
        }
    }
    int sum_x1 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x1 += data[i][i];
    }
    if (sum_x1 != sum) {
        result = -1;
        goto print;
    }
    int sum_x2 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x2 += data[i][n-1-i];
    }
    if (sum_x2 != sum) {
        result = -1;
        goto print;
    }

    print: printf("%d\n", result);
    return 0;
}


#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    int data[n][n];
    int zero_i, zero_j;
    int result;
    int sum = 0;
    int sum_zero = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%d", &data[i][j]);
            if (data[i][j] == 0) {
                zero_i = i;
                zero_j = j;
            }
        }
    }
    if (zero_i == 0) {
        for (int i = 0; i < n; ++i) {
            sum += data[1][i];
        }
    } else {
        for (int i = 0; i < n; ++i) {
            sum += data[0][i];
        }
    }
    for (int i = 0; i < n; ++i) {
        sum_zero += data[zero_i][i];
    }
    result = data[zero_i][zero_j] = sum - sum_zero;
    if (result < 0) {
        result = -1;
        goto print;
    }
    for (int i = 0; i < n; ++i) {
        int sum_i = 0;
        for (int j = 0; j < n; ++j) {
            sum_i += data[i][j];
        }
        if (sum_i != sum) {
            result = -1;
            goto print;
        }
    }
    for (int j = 0; j < n; ++j) {
        int sum_j = 0;
        for (int i = 0; i < n; ++i) {
            sum_j += data[i][j];
        }
        if (sum_j != sum) {
            result = -1;
            goto print;
        }
    }
    int sum_x1 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x1 += data[i][i];
    }
    if (sum_x1 != sum) {
        result = -1;
        goto print;
    }
    int sum_x2 = 0;
    for (int i = 0; i < n; ++i) {
        sum_x2 += data[i][n-1-i];
    }
    if (sum_x2 != sum) {
        result = -1;
        goto print;
    }

    print: printf("%d\n", result);
    return 0;
}


#include <stdio.h>
int n,OI,OJ;
long long ans,map[510][510];
int main()
{
    int i,j;
    long long sum,tmp;
    scanf("%d",&n);
    if(n == 1) { printf("1"); return 0;}
    for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%I64d",&map[i][j]);

    for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(!map[i][j])
    {
        OI = i; OJ = j;
        goto CALC;
    }

    CALC:
    for(i=1;i<=n;i++) if(i != OI)
    {
        sum = 0;
        for(j=1;j<=n;j++) sum += map[i][j];
        break;
    }
    for(j=1;j<=n;j++) ans += map[OI][j];
    ans = sum-ans;
    if(!ans) goto FAILED;
    map[OI][OJ] = ans;

    for(i=1;i<=n;i++)
    {
        tmp = 0;
        for(j=1;j<=n;j++) tmp += map[i][j];
        if(tmp != sum) goto FAILED;
    }
    for(j=1;j<=n;j++)
    {
        tmp = 0;
        for(i=1;i<=n;i++) tmp += map[i][j];
        if(tmp != sum) goto FAILED;
    }
    tmp = 0;
    for(i=1;i<=n;i++) tmp += map[i][i];
    if(tmp != sum) goto FAILED;
    tmp = 0;
    for(i=1;i<=n;i++) tmp += map[i][n-i+1];
    if(tmp != sum) goto FAILED;

    printf("%I64d",ans); return 0;
    FAILED:
    printf("-1"); return 0;
}


#include <stdio.h>
int n,OI,OJ;
long long ans,map[510][510];
int main()
{
    int i,j;
    long long sum,tmp;
    scanf("%d",&n);
    if(n == 1) { printf("1"); return 0;}
    for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%I64d",&map[i][j]);

    for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(!map[i][j])
    {
        OI = i; OJ = j;
        goto CALC;
    }

    CALC:
    for(i=1;i<=n;i++) if(i != OI)
    {
        sum = 0;
        for(j=1;j<=n;j++) sum += map[i][j];
        break;
    }
    for(j=1;j<=n;j++) ans += map[OI][j];
    ans = sum-ans;
    if(ans<=0) goto FAILED;
    map[OI][OJ] = ans;

    for(i=1;i<=n;i++)
    {
        tmp = 0;
        for(j=1;j<=n;j++) tmp += map[i][j];
        if(tmp != sum) goto FAILED;
    }
    for(j=1;j<=n;j++)
    {
        tmp = 0;
        for(i=1;i<=n;i++) tmp += map[i][j];
        if(tmp != sum) goto FAILED;
    }
    tmp = 0;
    for(i=1;i<=n;i++) tmp += map[i][i];
    if(tmp != sum) goto FAILED;
    tmp = 0;
    for(i=1;i<=n;i++) tmp += map[i][n-i+1];
    if(tmp != sum) goto FAILED;

    printf("%I64d",ans); return 0;
    FAILED:
    printf("-1"); return 0;
}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }
    if(sum2 != sum)
    {
        flag = 1;
    }

    sum2=0;
    for(i=n-1; i>=0; i--)
    {
        sum2 += mat[i][i];
    }
    if(sum2 != sum)
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }

    long long sum3=0;
    for(i=n-1; i>=0; i--)
    {
        sum3 += mat[i][i];
    }

    if(sum2 != sum || sum3 != sum2 || sum3 != sum)
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }
    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }
    if(sum2 != sum)
    {
        flag = 1;
    }

    sum2=0;
    for(i=n-1; i>=0; i--)
    {
        sum2 += mat[i][i];
    }
    if(sum2 != sum)
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }
    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;
    if(mat[x][y] < 0)
    {
        printf("-1");
        return 0;
    }

    /*
    for(i=0; i<n; i++)
    {
        sum2=0;
        for(j=0; j<n; j++)
            sum2 += mat[i][j];
        if(sum != sum2)
        {
            flag = 1;
            break;
        }
    }
    */

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            flag = 1;
            break;
        }
    }

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    long long int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%lld", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }

    long long sum3=0;
    for(i=n-1; i>=0; i--)
    {
        sum3 += mat[i][n-1-i];
    }

    if(sum2 == sum && sum3 == sum2 && sum3 == sum)
        flag = 0;
    else
        flag = 1;

    if(flag == 0)
        printf("%lld", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }

    long long sum3=0;
    for(i=n-1; i>=0; i--)
    {
        sum3 += mat[i][i];
    }
    if(sum2 != sum || sum3 != sum2)
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int x, y;
    int i, j;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
   {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum, sum1, sum2;
    int flag;
    for(i=0; i<n; i++)
    {
        if(i != x)
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;
    if(mat[x][y] < 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
            sum2 += mat[i][j];
        if(sum2 != sum)
        {
            flag = 1;
            break;
        }
    }

    if(flag == 0)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2=0;
            for(i=0; i<n; i++)
                sum2 += mat[i][j];
            if(sum2 != sum)
            {
                flag = 1;
                break;
            }
        }
    }

    long long xx=0, yy=0;
    if(flag == 0)
    {
        sum2 = 0;
        for(i=0; i<n; i++)
            sum2 += mat[xx++][yy++];
        if(sum2 != sum)
            flag = 1;
    }
    if(flag == 0)
    {
        sum2=0;
        xx=0;yy=n-1;
        for(i=0;i<n;i++)
            sum2 += mat[xx++][yy--];
        if(sum2 != sum)
            flag=1;
    }
    if(flag==0)
        printf("I64d", mat[x][y]);
    else
        printf("=1");
    return 0;
}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }

    long long sum3=0;
    for(i=n-1; i>=0; i--)
    {
        sum3 += mat[i][i];
    }

    if(sum2 == sum && sum3 == sum2 && sum3 == sum)
        flag = 0;
    else
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }

    long long sum3=0;
    for(i=n-1; i>=0; i--)
    {
        sum3 += mat[i][n-1-i];
    }

    if(sum2 == sum && sum3 == sum2 && sum3 == sum)
        flag = 0;
    else
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }
    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;
    if(mat[x][y] < 0)
    {
        printf("-1");
        return 0;
    }

    /*
    for(i=0; i<n; i++)
    {
        sum2=0;
        for(j=0; j<n; j++)
            sum2 += mat[i][j];
        if(sum != sum2)
        {
            flag = 1;
            break;
        }
    }
    */

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            flag = 1;
            break;
        }
    }

    if(flag == 0)
        printf("I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }
    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    /*
    for(i=0; i<n; i++)
    {
        sum2=0;
        for(j=0; j<n; j++)
            sum2 += mat[i][j];
        if(sum != sum2)
        {
            flag = 1;
            break;
        }
    }
    */

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            flag = 1;
            break;
        }
    }

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }

    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            //flag = 1;
            //break;
            printf("-1");
            return 0;
        }
    }

    sum2 = 0;
    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }

    long long sum3=0;
    for(i=n-1; i>=0; i--)
    {
        sum3 += mat[i][i];
    }
    if(sum2 != sum && sum3 != sum2)
        flag = 1;

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
        else
            for(j=0; j<n; j++)
                sum1 += mat[i][j];
    }

    mat[x][y] = sum - sum1;
    if(mat[x][y] < 0)
    {
        printf("-1");
        return 0;
    }

    /*
    for(i=0; i<n; i++)
    {
        sum2=0;
        for(j=0; j<n; j++)
            sum2 += mat[i][j];
        if(sum != sum2)
        {
            flag = 1;
            break;
        }
    }
    */

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
            if(sum2 != sum)
            {
                flag = 1;
                break;
            }
        }
    }

    if(flag == 0)
        printf("I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}


#include<stdio.h>

int main()
{
    int n;
    int mat[500][500];
    int i, j;
    int x,y;

    scanf("%d", &n);
    if(n == 1)
    {
        printf("1");
        return 0;
    }

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%d", &mat[i][j]);
            if(mat[i][j] == 0)
            {
                x = i;
                y = j;
            }
        }
    }

    long long sum=0, sum1=0, sum2=0;
    int flag = 0;
    for(i=0; i<n; i++)
    {
        if(i != x)
        {
            for(j=0; j<n; j++)
                sum += mat[i][j];
            break;
        }
    }
    for(j=0; j<n; j++)
        sum1 += mat[x][j];

    mat[x][y] = sum - sum1;

    if(mat[x][y] <= 0)
    {
        printf("-1");
        return 0;
    }

    /*
    for(i=0; i<n; i++)
    {
        sum2=0;
        for(j=0; j<n; j++)
            sum2 += mat[i][j];
        if(sum != sum2)
        {
            flag = 1;
            break;
        }
    }
    */

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[i][j];
        }
        if(sum2 != sum)
        {
            flag = 1;
            break;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 = 0;
        for(j=0; j<n; j++)
        {
            sum2 += mat[j][i];
        }
        if(sum2 != sum)
        {
            flag = 1;
            break;
        }
    }

    for(i=0; i<n; i++)
    {
        sum2 += mat[i][i];
    }
    if(sum2 != sum)
    {
        flag = 1;
    }

    if(flag == 0)
        printf("%I64d", mat[x][y]);
    else
        printf("-1");
    return 0;

}