Problem: At the foot of Liyushan Mountain, n tents will be carefully arranged to provide accommodation for those who are willing to experience the joy of approaching nature, the tranquility of the night, and the bright starry sky.

The i-th tent is located at the point of (x_i, y_i) and has a weight of w_i. A tent is important if and only if both x_i and y_i are even. You need to remove some tents such that for each remaining important tent (x, y), there do not exist 3 other tents (x'_1, y'_1), (x'_2, y'_2) and (x'_3, y'_3) such that both conditions are true: 

  1. |x'_j-x|, |y'_j - y|≤ 1 for all j ∈ \{1, 2, 3\}, and 
  2. these four tents form a parallelogram (or a rectangle) and one of its sides is parallel to the x-axis. 



Please maximize the sum of the weights of the tents that are not removed. Print the maximum value.

Input

The first line contains a single integer n (1≤ n≤ 1 000), representing the number of tents.

Each of the next n lines contains three integers x_i, y_i and w_i (-10^9≤ x_i,y_i ≤ 10^9, 1≤ w_i≤ 10^9), representing the coordinate of the i-th tent and its weight. No two tents are located at the same point.

Output

A single integer — the maximum sum of the weights of the remaining tents.

Examples

Input


5
0 0 4
0 1 5
1 0 3
1 1 1
-1 1 2


Output


12


Input


32
2 2 1
2 3 1
3 2 1
3 3 1
2 6 1
2 5 1
3 6 1
3 5 1
2 8 1
2 9 1
1 8 1
1 9 1
2 12 1
2 11 1
1 12 1
1 11 1
6 2 1
7 2 1
6 3 1
5 3 1
6 6 1
7 6 1
5 5 1
6 5 1
6 8 1
5 8 1
6 9 1
7 9 1
6 12 1
5 12 1
6 11 1
7 11 1


Output


24

Note

Here is an illustration of the second example. Black triangles indicate the important tents. This example also indicates all 8 forbidden patterns.

<image>

Solution (in CPP):

Solution:
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
using ll = long long;
using ld = long double;
ll MOD = 998244353;
const ll root = 3;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 1001;
struct Dinic {
	struct Edge { int to, rev; ll flo, cap; };
	int N; vector<vector<Edge>> adj;
	void init(int _N) { N = _N; adj.resize(N); }
	void add(int a, int b, ll cap, ll rcap = 0) {
	    //cout<<a<<" "<<b<<" "<<cap<<" ?????what\n";
		adj[a].senpai({b,(int)adj[b].size(),0,cap});
		adj[b].senpai({a,(int)adj[a].size()-1,0,rcap});
	}
	vector<int> lev, ptr;
	bool bfs(int s, int t) {
		lev = ptr = vector<int>(N);
		queue<int> Q({s}); lev[s] = 1;
		while (!Q.empty()) { int u = Q.front(); Q.pop();
		    for(auto e: adj[u]) {
				if (!lev[e.to] && e.cap-e.flo)
					Q.push(e.to), lev[e.to] = lev[u]+1;
			}
		}
		return lev[t];
	}
	ll dfs(int v, int t, ll flo) {
		if (v == t) return flo;
		for (int& i = ptr[v]; i < (adj[v].size()); i++) {
			Edge& e = adj[v][i]; ll dif = e.cap-e.flo;
			if (lev[e.to]!=lev[v]+1||!dif) continue;
			if (ll df = dfs(e.to,t,min(flo,dif))) { 
				e.flo += df; adj[e.to][e.rev].flo -= df;
				return df; }
		}
		return 0;
	}
	ll Flow(int s, int t) {
		ll tot = 0; while (bfs(s,t)) while (ll df = 
			dfs(s,t,numeric_limits<ll>::max())) tot += df;
		return tot;
	}
}G;
int n;
int s, t;
map<ttgl, int> mp;
array<int, 3> arr[mxN];
void solve() {
    cin>>n;
    s = 0;
    t = 1;
    int cnt = 2;
    G.init(2*n+2);
    ll res = 0;
    int x, y, w;
    owo(i, 0, n) {
        cin>>x>>y>>w;
        res += w;
        mp[{x, y}] = cnt;
        cnt+=2;
        arr[i] = {x, y, w};
    }
    owo(i, 0, n) {
        x = arr[i][0];
        y = arr[i][1];
        w = arr[i][2];
        int id = mp[{x, y}];
        G.add(id, id+1, w);
        if(abs(x%2)==1 && abs(y%2)==1) {
            G.add(id+1, t, INFLL);
        }else if(abs(x%2)==1 && abs(y%2)==0) {
            G.add(s, id, INFLL);
            if(mp[{x-1, y}] > 0) {
                G.add(id+1, mp[{x-1, y}], INFLL);
            }
            if(mp[{x+1, y}] > 0) {
                G.add(id+1, mp[{x+1, y}], INFLL);
            }
        }else if(x%2==0 && y%2==0) {
            if(mp[{x, y+1}] > 0) {
                G.add(id+1, mp[{x, y+1}], INFLL);
            }
            if(mp[{x, y-1}] > 0) {
                G.add(id+1, mp[{x, y-1}], INFLL);
            }
        }else {
            if(mp[{x-1, y}] > 0) {
                G.add(id+1, mp[{x-1, y}], INFLL);
            }
            if(mp[{x+1, y}] > 0) {
                G.add(id+1, mp[{x+1, y}], INFLL);
            }
        }
    }
    cout<<res - G.Flow(s, t)<<"\n";
    
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    int T = 1;
    owo(tc, 1, T+1) {
        solve();
    }
    return 0;
}