#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(i == x)
            continue;
        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");

    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");

    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    sum[x] += arr[x][y];
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
int main()
{
    scanf("%lld",&n);
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr;
    sumc = sumr = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(i == x)
            continue;
        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    cout << sumr - sr << "\n";

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502], sumi[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    rep(i,0,n)
        rep(j,0,n)
            sumi[i] += arr[j][i];

    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
  //  cout << sumr << " " << sumc << "\n";
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    sum[x] += arr[x][y]; sumi[y] += arr[x][y];
    bool can = true;
    for(int i = 0; i < n; ++i){
        if(sum[i] != sumr || sumi[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can || sumr - sr <= 0)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");

    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(i == x)
            continue;
        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502], sumi[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            sumi[j] += arr[j][i];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
    cout << sumr << " " << sumc << "\n";
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    sum[x] += arr[x][y]; sumi[y] += arr[x][y];
    bool can = true;
    for(int i = 0; i < n; ++i){
        if(sum[i] != sumr || sumi[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502], sumi[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    rep(i,0,n)
        rep(j,0,n)
            sumi[i] += arr[j][i];

    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
  //  cout << sumr << " " << sumc << "\n";
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    sum[x] += arr[x][y]; sumi[y] += arr[x][y];
    bool can = true;
    for(int i = 0; i < n; ++i){
        if(sum[i] != sumr || sumi[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502], sumi[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
bool solved(int i,int j)
{
    ll sr,sc,smr,sml;
    sr = sc = smr = sml = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    rep(i,0,n)
        sml += arr[i][i];
    rep(i,0,n)
        smr += arr[i][n - i - 1];
    return smr == sml && smr == sr && smr == sc;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            sumi[j] += arr[j][i];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr, sml,smr;
    sumc = sumr = smr = sml = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
  //  cout << sumr << " " << sumc << "\n";
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    if(sumr - sr == 0)
        return puts("-1");
    arr[x][y] = sumr - sr;
    sum[x] += arr[x][y]; sumi[y] += arr[x][y];
    bool can = true;
    for(int i = 0; i < n; ++i){
        if(sum[i] != sumr || sumi[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");

    solved(x,y) ? cout << sumr - sr : cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr;
    sumc = sumr = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(i == x)
            continue;
        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    cout << (sumr - sr == 0 ? -1 : sumr - sr) << "\n";

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (ll)1e10
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);
ll arr[502][502],n , x , y , sum[502];
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < n;
}
int main()
{
    scanf("%lld",&n);
    if(n == 1)
        return puts("1");
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            scanf("%lld",&arr[i][j]);
            sum[i] += arr[i][j];
            if(arr[i][j] == 0)
                x = i , y = j;
        }

    }
    ll sumc , sumr;
    sumc = sumr = 0;
    if(valid(x + 1, y + 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y + 1];

    else if(valid(x - 1, y + 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y + 1];

    else if(valid(x + 1, y - 1))
        rep(i,0,n)
            sumr += arr[x+1][i], sumc += arr[i][y - 1];

    else if(valid(x - 1, y - 1))
        rep(i,0,n)
            sumr += arr[x-1][i], sumc += arr[i][y - 1];
    if(sumr != sumc)return puts("-1");
    bool can = true;
    for(int i = 0; i < n; ++i){

        if(i == x)
            continue;
        if(sum[i] != sumr)
        {
            can = false;
            break;
        }
    }
    if(!can)
        return puts("-1");
    ll sc, sr;
    sc = sr = 0;
    rep(i,0,n)
        sr += arr[x][i],sc += arr[i][y];
    cout << sumr - sr << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<ll>> grid(n,vector<ll>(n));
    pair<int,int> idx = {-1,-1};
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            cin>>grid[i][j];
            if(grid[i][j]==0)
                idx = {i,j};
        }
    if(n==1 && idx.first != -1){
        cout<<1<<"\n";
        return 0;
    }
    unordered_set<ll> allsum;
    bool r,c,d,di;
    d = (idx.first == idx.second);
    di = (idx.first == n-idx.second-1);
    ll row_rem = -1,col_rem=-1;
    ll d1 = 0, d2 =0;
    for(int i=0; i<n; i++){
        d1 += grid[i][i];
        d2 += grid[i][n-i-1];
        r = (i==idx.first);
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += grid[i][j];
        }
        // cout<<r<<" "<<sum<<"\n";
        if(r)
            row_rem = sum;
        else{
            allsum.insert(sum);
        }
    }
    if(!d)
        allsum.insert(d1);
    if(!di)
        allsum.insert(d2);
    if(allsum.size()>1){
        // cout<<row_rem<<" "<<d1<<" "<<d2<<"\n";
        // for(auto& a:allsum)
        //     cout<<a<<" hi\n";
        cout<<-1<<"\n";
        return 0;
    }
    for(int j=0; j<n; j++){
        c = (j==idx.second);
        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += grid[i][j];
        }
        if(!c)
            allsum.insert(sum);
        else{
            col_rem = sum;
        }
    }
    if(allsum.size()>1 || ((((!d && !di) || (d && di)) && d1!=d2)) || (row_rem!=col_rem) ){
        // cout<<row_rem<<" "<<d1<<" "<<d2<<"\n";
        // for(auto& a:allsum)
        //     cout<<a<<" hi\n";
        cout<<-1<<"\n";
        return 0;
    }
    ll res = *allsum.begin() - row_rem;
    cout<<((res>0)?res:-1)<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<ll>> grid(n,vector<ll>(n));
    pair<int,int> idx = {-1,-1};
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            cin>>grid[i][j];
            if(grid[i][j]==0)
                idx = {i,j};
        }
    unordered_set<ll> allsum;
    bool r,c,d,di;
    d = (idx.first == idx.second);
    di = (idx.first == n-idx.second-1);
    ll row_rem = -1,col_rem=-1;
    ll d1 = 0, d2 =0;
    for(int i=0; i<n; i++){
        d1 += grid[i][i];
        d2 += grid[i][n-i-1];
        r = (i==idx.first);
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += grid[i][j];
        }
        // cout<<r<<" "<<sum<<"\n";
        if(r)
            row_rem = sum;
        else{
            allsum.insert(sum);
        }
    }
    if(!d)
        allsum.insert(d1);
    if(!di)
        allsum.insert(d2);
    if(allsum.size()>1){
        // cout<<row_rem<<" "<<d1<<" "<<d2<<"\n";
        // for(auto& a:allsum)
        //     cout<<a<<" hi\n";
        cout<<-1<<"\n";
        return 0;
    }
    for(int j=0; j<n; j++){
        c = (j==idx.second);
        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += grid[i][j];
        }
        if(!c)
            allsum.insert(sum);
        else{
            col_rem = sum;
        }
    }
    if(allsum.size()>1 || ((((!d && !di) || (d && di)) && d1!=d2)) || (row_rem!=col_rem)){
        // cout<<row_rem<<" "<<d1<<" "<<d2<<"\n";
        // for(auto& a:allsum)
        //     cout<<a<<" hi\n";
        cout<<-1<<"\n";
        return 0;
    }
    cout<<*allsum.begin() - row_rem<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<ll>> grid(n,vector<ll>(n));
    pair<int,int> idx = {-1,-1};
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            cin>>grid[i][j];
            if(grid[i][j]==0)
                idx = {i,j};
        }
    if(n==1 && idx.first != -1){
        cout<<1<<"\n";
        return 0;
    }
    unordered_set<ll> allsum;
    bool r,c,d,di;
    d = (idx.first == idx.second);
    di = (idx.first == n - idx.second-1);
    ll row_rem = -1,col_rem=-1;
    ll d1 = 0, d2 =0;
    ll beensum = 0;
    for(int i=0; i<n; i++){
        d1 += grid[i][i];
        d2 += grid[i][n-i-1];
        r = (i==idx.first);
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += grid[i][j];
        }
        if(r)
            row_rem = sum;
        else
            beensum = sum;
        allsum.insert(sum);
    }
    for(int j=0; j<n; j++){
        c = (j==idx.second);
        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += grid[i][j];
        }
        if(c)
            col_rem = sum;
        allsum.insert(sum);
    }
    allsum.insert(d1);
    allsum.insert(d2);
    for(auto a: allsum)
        cout<<a<<" ";
    cout<<row_rem<<" "<<col_rem<<" "<<d1<<" "<<d2<<"\n";
    if(allsum.size()!=2 || (row_rem!=col_rem) || (!d && d1!=beensum) || (!di && d2!=beensum)){
        cout<<-1<<"\n";
        return 0;
    }
    ll res = beensum - row_rem;
    cout<<((res>0)?res:-1)<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<ll>> grid(n,vector<ll>(n));
    pair<int,int> idx = {-1,-1};
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            cin>>grid[i][j];
            if(grid[i][j]==0)
                idx = {i,j};
        }
    if(n==1 && idx.first != -1){
        cout<<1<<"\n";
        return 0;
    }
    unordered_set<ll> allsum;
    bool r,c;
    ll row_rem = -1,col_rem=-1;
    ll d1 = 0, d2 =0;
    ll beensum = 0;
    for(int i=0; i<n; i++){
        d1 += grid[i][i];
        d2 += grid[i][n-i-1];
        r = (i==idx.first);
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += grid[i][j];
        }
        if(r)
            row_rem = sum;
        else
            beensum = sum;
        allsum.insert(sum);
    }
    for(int j=0; j<n; j++){
        c = (j==idx.second);
        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += grid[i][j];
        }
        if(c)
            col_rem = sum;
        allsum.insert(sum);
    }
    allsum.insert(d1);
    allsum.insert(d2);
    // for(auto a: allsum)
    //     cout<<a<<" ";
    // cout<<row_rem<<" "<<col_rem<<" "<<d1<<" "<<d2<<"\n";
    if(allsum.size()!=2 || (row_rem!=col_rem)){
        cout<<-1<<"\n";
        return 0;
    }
    ll res = beensum - row_rem;
    cout<<((res>0)?res:-1)<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<ll>> grid(n,vector<ll>(n));
    pair<int,int> idx = {-1,-1};
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            cin>>grid[i][j];
            if(grid[i][j]==0)
                idx = {i,j};
        }
    if(n==1 && idx.first != -1){
        cout<<1<<"\n";
        return 0;
    }
    unordered_set<ll> allsum;
    bool r,c,d,di;
    d = (idx.first == idx.second);
    di = (idx.first == n-idx.second-1);
    ll row_rem = -1,col_rem=-1;
    ll d1 = 0, d2 =0;
    for(int i=0; i<n; i++){
        d1 += grid[i][i];
        d2 += grid[i][n-i-1];
        r = (i==idx.first);
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += grid[i][j];
        }
        // cout<<r<<" "<<sum<<"\n";
        if(r)
            row_rem = sum;
        else{
            allsum.insert(sum);
        }
    }
    if(!d)
        allsum.insert(d1);
    if(!di)
        allsum.insert(d2);
    if(allsum.size()>1){
        // cout<<row_rem<<" "<<d1<<" "<<d2<<"\n";
        // for(auto& a:allsum)
        //     cout<<a<<" hi\n";
        cout<<-1<<"\n";
        return 0;
    }
    for(int j=0; j<n; j++){
        c = (j==idx.second);
        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += grid[i][j];
        }
        if(!c)
            allsum.insert(sum);
        else{
            col_rem = sum;
        }
    }
    if(allsum.size()>1 || ((((!d && !di) || (d && di)) && d1!=d2)) || (row_rem!=col_rem)){
        // cout<<row_rem<<" "<<d1<<" "<<d2<<"\n";
        // for(auto& a:allsum)
        //     cout<<a<<" hi\n";
        cout<<-1<<"\n";
        return 0;
    }
    cout<<*allsum.begin() - row_rem<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<ll>> grid(n,vector<ll>(n));
    pair<int,int> idx = {-1,-1};
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++){
            cin>>grid[i][j];
            if(grid[i][j]==0)
                idx = {i,j};
        }
    if(n==1 && idx.first != -1){
        cout<<1<<"\n";
        return 0;
    }
    unordered_set<ll> allsum;
    bool r,c,d,di;
    d = (idx.first == idx.second);
    di = (idx.first == n - idx.second-1);
    ll row_rem = -1,col_rem=-1;
    ll d1 = 0, d2 =0;
    ll beensum = 0;
    for(int i=0; i<n; i++){
        d1 += grid[i][i];
        d2 += grid[i][n-i-1];
        r = (i==idx.first);
        ll sum = 0;
        for(int j=0; j<n; j++){
            sum += grid[i][j];
        }
        if(r)
            row_rem = sum;
        else
            beensum = sum;
        allsum.insert(sum);
    }
    for(int j=0; j<n; j++){
        c = (j==idx.second);
        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += grid[i][j];
        }
        if(c)
            col_rem = sum;
        allsum.insert(sum);
    }
    allsum.insert(d1);
    allsum.insert(d2);
    // for(auto a: allsum)
    //     cout<<a<<" ";
    // cout<<row_rem<<" "<<col_rem<<" "<<d1<<" "<<d2<<"\n";
    if(allsum.size()!=2 || (row_rem!=col_rem) || (!d && d1!=beensum) || (!di && d2!=beensum)){
        cout<<-1<<"\n";
        return 0;
    }
    ll res = beensum - row_rem;
    cout<<((res>0)?res:-1)<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }
    if(v[0]==v.back() && row==col && row!=ans)
        cout<<ans-col;
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0,d1=0,d2=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }

//    cout<<row<<" "<<col<<" "<<d1<<" "<<d2<<"\n";
    if(v[0]==v.back() && row==col && row!=ans)
    {
        v.clear();
        int tmp=col;
        d1=0,d2=0;
//        cout<<a[x][y]<<"\n";
        a[x][y]=ans-tmp;
//        cout<<a[x][y]<<"\n";
        for(int j=1; j<=n; j++)
        {
            row=0,col=0;
            for(int i=1; i<=n; i++)
            {
                col+=a[i][j];
                row+=a[j][i];
            }
            v.push_back(row);
            v.push_back(col);
        }

        for(int i=1; i<=n; i++)
        {
            d1+=a[i][i];
            d2+=a[i][n-i+1];
        }
        v.push_back(d1);
        v.push_back(d2);
/*        for(auto &x : v)
            cout<<x<<" ";
        cout<<"\n";
*/        sort(v.begin(), v.end());
        if(v[0]==v.back())
            cout<<ans-tmp;
        else
            cout<<"-1";
    }
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }
    if(v[0]==v.back() && row==col)
        cout<<ans-col;
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0,d1=0,d2=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }

//    cout<<row<<" "<<col<<" "<<d1<<" "<<d2<<"\n";
    if(v[0]==v.back() && row==col && row!=ans)
    {
        v.clear();
        d1=0,d2=0;
//        cout<<a[x][y]<<"\n";
        a[x][y]=col;
//        cout<<a[x][y]<<"\n";
        for(int j=1; j<=n; j++)
        {
            row=0,col=0;
            for(int i=1; i<=n; i++)
            {
                col+=a[i][j];
                row+=a[j][i];
            }
            v.push_back(row);
            v.push_back(col);
        }

        for(int i=1; i<=n; i++)
        {
            d1+=a[i][i];
            d2+=a[i][n-i+1];
        }
        v.push_back(d1);
        v.push_back(d2);
/*        for(auto &x : v)
            cout<<x<<" ";
        cout<<"\n";
*/        sort(v.begin(), v.end());
        if(v[0]==v.back() && a[x][y]>0)
            cout<<a[x][y];
        else
            cout<<"-1";
    }
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0,d1=0,d2=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }

//    cout<<row<<" "<<col<<" "<<d1<<" "<<d2<<"\n";
    if(v[0]==v.back() && row==col && row!=ans)
    {
        v.clear();
        d1=0,d2=0;
//        cout<<a[x][y]<<"\n";
        a[x][y]=ans-col;
//        cout<<a[x][y]<<"\n";
        for(int j=1; j<=n; j++)
        {
            row=0,col=0;
            for(int i=1; i<=n; i++)
            {
                col+=a[i][j];
                row+=a[j][i];
            }
            v.push_back(row);
            v.push_back(col);
        }

        for(int i=1; i<=n; i++)
        {
            d1+=a[i][i];
            d2+=a[i][n-i+1];
        }
        v.push_back(d1);
        v.push_back(d2);
/*        for(auto &x : v)
            cout<<x<<" ";
        cout<<"\n";
*/        sort(v.begin(), v.end());
        if(v[0]==v.back() && a[x][y]>0)
            cout<<a[x][y];
        else
            cout<<"-1";
    }
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }
    if(v[0]==v.back() && row==col && row!=0)
        cout<<ans-col;
    else
        cout<<"-1";
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

vector <int> v;

int32_t main()
{
    int a[505][505];
    int n,T,ans=5;
    int x,y,row=0,col=0,d1=0,d2=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0)
                x=i,y=j;
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(x==i) continue;
        ans=0;
        for(int j=1; j<=n; j++)
        {
            ans+=a[i][j];
        }
        v.push_back(ans);
    }

    sort(v.begin(), v.end());

    for(int i=1; i<=n; i++)
    {
        col+=a[i][y];
    }
    for(int i=1; i<=n; i++)
    {
        row+=a[x][i];
    }

    for(int i=1; i<=n; i++)
        d1+=a[i][i];
    for(int i=1; i<=n; i++)
        d2+=a[i][n-i+1];

//    cout<<row<<" "<<col<<" "<<d1<<" "<<d2<<"\n";
    if(x+y==n+1 && x!=y && d2!=row)
    {
        cout<<"-1";return 0;
    }
    if(x+y==n+1 && x==y && d1!=d2 && d2!=row)
    {
        cout<<"-1";return 0;
    }

    if(v[0]==v.back() && row==col && row!=ans && (x!=y || d1==row ))
        cout<<ans-col;
    else
        cout<<"-1";
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#define int long long int
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	if(sum-ssum>0)cout<<sum-ssum<<endl;
	else cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    ll n;
	cin>>n;
	ll arr[n][n];
	ll x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	ll sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	ll ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		ll currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		ll currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	ll currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	if(sum-ssum>0)cout<<sum-ssum<<endl;
	else cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	cout<<sum-ssum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	if(sum-ssum>0)cout<<sum-ssum<<endl;
	else cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	cout<<sum-ssum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	cout<<"waassssuuppp"<<endl;
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	cout<<sum-ssum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	cout<<sum-ssum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	if(sum-ssum>0)cout<<sum-ssum<<endl;
	else cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
#define int ll
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
	cin>>n;
	int arr[n][n];
	int x_empty,y_empty;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin>>arr[i][j];
			if(arr[i][j]==0){x_empty=i;y_empty=j;}
		}
	}
	int sum=0;
	if(x_empty!=0){
		for(int i =0;i<n;i++){
			sum+=arr[x_empty-1][i];
		}
	}
	else{
		for(int i =0;i<n;i++){
			sum+=arr[x_empty+1][i];
		}
	}
	int ssum=0;
	for(int i =0;i<n;i++){
		ssum+=arr[x_empty][i];
	}
	arr[x_empty][y_empty]=sum-ssum;

	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[i][j];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	for(int i = 0;i<n;i++){
		int currsum=0;
		for(int j =0;j<n;j++){
			currsum+=arr[j][i];
		}
		if(currsum!=sum){
			cout<<"-1";return;
		}
	}
	int currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][i];
	}
	if(sum!=currsum){cout<<"-1";return;}
	currsum=0;
	for(int i = 0;i<n;i++){
		currsum+=arr[i][n-i-1];
	}
	if(sum!=currsum){cout<<"-1";return;}
	if(sum-ssum>0)cout<<sum-ssum<<endl;
	else cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
int mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    if(Ans-SS==0)return cout<<-1,0;
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D2!=Ans||D1!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
int mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    //cout<<Ans<<'\n';
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D2!=Ans||D1!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
long long mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    if(Ans-SS<=0)return cout<<-1,0;
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=SS)return cout<<-1,0;
    }
    if(D2!=D2)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
int mm[N][N];
int main()
{
    int n,idxi,idxj,Ans,x;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D2!=Ans||D1!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
int mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    if(Ans-SS<=0)return cout<<-1,0;
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D2!=Ans||D1!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
long long mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    if(Ans-SS<=0)return cout<<-1,0;
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D1!=Ans||D2!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
int mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    if(Ans-SS)return cout<<-1,0;
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D2!=Ans||D1!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
const int N=500+10;
int mm[N][N];
int main()
{
    int n,idxi,idxj,x;
    long long Ans=0;
    cin>>n;
    if(n==1)
    {
        cin>>x;
        cout<<1;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        long long S=0;
        bool ok=true;
        for(int j=0;j<n;++j)
        {
            cin>>mm[i][j];
            if(mm[i][j]==0)
            {
                 idxi=i,idxj=j;
                 ok=false;
            }
            S+=mm[i][j];
        }
        if(ok)Ans=S;
    }
    long long SS=0;
    for(int i=0;i<n;++i)
    {
        SS+=mm[idxi][i];
    }
    mm[idxi][idxj]=Ans-SS;
    long long D1=0,D2=0;
    cout<<Ans<<'\n';
    for(int i=0;i<n;++i)
    {
        long long S=0,SS=0,D=0;
        for(int j=0;j<n;++j)
        {
            if(i==j)D1+=mm[i][j];
            if(i+j==n-1)D2+=mm[i][j];
            S+=mm[i][j];
            SS+=mm[j][i];
        }
        if(S!=Ans||SS!=Ans)return cout<<-1,0;
    }
    if(D2!=Ans||D1!=Ans)cout<<-1;
    else cout<<mm[idxi][idxj];
    return 0;
}


//https://codeforces.com/contest/711/problem/B
#include <bits/stdc++.h>
using namespace std;

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define en '\n'

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef list<int> li;
typedef map<int, int> mi;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//think of special cases, limits, ll vs int

int n;
int a[505][505];

void solve(){
    cin>>n;

    int r0, c0;

    fori(i, 1, n){
        fori(j, 1, n){
            cin>>a[i][j];

            if(a[i][j]==0){
                r0 = i;
                c0 = j;
            }
        }
    }

	if (n == 1) {
		cout << 1 << endl;
		return;
	}

    set<lli> st;

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[i][j];
        }

        st.insert(sum);
    }

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[j][i];
        }

        st.insert(sum);
    }
    lli sum = 0;

    fori(i, 1, n){
        sum += a[i][i];
    }

    st.insert(sum);

    sum = 0;

    fori(i, 1, n){
        sum += a[i][n+1-i];
    }

    st.insert(sum);

    if(sz(st) > 2){
        cout<<-1;
        return;
    }

    lli a[2], i = 0;

    for(auto x:st)
    a[i++] = x;

    cout<<a[1]-a[0];
}
//think of special cases, limits, ll vs int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int t = 1;

    while(t--){
        solve();
    }
}


//https://codeforces.com/contest/711/problem/B
#include <bits/stdc++.h>
using namespace std;

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define en '\n'

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef list<int> li;
typedef map<int, int> mi;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//think of special cases, limits, ll vs int

int n;
int a[505][505];

void solve(){
    cin>>n;

    int r0, c0;

    fori(i, 1, n){
        fori(j, 1, n){
            cin>>a[i][j];

            if(a[i][j]==0){
                r0 = i;
                c0 = j;
            }
        }
    }

	if (n == 1) {
		cout << 1 << endl;
		return;
	}

    set<lli> st;

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[i][j];
        }

        st.insert(sum);
    }

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[j][i];
        }

        st.insert(sum);
    }
    lli sum = 0;

    fori(i, 1, n){
        sum += a[i][i];
    }

    st.insert(sum);

    sum = 0;

    fori(i, 1, n){
        sum += a[i][n+1-i];
    }

    st.insert(sum);

    if(sz(st) > 2){
        cout<<-1;
        return;
    }

    int a[2], i = 0;

    for(auto x:st)
    a[i++] = x;

    cout<<a[1]-a[0];
}
//think of special cases, limits, ll vs int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int t = 1;

    while(t--){
        solve();
    }
}


//https://codeforces.com/contest/711/problem/B
#include <bits/stdc++.h>
using namespace std;

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define en '\n'

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef list<int> li;
typedef map<int, int> mi;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//think of special cases, limits, ll vs int

int n;
int a[505][505];

void solve(){
    cin>>n;

    int r0, c0;

    fori(i, 1, n){
        fori(j, 1, n){
            cin>>a[i][j];

            if(a[i][j]==0){
                r0 = i;
                c0 = j;
            }
        }
    }

    set<lli> st;

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[i][j];
        }

        st.insert(sum);
    }

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[j][i];
        }

        st.insert(sum);
    }
    lli sum = 0;

    fori(i, 1, n){
        sum += a[i][i];
    }

    st.insert(sum);

    sum = 0;

    fori(i, 1, n){
        sum += a[i][n+1-i];
    }

    st.insert(sum);

    if(sz(st) > 2){
        cout<<-1;
        return;
    }

    int a[2], i = 0;

    for(auto x:st)
    a[i++] = x;

    cout<<a[1]-a[0];
}
//think of special cases, limits, ll vs int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int t = 1;

    while(t--){
        solve();
    }
}


//https://codeforces.com/contest/711/problem/B
#include <bits/stdc++.h>
using namespace std;

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define en '\n'

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef list<int> li;
typedef map<int, int> mi;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//think of special cases, limits, ll vs int

int n;
lli a[505][505];

void solve(){
    cin>>n;

    fori(i, 1, n){
        fori(j, 1, n){
            cin>>a[i][j];
        }
    }

	if (n == 1) {
		cout << 1 << endl;
		return;
	}

    set<lli> st;

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[i][j];
        }

        st.insert(sum);
    }

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[j][i];
        }

        st.insert(sum);
    }

    lli sum = 0;

    fori(i, 1, n){
        sum += a[i][i];
    }

    st.insert(sum);

    sum = 0;

    fori(i, 1, n){
        sum += a[i][n+1-i];
    }

    st.insert(sum);

    if(sz(st) > 2){
        cout<<-1;
        return;
    }

    lli b[3], i = 0;

    for(auto x:st)
    b[i++] = x;

    cout<<b[1]-b[0];
}
//think of special cases, limits, ll vs int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int t = 1;

    while(t--){
        solve();
    }
}


//https://codeforces.com/contest/711/problem/B
#include <bits/stdc++.h>
using namespace std;

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define en '\n'

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef list<int> li;
typedef map<int, int> mi;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//think of special cases, limits, ll vs int

int n;
lli a[505][505];
lli b[3];

void solve(){
    cin>>n;

    fori(i, 1, n){
        fori(j, 1, n){
            cin>>a[i][j];
        }
    }

	if (n == 1) {
		cout << 1 << endl;
		return;
	}

    set<lli> st;

    fori(i, 1, n){
        lli sum = 0;

        int f = 0;

        fori(j, 1, n){

            if(a[i][j] == 0){
                f = 1;
            }
            sum += a[i][j];
        }

        if(f == 1){
            b[0] = sum;
        } else {
            b[1] = sum;
        }

        st.insert(sum);
    }

    fori(i, 1, n){
        lli sum = 0;

        int f = 0;
        fori(j, 1, n){
            if(a[i][j] == 0){
                f = 1;
            }

            sum += a[j][i];
        }

        if(f == 1){
            b[0] = sum;
        } else {
            b[1] = sum;
        }

        st.insert(sum);
    }

    lli sum = 0;

    fori(i, 1, n){
        int f = 0;

        if(a[i][i] == 0){
            f = 1;
        }

        if(f == 1){
            b[0] = sum;
        } else {
            b[1] = sum;
        }

        sum += a[i][i];
    }

    st.insert(sum);

    sum = 0;

    fori(i, 1, n){
        int f = 0;

        if(a[i][n+1-i] == 0){
            f = 1;
        }

        if(f == 1){
            b[0] = sum;
        } else {
            b[1] = sum;
        }

        sum += a[i][n+1-i];
    }

    st.insert(sum);

    if(sz(st) != 2){
        cout<<-1;
        return;
    }

    lli c[3];
    int i = 0;

    for(auto x:st)
    c[i++] = x;

    if(c[1] == b[1]){
        cout<<-1;
        return;
    }

    cout<<c[1]-c[0];
}
//think of special cases(n == 1), limits, ll vs int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int t = 1;

    while(t--){
        solve();
    }
}


//https://codeforces.com/contest/711/problem/B
#include <bits/stdc++.h>
using namespace std;

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define en '\n'

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef list<int> li;
typedef map<int, int> mi;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//think of special cases, limits, ll vs int

int n;
lli a[505][505];

void solve(){
    cin>>n;

    fori(i, 1, n){
        fori(j, 1, n){
            cin>>a[i][j];
        }
    }

	if (n == 1) {
		cout << 1 << endl;
		return;
	}

    set<lli> st;

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[i][j];
        }

        st.insert(sum);
    }

    fori(i, 1, n){
        lli sum = 0;

        fori(j, 1, n){
            sum += a[j][i];
        }

        st.insert(sum);
    }

    lli sum = 0;

    fori(i, 1, n){
        sum += a[i][i];
    }

    st.insert(sum);

    sum = 0;

    fori(i, 1, n){
        sum += a[i][n+1-i];
    }

    st.insert(sum);

    if(sz(st) != 2){
        cout<<-1;
        return;
    }

    lli b[3], i = 0;

    for(auto x:st)
    b[i++] = x;

    cout<<b[1]-b[0];
}
//think of special cases, limits, ll vs int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int t = 1;

    while(t--){
        solve();
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define sqr(x) ((x)*(x))
#define cbr(x) ((x)*(x)*(x))
#define max(a, b) (((a)<(b))? (b):(a))
#define min(a, b) (((a)<(b))? (a):(b))
#define all(a) a.begin(), a.end()

#define _sp system("pause");
#define _ln cout << "------------------------------------------------\n";
#define FI(a, n) for(int i=a;i<n;i++)
#define FJ(a, n) for(int j=a;j<n;j++)
#define REP(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define rep(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define per(b, a, c) for(int (c) = (b); (c) >= (a); (c)--)

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define x first
#define y second

#define x1 sasimathx1
#define y1 sasimathy1

ll delbit(ll a, ll k) { return a & (~(1 << k)); }
bool getbit(ll a, ll k) { return 1 & (a >> k); }
ll setbit(ll a, ll k) { return a |= (1 << k); }

inline ll mulmod(ll x, ll n, ll _mod) { ll res = 0; while (n) { if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod) { ll res = 1; while (n) { if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { ll t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b) { int t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c) { return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }
double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); }

//DBG
template<typename T, typename T2>void printarr(T  a[], T2 sz, T2 beg = 0) { for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
#define DBG(a)         cout<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b)       cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBG3(a,b,c)     cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"

//Files
#define FILE_MODE(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)

//constants
#define PI    3.1415926535897932
#define INF   1011111111
#define LLINF 1000111000111000111LL
#define eps   1e-14
//-------------------------------------------------
#define N 300010

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	if (n % 2 != 0) {
		cout << "-1\n";
		return 0;
	}

	char c[2][3] = {"ab", "cd"};
	bool f = 0;
	for (int j = 0; j < n; j += 2) {
		cout << c[0][f] << c[0][f];
			f = !f;
	}
	cout << "\nz";
	f = 0;
	for (int j = 0; j < n - 2; j += 2) {
		cout << c[1][f] << c[1][f];
		f = !f;
	}
	cout << "z\n";

	cout << 'z';
	f = 0;
	for (int j = 0; j < n - 2; j += 2) {
		cout << c[0][f] << c[0][f];
		f = !f;
	}
	cout << "z\n";

	f = 0;
	for (int j = 0; j < n; j += 2) {
		cout << c[1][f] << c[1][f];
		f = !f;
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define sqr(x) ((x)*(x))
#define cbr(x) ((x)*(x)*(x))
#define max(a, b) (((a)<(b))? (b):(a))
#define min(a, b) (((a)<(b))? (a):(b))
#define all(a) a.begin(), a.end()

#define _sp system("pause");
#define _ln cout << "------------------------------------------------\n";
#define FI(a, n) for(int i=a;i<n;i++)
#define FJ(a, n) for(int j=a;j<n;j++)
#define REP(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define rep(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define per(b, a, c) for(int (c) = (b); (c) >= (a); (c)--)

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define x first
#define y second

#define x1 sasimathx1
#define y1 sasimathy1

ll delbit(ll a, ll k) { return a & (~(1 << k)); }
bool getbit(ll a, ll k) { return 1 & (a >> k); }
ll setbit(ll a, ll k) { return a |= (1 << k); }

inline ll mulmod(ll x, ll n, ll _mod) { ll res = 0; while (n) { if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod) { ll res = 1; while (n) { if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { ll t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b) { int t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c) { return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }
double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); }

//DBG
template<typename T, typename T2>void printarr(T  a[], T2 sz, T2 beg = 0) { for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
#define DBG(a)         cout<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b)       cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBG3(a,b,c)     cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"

//Files
#define FILE_MODE(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)

//constants
#define PI    3.1415926535897932
#define INF   1011111111
#define LLINF 1000111000111000111LL
#define eps   1e-14
//-------------------------------------------------
#define N 300010

string m[4];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	if (n == 1) {
		cout << "-1\n";
		return 0;
	}
	string c[2] = { "ab", "cd" };
	if (n % 2 != 0) {
		bool f = 0;
		for (int j = 0; j < n / 2; j++) {
			m[0] += c[0][f];
			m[0] += c[0][f];
			f = !f;
		}
		m[0] += 'z';
		f = 0;
		for (int j = 0; j < n / 2; j++) {
			m[1] += c[1][f];
			m[1] += c[1][f];
			f = !f;
		}
		m[1] += 'z';
		m[2] += 'z';
		f = 0;
		for (int j = 0; j < n / 2; j++) {
			m[2] += c[0][f];
			m[2] += c[0][f];
			f = !f;
		}
		m[3] += 'z';

		f = 0;
		for (int j = 0; j < n / 2; j++) {
			m[3] += c[1][f];
			m[3] += c[1][f];
			f = !f;
		}
	}
	else {
		if (n == 2) {
			m[0] = "aa";
			m[1] = "bb";
			m[2] = "aa";
			m[3] = "bb";
		}
		else {

			bool f = 0;
			for (int j = 0; j < n; j += 2) {
				m[0] += c[0][f];
				m[0] += c[0][f];
				f = !f;
			}

			m[1] += 'z';
			f = 0;
			for (int j = 0; j < n - 2; j += 2) {
				m[1] += c[1][f];
				m[1] += c[1][f];
				f = !f;
			}
			m[1] += 'z';
			m[2] += 'z';
			f = 0;
			for (int j = 0; j < n - 2; j += 2) {
				m[2] += c[0][f];
				m[2] += c[0][f];
				f = !f;
			}
			m[2] += 'z';

			f = 0;
			for (int j = 0; j < n; j += 2) {
				m[3] += c[1][f];
				m[3] += c[1][f];
				f = !f;
			}
		}
	}
	rep(0, 4, i)
		cout << m[i] << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define sqr(x) ((x)*(x))
#define cbr(x) ((x)*(x)*(x))
#define max(a, b) (((a)<(b))? (b):(a))
#define min(a, b) (((a)<(b))? (a):(b))
#define all(a) a.begin(), a.end()

#define _sp system("pause");
#define _ln cout << "------------------------------------------------\n";
#define FI(a, n) for(int i=a;i<n;i++)
#define FJ(a, n) for(int j=a;j<n;j++)
#define REP(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define rep(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define per(b, a, c) for(int (c) = (b); (c) >= (a); (c)--)

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define x first
#define y second

#define x1 sasimathx1
#define y1 sasimathy1

ll delbit(ll a, ll k) { return a & (~(1 << k)); }
bool getbit(ll a, ll k) { return 1 & (a >> k); }
ll setbit(ll a, ll k) { return a |= (1 << k); }

inline ll mulmod(ll x, ll n, ll _mod) { ll res = 0; while (n) { if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod) { ll res = 1; while (n) { if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { ll t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b) { int t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c) { return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }
double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); }

//DBG
template<typename T, typename T2>void printarr(T  a[], T2 sz, T2 beg = 0) { for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
#define DBG(a)         cout<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b)       cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBG3(a,b,c)     cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"

//Files
#define FILE_MODE(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)

//constants
#define PI    3.1415926535897932
#define INF   1011111111
#define LLINF 1000111000111000111LL
#define eps   1e-14
//-------------------------------------------------
#define N 300010

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	if (n % 2 != 0) {
		cout << "-1\n";
		return 0;
	}
	if (n == 2) {
		cout << "aa\nbb\naa\nbb\n";
		return 0;
	}

	char c[2][3] = {"ab", "cd"};
	bool f = 0;
	for (int j = 0; j < n; j += 2) {
		cout << c[0][f] << c[0][f];
			f = !f;
	}
	cout << "\nz";
	f = 0;
	for (int j = 0; j < n - 2; j += 2) {
		cout << c[1][f] << c[1][f];
		f = !f;
	}
	cout << "z\n";

	cout << 'z';
	f = 0;
	for (int j = 0; j < n - 2; j += 2) {
		cout << c[0][f] << c[0][f];
		f = !f;
	}
	cout << "z\n";

	f = 0;
	for (int j = 0; j < n; j += 2) {
		cout << c[1][f] << c[1][f];
		f = !f;
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <iterator>
#include <iomanip>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define sqr(x) ((x)*(x))
#define cbr(x) ((x)*(x)*(x))
#define max(a, b) (((a)<(b))? (b):(a))
#define min(a, b) (((a)<(b))? (a):(b))
#define all(a) a.begin(), a.end()

#define _sp system("pause");
#define _ln cout << "------------------------------------------------\n";
#define FI(a, n) for(int i=a;i<n;i++)
#define FJ(a, n) for(int j=a;j<n;j++)
#define REP(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define rep(a, b, c) for(int (c) = (a); (c) < (b); (c)++)
#define per(b, a, c) for(int (c) = (b); (c) >= (a); (c)--)

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define x first
#define y second

#define x1 sasimathx1
#define y1 sasimathy1

ll delbit(ll a, ll k) { return a & (~(1 << k)); }
bool getbit(ll a, ll k) { return 1 & (a >> k); }
ll setbit(ll a, ll k) { return a |= (1 << k); }

inline ll mulmod(ll x, ll n, ll _mod) { ll res = 0; while (n) { if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod) { ll res = 1; while (n) { if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { ll t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b) { int t; while (b) { a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c) { return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }
double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); }

//DBG
template<typename T, typename T2>void printarr(T  a[], T2 sz, T2 beg = 0) { for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
#define DBG(a)         cout<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b)       cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBG3(a,b,c)     cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"

//Files
#define FILE_MODE(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)

//constants
#define PI    3.1415926535897932
#define INF   1011111111
#define LLINF 1000111000111000111LL
#define eps   1e-14
//-------------------------------------------------
#define N 300010

string m[4];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	string c[2] = { "ab", "cd" };
	if (n % 2 != 0) {
		if (n == 1) {
			m[0] += 'a';
			m[1] += 'a';
			m[2] += 'b';
			m[3] += 'b';
		}
		else {
			bool f = 0;
			for (int j = 0; j < n / 2; j++) {
				m[0] += c[0][f];
				m[0] += c[0][f];
				f = !f;
			}
			m[0] += 'z';
			f = 0;
			for (int j = 0; j < n / 2; j++) {
				m[1] += c[1][f];
				m[1] += c[1][f];
				f = !f;
			}
			m[1] += 'z';
			m[2] += 'z';
			f = 0;
			for (int j = 0; j < n / 2; j++) {
				m[2] += c[0][f];
				m[2] += c[0][f];
				f = !f;
			}
			m[3] += 'z';

			f = 0;
			for (int j = 0; j < n / 2; j++) {
				m[3] += c[1][f];
				m[3] += c[1][f];
				f = !f;
			}
		}
	}
	else {
		if (n == 2) {
			m[0] = "aa";
			m[1] = "bb";
			m[2] = "aa";
			m[3] = "bb";
		}
		else {

			bool f = 0;
			for (int j = 0; j < n; j += 2) {
				m[0] += c[0][f];
				m[0] += c[0][f];
				f = !f;
			}

			m[1] += 'z';
			f = 0;
			for (int j = 0; j < n - 2; j += 2) {
				m[1] += c[1][f];
				m[1] += c[1][f];
				f = !f;
			}
			m[1] += 'z';
			m[2] += 'z';
			f = 0;
			for (int j = 0; j < n - 2; j += 2) {
				m[2] += c[0][f];
				m[2] += c[0][f];
				f = !f;
			}
			m[2] += 'z';

			f = 0;
			for (int j = 0; j < n; j += 2) {
				m[3] += c[1][f];
				m[3] += c[1][f];
				f = !f;
			}
		}
	}
	rep(0, 4, i)
		cout << m[i] << endl;

	return 0;
}