#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 1005;
const int inf = 0x3f3f3f3f;
const ll Inf = 1000000000000000;
int n;
int x[N], y[N], w[N], typ[N];
struct Flow
{
	static const int Node = 2010, Edge = 60000;
	int n, S, T;
	int e = 1, first[Node], cur[Node], nxt[Edge << 1], point[Edge << 1]; ll value[Edge << 1];
	int dep[Node], q[Node];
	void init(int m, int s, int t)
	{
		n = m; S = s; T = t; e = 1;
		memset(first, -1, sizeof(int) * (n + 1));
	}

	void add_edge(int x, int y, ll z)
	{
		nxt[++e] = first[x];
		first[x] = e;
		point[e] = y;
		value[e] = z;
	}

	void add_arc(int x, int y, ll z)
	{
		add_edge(x, y, z);
		add_edge(y, x, 0);
	}
	
	int bfs(int s, int t)
	{
		memset(dep, 0x3f, sizeof(int) * (n + 1));
		memcpy(cur, first, sizeof(int) * (n + 1));
		int head = 1, tail = 0;
		dep[s] = 0; q[++tail] = s;
		while (head <= tail)
		{
			int x = q[head++];
			for (int i = first[x]; ~i; i = nxt[i])
			{
				int to = point[i];
				if (value[i] && checkmin(dep[to], dep[x] + 1))
				{
					q[++tail] = to;
				}
			}
		}
		if (dep[t] == inf) return 0;
		else return 1;
	}

	ll dfs(int now, ll flow)
	{
		if (now == T) return flow;
		ll used = 0;
		for (int i = first[now]; ~i; i = nxt[i])
		{
			int to = point[i];
			if (dep[to] == dep[now] + 1 && value[i])
			{
				ll low = dfs(to, _min(flow - used, value[i]));
				if (low)
				{
					used += low;
					value[i] -= low; value[i ^ 1] += low;
				}
			}
		}
		return used;
	}

	ll maxflow()
	{
		ll mf = 0;
		while (bfs(S, T))
		{
			while (1)
			{
				ll t = dfs(S, Inf);
				if (t == 0) break;
				mf += t;
			}
		}
		return mf;
	}
}G;

void init()
{
	read(n);
	for (int i = 1; i <= n; ++i)
	{
		read(x[i]); read(y[i]); read(w[i]);
		int ox = x[i] & 1, oy = y[i] & 1;
		if (!ox && !oy) typ[i] = 2;
		if (!ox && oy) typ[i] = 1;
		if (ox && oy) typ[i] = 0;
		if (ox && !oy) typ[i] = 3;
	}
	G.init(n + n + 2, n + n + 1, n + n + 2);
	for (int i = 1; i <= n; ++i) G.add_arc(i, i + n, w[i]);
	for (int i = 1; i <= n; ++i) if (typ[i] == 0) G.add_arc(G.S, i, Inf);
	for (int i = 1; i <= n; ++i) if (typ[i] == 3) G.add_arc(i + n, G.T, Inf);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j) if (typ[j] == typ[i] + 1)
		{
			if (typ[i] == 0)
			{
				if (y[i] != y[j]) continue;
				if (abs(x[i] - x[j]) != 1) continue;
				G.add_arc(i + n, j, Inf);
			}
			else if (typ[i] == 1)
			{
				if (x[i] != x[j]) continue;
				if (abs(y[i] - y[j]) != 1) continue;
				G.add_arc(i + n, j, Inf);
			}
			else
			{
				if (y[i] != y[j]) continue;
				if (abs(x[i] - x[j]) != 1) continue;
				G.add_arc(i + n, j, Inf);
			}
		}
	}
}

void solve()
{
	ll ans = G.maxflow(), all = 0;
	for (int i = 1; i <= n; ++i) all += w[i];
	ans = all - ans;
	printf("%lld\n", ans);
}

int main()
{
	//setIO("");
	init();
	solve();
	return 0;
}

### Prompt

Please formulate a cpp solution to the following 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>

### Response

```cpp
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 1005;
const int inf = 0x3f3f3f3f;
const ll Inf = 1000000000000000;
int n;
int x[N], y[N], w[N], typ[N];
struct Flow
{
	static const int Node = 2010, Edge = 60000;
	int n, S, T;
	int e = 1, first[Node], cur[Node], nxt[Edge << 1], point[Edge << 1]; ll value[Edge << 1];
	int dep[Node], q[Node];
	void init(int m, int s, int t)
	{
		n = m; S = s; T = t; e = 1;
		memset(first, -1, sizeof(int) * (n + 1));
	}

	void add_edge(int x, int y, ll z)
	{
		nxt[++e] = first[x];
		first[x] = e;
		point[e] = y;
		value[e] = z;
	}

	void add_arc(int x, int y, ll z)
	{
		add_edge(x, y, z);
		add_edge(y, x, 0);
	}
	
	int bfs(int s, int t)
	{
		memset(dep, 0x3f, sizeof(int) * (n + 1));
		memcpy(cur, first, sizeof(int) * (n + 1));
		int head = 1, tail = 0;
		dep[s] = 0; q[++tail] = s;
		while (head <= tail)
		{
			int x = q[head++];
			for (int i = first[x]; ~i; i = nxt[i])
			{
				int to = point[i];
				if (value[i] && checkmin(dep[to], dep[x] + 1))
				{
					q[++tail] = to;
				}
			}
		}
		if (dep[t] == inf) return 0;
		else return 1;
	}

	ll dfs(int now, ll flow)
	{
		if (now == T) return flow;
		ll used = 0;
		for (int i = first[now]; ~i; i = nxt[i])
		{
			int to = point[i];
			if (dep[to] == dep[now] + 1 && value[i])
			{
				ll low = dfs(to, _min(flow - used, value[i]));
				if (low)
				{
					used += low;
					value[i] -= low; value[i ^ 1] += low;
				}
			}
		}
		return used;
	}

	ll maxflow()
	{
		ll mf = 0;
		while (bfs(S, T))
		{
			while (1)
			{
				ll t = dfs(S, Inf);
				if (t == 0) break;
				mf += t;
			}
		}
		return mf;
	}
}G;

void init()
{
	read(n);
	for (int i = 1; i <= n; ++i)
	{
		read(x[i]); read(y[i]); read(w[i]);
		int ox = x[i] & 1, oy = y[i] & 1;
		if (!ox && !oy) typ[i] = 2;
		if (!ox && oy) typ[i] = 1;
		if (ox && oy) typ[i] = 0;
		if (ox && !oy) typ[i] = 3;
	}
	G.init(n + n + 2, n + n + 1, n + n + 2);
	for (int i = 1; i <= n; ++i) G.add_arc(i, i + n, w[i]);
	for (int i = 1; i <= n; ++i) if (typ[i] == 0) G.add_arc(G.S, i, Inf);
	for (int i = 1; i <= n; ++i) if (typ[i] == 3) G.add_arc(i + n, G.T, Inf);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j) if (typ[j] == typ[i] + 1)
		{
			if (typ[i] == 0)
			{
				if (y[i] != y[j]) continue;
				if (abs(x[i] - x[j]) != 1) continue;
				G.add_arc(i + n, j, Inf);
			}
			else if (typ[i] == 1)
			{
				if (x[i] != x[j]) continue;
				if (abs(y[i] - y[j]) != 1) continue;
				G.add_arc(i + n, j, Inf);
			}
			else
			{
				if (y[i] != y[j]) continue;
				if (abs(x[i] - x[j]) != 1) continue;
				G.add_arc(i + n, j, Inf);
			}
		}
	}
}

void solve()
{
	ll ans = G.maxflow(), all = 0;
	for (int i = 1; i <= n; ++i) all += w[i];
	ans = all - ans;
	printf("%lld\n", ans);
}

int main()
{
	//setIO("");
	init();
	solve();
	return 0;
}

```