#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
const int N = 1000000;

int main() {
	char A[N];
	int k;
	scanf("%d", &k);
	scanf("%s", A);
	int n = strlen(A);

	if (k == 0) {
		int dp[N];
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++) {
			if (A[i] == '1') dp[i] = 0;
			else dp[i] = (i == 0 ? 0 : dp[i - 1]) + 1;
		}

		ll ans = 0;
		for (int i = 0; i < n; i++)
			if (A[i] == '0' && (i == n - 1 || A[i + 1] == '1'))
				ans += ((ll)dp[i] + 1l)*(ll)dp[i] / 2;

		printf("%I64d\n", ans);
		return 0;
	}

	int dp[N],pre[N],next[N];
	memset(dp, 0, sizeof(dp));
	memset(pre, -1, sizeof(pre));
	memset(next, -1, sizeof(next));

	for (int i = 0; i < n; i++) {
		dp[i] = (i == 0 ? 0 : dp[i - 1]);
		if (A[i] == '1') dp[i]++;
	}

	int cur = -1;
	for (int i = 0; i < n; i++)
		if (A[i] == '1') {
			pre[i] = cur;
			cur = i;
		}

	cur = n;
	for (int i = n - 1; i >= 0; i--)
		if (A[i] == '1') {
			next[i] = cur;
			cur = i;
		}
	int l = 0, r = 0;
	ll ans = 0;

	while (l < n && r < n) {
		while (r < n && dp[r] - (l == 0 ? 0 : dp[l - 1]) < k) r++;
		while (l < n && A[l] != '1') l++;

		if (l >= n || r >= n) break;

		ans += (ll)(next[r] - r)*(ll)(l - pre[l]);
		l++;
	}

	printf("%I64d\n", ans);

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const int N = 1000000;

int main() {
	char A[N];
	int k;
	scanf("%d", &k);
	scanf("%s", A);
	int n = strlen(A);

	if (k == 0) {
		int dp[N];
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++) {
			if (A[i] == '1') dp[i] = 0;
			else dp[i] = (i == 0 ? 0 : dp[i - 1]) + 1;
		}

		ll ans = 0;
		for (int i = 0; i < n; i++)
			if (A[i] == '0' && (i == n - 1 || A[i + 1] == '1'))
				ans += ((ll)dp[i] + 1l)*(ll)dp[i] / 2;

		printf("%I64d\n", ans);
		return 0;
	}

	int dp[N],pre[N],next[N];
	memset(dp, 0, sizeof(dp));
	memset(pre, -1, sizeof(pre));
	memset(next, -1, sizeof(next));

	for (int i = 0; i < n; i++) {
		dp[i] = (i == 0 ? 0 : dp[i - 1]);
		if (A[i] == '1') dp[i]++;
	}

	int cur = -1;
	for (int i = 0; i < n; i++)
		if (A[i] == '1') {
			pre[i] = cur;
			cur = i;
		}

	cur = n;
	for (int i = n - 1; i >= 0; i--)
		if (A[i] == '1') {
			next[i] = cur;
			cur = i;
		}
	int l = 0, r = 0;
	ll ans = 0;

	while (l < n && r < n) {
		while (r < n && dp[r] - (l == 0 ? 0 : dp[l - 1]) < k) r++;
		while (l < n && A[l] != '1') l++;

		if (l >= n || r >= n) break;

		ans += (ll)(next[r] - r)*(ll)(l - pre[l]);
		l++;
	}

	printf("%I64d\n", ans);

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const int N = 1000000;

int main() {
	char A[N];
	int k;
	scanf("%d", &k);
	scanf("%s", A);
	int n = strlen(A);

	if (k == 0) {
		int dp[N];
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++) {
			if (A[i] == '1') dp[i] = 0;
			else dp[i] = (i == 0 ? 0 : dp[i - 1]) + 1;
		}

		ll ans = 0;
		for (int i = 0; i < n; i++)
			if (A[i] == '0' && (i == n - 1 || A[i + 1] == '1'))
				ans += (dp[i] + 1)*dp[i] / 2;

		printf("%I64d\n", ans);
		return 0;
	}

	int dp[N],pre[N],next[N];
	memset(dp, 0, sizeof(dp));
	memset(pre, -1, sizeof(pre));
	memset(next, -1, sizeof(next));

	for (int i = 0; i < n; i++) {
		dp[i] = (i == 0 ? 0 : dp[i - 1]);
		if (A[i] == '1') dp[i]++;
	}

	int cur = -1;
	for (int i = 0; i < n; i++)
		if (A[i] == '1') {
			pre[i] = cur;
			cur = i;
		}

	cur = n;
	for (int i = n - 1; i >= 0; i--)
		if (A[i] == '1') {
			next[i] = cur;
			cur = i;
		}

	int l = 0, r = 0;
	ll ans = 0;

	while (l < n && r < n) {
		while (r < n && dp[r] - (l == 0 ? 0 : dp[l - 1]) < k) r++;
		while (l < n && A[l] != '1') l++;

		if (l >= n || r >= n) break;

		ans += (next[r] - r)*(l - pre[l]);
		l++;
	}

	printf("%I64d\n", ans);

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const int N = 1000000;

int main() {
	char A[N];
	int k;
	scanf("%d", &k);
	scanf("%s", A);
	int n = strlen(A);

	if (k == 0) {
		int dp[N];
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++)
			dp[i] = (i == 0 ? 0 : dp[i - 1]) + (A[i] == '0' ? 1 : 0);

		ll ans = 0;
		for (int i = 0; i < n; i++) {
			if (A[i] == '0' && (i == n - 1 || A[i + 1] == '1'))
				ans += (dp[i] + 1)*dp[i] / 2;
		}

		printf("%I64d\n", ans);
		return 0;
	}

	int dp[N],pre[N],next[N];
	memset(dp, 0, sizeof(dp));
	memset(pre, -1, sizeof(pre));
	memset(next, -1, sizeof(next));

	for (int i = 0; i < n; i++) {
		dp[i] = (i == 0 ? 0 : dp[i - 1]);
		if (A[i] == '1') dp[i]++;
	}

	int cur = -1;
	for (int i = 0; i < n; i++)
		if (A[i] == '1') {
			pre[i] = cur;
			cur = i;
		}

	cur = n;
	for (int i = n - 1; i >= 0; i--)
		if (A[i] == '1') {
			next[i] = cur;
			cur = i;
		}

	int l = 0, r = 0;
	ll ans = 0;

	while (l < n && r < n) {
		while (r < n && dp[r] - (l == 0 ? 0 : dp[l - 1]) < k) r++;
		while (l < n && A[l] != '1') l++;

		if (l >= n || r >= n) break;

		ans += (next[r] - r)*(l - pre[l]);
		l++;
	}

	printf("%I64d\n", ans);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define FOR(fi, st, en) for(int fi = st; fi < en; fi++)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int k; cin>>k;
    string s; cin>>s;
    vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    ll ans = 0;
    for(i = 0; i < s.size(); i++){
        int x = k + (i?sum[i-1]:0);
        auto it = lb(sum.begin()+i, sum.end(), x);
        if(*it != x) continue;
        auto it2 = up(sum.begin()+i, sum.end(), x);
        ans += it2 - it;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define FOR(fi, st, en) for(int fi = st; fi < en; fi++)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N = 1e6+10;
int cnt[N];

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int k; cin>>k;
    string s; cin>>s;
    vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    FOR(i, 0, s.size()) cnt[ sum[i] ]++;
    ll ans = 0;
    FOR(i, 0, s.size()){
        int x = k;
        if(i) x += sum[i-1];
        if(x <= 1e6) ans += cnt[x];
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    int k; cin>>k;
    string s; cin>>s;
    int i = 0, j = 0, cnt = 0, n = s.size();
    while(j < n){
        cnt += s[j] - 48;
        if(cnt == k) break;
        j++;
    }
    ll ans = 0, c = j < n;
    while(j + 1 < n && s[j+1] == '0') j++, c++;
    ans += c;
    if(s[0] == '1') cnt--;
    while(1){
        ++i;
        if(i >= n) break;
        if(cnt < k){
            while(j < n){
                cnt += s[j] - 48;
                if(cnt == k) break;
                j++;
            }
            if(j >= n) break;
            c = 1;
            while(j + 1 < n && s[j+1] == '0') j++, c++;
        }
        ans+=c;
        if(s[i] == '1') cnt--;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define FOR(fi, st, en) for(int fi = st; fi < en; fi++)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N = 1e6+10;
int cnt[N];

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int k; cin>>k;
    string s; cin>>s;
    if(k == 0){
        vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    ll ans = 0;
    for(i = 0; i < s.size(); i++){
        int x = k + (i?sum[i-1]:0);
        auto it = lb(sum.begin()+i, sum.end(), x);
        if(*it != x) continue;
        auto it2 = up(sum.begin()+i, sum.end(), x);
        ans += it2 - it;
    }
    cout << ans << endl;
    return 0;
    }
    vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    FOR(i, 0, s.size()) cnt[ sum[i] ]++;
    ll ans = 0;
    FOR(i, 0, s.size()){
        int x = k;
        if(i) x += sum[i-1];
        if(x <= 1e6) ans += cnt[x];
    }
    cout << ans << endl;
    show(sum);
    for(i = 0; i <= 10; i++) cout << cnt[i] << " ";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define FOR(fi, st, en) for(int fi = st; fi < en; fi++)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int k; cin>>k;
    string s; cin>>s;
    vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    ll ans = 0;
    for(i = 0; i < s.size(); i++){
        int x = k + (i?sum[i-1]:0);
        auto it = lb(all(sum), x);
        ans += sum.end() - it;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define FOR(fi, st, en) for(int fi = st; fi < en; fi++)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int k; cin>>k;
    string s; cin>>s;
    vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    ll ans = 0;
    for(i = 0; i < s.size(); i++){
        int x = k + (i?sum[i-1]:0);
        auto it = lb(all(sum), x);
        auto it2 = up(all(sum), x);
        ans += it2 - it;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define FOR(fi, st, en) for(int fi = st; fi < en; fi++)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N = 1e6+10;
int cnt[N];

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int k; cin>>k;
    string s; cin>>s;
    if(k == 0){
        vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    ll ans = 0;
    for(i = 0; i < s.size(); i++){
        int x = k + (i?sum[i-1]:0);
        auto it = lb(sum.begin()+i, sum.end(), x);
        if(*it != x) continue;
        auto it2 = up(sum.begin()+i, sum.end(), x);
        ans += it2 - it;
    }
    cout << ans << endl;
    return 0;
    }
    vi sum(s.size());
    sum[0] = s[0] - 48;
    FOR(i,1,s.size()) sum[i] = sum[i-1] + s[i] - 48;
    FOR(i, 0, s.size()) cnt[ sum[i] ]++;
    ll ans = 0;
    FOR(i, 0, s.size()){
        int x = k;
        if(i) x += sum[i-1];
        if(x <= 1e6) ans += cnt[x];
    }
    cout << ans << endl;
//    show(sum);
//    for(i = 0; i <= 10; i++) cout << cnt[i] << " ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 1000006
int main()
{
    ll k,ans=0,y;
    char strn[sz];
    cin >> k;
    getchar();
    scanf("%s",strn);

    vector<int>vect;
    ll p=0,cnt=0,i,z,l=strlen(strn);
    if(k==0)
    {
        y=0;
        for(i=0; i<l; i++)
        {
            if(strn[i]=='0') y++;
            else
            {
                ans+=((y*(y+1))/2);
                y=0;
            }
        }
        ans+=((y*(y+1))/2);

        cout <<ans;
        return 0;
    }
    int c=0,kk=0;
    for(i=0; i<l; i++)
    {
        if(strn[i]=='1')
        {
            vect.push_back(i);
            kk++;
        }
        cnt+=strn[i]-48;
        if(cnt==k+1)
        {
            kk=vect.size();
            z=vect[c]-p+1;
            y=i-vect[kk-2];
            ans+=(y*z);
            p=vect[c]+1;
            c++;
            cnt=k;
        }
    }
    if(cnt==k)
    {
        kk=vect.size();
        z=vect[c]-p+1;
        y=i-vect[kk-1];
        ans+=(y*z);
    }
    cout << ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,ans=0,y;
    string strn;
    cin >> k;
    getchar();
    cin >> strn;
    vector<int>vect;
    int p=0,cnt=0,i,z;
    for(i=0; i<strn.size(); i++)
    {
        if(strn[i]=='1') vect.push_back(i);
        cnt+=strn[i]-48;
        if(cnt==k+1)
        {
            //if(v[0]==p) z=1;
            /*else*/ z=vect[0]-p+1;
            //if(v[k-1]==i-1) y=1;
            /*else*/ y=i-vect[k-1];
            //cout << y <<" "<<z<<endl;
            ans+=(y*z);
            p=vect[0]+1;
            vect.erase(vect.begin()+0);
            cnt=k;
        }
    }
    //if(v[0]==p) z=1;
    /*else */
    //if(v[k-1]==i-1) y=1;
   /* else*/
  // cout << y << " "<<z<<endl;
    if(cnt==k)
    {
        z=vect[0]-p+1;
        y=i-vect[k-1];
        ans+=(y*z);
    }
    cout << ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 1000006
int main()
{
    ll k,ans=0,y;
    char strn[sz];
    cin >> k;
    getchar();
    scanf("%s",strn);

    vector<int>vect;
    ll p=0,cnt=0,i,z,l=strlen(strn);
    if(k==0)
    {
        y=0;
        for(i=0; i<l; i++)
        {
            if(strn[i]=='0') y++;
            else
            {
                ans+=((y*(y+1))/2);
                y=0;
            }
        }
        ans+=((y*(y+1))/2);

        cout <<ans;
        return 0;
    }
    for(i=0; i<l; i++)
    {
        if(strn[i]=='1') vect.push_back(i);
        cnt+=strn[i]-48;
        if(cnt==k+1)
        {
            //if(v[0]==p) z=1;
            /*else*/ z=vect[0]-p+1;
            //if(v[k-1]==i-1) y=1;
            /*else*/ y=i-vect[k-1];
            //cout << y <<" "<<z<<endl;
            ans+=(y*z);
            p=vect[0]+1;
            vect.erase(vect.begin()+0);
            cnt=k;
        }
    }
    //if(v[0]==p) z=1;
    /*else */
    //if(v[k-1]==i-1) y=1;
   /* else*/
  // cout << y << " "<<z<<endl;
    if(cnt==k)
    {
        z=vect[0]-p+1;
        y=i-vect[k-1];
        ans+=(y*z);
    }
    cout << ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll k,ans=0,y;
    string strn;
    cin >> k;
    getchar();
    cin >> strn;

    vector<int>vect;
    ll p=0,cnt=0,i,z;
    if(k==0)
    {
        y=0;
        for(i=0; i<strn.size(); i++)
        {
            if(strn[i]=='0') y++;
            else
            {
                ans+=((y*(y+1))/2);
                y=0;
            }
        }
        ans+=((y*(y+1))/2);

        cout <<ans;
        return 0;
    }
    for(i=0; i<strn.size(); i++)
    {
        if(strn[i]=='1') vect.push_back(i);
        cnt+=strn[i]-48;
        if(cnt==k+1)
        {
            //if(v[0]==p) z=1;
            /*else*/ z=vect[0]-p+1;
            //if(v[k-1]==i-1) y=1;
            /*else*/ y=i-vect[k-1];
            //cout << y <<" "<<z<<endl;
            ans+=(y*z);
            p=vect[0]+1;
            vect.erase(vect.begin()+0);
            cnt=k;
        }
    }
    //if(v[0]==p) z=1;
    /*else */
    //if(v[k-1]==i-1) y=1;
   /* else*/
  // cout << y << " "<<z<<endl;
    if(cnt==k)
    {
        z=vect[0]-p+1;
        y=i-vect[k-1];
        ans+=(y*z);
    }
    cout << ans<<endl;
}


/*
    Author: Zhouxing Shi
    Created on Nov5, 2014
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb(x) push_back(x)
#define mp(x, y) (make_pair(x, y))
#define clr(x) memset(x, 0, sizeof(x))
#define xx first
#define yy second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int inf = ~0U >> 1;
const ll INF = ~0ULL >> 1;;
const double pi = acos(-1.0);
template <class T> inline T sqr(T a) { return a * a; }
template <class T> inline void read(T &n)
{
    char c;
	for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar()); n = c - '0';
    for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
int Pow(int base, int n, int mo)
{
	if (n == 0) return 1;
	if (n == 1) return base;
	int tmp = Pow(base, n >> 1, mo);
	tmp = (ll)tmp * tmp % mo;
	if (n & 1) tmp = (ll)tmp * base % mo;
	return tmp;
}
struct point
{
	int x, y;
	point(){}
	point(int _x, int _y) : x(_x), y(_y) {}
} ;

//***************************

int n, best;
int a[100][100], C[100];

int main()
{
	scanf("%d", &n);
	rep(i, 1, n) rep(j, 1, n) scanf("%d", &a[i][j]);
	int x = (n + 1) / 2;
	REP(i, 0, 1 << x)
	{
		int ret = 0;
		rep(j, 1, x) C[j] = bool((1 << j - 1) & i), ret += (C[j] ? -1 : 1) * a[j][x];
		rep(j, x + 1, n) C[j] = C[x] ^ C[j - x], ret += (C[j] ? -1 : 1) * a[j][x];
		rep(col, 1, x - 1)
		{
			int cur = 0;
			rep(k, 0, 1)
			{
				int tmp = 0;
				rep(row, 1, x - 1)
				{
					int t = 0;
					rep(kk, 0, 1)
					{
						int tt = 0;
						tt += (kk ? -1 : 1) * a[row][col];
						tt += ((kk ^ C[row]) ? -1 : 1) * a[row][col + x];
						tt += ((kk ^ k) ? -1 : 1) * a[row + x][col];
						tt += ((kk ^ C[row] ^ k ^ C[x]) ? -1 : 1) * a[row + x][col + x];
						t = max(t, tt);
					}
					tmp += t;
				}
				cur = max(cur, tmp + (k ? -1 : 1) * a[x][col] + ((k ^ C[x]) ? -1 : 1) * a[x][col + x]);
			}
			ret += cur;
		}
		best = max(best, ret);
	}
	printf("%d\n", best);
	return 0;
}


#include <sstream>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
using namespace std;

// begin insert defines
#define two(x) (1u<<(x))
#define Rep(i,n) for(int n_ = (n), i = 0; i< n_; ++i)
template <class T> inline void gmax (T &a, T b) {if (a < b) a = b;}
// end insert defines

int N, X;

int calc(vector<vector<int> > &a, int mask) {
    int ret = 0;
    Rep(i, X + 1) ret += two(i) & mask ? -a[i][X] : a[i][X];
    Rep(i, X) ret += (bool)(two(i) & mask) ^ (bool)((mask >> X) & 1) ? -a[X + i + 1][X] : a[X + i + 1][X];
    Rep(j, X) {
        int t1 = a[X][j] + (((mask >> X) & 1) ? -1 : 1) * a[X][X + 1 + j];
        Rep(i, X) {
            int t = a[i][j];
            t += a[X + 1 + i][j];
            t += (two(i) & mask ? -1 : 1) * a[i][X + 1 + j];
            t += ((bool)(two(i) & mask) ^ (bool)((mask >> X) & 1) ? -1 : 1) * a[X + i + 1][X + 1 + j];
            t1 += max(t, -t);
        }
        int t2 = -a[X][j] + (((mask >> X) & 1) ? 1 : -1) * a[X][X + 1 + j];
        Rep(i, X) {
            int t = a[i][j];
            t += -a[X + 1 + i][j];
            t += (two(i) & mask ? -1 : 1) * a[i][X + 1 + j];
            t += ((bool)(two(i) & mask) ^ (bool)((mask >> X) & 1) ? 1 : -1) * a[X + i + 1][X + 1 + j];
            t2 += max(t, -t);
        }
        ret += max(t1, t2);
    }
    return ret;
}

int main(int argc, char *argv[])
{
    cin >> N;
    X = N / 2;
    vector<vector<int> > a(N, vector<int>(N));
    int mx = 0;
    Rep(i, N) Rep(j, N) cin >> a[i][j], mx += a[i][j];
    Rep(i, two(X + 1)) gmax(mx, calc(a, i));
    cout << mx << endl;
    return 0;
}


#include <sstream>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
using namespace std;

// begin insert defines
#define two(x) (1u<<(x))
#define Rep(i,n) for(int n_ = (n), i = 0; i< n_; ++i)
template <class T> inline void gmax (T &a, T b) {if (a < b) a = b;}
// end insert defines

int N, X;

int calc(vector<vector<int> > &a, int mask) {
    int ret = 0;
    Rep(i, X + 1) ret += two(i) & mask ? -a[i][X] : a[i][X];
    Rep(i, X) ret += (bool)(two(i) & mask) ^ (bool)((mask >> X) & 1) ? -a[X + i + 1][X] : a[X + i + 1][X];
    Rep(j, X) {
        int t1 = a[X][j] + (((mask >> X) & 1) ? -1 : 1) * a[X][X + 1 + j];
        Rep(i, X) {
            int t = a[i][j];
            t += a[X + 1 + i][j];
            t += (two(i) & mask ? -1 : 1) * a[i][X + 1 + j];
            t += (bool)((two(i) & mask) ^ (bool)((mask >> X) & 1) ? -1 : 1) * a[X + i + 1][X + 1 + j];
            t1 += max(t, -t);
        }
        int t2 = -a[X][j] + (((mask >> X) & 1) ? 1 : -1) * a[X][X + 1 + j];
        Rep(i, X) {
            int t = a[i][j];
            t += -a[X + 1 + i][j];
            t += (two(i) & mask ? -1 : 1) * a[i][X + 1 + j];
            t += (bool)((two(i) & mask) ^ (bool)((mask >> X) & 1) ? 1 : -1) * a[X + i + 1][X + 1 + j];
            t2 += max(t, -t);
        }
        ret += max(t1, t2);
    }
    return ret;
}

int main(int argc, char *argv[])
{
    cin >> N;
    X = N / 2;
    vector<vector<int> > a(N, vector<int>(N));
    int mx = 0;
    Rep(i, N) Rep(j, N) cin >> a[i][j], mx += a[i][j];
    Rep(i, two(X + 1)) gmax(mx, calc(a, i));
    cout << mx << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int N,M,a[35][35],b[35];

void init()
{
	scanf("%d",&N),M=N/2+1;
	for (int i=1; i<=N; i++)
		for (int j=1; j<=N; j++) scanf("%d",&a[i][j]);
}

int calc()
{
	int res=0;
	for (int i=1; i<M; i++)
	{
		int s=-1e9;
		for (int x=-1; x<=1; x+=2)
		{
			int t=x*a[i][M]+x*b[M]*a[i+M][M];
			for (int j=1; j<M; j++) t+=abs(a[i][j]+x*a[i][j+M]+b[j]*a[i+M][j]+x*b[j+M]*a[i+M][j+M]);
			s=max(s,t);
		}
		res+=s;
	}
	for (int i=1; i<=N; i++) res+=b[i]*a[M][i];
	return res;
}

void doit()
{
	int ans=-1e9;
	for (int i=0; i<1<<M; i++)
	{
		for (int j=M; j; j--) b[j]=(i>>j-1)&1?1:-1,b[j+M]=b[j]*b[M];
		ans=max(ans,calc());
	}
	cout<<ans<<endl;
}

int main()
{
	init();
	doit();
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#if __cplusplus > 201103L
#include <initializer_list>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#ifndef ONLINE_JUDGE
#define DEBUG
#endif

#define oo 0x3F3F3F3F
#ifdef DEBUG
#define cvar(x) cerr << "<" << #x << ": " << x << ">"
#define evar(x) cvar (x) << endl
template<class T> void DISP(const char *s, T x, int n) {cerr << "[" << s << ": "; for (int i = 0; i < n; ++i) cerr << x[i] << " "; cerr << "]" << endl;}
#define disp(x,n) DISP(#x " to " #n, x, n)
#else
#define cvar(...) ({})
#define evar(...) ({})
#define disp(...) ({})
#endif
#define car first
#define cdr second
#define PB push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int _end_ = (b), i = (a); i <= _end_; ++i)
#define ROF(i, a, b) for (int _end_ = (b), i = (a); i >= _end_; --i)

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef long double real;

int64 fpm(int64 b, int64 e, int64 m) { int64 t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; }
template<class T> inline bool chkmin(T &a, T b) {return a > b ? a = b, true : false;}
template<class T> inline bool chkmax(T &a, T b) {return a < b ? a = b, true : false;}
template<class T> inline T sqr(T x) {return x * x;}
template <typename T> T gcd(T x, T y) {for (T t; x; t = x, x = y % x, y = t); return y; }

template<class edge> struct Graph {
     vector<vector<edge> > adj;
     Graph(int n) {adj.clear (); adj.resize (n + 5);}
     Graph() {adj.clear (); }
     void resize(int n) {adj.resize (n + 5); }
     void add(int s, edge e){adj[s].push_back (e);}
     void del(int s, edge e) {adj[s].erase (find (iter (adj[s]), e)); }
     vector<edge>& operator [](int t) {return adj[t];}
};

const int maxn = 40;

int n, x;
int ans = -oo;
int w[maxn][maxn], v[maxn][maxn], f[maxn][maxn];

int calc(int i, int j, int xj) {
    return abs(w[i][j] + w[i][j + x] * f[i][x] + w[i + x][j] * xj + w[i + x][j + x] * f[i][x] * xj * f[x][x]);
}

void update() {
    int ret = w[x][x] * f[x][x];
    FOR (i, 1, x - 1) {
        ret += f[i][x] * f[x][x] * w[i + x][x] + f[i][x] * w[i][x];
    }
    FOR (j, 1, x - 1) {
        int a = w[x][j] + f[x][x] * w[x][j + x], b = -w[x][j] - f[x][x] * w[x][j + x];
        FOR (i, 1, x - 1) {
            a += calc(i, j, +1);
            b += calc(i, j, -1);
        }
        ret += max(a, b);
    }
    chkmax(ans, ret);
}

void dfs(int d) {
    if (d > x) {
        return update();
    }
    f[d][x] = +1, dfs(d + 1);
    f[d][x] = -1, dfs(d + 1);
}

int main(int argc, char **argv) {
#ifndef ONLINE_JUDGE
     freopen("D.in" , "r", stdin);
     freopen("D.out", "w", stdout);
#endif
     ios_base::sync_with_stdio(false);
     cin >> n, x = (n + 1) / 2;
     FOR (i, 1, n) {
         FOR (j, 1, n) {
             cin >> w[i][j];
         }
     }
     dfs(1);

     cout << ans << endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PI;
typedef long long LL;
typedef double D;
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define R(I,N) for(int I=0;I<N;I++)
#define F(I,A,B) for(int I=A;I<B;I++)
#define FD(I,N) for(int I=N-1;I>=0;I--)
#define make(A) scanf("%d",&A)
template<typename C> void ma(C& a,C b){if(a<b)a=b;}
template<typename C> void mi(C& a,C b){if(a>b)a=b;}
#define MAX 41
int n,x;
int t[MAX][MAX];
int w[MAX],tt[MAX];
int wyn;
inline int zn(int a){
  return a?-1:1;
}
int licz3(){
  int wyn1=tt[x-1],wyn2=tt[x-1]*-1;
  R(i,x-1){
    wyn1 += abs(tt[i] + tt[x+i]);
    wyn2 += abs(tt[i] - tt[x+i]);
  }
  return max(wyn1,wyn2);
}
void licz2(){
  int war = 0;
  F(i,x,n)w[i] = w[i-x] ^ w[x-1];
  R(i,n)war += t[x-1][i] * zn(w[i]);
 // R(i,n)printf("%d ",w[i]);
 // printf("\n");
  R(i,x-1){
    R(j,n){
      tt[j] = t[i][j] + t[i+x][j] * zn(w[j]);
    }
    int pom = licz3();
    war += pom;
  //  printf("%d ",pom);
  }
 // printf("\n%d\n",war);
  if(war > wyn)
    wyn = war;
}
void licz(int nr){
  if(nr == x){
    licz2();
    return;
  }
  w[nr] = 0;
  licz(nr+1);
  w[nr] = 1;
  licz(nr+1);
}
main(){
  make(n);x=(n+1)/2;
  R(i,n)R(j,n){
    make(t[i][j]);
    wyn += t[i][j];
  }
  licz(0);
  printf("%d\n",wyn);
}


import java.io.*;

public class CF321D {

    public static void solve(Input in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int m = (n + 1) / 2;
        int[][] a = new int[n][n];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                a[i][j] = in.nextInt();
            }
        }
        long ans = Long.MIN_VALUE;
        for (int mask = 0; mask < 1 << m; ++mask) {
            long cur = sgn(mask, m - 1) * a[m - 1][m - 1];
            for (int j = 0; j < m - 1; ++j) {
                cur += sgn(mask, j) * (a[m - 1][j] + sgn(mask, m - 1) * a[m - 1][j + m]);
            }
            for (int i = 0; i < m - 1; ++i) {
                long rowMax = Long.MIN_VALUE;
                for (int b = 0; b < 2; ++b) {
                    long rowCur = sgn(b, 0) * (a[i][m - 1] + sgn(mask, m - 1) * a[i + m][m - 1]);
                    for (int j = 0; j < m - 1; ++j) {
                        rowCur += Math.abs(a[i][j] + sgn(b, 0) * a[i][j + m] + sgn(mask, j) * a[i + m][j] + sgn(b, 0) * sgn(mask, j) * sgn(mask, m - 1) * a[i + m][j + m]);
                    }
                    rowMax = Math.max(rowMax, rowCur);
                }
                cur += rowMax;
            }
            ans = Math.max(ans, cur);
        }
        out.println(ans);
    }

    private static int sgn(int mask, int i) {
        return (mask & (1 << i)) != 0 ? -1 : 1;
    }

    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);
        out.close();
    }

    static class Input {
        BufferedReader in;
        StringBuilder sb = new StringBuilder();

        public Input(BufferedReader in) {
            this.in = in;
        }

        public Input(String s) {
            this.in = new BufferedReader(new StringReader(s));
        }

        public String next() throws IOException {
            sb.setLength(0);
            while (true) {
                int c = in.read();
                if (c == -1) {
                    return null;
                }
                if (" \n\r\t".indexOf(c) == -1) {
                    sb.append((char)c);
                    break;
                }
            }
            while (true) {
                int c = in.read();
                if (c == -1 || " \n\r\t".indexOf(c) != -1) {
                    break;
                }
                sb.append((char)c);
            }
            return sb.toString();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }
}


import java.io.*;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) throws Throwable {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int x = n >> 1;
    int[][] a = new int[n][n];
    int[][] b = new int[n][n];
    for (int i = 0; i < n; i++) {
      String[] ss = br.readLine().split(" +");
      for (int j = 0; j < n; j++)
        a[i][j] = Integer.parseInt(ss[j]);
    }
    int ans = Integer.MIN_VALUE;
    int allmask = 1 << x + 1;
    for (int mask = 0; mask < allmask; mask++) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          b[i][j] = a[i][j];
      for (int i = 0; i <= x; i++)
        if ((mask >> i & 1) != 0)
          for (int p = 0; p <= x; p++)
            for (int q = 0; q <= x; q++)
              b[x+p][i+q] = -b[x+p][i+q];
      int cur = 0;
      for (int i = 0; i < n; i++)
        cur += b[x][i];
      for (int i = 0; i < x; i++)
        for (int j = 0; j < n; j++)
          b[i][j] += b[x+i+1][j];
      for (int i = 0; i < x; i++) {
        int t1 = b[i][x];
        int t2 = -b[i][x];
        for (int j = 0; j < x; j++) {
          t1 += max(b[i][j] + b[i][x+j+1], -b[i][j] - b[i][x+j+1]);
          t2 += max(b[i][j] - b[i][x+j+1], -b[i][j] + b[i][x+j+1]);
        }
        cur += max(t1, t2);
      }
      ans = max(ans, cur);
    }
    System.out.println(ans);
  }
}


#include <algorithm>

#include <stdio.h>

#include <memory.h>

#include <string.h>

#include <ctype.h>

#include <cmath>

#include <ctime>

#include <queue>

#include <vector>

#include <string>

#include <set>

#include <map>

#include <bitset>

using namespace std;

typedef long long INT;

typedef pair<int, int> pii;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template <class T> inline void chkmin(T &a, T b) { if (a>b) a=b; }

template <class T> inline void chkmax(T &a, T b) { if (a<b) a=b; }

#define NN 50

int N, x, board[NN][NN], ori[NN][NN], a[NN];

void flip(int r, int c) {

	for (int i=0; i<x; i++)

		for (int j=0; j<x; j++)

			board[r+i][c+j]*=-1;

}

int main() {

	int i, j, k, ans, sum;

	scanf("%d", &N);

	for (i=0; i<N; i++)

		for (j=0; j<N; j++)

			scanf("%d", &board[i][j]);

	memcpy(ori, board, sizeof(ori));

	x=(N+1)/2; ans=-1000000000;

	for (i=0; i<(1<<x); i++) {

		memcpy(board, ori, sizeof(board));

		for (j=0; j<x; j++)

			if (i&(1<<j)) flip(j, x-1);

		memset(a, 0, sizeof(int)*N);

		for (j=0; j<N; j++) {

			for (k=0; k<x-1; k++)

				a[j]+=abs(board[j][k]+board[j][k+x]);

			a[j]+=board[j][x-1];

		}

		sum=0;

		for (j=0; j<x-1; j++) sum+=abs(a[j]+a[j+x]);

		sum+=a[x-1]; chkmax(ans, sum);

		for (j=x-1; j<N; j++) a[j]*=-1;

		sum=0;

		for (j=0; j<x-1; j++) sum+=abs(a[j]+a[j+x]);

		sum+=a[x-1]; chkmax(ans, sum);

	}

	printf("%d\n", ans);

	return 0;

}


#include <algorithm>

#include <stdio.h>

#include <memory.h>

#include <queue>

#include <cmath>

#include <set>

#include <map>

#include <string.h>

#include <string>

#include <ctype.h>

#include <ctime>

#include <complex>

#include <bitset>

using namespace std;

typedef long long INT;

typedef pair<int, int> pii;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template <class T> inline void chkmin(T &a, T b) { if (a>b) a=b; }

template <class T> inline void chkmax(T &a, T b) { if (a<b) a=b; }

#define NN 60

#define inf 0x3f3f3f3f

int N, x;

int a[NN][NN], b[NN][NN], p[NN];

void flip(int r, int c) {

	int i, j;

	for (i=0; i<x; i++)

		for (j=0; j<x; j++)

			b[r+i][c+j]*=-1;

}

int main() {

	int i, j, s, s1, s2, ans, cur;

	scanf("%d", &N);

	for (i=0; i<N; i++)

		for (j=0; j<N; j++)

			scanf("%d", &a[i][j]);

	x=(N+1)/2; ans=-inf;

	for (s=0; s<(1<<x); s++) {

		memcpy(b, a, sizeof(a));

		for (i=0; i<x; i++)

			if (s&(1<<i)) flip(i, x-1);

		cur=0;

		for (i=0; i<N; i++) cur+=b[i][x-1];

		for (j=0; j<x-1; j++) {

			for (i=0; i<N; i++) p[i]=b[i][j]+b[i][j+x];

			s1=p[x-1];

			for (i=0; i<x-1; i++) s1+=abs(p[i]+p[i+x]);

			for (i=x-1; i<N; i++) p[i]=-p[i];

			s2=p[x-1];

			for (i=0; i<x-1; i++) s2+=abs(p[i]+p[i+x]);

			cur+=max(s1, s2);

		}

		chkmax(ans, cur);

	}

	printf("%d\n", ans);

	return 0;

}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int M=35;
int A[M][M],B[M][M];
inline void Max(int &a,int b){
	if(a<b)a=b;
}
int main(){
	int n;cin>>n;
	int m=n+1>>1,ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)cin>>A[i][j];
	for(int s=0;s<1<<m;++s){
		for(int i=1;i<=m;++i)
			B[m][i]=s&1<<i-1?1:0;
		for(int i=m+1;i<=n;++i)
			B[m][i]=B[m][i-m]^B[m][m];
		for(int j=1;j<=n;++j){
			if(B[m][j])
				for(int i=1;i<m;++i)
					B[i][j]=A[i][j]-A[i+m][j];
					// the up is 0(1) and the down is 1(-1)
			else for(int i=1;i<m;++i)
				B[i][j]=A[i][j]+A[i+m][j];
					//both up and down is 0(1)
		}
		int res=0;
		for(int i=1;i<m;++i){
			int w1=B[i][m],w2=-B[i][m];
			for(int j=1;j<m;++j){
				w1+=abs(B[i][j]+B[i][j+m]);
				w2+=abs(B[i][j]-B[i][j+m]);
			}
			res+=max(w1,w2);
		}
		for(int i=1;i<=n;++i){
			B[m][i]=B[m][i]?-1:1;
			B[m][i]*=A[m][i],res+=B[m][i];
		}
		Max(ans,res);
	}
	cout<<ans<<endl;
	return 0;
}


#include <climits>
#include <cstdio>

#ifdef _WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif

const int MAXN = 35;

int n;
int a[MAXN][MAXN];

void init()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			scanf("%d", &a[i][j]);
}

void solve()
{
	int m = (n + 1) >> 1;
	int ans = INT_MIN;

	for (int i = 0; i < (1 << m); ++i)
	{
		int c[MAXN];
		int sum = 0;

		for (int j = 0; j < m; ++j)
			c[j] = (i >> j) & 1;
		for (int j = m; j < n; ++j)
			c[j] = c[j - m] ^ c[m - 1];

		for (int j = 0; j < n; ++j)
			if (c[j]) c[j] = -1;
			else c[j] = 1;

		for (int j = 0; j < n; ++j)
			sum += c[j] * a[m - 1][j];

		for (int j = 0; j < m - 1; ++j)
			for (int k = 0; k < n; ++k)
			{
				int tmp = a[j][k] + c[k] * a[j + m][k];
				if (tmp < 0) tmp = -tmp;
				sum += tmp;
			}

		if (sum > ans) ans = sum;
	}

	printf("%d\n", ans);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("8787.in", "r", stdin);
	freopen("8787.out", "w", stdout);
#endif

	init();
	solve();

#ifndef ONLINE_JUDGE
	fclose(stdin); fclose(stdout);
#endif
	return 0;
}


#include <climits>
#include <cstdio>

#ifdef _WIN32
#define LLFORMAT "I64"
#else
#define LLFORMAT "ll"
#endif

const int MAXN = 35;

int n;
int a[MAXN][MAXN];

void init()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			scanf("%d", &a[i][j]);
}

void solve()
{
	int m = (n + 1) >> 1;
	int ans = INT_MIN;

	for (int i = 0; i < (1 << m); ++i)
	{
		int c[MAXN];
		int sum = 0;

		for (int j = 0; j < m; ++j)
			c[j] = (i >> j) & 1;
		for (int j = m; j < n; ++j)
			c[j] = c[j - m] ^ c[m - 1];

		for (int j = 0; j < n; ++j)
			if (c[j]) c[j] = -1;
			else c[j] = 1;

		for (int j = 0; j < n; ++j)
			sum += c[j] * a[m - 1][j];

		for (int j = 0; j < m - 1; ++j)
		{
			int now = 0;
			for (int k = -1; k <= 1; k += 2)
			{
				int ss = a[j][m - 1] * k + a[j + m][m - 1] * (k * c[m - 1]);
				for (int p = 0; p < m - 1; ++p)
				{
					int tmp = a[j][p] + a[j][p + m] * k + a[j + m][p] * c[p] + a[j + m][p + m] * (k * c[p + m]);
					if (tmp < 0) tmp = -tmp;
					ss += tmp;
				}
				if (ss > now) now = ss;
			}
			sum += now;
		}

		if (sum > ans) ans = sum;
	}

	printf("%d\n", ans);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("8787.in", "r", stdin);
	freopen("8787.out", "w", stdout);
#endif

	init();
	solve();

#ifndef ONLINE_JUDGE
	fclose(stdin); fclose(stdout);
#endif
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 35;
const int inf = 1987654321;
int map[N][N][2];
int fan[N];
int n,m;
int ans=-inf;
void calc()
{
	int i,j,k;
	int now=0;
	for(i=1;i<m;i++)
		fan[i+m]=fan[m]^fan[i];
	for(i=1;i<=n;i++)
		now+=map[i][m][fan[i]];
	for(i=1;i<m;i++)
	{
		int z=-inf;
		for(k=0;k<=1;k++)
		{
			int t=map[m][i][k]+map[m][m+i][k^fan[m]];
			for(j=1;j<m;j++)
			{
				int s=map[j][i][0];
				s+=map[j+m][i][k];
				s+=map[j][i+m][fan[j]];
				s+=map[j+m][i+m][k^fan[j+m]];
				s=max(s,-s);
				t+=s;
			}
			z=max(z,t);
		}
		now+=z;
	}
	ans=max(ans,now);
}
void dfs(int x)
{
	if(x>m)
	{
		calc();
		return;
	}
	fan[x]=0;
	dfs(x+1);
	fan[x]=1;
	dfs(x+1);
}
int main()
{
	int i,j;
	scanf("%d",&n);
	m=(n+1)>>1;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&map[i][j][0]);
			map[i][j][1]=-map[i][j][0];
		}
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 35;
const int inf = 1987654321;
int map[N][N][2];
int fan[N];
int n,m;
int ans=-inf;
void calc()
{
	int i,j,k;
	int now=0;
	for(i=1;i<=n;i++)
		now+=map[i][m][fan[i]];
	for(i=1;i<m;i++)
		fan[i+m]=fan[m]^fan[1];
	for(i=1;i<m;i++)
	{
		int z=-inf;
		for(k=0;k<=1;k++)
		{
			int t=map[m][i][k]+map[m][m+i][k^fan[m]];
			for(j=1;j<m;j++)
			{
				int s=map[j][i][0];
				s+=map[j+m][i][k];
				s+=map[j][i+m][fan[j]];
				s+=map[j+m][i+m][k^fan[j+m]];
				s=max(s,-s);
				t+=s;
			}
			z=max(z,t);
		}
		now+=z;
	}
	ans=max(ans,now);
}
void dfs(int x)
{
	if(x>m)
	{
		calc();
		return;
	}
	fan[x]=0;
	dfs(x+1);
	fan[x]=1;
	dfs(x+1);
}
int main()
{
	int i,j;
	scanf("%d",&n);
	m=(n+1)>>1;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&map[i][j][0]);
			map[i][j][1]=-map[i][j][0];
		}
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <ctime>
#include <map>
#include <queue>
#include <set>
using namespace std;

const int maxn=40;
int n;
int a[maxn][maxn];
int sz[maxn][maxn];
int x;
int ans,sum;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	 for (int j=1;j<=n;j++)
	    scanf("%d",&a[i][j]),ans+=a[i][j];
	x=(n+1)/2;
	for (int i=0;i<(1 << x);i++)
	{
		sum=0;
		for (int j=1;j<=x;j++)
		 if (i&(1 << (j-1)))
		  sum+=-a[x][j];
		   else sum+=a[x][j];
	    int mid=min(i&(1 << (x-1)),1);
		for (int j=x+1;j<=n;j++)
		 {
		 	int g1=min(i&(1 << (j-x-1)),1);
		 	g1^=mid;
		 	if (g1) sum+=-a[x][j];
		 	 else sum+=a[x][j];
		 }
		for (int j=1;j<x;j++)
		{
			int s1=0,s2=0;
			s1+=a[j][x];s2+=-a[j][x];
			if (mid) s1+=-a[j+x][x],s2+=a[j+x][x];
			 else s1+=a[j+x][x],s2+=-a[j+x][x];
			for (int k=1;k<x;k++)
			{
				int s3=0,s4=0;
				int sh=0,zs=min(i&(1 << (k-1)),1);
				int xh=sh^mid,rs=zs^mid;
				s3+=a[j][k],s4+=-a[j][k];
				if (sh) s3+=-a[j][k+x],s4+=a[j][k+x];
				 else s3+=a[j][k+x],s4+=-a[j][k+x];
				if (zs) s3+=-a[j+x][k],s4+=a[j+x][k];
				 else s3+=a[j+x][k],s4+=-a[j+x][k];
				if (sh^rs) s3+=-a[j+x][k+x],s4+=a[j+x][k+x];
				 else s3+=a[j+x][k+x],s4+=-a[j+x][k+x];
				s1+=max(s3,s4);
				s3=0,s4=0;
				sh=1;xh^=1;
				s3+=a[j][k],s4+=-a[j][k];
				if (sh) s3+=-a[j][k+x],s4+=a[j][k+x];
				 else s3+=a[j][k+x],s4+=-a[j][k+x];
				if (zs) s3+=-a[j+x][k],s4+=a[j+x][k];
				 else s3+=a[j+x][k],s4+=-a[j+x][k];
				if (sh^rs) s3+=-a[j+x][k+x],s4+=a[j+x][k+x];
				 else s3+=a[j+x][k+x],s4+=-a[j+x][k+x];
				s2+=max(s3,s4);
			}
			sum+=max(s1,s2);
		}
	    ans=max(ans,sum);
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 34
#define INF 0x7fffffff
using namespace std;
int n,x,a[N][N];
namespace pendejo
{
	int b[N][N],ans=-INF;
	int check(int y)
	{
		int i,j,k,l;
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				b[i][j]=a[i][j];
		int s=0;
		for(i=1;i<=x;i++)
			for(j=1;j<=x;j++)
				if(y&(1<<((i-1)*x+j)>>1))
					for(k=i;k<i+x;k++)
						for(l=j;l<j+x;l++)
							b[k][l]=-b[k][l];
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				s+=b[i][j];
		return s;
	}
	void work()
	{
		int i;
		for(i=0;i<(1<<(x*x));i++)
			ans=max(ans,check(i));
		printf("%d\n",ans);
	}
}
namespace gzotpa
{
	int b[N][N],ans=-INF;
	int getrowmx(int p)
	{
		int i,j,mx=-INF;
		int q=p+x;
		int A=1,D=1*b[x][x];
		int sum=A*a[x][p]+D*a[x][p+x];
		for(i=1;i<x;i++)
		{
			int Q1=1,E1=Q1*b[i][x],Z1=Q1*A,C1=E1*D;
			int Q2=-1,E2=Q2*b[i][x],Z2=Q2*A,C2=E2*D;
			sum+=max(Q1*a[i][p]+Z1*a[i+x][p]+E1*a[i][p+x]+C1*a[i+x][p+x],
				 	 Q2*a[i][p]+Z2*a[i+x][p]+E2*a[i][p+x]+C2*a[i+x][p+x]);
		}
		mx=max(mx,sum);
		A=-1,D=-1*b[x][x];
		sum=A*a[x][p]+D*a[x][p+x];
		for(i=1;i<x;i++)
		{
			int Q1=1,E1=Q1*b[i][x],Z1=Q1*A,C1=E1*D;
			int Q2=-1,E2=Q2*b[i][x],Z2=Q2*A,C2=E2*D;
			sum+=max(Q1*a[i][p]+Z1*a[i+x][p]+E1*a[i][p+x]+C1*a[i+x][p+x],
					 Q2*a[i][p]+Z2*a[i+x][p]+E2*a[i][p+x]+C2*a[i+x][p+x]);
		}
		mx=max(mx,sum);
		return mx;
	}
	int check(int y)
	{
		int i,s=0;
		for(i=1;i<=x;i++)
		{
			if(y&(1<<i>>1))
				b[i][x]=-1;
			else
				b[i][x]=1;
		}
		for(i=x+1;i<=n;i++)
			b[i][x]=b[i-x][x]*b[x][x];
		for(i=1;i<=n;i++)
			s+=b[i][x]*a[i][x];
		for(i=1;i<x;i++)
			s+=getrowmx(i);
		return s;
	}
	void work()
	{
		int i,j;
		for(i=0;i<(1<<x);i++)
			ans=max(ans,check(i));
		printf("%d\n",ans);
	}
}
int main()
{
	int i,j;
	scanf("%d",&n);
	x=(n+1)>>1;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	if(n<=7)
	{
		using namespace pendejo;
		work();
	}
	else
	{
		using namespace gzotpa;
		work();
	}
	return 0;
}


#include <cstdio>
static const int MAXN = 33;
static const int MAXX = 17;

int n, x;
int a[MAXN][MAXN];
bool b[MAXN][MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]);

    x = (n + 1) / 2;
    int ans = 0x80000000, cur;
    for (int mask = 0; mask < (1 << x); ++mask) {
        for (int i = 0; i < x; ++i) b[x - 1][i] = (mask >> i) & 1;
        for (int i = x; i < n; ++i) b[x - 1][i] = ((mask >> (x - 1)) & 1) ^ b[x - 1][i - x];
        for (int i = 0; i < x - 1; ++i)
            for (int j = 0; j < n; ++j)
                if (b[x - 1][j] == true) {
                    if (a[i][j] - a[i + x][j] >= 0) { b[i][j] = false; b[i + x][j] = true; }
                    else { b[i][j] = true; b[i + x][j] = false; }
                } else {
                    if (a[i][j] + a[i + x][j] >= 0) { b[i][j] = b[i + x][j] = false; }
                    else { b[i][j] = b[i + x][j] = true; }
                }
        cur = 0;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j) cur += a[i][j] * (b[i][j] ? -1 : 1);
        if (ans < cur) ans = cur;
    }

    printf("%d\n", ans);
    return 0;
}


#include <cstdio>
static const int INF = 0x7fffffff;
static const int MAXN = 33;
static const int MAXX = 17;
template <typename T> inline T min(const T a, const T b) { return a < b ? a : b; }
template <typename T> inline T max(const T a, const T b) { return a > b ? a : b; }
template <typename T> inline T abs(const T x) { return x > 0 ? x : -x; }

int n, x;
int a[MAXN][MAXN];
short centre_row[MAXN], centre_col;
static const int mul[2] = { 1, -1 };

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]);

    x = (n + 1) / 2;
    int ans = -INF, sum;
    for (int mask = 0; mask < (1 << x); ++mask) {
        sum = 0;
        for (int i = 0; i < x; ++i) centre_row[i] = (mask >> i) & 1;
        for (int i = x; i < n; ++i) centre_row[i] = ((mask >> (x - 1)) & 1) ^ centre_row[i - x];
        for (int i = 0; i < n; ++i) sum += a[x - 1][i] * mul[centre_row[i]];

        //printf("%d: CRow = %d\n", mask, sum);
        for (int i = 0; i < x - 1; ++i) {
            int cur = -INF;
            for (centre_col = 0; centre_col <= 1; ++centre_col) {
                int sol = a[i][x - 1] * mul[centre_col] + a[i + x][x - 1] * mul[centre_col ^ centre_row[x - 1]];
                for (int j = 0; j < x - 1; ++j)
                    sol += abs(a[i][j] + a[i][j + x] * mul[centre_col] + a[i + x][j] * mul[centre_row[j]] + a[i + x][j + x] * mul[centre_col ^ centre_row[j] ^ centre_row[x - 1]]);
                cur = max(cur, sol);
            }
            sum += cur;
            //printf("%d: Row %d,%d sum = %d\n", mask, i, i + x, cur);
        }
        //printf("%d: Sum = %d\n", mask, sum);
        ans = max(ans, sum);
    }

    printf("%d\n", ans);
    return 0;
}


/*
* @Author: 逸闲
* @Date:   2016-05-24 21:07:35
* @Last Modified by:   逸闲
* @Last Modified time: 2016-05-28 16:10:33
*/

#include "cstdio"
#include "cstdlib"
#include "iostream"
#include "algorithm"
#include "cstring"
#include "queue"

using namespace std;

#define INF 0x3F3F3F3F
#define MAX_SIZE 35
#define Eps
#define Mod
#define Get(x, a) (x ? x -> a : 0)
#define Flag(x) (x ? -1 : 1)

inline int Get_Int()
{
	int Num = 0, Flag = 1;
	char ch;
	do
	{
		ch = getchar();
		if(ch == '-')
			Flag = -Flag;
	}
	while(ch < '0' || ch > '9');
	do
	{
		Num = Num * 10 + ch - '0';
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9');
	return Num * Flag;
}

int N, M, Ans, Sum;
int A[MAX_SIZE][MAX_SIZE], Reverse[MAX_SIZE];

int main()
{
	cin >> N;
	M = N + 1 >> 1;
	for(int i = 1; i <= N; ++i)
		for(int j = 1; j <= N; ++j)
			A[i][j] = Get_Int();
	for(int S = 0; S < (1 << M); ++S)
	{
		Sum = 0;
		for(int i = M; i; --i)
		{
			Reverse[i] = (S >> i - 1 & 1);
			Reverse[i + M] = Reverse[i] ^ Reverse[M];
		}
		for(int i = 1; i <= N; ++i)
			Sum += A[i][M] * Flag(Reverse[i]);
		for(int i = 1; i < M; ++i)
		{
			int MaxA = 0;
			for(int x = 0; x <= 1; ++x)
			{
				int x1 = x ^ Reverse[M];
				int SumA = A[M][i] * Flag(x) + A[M][M + i] * Flag(x1);
				for(int j = 1; j < M; ++j)
				{
					int MaxB = 0;
					for(int y = 0; y <= 1; ++y)
					{
						int y1 = y ^ Reverse[j], y2 = y ^ x, y3 = y1 ^ x1;
						MaxB = max(MaxB, A[j][i] * Flag(y) + A[j][i + M] * Flag(y1) + A[j + M][i] * Flag(y2) + A[j + M][i + M] * Flag(y3));
					}
					SumA += MaxB;
				}
				MaxA = max(MaxA, SumA);
			}
			Sum += MaxA;
		}
		Ans = max(Ans, Sum);
	}
	cout << Ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 34
#define INF 0x7fffffff
using namespace std;
int n,x,a[N][N];
namespace pendejo
{
	int b[N][N],ans=-INF;
	int check(int y)
	{
		int i,j,k,l;
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				b[i][j]=a[i][j];
		int s=0;
		for(i=1;i<=x;i++)
			for(j=1;j<=x;j++)
				if(y&(1<<((i-1)*x+j)>>1))
					for(k=i;k<i+x;k++)
						for(l=i;l<j+x;l++)
							b[k][l]=-b[k][l];
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				s+=b[i][j];
		return s;
	}
	void work()
	{
		int i;
		for(i=0;i<(1<<(x*x));i++)
			ans=max(ans,check(i));
		printf("%d\n",ans);
	}
}
namespace gzotpa
{
	int b[N][N],ans=-INF;
	int getrowmx(int p)
	{
		int i,j,mx=-INF;
		int q=p+x;
		int A=1,D=1*b[x][x];
		int sum=A*a[x][p]+D*a[x][p+x];
		for(i=1;i<x;i++)
		{
			int Q1=1,E1=Q1*b[i][x],Z1=Q1*A,C1=E1*A;
			int Q2=-1,E2=Q2*b[i][x],Z2=Q2*D,C2=E2*D;
			sum+=max(Q1*a[i][p]+Z1*a[i+x][p]+E1*a[i][p+x]+C1*a[i+x][p+x],
				 	 Q2*a[i][p]+Z2*a[i+x][p]+E2*a[i][p+x]+C2*a[i+x][p+x]);
		}
		mx=max(mx,sum);
		A=-1,D=-1*b[x][x];
		sum=A*a[x][p]+D*a[x][p+x];
		for(i=1;i<x;i++)
		{
			int Q1=1,E1=Q1*b[i][x],Z1=Q1*A,C1=E1*A;
			int Q2=-1,E2=Q2*b[i][x],Z2=Q2*D,C2=E2*D;
			sum+=max(Q1*a[i][p]+Z1*a[i+x][p]+E1*a[i][p+x]+C1*a[i+x][p+x],
					 Q2*a[i][p]+Z2*a[i+x][p]+E2*a[i][p+x]+C2*a[i+x][p+x]);
		}
		mx=max(mx,sum);
		return mx;
	}
	int check(int y)
	{
		int i,s=0;
		for(i=1;i<=x;i++)
		{
			if(y&(1<<i>>1))
				b[i][x]=-1;
			else
				b[i][x]=1;
		}
		for(i=x+1;i<=n;i++)
			b[i][x]=b[i-x][x]*b[x][x];
		for(i=1;i<=n;i++)
			s+=b[i][x]*a[i][x];
		for(i=1;i<x;i++)
			s+=getrowmx(i);
		return s;
	}
	void work()
	{
		int i,j;
		for(i=0;i<(1<<x);i++)
			ans=max(ans,check(i));
		printf("%d\n",ans);
	}
}
int main()
{
	int i,j;
	scanf("%d",&n);
	x=(n+1)>>1;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	if(n<=7)
	{
		using namespace pendejo;
		work();
	}
	else
	{
		using namespace gzotpa;
		work();
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 34
#define INF 0x7fffffff
using namespace std;
int n,x,a[N][N];
namespace pendejo
{
	int b[N][N],ans=-INF;
	int check(int y)
	{
		int i,j,k,l;
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				b[i][j]=a[i][j];
		int s=0;
		for(i=1;i<=x;i++)
			for(j=1;j<=x;j++)
				if(y&(1<<((i-1)*x+j)>>1))
					for(k=i;k<i+x;k++)
						for(l=i;l<j+x;l++)
							b[k][l]=-b[k][l];
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				s+=b[i][j];
		return s;
	}
	void work()
	{
		int i;
		for(i=0;i<(1<<(x*x));i++)
			ans=max(ans,check(i));
		printf("%d\n",ans);
	}
}
namespace gzotpa
{
	int b[N][N],ans=-INF;
	int getrowmx(int p)
	{
		int i,j,mx=-INF;
		int q=p+x;
		int A=1,D=1*b[x][x];
		int sum=A*a[x][p]+D*a[x][p+x];
		for(i=1;i<x;i++)
		{
			int Q1=1,E1=Q1*b[i][x],Z1=Q1*A,C1=E1*A;
			int Q2=-1,E2=Q2*b[i][x],Z2=Q2*D,C2=E2*D;
			sum+=max(Q1*a[i][p]+Z1*a[i+x][p]+E1*a[i][p+x]+C1*a[i+x][p+x],
				 	 Q2*a[i][p]+Z2*a[i+x][p]+E2*a[i][p+x]+C2*a[i+x][p+x]);
		}
		mx=max(mx,sum);
		A=-1,D=-1*b[x][x];
		sum=A*a[x][p]+D*a[x][p+x];
		for(i=1;i<x;i++)
		{
			int Q1=1,E1=Q1*b[i][x],Z1=Q1*A,C1=E1*A;
			int Q2=-1,E2=Q2*b[i][x],Z2=Q2*D,C2=E2*D;
			sum+=max(Q1*a[i][p]+Z1*a[i+x][p]+E1*a[i][p+x]+C1*a[i+x][p+x],
					 Q2*a[i][p]+Z2*a[i+x][p]+E2*a[i][p+x]+C2*a[i+x][p+x]);
		}
		mx=max(mx,sum);
		return mx;
	}
	int check(int y)
	{
		int i,s=0;
		for(i=1;i<=x;i++)
		{
			if(y&(1<<i>>1))
				b[i][x]=-1;
			else
				b[i][x]=1;
		}
		for(i=x+1;i<=n;i++)
			b[i][x]=b[i-x][x]*b[x][x];
		for(i=1;i<=n;i++)
			s+=b[i][x]*a[i][x];
		for(i=1;i<x;i++)
			s+=getrowmx(i);
		return s;
	}
	void work()
	{
		int i,j;
		for(i=0;i<(1<<x);i++)
			ans=max(ans,check(i));
		printf("%d\n",ans);
	}
}
int main()
{
	int i,j;
	scanf("%d",&n);
	x=(n+1)>>1;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	using namespace gzotpa;
	work();
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 50;
int n, m, a[N][N], b[N][N], ans;
void Check() {
	/* Rep(i, 1, n) {
		Rep(j, 1, n) cout << a[i][j]<<" ";
		puts("");
	}
	puts(""); */
	int sum = 0;
	Rep(i, 1, m - 1) {
		Rep(j, 1, m - 1)
			b[i][j] = abs(a[i][j] + a[i + m][j] + a[i][j + m] + a[i + m][j + m]), sum += b[i][j];
		sum += a[i][m] + a[m + i][m] + a[m][i] + a[m][m + i];
	}
	sum += a[m][m];
	//cout << sum << endl;
	Rep(j, 1, m - 1) {
		int ret = - (a[m][j] * 2 + a[m][m + j] * 2);
		Rep(i, 1, m - 1) {
			ret += abs(a[i][j] + a[i][j + m] - a[i + m][j] - a[i + m][j + m]) - b[i][j];
			// cout << i <<" "<<j<<" "<<b[i][j]<<endl;
		}
		// cout << ret << endl;
		if (ret > 0) sum += ret;
	}
	ans = max(ans, sum);
}
void Dfs(int x) {
	if (x == m + 1) { Check(); return ; }
	if (x == 3) Dfs(x + 1);
	Rep(i, 0, m - 1) {
		Rep(j, 0, m - 1) a[x + i][m + j] *= -1;
	}
	Dfs(x + 1);
	Rep(i, 0, m - 1) {
		Rep(j, 0, m - 1) a[x + i][m + j] *= -1;
	}
}
int main()
{
	scanf ("%d", &n); m = (n + 1) / 2;
	Rep(i, 1, n) {
		Rep(j, 1, n) scanf ("%d", &a[i][j]);
	}
	Dfs(1);
	cout << ans << endl;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int n,m,a[35][35],ret,ans=-1<<30;
int c[35];
void solve(int x,int z)
{
	if(x>m){
		for(int i=1;i<m;i++)z+=a[i+m][m]*c[m]*c[i];
		//cout<<z<<" "<<c[1]<<" "<<c[2]<<endl;
		int p=0,tot=z;
		for(int i=1;i<m;i++){
			ret=a[m][i]+c[m]*a[m][i+m];//cout<<ret<<" ============"<<endl;
			for(int j=1;j<m;j++){
				int x=a[j][i]+c[j]*a[j][i+m];
				int y=a[j+m][i]+c[j]*c[m]*a[j+m][i+m];
				ret+=max(x+y,-x-y);
			}
			p=ret;ret=-a[m][i]+c[m]*(-1)*a[m][i+m];//cout<<ret<<" ;;;;;;;;;;;"<<endl;
			for(int j=1;j<m;j++){
				int x=a[j][i]+c[j]*a[j][i+m];
				int y=-1*(a[j+m][i]+c[j]*c[m]*a[j+m][i+m]);
				ret+=max(x+y,-x-y);
			}
			p=max(p,ret);//cout<<p<<endl;
			tot+=p;
		}
		ans=max(ans,tot);
		return ;
	}
	c[x]=-1;
	solve(x+1,z+a[x][m]*(-1));
	c[x]=1;
	solve(x+1,z+a[x][m]);
}
int main()
{
	cin>>n;
	m=n/2+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);
	solve(1,0);
	cout<<ans<<endl;

    //system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 50;
int n, m, a[N][N], b[N][N], ans;
void Check() {
	/* Rep(i, 1, n) {
		Rep(j, 1, n) cout << a[i][j]<<" ";
		puts("");
	}
	puts(""); */
	int sum = 0;
	Rep(i, 1, m - 1) {
		Rep(j, 1, m - 1)
			b[i][j] = abs(a[i][j] + a[i + m][j] + a[i][j + m] + a[i + m][j + m]), sum += b[i][j];
		sum += a[i][m] + a[m + i][i] + a[m][i] + a[m][m + i];
	}
	sum += a[m][m];
	Rep(i, 1, m - 1) {
		int ret = - (a[m][i] * 2 + a[m][m + i] * 2);
		Rep(j, 1, m - 1) {
			ret += abs(a[i][j] + a[i][j + m] - a[i + m][j] - a[i + m][j + m]) - b[i][j];
		}
		if (ret > 0) sum += ret;
	}
	ans = max(ans, sum);
}
void Dfs(int x) {
	if (x == m + 1) { Check(); return ; }
	Dfs(x + 1);
	Rep(i, 0, m - 1) {
		Rep(j, 0, m - 1) a[x + i][m + j] *= -1;
	}
	Dfs(x + 1);
	Rep(i, 0, m - 1) {
		Rep(j, 0, m - 1) a[x + i][m + j] *= -1;
	}
}
int main()
{
	scanf ("%d", &n); m = (n + 1) / 2;
	Rep(i, 1, n) {
		Rep(j, 1, n) scanf ("%d", &a[i][j]);
	}
	Dfs(1);
	cout << ans << endl;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int n,m,a[35][35],ret,ans=-1<<30;
int c[35];
void solve(int x,int z)
{
	if(x>m){
		for(int i=1;i<m;i++)z+=a[i+m][m]*c[m]*c[i];
		//cout<<z<<" "<<c[1]<<" "<<c[2]<<endl;
		int p=0,tot=z;
		for(int i=1;i<m;i++){
			ret=a[m][i]+c[m]*a[m][i+m];//cout<<ret<<" ============"<<endl;
			for(int j=1;j<m;j++){
				int x=a[j][i]+c[j]*a[j+m][i];
				int y=a[j+m][i]+c[j]*c[m]*a[j+m][i+m];
				ret+=max(x+y,-x-y);
			}
			p=ret;ret=-a[m][i]+c[m]*(-1)*a[m][i+m];//cout<<ret<<" ;;;;;;;;;;;"<<endl;
			for(int j=1;j<m;j++){
				int x=a[j][i]+c[j]*a[j+m][i];
				int y=-1*(a[j+m][i]+c[j]*c[m]*a[j+m][i+m]);
				ret+=max(x+y,-x-y);
			}
			p=max(p,ret);//cout<<p<<endl;
			tot+=p;
		}
		ans=max(ans,tot);
		return ;
	}
	c[x]=-1;
	solve(x+1,z+a[x][m]*(-1));
	c[x]=1;
	solve(x+1,z+a[x][m]);
}
int main()
{
	cin>>n;
	m=n/2+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);
	solve(1,0);
	cout<<ans<<endl;

    //system("pause");
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>

const int mod = 1e9+7;
const int N = 200010;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
const double eps=1e-8;

using namespace std;

typedef long long ll;

#define pb push_back

int n, a[51][51], t[51][51];

int work(int x, int m){
	memcpy(a, t, sizeof(a));
	for(int k = 0; k < m; k++){
		if(x & (1 << k)){
			for(int i = m; i <= n; i++)
				for(int j = k + 1; j <= k + m; j++)
					a[i][j] = -a[i][j];
		}
	}
	//cout << x << endl;
	//for(int i = 1; i <= n; i++, cout << endl)
	//	for(int j = 1; j <= n; j++)
	//		cout << a[i][j] << " ";
	//cout << endl;
	int ret = 0;
	for(int i = 1; i < m; i++)
		for(int j = 1; j <= n; j++)
			a[i][j] += a[i + m][j];
	//for(int i = 1; i <= m; i++, cout << endl)
	//	for(int j = 1; j <= n; j++)
	//		cout << a[i][j] << " ";
	//cout << endl;
	for(int i = 1; i <= n; i++)
		ret += a[m][i];
	for(int i = 1; i < m; i++){
		int t1 = a[i][m], t2 = -a[i][m];
		for(int j = 1; j < m; j++){
			t1 += abs(a[i][j] + a[i][j + m]);
			t2 += abs(a[i][j] - a[i][j + m]);
		}
		ret += max(t1, t2);
	}
	//cout << ret << endl;
	//cout << "////////////////////////////////\n";
	return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			scanf("%d", &t[i][j]);
	int m = (n + 1) / 2;
	int ret = -1e9;
	for(int k = 0; k < (1 << m); k++){
		ret = max(ret, work(k, m));
	}
	cout << ret << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 50;
int n, m, a[N][N], b[N][N], ans;
void Check() {
	/* Rep(i, 1, n) {
		Rep(j, 1, n) cout << a[i][j]<<" ";
		puts("");
	}
	puts(""); */
	int sum = 0;
	Rep(i, 1, m - 1) {
		Rep(j, 1, m - 1)
			b[i][j] = abs(a[i][j] + a[i + m][j] + a[i][j + m] + a[i + m][j + m]), sum += b[i][j];
		sum += a[i][m] + a[m + i][m] + a[m][i] + a[m][m + i];
	}
	sum += a[m][m];
	//cout << sum << endl;
	Rep(j, 1, m - 1) {
		int ret = - (a[m][j] * 2 + a[m][m + j] * 2);
		Rep(i, 1, m - 1) {
			ret += abs(a[i][j] + a[i][j + m] - a[i + m][j] - a[i + m][j + m]) - b[i][j];
			// cout << i <<" "<<j<<" "<<b[i][j]<<endl;
		}
		// cout << ret << endl;
		if (ret > 0) sum += ret;
	}
	ans = max(ans, sum);
}
void Dfs(int x) {
	if (x == m + 1) { Check(); return ; }
	Dfs(x + 1);
	Rep(i, 0, m - 1) {
		Rep(j, 0, m - 1) a[x + i][m + j] *= -1;
	}
	Dfs(x + 1);
	Rep(i, 0, m - 1) {
		Rep(j, 0, m - 1) a[x + i][m + j] *= -1;
	}
}
int main()
{
	scanf ("%d", &n); m = (n + 1) / 2;
	Rep(i, 1, n) {
		Rep(j, 1, n) scanf ("%d", &a[i][j]);
	}
	Dfs(1);
	cout << ans << endl;

    return 0;
}


#include <cstdio>
#include <cstring>
#define max(a, b) (a > b ? a : b)
#define val(i, j) (F[i][j] ? -A[i][j] : A[i][j])
#define val4(i, j) (val(i, j) + val(i+m, j) + val(i, j+m) + val(i+m, j+m))

const int N = 35;

int n, m, A[N][N];
bool F[N][N];

int main()
{
	scanf("%d", &n);
	m = (n + 1) >> 1;
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", &A[i][j]);
			ans += A[i][j];
		}

	memset(F, 0, sizeof(F));
	for (int stat = 0; stat < 1 << m; stat++)
	{
		int sum = 0;

		for (int i = 1; i <= m; i++)
		{
			F[m][i] = stat >> (i - 1) & 1;
			sum += val(m, i);
		}
		for (int i = m + 1; i <= n; i++)
		{
			F[m][i] = F[m][i-m] ^ F[m][m];
			sum += val(m, i);
		}

		for (int i = 1; i < m; i++)
		{
			int s;
			for (int j = 0; j < 2; j++, F[i][m] ^= 1)
			{
				F[i][i+m] = F[i][m] ^ F[m][m];
				int ts = val(i, m) + val(i+m, m);
				for (int k = 1; k < m; k++)
				{
					int t;
					for (int l = 0; l < 2; l++, F[i][k] ^= 1)
					{
						F[i][k+m] = F[i][k] ^ F[i][m];
						F[i+m][k] = F[i][k] ^ F[m][k];
						F[i+m][k+m] = F[i][k+m] ^ F[m][k+m];
						t = l ? max(t, val4(i, k)) : val4(i, k);
					}
					ts += t;
				}
				s = F[i][m] ? max(s, ts) : ts;
			}
			sum += s;
		}

		ans = max(ans, sum);
	}

	printf("%d\n", ans);

	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#define val(i, j) (A[i][j] * F[i][j])

const int N = 35;

int n, m;
int A[N][N], F[N][N];

int main()
{
	scanf("%d", &n);
	m = (n + 1) >> 1;
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", &A[i][j]);
			ans += A[i][j];
		}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) F[i][j] = 1;
	for (int stat = 0; stat < 1 << m; stat++)
	{
		int sum = 0;

		for (int i = 1; i <= m; i++)
		{
			F[m][i] = (stat >> (i - 1) & 1) ? -1 : 1;
			sum += val(m, i);
		}
		for (int i = m + 1; i <= n; i++)
		{
			F[m][i] = F[m][i-m] * F[m][m];
			sum += val(m, i);
		}

		for (int i = 1; i < m; i++)
		{
			int s, ti = i + m;
			for (int j = 0; j < 2; j++, F[i][m] *= -1)
			{
				F[i+m][m] = F[i][m] * F[m][m];
				int t = val(i, m) + val(i+m, m);
				for (int k = 1; k < m; k++)
				{
					int tk = k + m;
					F[i][tk] = F[i][k] * F[i][m];
					F[ti][k] = F[i][k] * F[m][k];
					F[ti][tk] = F[i][tk] * F[m][tk];
					t += fabs(val(i, k) + val(i, tk) + val(ti, k) + val(ti, tk));
				}
				if (!j || t > s) s = t;
			}
			sum += s;
		}

		if (sum > ans) ans = sum;
	}

	printf("%d\n", ans);

	return 0;
}


#include <cstdio>
#include <cstring>
#define max(a, b) (a > b ? a : b)
#define val(i, j) (F[i][j] ? -A[i][j] : A[i][j])
#define val4(i, j) (val(i, j) + val(i+m, j) + val(i, j+m) + val(i+m, j+m))

const int N = 35;

int n, m, A[N][N];
bool F[N][N];

int main()
{
	scanf("%d", &n);
	m = (n + 1) >> 1;
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", &A[i][j]);
			ans += A[i][j];
		}

	memset(F, 0, sizeof(F));
	for (int stat = 0; stat < 1 << m; stat++)
	{
		int sum = 0;

		for (int i = 1; i <= m; i++)
		{
			F[m][i] = stat >> (i - 1) & 1;
			sum += val(m, i);
		}
		for (int i = m + 1; i <= n; i++)
		{
			F[m][i] = F[m][i-m] ^ F[m][m];
			sum += val(m, i);
		}

		for (int i = 1; i < m; i++)
		{
			int s;
			for (int j = 0; j < 2; j++, F[i][m] ^= 1)
			{
				F[i+m][m] = F[i][m] ^ F[m][m];
				int ts = val(i, m) + val(i+m, m);
				for (int k = 1; k < m; k++)
				{
					int t;
					for (int l = 0; l < 2; l++, F[i][k] ^= 1)
					{
						F[i][k+m] = F[i][k] ^ F[i][m];
						F[i+m][k] = F[i][k] ^ F[m][k];
						F[i+m][k+m] = F[i][k+m] ^ F[m][k+m];
						t = l ? max(t, val4(i, k)) : val4(i, k);
					}
					ts += t;
				}
				s = F[i][m] ? max(s, ts) : ts;
			}
			sum += s;
		}

		ans = max(ans, sum);
	}

	printf("%d\n", ans);

	return 0;
}


#include <cstdio>
#include <cstring>
#define max(a, b) (a > b ? a : b)
#define val(i, j) (F[i][j] ? -A[i][j] : A[i][j])
#define val4(i, j) (val(i, j) + val(i+m, j) + val(i, j+m) + val(i+m, j+m))

const int N = 35;

int n, m, A[N][N];
bool F[N][N];

int main()
{
	scanf("%d", &n);
	m = (n + 1) >> 1;
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", &A[i][j]);
			ans += A[i][j];
		}

	memset(F, 0, sizeof(F));
	for (int s = 0; s < 1 << m; s++)
	{
		int sum = 0;

		for (int i = 1; i <= m; i++)
		{
			F[m][i] = s >> (i - 1) & 1;
			sum += val(m, i);
		}
		for (int i = m + 1; i <= n; i++)
		{
			F[m][i] = F[m][i-m] ^ F[m][m];
			sum += val(m, i);
		}

		for (int i = 1; i < m; i++)
		{
			int s;
			for (int j = 0; j < 2; j++, F[i][m] ^= 1, F[i+m][m] ^= 1)
			{
				int ts = val(i, m) + val(i+m, m);
				for (int k = 1; k < m; k++)
				{
					int t;
					for (int l = 0; l < 2; l++, F[i][k] ^= 1)
					{
						F[i][k+m] = F[i][k] ^ F[i][m];
						F[i+m][k] = F[i][k] ^ F[m][k];
						F[i+m][k+m] = F[i][k+m] ^ F[m][k+m];
						t = l ? max(t, val4(i, k)) : val4(i, k);
					}
					ts += t;
				}
				s = j ? max(s, ts) : ts;
			}
			sum += s;
		}

		ans = max(ans, sum);
	}

	printf("%d\n", ans);

	return 0;
}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int a[35][35];
bool odd[35];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i < n; ++i)
        for(int j=0; j < n; ++j)
            scanf("%d", a[i]+j);
    int x=(n+1)/2;
    int ans=-999999999;
    for(int i=0; i < 1<<x; ++i){
        odd[0]=0;
        int sum=0;
        for(int j=0; j < n; ++j){
            odd[j+1]=odd[j];
            if(j <= x && (i & (1<<j)))
                odd[j+1]^=1;
            if(j >= x && (i & (1<<(j-x))))
                odd[j+1]^=1;
            for(int k=0; k < x-1; ++k){
                int y=a[j][k];
                if(odd[j+1])
                    y -= a[j][k+x];
                else
                    y += a[j][k+x];
                sum += abs(y);
            }
            if(odd[j+1])
                sum -= a[j][x-1];
            else
                sum += a[j][x-1];
        }
        if(sum > ans)
            ans=sum;
    }
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <set>
#include <queue>
#include <map>
#include <vector>
#define ll long long
#define clr(x,y) memset(x,y,sizeof(x))
using namespace std;

const int inf = 1e9;
int n,k;
int a[40][40],f[40][40];

int get(int i,int j){
    return f[i][j]?-a[i][j]:a[i][j];
}
int getP(int x,int y){
    f[x+k+1][y] = f[x][y]^f[k][y];
    f[x][y+k+1] = f[x][y]^f[x][k];
    f[x+k+1][y+k+1] = f[x+k+1][y] ^f[x+k+1][k];

    return get(x,y)+get(x+k+1,y)+get(x,y+k+1)+get(x+k+1,y+k+1);
}
int getRow(int r){
    int res = 0 ;
    res += get(r,k);
    res += get(r+k+1,k);
    for(int i=0;i<k;i++){
        f[r][i] = 0;
        res += abs(getP(r,i));
    }
    return res;
}

int solve(){
    int res = 0;
    for(int i=0;i<n;i++)
        res += get(k,i);
    for(int i=0;i<k;i++){
        int temp = -inf;
        f[i][k]=0;
        f[i+k+1][k] = f[i][k]^f[k][k];
        temp = max(temp,getRow(i));

        f[i][k]=1;
        f[i+k+1][k] = f[i][k]^f[k][k];
        temp = max(temp,getRow(i));
        res += temp;
    }
    return res;
}

int main()
{
//    freopen("in","r",stdin);
    cin>>n;
    k = n/2;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    int ans = -inf;

    for(int i=0;i<(1<<(k+1));i++){
        for(int j=0;j<=k;j++)
            f[k][j] = (i>>j)&1;
        for(int j=k+1;j<n;j++)
            f[k][j] =  f[k][j-k-1] ^ f[k][k];
        ans = max(ans,solve());
    }
    cout<<ans;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <set>
#include <queue>
#include <map>
#include <vector>
#define ll long long
#define clr(x,y) memset(x,y,sizeof(x))
using namespace std;

const int inf = 1e9;
int n,k;
int a[40][40],f[40][40];

int get(int i,int j){
    return f[i][j]?-a[i][j]:a[i][j];
}
int getP(int x,int y){
    f[x+k+1][y] = f[x][y]^f[k][y];
    f[x][y+k+1] = f[x][y]^f[x][k];
    f[x+k+1][y+k+1] = f[x+k+1][y] ^f[x+k+1][k];

    return get(x,y)+get(x+k+1,y)+get(x,y+k+1)+get(x+k+1,y+k+1);
}
int getRow(int r){
    int res = 0 ;
    res += get(r,k);
    res += get(r+k+1,k);
    for(int i=0;i<k;i++){
        int temp = -inf;
        f[r][i] = 0;
        temp = max(temp,getP(r,i));

        f[r][i] = 1;
        temp = max(temp,getP(r,i));
        res += temp;
    }
    return res;
}

int solve(){
    int res = 0;
    for(int i=0;i<n;i++)
        res += get(k,i);
    for(int i=0;i<k;i++){
        int temp = -inf;
        f[i][k]=0;
        f[i+k+1][k] = f[i][k]^f[k][k];
        temp = max(temp,getRow(i));

        f[i][k]=1;
        f[i+k+1][k] = f[i][k]^f[k][k];
        temp = max(temp,getRow(i));
        res += temp;
    }
    return res;
}

int main()
{
//    freopen("in","r",stdin);
    cin>>n;
    k = n/2;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    int ans = -inf;

    for(int i=0;i<(1<<(k+1));i++){
        for(int j=0;j<=k;j++)
            f[k][j] = (i>>j)&1;
        for(int j=k+1;j<n;j++)
            f[k][j] =  f[k][j-k-1] ^ f[k][k];
        ans = max(ans,solve());
    }
    cout<<ans;
    return 0;
}


#include <algorithm> //STL通用算法
#include <cmath> //定义数学函数
#include <cstdio> //定义输入/输出函数
#include <iostream> //数据流输入/输出
#include <cstring> //字符串处理
#include <string> //字符串类
#include <ctime> //定义关于时间的函数
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
/*#include <bitset> //STL位集容器
#include <cstype> //字符处理
#include <cerrno> //定义错误码
#include <complex> //复数类
#include <clocale> //定义本地化函数
#include <cstdlib> //定义杂项函数及内存分配函数
#include <deque> //STL双端队列容器
#include <exception> //异常处理类
#include <fstream> //文件输入/输出
#include <functional> //STL定义运算函数(代替运算符)
#include <limits> //定义各种数据类型最值常量
#include <list> //STL线性列表容器
#include <map> //STL映射容器
#include <iomanip> //参数化输入/输出
#include <ios> //基本输入/输出支持
#include <iosfwd> //输入/输出系统使用的前置声明
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <queue> //STL队列容器
#include <set> //STL集合容器
#include <sstream> //基于字符串的流
#include <stack> //STL堆栈容器
#include <stdexcept> //标准异常类
#include <streambuf> //底层输入/输出支持
#include <utility> //STL通用模板类
#include <vector> //STL动态数组容器
#include <cwchar.h>//宽字符处理及输入/输出
#include <cwctype.h> //宽字符分类*/

using namespace std;

int ans;

int max(int x,int y) {return x>y?x:y;}

int min(int x,int y) {return x<y?x:y;}

int read()
{
	int x=0,f=1;char ch=getchar() ;
	while (ch<'0' || ch>'9') {if (ch=='-') f=-1;ch=getchar() ;}
	while ('0'<=ch && ch<='9') {x=x*10+(ch^48) ;ch=getchar() ;}
	return x*f;
}

void write(int x)
{
	int buf[50];
	if (x<0)  putchar('-') ,x=-x;
	buf[0]=0;
	while (x)  buf[++buf[0]]=x%10,x/=10;
	if (!buf[0])  buf[0]=1,buf[1]=0;
	while (buf[0])  putchar('0'+buf[buf[0]--]) ;
}

int x,n;
int a[40][40],vis[40][40][3][3][3],g[40][40][3][3][3],f[8],s[40];

int calc(int u,int k)
{
	int ts,tt,res=0;

	if (k) res-=a[u][x]; else res+=a[u][x];
	if (s[x]^k) res-=a[u+x][x]; else res+=a[u+x][x];

	for (int i=1;i<x;i++)
	{
		if (!vis[u][i][s[x]][k][s[i]])
		{
			tt=ts=0;
			f[1]=1;f[2]=f[1]^k;f[3]=f[1]^s[i];f[4]=f[3]^s[x]^k;

			if (f[1]) ts-=a[u][i]; else ts+=a[u][i];
			if (f[2]) ts-=a[u][i+x]; else ts+=a[u][i+x];
			if (f[3]) ts-=a[u+x][i]; else ts+=a[u+x][i];
			if (f[4]) ts-=a[u+x][i+x]; else ts+=a[u+x][i+x];

			f[1]=0;f[2]=f[1]^k;f[3]=f[1]^s[i];f[4]=f[3]^s[x]^k;

			tt+=a[u][i];
			if (f[2]) tt-=a[u][i+x]; else tt+=a[u][i+x];
			if (f[3]) tt-=a[u+x][i]; else tt+=a[u+x][i];
			if (f[4]) tt-=a[u+x][i+x]; else tt+=a[u+x][i+x];

			g[u][i][s[x]][k][s[i]]=max(ts,tt);
			vis[u][i][s[x]][k][s[i]]=1;
		}
		res+=g[u][i][s[x]][k][s[i]];
	}
	return res;
}

void q1(int y)
{
	for (int i=1;i<=x;i++)
		s[i]=y&(1<<(i-1))&1;
	for (int i=x+1;i<=n;i++) s[i]=s[x]^s[i-x];
	int tmp=0;
	for (int i=1;i<=n;i++)
	{
		if (s[i]) tmp-=a[x][i];
		else tmp+=a[x][i];
	}
	for (int i=1;i<x;i++) tmp+=max(calc(i,0),calc(i,1));
	ans=max(ans,tmp);
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) a[i][j]=read();
	x=(n+1)/2;
	ans=-inf;
	for (int T=0;T<(1<<x);T++) q1(T);
	cout<<ans;
}


#include <algorithm> //STLÍ¨ÓÃËã·¨
#include <cmath> //¶¨ÒåÊýÑ§º¯Êý
#include <cstdio> //¶¨ÒåÊäÈë/Êä³öº¯Êý
#include <iostream> //Êý¾ÝÁ÷ÊäÈë/Êä³ö
#include <cstring> //×Ö·û´®´¦Àí
#include <string> //×Ö·û´®Àà
#include <ctime> //¶¨Òå¹ØÓÚÊ±¼äµÄº¯Êý
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
/*#include <bitset> //STLÎ»¼¯ÈÝÆ÷
#include <cstype> //×Ö·û´¦Àí
#include <cerrno> //¶¨Òå´íÎóÂë
#include <complex> //¸´ÊýÀà
#include <clocale> //¶¨Òå±¾µØ»¯º¯Êý
#include <cstdlib> //¶¨ÒåÔÓÏîº¯Êý¼°ÄÚ´æ·ÖÅäº¯Êý
#include <deque> //STLË«¶Ë¶ÓÁÐÈÝÆ÷
#include <exception> //Òì³£´¦ÀíÀà
#include <fstream> //ÎÄ¼þÊäÈë/Êä³ö
#include <functional> //STL¶¨ÒåÔËËãº¯Êý(´úÌæÔËËã·û)
#include <limits> //¶¨Òå¸÷ÖÖÊý¾ÝÀàÐÍ×îÖµ³£Á¿
#include <list> //STLÏßÐÔÁÐ±íÈÝÆ÷
#include <map> //STLÓ³ÉäÈÝÆ÷
#include <iomanip> //²ÎÊý»¯ÊäÈë/Êä³ö
#include <ios> //»ù±¾ÊäÈë/Êä³öÖ§³Ö
#include <iosfwd> //ÊäÈë/Êä³öÏµÍ³Ê¹ÓÃµÄÇ°ÖÃÉùÃ÷
#include <istream> //»ù±¾ÊäÈëÁ÷
#include <ostream> //»ù±¾Êä³öÁ÷
#include <queue> //STL¶ÓÁÐÈÝÆ÷
#include <set> //STL¼¯ºÏÈÝÆ÷
#include <sstream> //»ùÓÚ×Ö·û´®µÄÁ÷
#include <stack> //STL¶ÑÕ»ÈÝÆ÷
#include <stdexcept> //±ê×¼Òì³£Àà
#include <streambuf> //µ×²ãÊäÈë/Êä³öÖ§³Ö
#include <utility> //STLÍ¨ÓÃÄ£°åÀà
#include <vector> //STL¶¯Ì¬Êý×éÈÝÆ÷
#include <cwchar.h>//¿í×Ö·û´¦Àí¼°ÊäÈë/Êä³ö
#include <cwctype.h> //¿í×Ö·û·ÖÀà*/

using namespace std;

int ans;

int max(int x,int y) {return x>y?x:y;}

int min(int x,int y) {return x<y?x:y;}

int read()
{
	int x=0,f=1;char ch=getchar() ;
	while (ch<'0' || ch>'9') {if (ch=='-') f=-1;ch=getchar() ;}
	while ('0'<=ch && ch<='9') {x=x*10+(ch^48) ;ch=getchar() ;}
	return x*f;
}

void write(int x)
{
	int buf[50];
	if (x<0)  putchar('-') ,x=-x;
	buf[0]=0;
	while (x)  buf[++buf[0]]=x%10,x/=10;
	if (!buf[0])  buf[0]=1,buf[1]=0;
	while (buf[0])  putchar('0'+buf[buf[0]--]) ;
}

int x,n;
int a[40][40],vis[40][40][3][3][3],g[40][40][3][3][3],f[8],s[40];

int calc(int u,int k)
{
	int ts,tt,res=0;

	if (k) res-=a[u][x]; else res+=a[u][x];
	if (s[x]^k) res-=a[u+x][x]; else res+=a[u+x][x];

	for (int i=1;i<x;i++)
	{
		if (!vis[u][i][s[x]][k][s[i]])
		{
			tt=ts=0;
			f[1]=1;f[2]=f[1]^k;f[3]=f[1]^s[i];f[4]=f[3]^s[x]^k;

			if (f[1]) ts-=a[u][i]; else ts+=a[u][i];
			if (f[2]) ts-=a[u][i+x]; else ts+=a[u][i+x];
			if (f[3]) ts-=a[u+x][i]; else ts+=a[u+x][i];
			if (f[4]) ts-=a[u+x][i+x]; else ts+=a[u+x][i+x];

			f[1]=0;f[2]=f[1]^k;f[3]=f[1]^s[i];f[4]=f[3]^s[x]^k;

			tt+=a[u][i];
			if (f[2]) tt-=a[u][i+x]; else tt+=a[u][i+x];
			if (f[3]) tt-=a[u+x][i]; else tt+=a[u+x][i];
			if (f[4]) tt-=a[u+x][i+x]; else tt+=a[u+x][i+x];

			g[u][i][s[x]][k][s[i]]=max(ts,tt);
			vis[u][i][s[x]][k][s[i]]=1;
		}
		res+=g[u][i][s[x]][k][s[i]];
	}
	return res;
}

void q1(int y)
{
	for (int i=1;i<=x;i++)
		if (y&(1<<(i-1))) s[i]=1;
		else s[i]=0;
	for (int i=x+1;i<=n;i++) s[i]=s[x]^s[i-x];
	int tmp=0;
	for (int i=1;i<=n;i++)
	{
		if (s[i]) tmp-=a[x][i];
		else tmp+=a[x][i];
	}
	for (int i=1;i<x;i++) tmp+=max(calc(i,0),calc(i,1));
	ans=max(ans,tmp);
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) a[i][j]=read();
	x=(n+1)/2;
	ans=-inf;
	for (int T=0;T<(1<<x);T++) q1(T);
	cout<<ans;
}


#include <algorithm> //STLÍ¨ÓÃËã·¨
#include <cmath> //¶¨ÒåÊýÑ§º¯Êý
#include <cstdio> //¶¨ÒåÊäÈë/Êä³öº¯Êý
#include <iostream> //Êý¾ÝÁ÷ÊäÈë/Êä³ö
#include <cstring> //×Ö·û´®´¦Àí
#include <string> //×Ö·û´®Àà
#include <ctime> //¶¨Òå¹ØÓÚÊ±¼äµÄº¯Êý
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
/*#include <bitset> //STLÎ»¼¯ÈÝÆ÷
#include <cstype> //×Ö·û´¦Àí
#include <cerrno> //¶¨Òå´íÎóÂë
#include <complex> //¸´ÊýÀà
#include <clocale> //¶¨Òå±¾µØ»¯º¯Êý
#include <cstdlib> //¶¨ÒåÔÓÏîº¯Êý¼°ÄÚ´æ·ÖÅäº¯Êý
#include <deque> //STLË«¶Ë¶ÓÁÐÈÝÆ÷
#include <exception> //Òì³£´¦ÀíÀà
#include <fstream> //ÎÄ¼þÊäÈë/Êä³ö
#include <functional> //STL¶¨ÒåÔËËãº¯Êý(´úÌæÔËËã·û)
#include <limits> //¶¨Òå¸÷ÖÖÊý¾ÝÀàÐÍ×îÖµ³£Á¿
#include <list> //STLÏßÐÔÁÐ±íÈÝÆ÷
#include <map> //STLÓ³ÉäÈÝÆ÷
#include <iomanip> //²ÎÊý»¯ÊäÈë/Êä³ö
#include <ios> //»ù±¾ÊäÈë/Êä³öÖ§³Ö
#include <iosfwd> //ÊäÈë/Êä³öÏµÍ³Ê¹ÓÃµÄÇ°ÖÃÉùÃ÷
#include <istream> //»ù±¾ÊäÈëÁ÷
#include <ostream> //»ù±¾Êä³öÁ÷
#include <queue> //STL¶ÓÁÐÈÝÆ÷
#include <set> //STL¼¯ºÏÈÝÆ÷
#include <sstream> //»ùÓÚ×Ö·û´®µÄÁ÷
#include <stack> //STL¶ÑÕ»ÈÝÆ÷
#include <stdexcept> //±ê×¼Òì³£Àà
#include <streambuf> //µ×²ãÊäÈë/Êä³öÖ§³Ö
#include <utility> //STLÍ¨ÓÃÄ£°åÀà
#include <vector> //STL¶¯Ì¬Êý×éÈÝÆ÷
#include <cwchar.h>//¿í×Ö·û´¦Àí¼°ÊäÈë/Êä³ö
#include <cwctype.h> //¿í×Ö·û·ÖÀà*/

using namespace std;

int ans;

int max(int x,int y) {return x>y?x:y;}

int min(int x,int y) {return x<y?x:y;}

int read()
{
	int x=0,f=1;char ch=getchar() ;
	while (ch<'0' || ch>'9') {if (ch=='-') f=-1;ch=getchar() ;}
	while ('0'<=ch && ch<='9') {x=x*10+(ch^48) ;ch=getchar() ;}
	return x*f;
}

void write(int x)
{
	int buf[50];
	if (x<0)  putchar('-') ,x=-x;
	buf[0]=0;
	while (x)  buf[++buf[0]]=x%10,x/=10;
	if (!buf[0])  buf[0]=1,buf[1]=0;
	while (buf[0])  putchar('0'+buf[buf[0]--]) ;
}

int x,n;
int a[40][40],vis[40][40][3][3][3],g[40][40][3][3][3],f[8],s[40];

int calc(int u,int k)
{
	int ts,tt,res=0;

	if (k) res-=a[u][x]; else res+=a[u][x];
	if (s[x]^k) res-=a[u+x][x]; else res+=a[u+x][x];

	for (int i=1;i<x;i++)
	{
		if (!vis[u][i][s[x]][k][s[i]])
		{
			tt=ts=0;
			f[1]=1;f[2]=f[1]^k;f[3]=f[1]^s[i];f[4]=f[3]^s[x]^k;

			if (f[1]) ts-=a[u][i]; else ts+=a[u][i];
			if (f[2]) ts-=a[u][i+x]; else ts+=a[u][i+x];
			if (f[3]) ts-=a[u+x][i]; else ts+=a[u+x][i];
			if (f[4]) ts-=a[u+x][i+x]; else ts+=a[u+x][i+x];

			f[1]=0;f[2]=f[1]^k;f[3]=f[1]^s[i];f[4]=f[3]^s[x]^k;

			tt+=a[u][i];
			if (f[2]) tt-=a[u][i+x]; else tt+=a[u][i+x];
			if (f[3]) tt-=a[u+x][i]; else tt+=a[u+x][i];
			if (f[4]) tt-=a[u+x][i+x]; else tt+=a[u+x][i+x];

			g[u][i][s[x]][k][s[i]]=max(ts,tt);
			vis[u][i][s[x]][k][s[i]]=1;
		}
		res+=g[u][i][s[x]][k][s[i]];
	}
	return res;
}

void q1(int y)
{
	for (int i=1;i<=x;i++)
		s[i]=y&(1<<(i-1));
	for (int i=x+1;i<=n;i++) s[i]=s[x]^s[i-x];
	int tmp=0;
	for (int i=1;i<=n;i++)
	{
		if (s[i]) tmp-=a[x][i];
		else tmp+=a[x][i];
	}
	for (int i=1;i<x;i++) tmp+=max(calc(i,0),calc(i,1));
	ans=max(ans,tmp);
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) a[i][j]=read();
	x=(n+1)/2;
	ans=-inf;
	for (int T=0;T<(1<<x);T++) q1(T);
	cout<<ans;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=36;

int N, X, ans(0x80000000), A[maxn][maxn];

int main()
{
	scanf("%d",&N);
	X=N/2;
	for (int i=0;i<N;i++)
		for (int j=0;j<N;j++)
			scanf("%d",&A[i][j]);
	for (long long mid=0;mid<(1<<X<<1);mid++)
	{
		int tot(0);
		bool C(mid&(1<<X));
		long long MID=(C? mid+(~mid<<X<<1): mid+(mid<<X<<1));
		for (int i=0;i<N;i++)
			tot+=(MID&(1ll<<i)?-1:1)*A[X][i];
		for (int i=0;i<X;i++)
		{
			int now1(A[i][X]+(C?-1:1)*A[i+X+1][X]), now2(-now1);
			for (int j=0;j<X;j++)
			{
				bool L(MID&(1ll<<j)), R(L^C);
				now1+=abs(A[i][j]+A[i][j+X+1]+(L?-1:1)*A[i+X+1][j]+(R?-1:1)*A[i+X+1][j+X+1]);
				now2+=abs(A[i][j]-A[i][j+X+1]+(L?-1:1)*A[i+X+1][j]-(R?-1:1)*A[i+X+1][j+X+1]);
			}
			tot+=max(now1,now2);
		}
		ans=max(ans,tot);
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAXN = 35;

int X;
int a[2][MAXN][MAXN],N,v[MAXN],Ans = -(1 << 30);

int Calc(int row)
{
	int sum = a[0][row][X] + a[v[X]][row + X][X];
	for(int i = 1;i < X;i ++)
		sum += abs(a[0][row][i] + a[v[i]][row + X][i] + a[0][row][i + X] + a[v[X] ^ v[i]][row + X][i + X]);
	int tmp = a[1][row][X] + a[v[X] ^ 1][row + X][X];
	for(int i = 1;i < X;i ++)
		tmp += abs(a[0][row][i] + a[v[i]][row + X][i] + a[1][row][i + X] + a[v[X] ^ v[i] ^ 1][row + X][i + X]);
	return max(sum,tmp);
}

int Check(int s)
{
	for(int i = 0;i < X;i ++)
		v[i + 1] = (s & (1 << i)) > 0;
	for(int i = 1;i <= X;i ++) v[i + X] = (v[i] ^ v[X]);
	int tmp = 0;
	for(int i = 1;i <= N;i ++) tmp += a[v[i]][X][i];
	for(int i = 1;i < X;i ++)
		tmp += Calc(i);
	return tmp;
}

int main()
{
//	freopen("data.in","r",stdin),freopen("data.out","w",stdout);
	scanf("%d", &N);
	X = (N + 1) >> 1;
	for(int i = 1;i <= N;i ++)
		for(int j = 1;j <= N;j ++)
			scanf("%d", &a[0][i][j]),a[1][i][j] = -a[0][i][j];
	for(int s = 0;s < (1 << X);s ++)
		Ans = max(Ans,Check(s));
	printf("%d\n", Ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 33
#define inf 0x3f3f3f3f
#define eps 1e-8
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

typedef pair<int, int> pii;
typedef long long INT;

int N, x, ans;
int a[NN][NN], b[NN][NN], p[NN];

int main() {
	scanf("%d", &N); x=(N+1)/2;
	for (int i=0; i<N; i++)
		for (int j=0; j<N; j++) scanf("%d", &a[i][j]);

	ans=-inf;

	for (int s=0; s<(1<<x); s++) {
		memcpy(b, a, sizeof(b));
		for (int i=0; i<x; i++) if (s&(1<<i)) {
			for (int j=0; j<x; j++) for (int k=0; k<x; k++) {
				b[i+j][x-1+k]*=-1;
			}
		}
		int cur=0;
		for (int i=0; i<N; i++) cur+=b[i][x-1];
		for (int j=0; j<x-1; j++) {
			for (int i=0; i<N; i++) p[i]=b[i][j]+b[i][j+x];
			int s1=p[x-1], s2=-p[x-1];
			for (int i=0; i<x-1; i++) {
				s1+=abs(p[i]+p[i+x]);
				s2+=abs(p[i]-p[i+x]);
			}
			cur+=max(s1, s2);
		}
		ans=max(ans, cur);
	}

	printf("%d\n", ans);

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <iostream>
#define x first
#define left left1
#define y second
#define mp make_pair
#define pb push_back
#define ABS(a) ((a)>0?(a):(-(a)))
using namespace std;
typedef long long LL;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int NMax=40,MMax=200;
int N,nn,A[NMax][NMax],B[NMax];
int get(int a,int b) {
	 return (a^b);
}
int P(int a,int b) {
	if(b) return a*-1;
	else return a;
}
int main()
{
	scanf("%d",&N);
	nn=(N+1)>>1;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++) scanf("%d",&A[i][j]);
	int ret=-100000000;
	for(int I=0;I<(1<<nn);I++) {
		int cnt=0;
		int k=I;
		for(int i=1;i<=nn;i++) {
			B[i]=(I&1);
			cnt+=P(A[i][nn],B[i]);
			I>>=1;
		}
		I=k;
		for(int i=1;i<nn;i++) {
			int tot0=P(A[nn][i],0),tot1=-tot0;
			for(int j=1;j<nn;j++) {
					int maxx=-100000000;
					for(int x=0;x<2;x++){
						int y=0;
						int x1=get(x,B[j]),x2=get(y,B[nn]),x3=get(B[j],B[nn]),x4=get(x,y),x5=get(x1,x2);
						if(get(x3,x4)==x5)
							maxx=max(maxx,P(A[j][i],x)+P(A[j][nn+i],x1)+P(A[nn][nn+i],x2)+P(A[nn+j][nn],x3)+P(A[nn+j][i],x4)+P(A[nn+j][nn+i],x5));
					}
					tot0+=maxx;
			}
			for(int j=1;j<nn;j++) {
					int maxx=-100000000;
					for(int x=0;x<2;x++){
						int y=1;
						int x1=get(x,B[j]),x2=get(y,B[nn]),x3=get(B[j],B[nn]),x4=get(x,y),x5=get(x1,x2);
						if(get(x3,x4)==x5)
							maxx=max(maxx,P(A[j][i],x)+P(A[j][nn+i],x1)+P(A[nn][nn+i],x2)+P(A[nn+j][nn],x3)+P(A[nn+j][i],x4)+P(A[nn+j][nn+i],x5));
					}
					tot1+=maxx;
			}
			cnt+=max(tot0,tot1);
		}
		ret=max(ret,cnt);
	}
	printf("%d\n",ret);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <iostream>
#define x first
#define left left1
#define y second
#define mp make_pair
#define pb push_back
#define ABS(a) ((a)>0?(a):(-(a)))
using namespace std;
typedef long long LL;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int NMax=40,MMax=200;
int N,nn,A[NMax][NMax],B[NMax];
int get(int a,int b) {
	 return (a^b);
}
int P(int a,int b) {
	if(b) return a*-1;
	else return a;
}
int main()
{
	scanf("%d",&N);
	nn=(N+1)>>1;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++) scanf("%d",&A[i][j]);
	int ret=-100000000;
	for(int I=0;I<(1<<nn);I++) {
		int cnt=0;
		int k=I;
		for(int i=1;i<=nn;i++) {
			B[i]=(I&1);
			cnt+=P(A[i][nn],B[i]);
			I>>=1;
		}
		I=k;
		for(int i=1;i<nn;i++) cnt+=P(A[i+nn][nn],get(B[i],B[nn]));
		for(int i=1;i<nn;i++) {
			int tot0=P(A[nn][i],0)+P(A[nn][nn+i],get(0,B[nn])),tot1=P(A[nn][i],1)+P(A[nn][nn+i],get(1,B[nn]));
			for(int j=1;j<nn;j++) {
					int maxx=-100000000;
					for(int x=0;x<2;x++){
						int y=0;
						int x1=get(x,B[j]),x2=get(y,B[nn]),x3=get(B[j],B[nn]),x4=get(x,y),x5=get(x1,x2);
						if(get(x3,x4)==x5)
							maxx=max(maxx,P(A[j][i],x)+P(A[j][nn+i],x1)+P(A[nn+j][i],x4)+P(A[nn+j][nn+i],x5));
					}
					if(maxx!=-100000000)tot0+=maxx;
					else tot0=-100000000;
			}
			for(int j=1;j<nn;j++) {
					int maxx=-100000000;
					for(int x=0;x<2;x++){
						int y=1;
						int x1=get(x,B[j]),x2=get(y,B[nn]),x3=get(B[j],B[nn]),x4=get(x,y),x5=get(x1,x2);
						if(get(x3,x4)==x5)
							maxx=max(maxx,P(A[j][i],x)+P(A[j][nn+i],x1)+P(A[nn+j][i],x4)+P(A[nn+j][nn+i],x5));
					}
					if(maxx!=-100000000)tot1+=maxx;
					else tot1=-100000000;
			}
			cnt+=max(tot0,tot1);
		}
		ret=max(ret,cnt);
	}
	printf("%d\n",ret);
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int A[34][34];
int F[34][34];
inline int val(int i, int j) {
    return (F[i][j] ? -1 : +1) * A[i][j];
}
const int inf = -1234567890;
int row(int i, int k) {
    int ret = 0;
    for (int j=1; j<k; ++j) {
       F[i][j] = 0;
       F[i][j+k] = F[i][j]^F[i][k];
       F[i+k][j] = F[i][j]^F[k][j];
       F[i+k][j+k] = F[i+k][j]^F[i+k][k];
       int best = val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k);
       F[i][j] = 1;
       F[i][j+k] = F[i][j]^F[i][k];
       F[i+k][j] = F[i][j]^F[k][j];
       F[i+k][j+k] = F[i+k][j]^F[i+k][k];
       best = max(best, val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k));
       ret += best;
    }

    return ret;
}
int eval(int n, int k) {
    int ret = 0;
    for (int i=1; i<k; ++i) {
        F[i][k] = 0;
        F[i+k][k] = F[i][k]^F[k][k];
        int best = val(i, k) + val(i+k, k) + row(i, k);
        F[i][k] = 1;
        F[i+k][k] = F[i][k]^F[k][k];
        best = max(best, val(i, k) + val(i+k, k) + row(i, k));
        ret += best;
    }

    for (int j=1; j<=n; ++j) {
        ret += val(k, j);
    }
    return ret;
}
int main() {
    int n;
    cin >> n;
    for (int i=1; i<n; ++i) {
        for (int j=1; j<n; ++j) {
            cin >> A[i][j];
        }
    }
    int k = (n+1)/2;
    int sol = -inf;
    for (unsigned mask=0; mask<(1u<<k); ++mask) {
        for (int j=0; j<k; ++j) {
            F[k][j+1] = !!(mask&(1u<<j));
        }
        for (int j=1; j<k; ++j) {
            F[k][j+k] = F[k][j]^F[k][k];
        }
        sol = max(sol, eval(n, k));
    }
    cout << sol << '\n';
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int A[34][34];
int F[34][34];
inline int val(int i, int j) {
    return (F[i][j] ? -1 : +1) * A[i][j];
}
const int inf = 1234567890;
int row(int i, int k) {
    int ret = 0;
    for (int j=1; j<k; ++j) {
       F[i][j] = 0;
       F[i][j+k] = F[i][j]^F[i][k];
       F[i+k][j] = F[i][j]^F[k][j];
       F[i+k][j+k] = F[i+k][j]^F[i+k][k];
       int best = val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k);
       F[i][j] = 1;
       F[i][j+k] = F[i][j]^F[i][k];
       F[i+k][j] = F[i][j]^F[k][j];
       F[i+k][j+k] = F[i+k][j]^F[i+k][k];
       best = max(best, val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k));
       ret += best;
    }

    return ret;
}
int eval(int n, int k) {
    int ret = 0;
    for (int i=1; i<k; ++i) {
        F[i][k] = 0;
        F[i+k][k] = F[i][k]^F[k][k];
        int best = val(i, k) + val(i+k, k) + row(i, k);
        F[i][k] = 1;
        F[i+k][k] = F[i][k]^F[k][k];
        best = max(best, val(i, k) + val(i+k, k) + row(i, k));
        ret += best;
    }

    for (int j=1; j<=n; ++j) {
        ret += val(k, j);
    }
    return ret;
}
int main() {
    int n;
    cin >> n;
    for (int i=1; i<n; ++i) {
        for (int j=1; j<n; ++j) {
            cin >> A[i][j];
        }
    }
    int k = (n+1)/2;
    int sol = -inf;
    for (unsigned mask=0; mask<(1u<<k); ++mask) {
        for (int j=0; j<k; ++j) {
            F[k][j+1] = !!(mask&(1u<<j));
        }
        for (int j=1; j<k; ++j) {
            F[k][j+k] = F[k][j]^F[k][k];
        }
        sol = max(sol, eval(n, k));
    }
    cout << sol << '\n';
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int A[34][34];
int F[34][34];
inline int val(int i, int j) {
    return (F[i][j] ? -1 : +1) * A[i][j];
}
const int inf = 1234567890;
int row(int i, int k) {
    int ret = 0;
    for (int j=1; j<k; ++j) {
        int best = -inf;
        for (int v=0; v<2; ++v) {
            F[i][j] = v;
            F[i][j+k] = F[i][j]^F[i][k];
            F[i+k][j] = F[i][j]^F[k][j];
            F[i+k][j+k] = F[i+k][j]^F[i+k][k];
            /*
            for (int i=0; i<3; ++i) {
                for (int j=0; j<3; ++j) {
                    cerr << F[i+1][j+1] << ' ';
                }
                cerr << '\n';
            }
            cerr << '\n';
            */
            best = max(best, val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k));
        }
        ret += best;
    }

    return ret;
}
int eval(int n, int k) {
    int ret = 0;
    for (int i=1; i<k; ++i) {
        int best = -inf;
        for (int v=0; v<2; ++v) {
            F[i][k] = v;
            F[i+k][k] = F[i][k]^F[k][k];
            best = max(best, val(i, k) + val(i+k, k) + row(i, k));
        }
        ret += best;
    }

    //cerr << ret << " => ";
    for (int j=1; j<=n; ++j) {
        ret += val(k, j);
    }
    //cerr << ret << '\n';
    return ret;
}
int main() {
    int n;
    cin >> n;
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=n; ++j) {
            cin >> A[i][j];
        }
    }
    int k = (n+1)/2;
    int sol = -inf;
    for (unsigned mask=0; mask<(1u<<k); ++mask) {
        for (int j=0; j<k; ++j) {
            F[k][j+1] = !!(mask&(1u<<j));
        }
        for (int j=1; j<k; ++j) {
            F[k][j+k] = F[k][j]^F[k][k];
        }
        sol = max(sol, eval(n, k));
    }
    cout << sol << '\n';
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int A[34][34];
int F[34][34];
inline int val(int i, int j) {
    return (F[i][j] ? -1 : +1) * A[i][j];
}
const int inf = -1234567890;
int row(int i, int k) {
    int ret = 0;
    for (int j=1; j<k; ++j) {
       F[i][j] = 0;
       F[i][j+k] = F[i][j]^F[i][k];
       F[i+k][j] = F[i][j]^F[k][j];
       F[i+k][j+k] = F[i+k][j]^F[i+k][k];
       int best = val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k);
       F[i][j] = 1;
       F[i][j+k] = F[i][j]^F[i][k];
       F[i+k][j] = F[i][j]^F[k][j];
       F[i+k][j+k] = F[i+k][j]^F[i+k][k];
       best = max(best, val(i, j) + val(i+k, j) + val(i, j+k) + val(i+k, j+k));
       ret += best;
    }

    return ret;
}
int eval(int n, int k) {
    int ret = 0;
    for (int i=1; i<k; ++i) {
        F[i][k] = 0;
        F[i+k][k] = F[i][k]^F[k][k];
        int best = val(i, k) + val(i+k, k) + row(i, k);
        F[i][k] = 1;
        F[i+k][k] = F[i][k]^F[k][k];
        best = max(best, val(i, k) + val(i+k, k) + row(i, k));
        ret += best;
    }

    for (int j=1; j<=n; ++j) {
        ret += val(k, j);
    }
    return ret;
}
int main() {
    int n;
    cin >> n;
    for (int i=1; i<n; ++i) {
        for (int j=1; j<n; ++j) {
            cin >> A[i][j];
        }
    }
    int k = (n+1)/2;
    int sol = -inf;
    for (unsigned mask=0; mask<(1u<<k); ++mask) {
        for (int j=0; j<k; ++j) {
            F[k][j+1] = !!(mask&(1u<<j));
        }
        for (int j=1; j<k; ++j) {
            F[k][j+k] = F[k][j]^F[k][k];
        }
        sol = max(sol, eval(n, k));
    }
	return 0;
}