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>

Source: codeforces | Difficulty: VERY_HARD
Tags: Graph algorithms

Flows and cuts

Constructive algorithms


Solutions:
import sys, io, os
try:
	Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	Z = lambda : sys.stdin.readline().encode()
Y = lambda : map(int, Z().split())
INF = float('inf')
big = 10 ** 13

class D:

	def __init__(self, n):
		self.lvl = [0] * n
		self.ptr = [0] * n
		self.q = [0] * n
		self.adj = [[] for _ in range(n)]

	def add(self, a, b, c, rcap=0):
		self.adj[a].append([b, len(self.adj[b]), c, 0])
		self.adj[b].append([a, len(self.adj[a]) - 1, rcap, 0])

	def dfs(self, v, t, f):
		if v == t or not f:
			return f
		for i in range(self.ptr[v], len(self.adj[v])):
			e = self.adj[v][i]
			if self.lvl[e[0]] == self.lvl[v] + 1:
				p = self.dfs(e[0], t, min(f, e[2] - e[3]))
				if p:
					self.adj[v][i][3] += p
					self.adj[e[0]][e[1]][3] -= p
					return p
			self.ptr[v] += 1
		return 0

	def calc(self, s, t):
		(flow, self.q[0]) = (0, s)
		for l in range(31):
			while True:
				(self.lvl, self.ptr) = ([0] * len(self.q), [0] * len(self.q))
				(qi, qe, self.lvl[s]) = (0, 1, 1)
				while qi < qe and (not self.lvl[t]):
					v = self.q[qi]
					qi += 1
					for e in self.adj[v]:
						if not self.lvl[e[0]] and e[2] - e[3] >> 30 - l:
							self.q[qe] = e[0]
							qe += 1
							self.lvl[e[0]] = self.lvl[v] + 1
				p = self.dfs(s, t, INF)
				while p:
					flow += p
					p = self.dfs(s, t, INF)
				if not self.lvl[t]:
					break
		return flow
r = lambda x, y: (y & 1) * 2 + 1 - (x + y & 1)
n = int(Z())
p = {}
d = D(2 * n + 2)
w = [0] * n
for i in range(n):
	(x, y, z) = Y()
	w[i] = z
	p[x, y] = i
for (x, y) in p:
	i = p[x, y]
	v = r(x, y)
	d.add(i, i + n, w[i])
	if v < 1:
		d.add(2 * n, i, big)
		if (x + 1, y) in p:
			d.add(i + n, p[x + 1, y], big)
		if (x - 1, y) in p:
			d.add(i + n, p[x - 1, y], big)
	elif v < 2:
		if (x, y + 1) in p:
			d.add(i + n, p[x, y + 1], big)
		if (x, y - 1) in p:
			d.add(i + n, p[x, y - 1], big)
	elif v < 3:
		if (x + 1, y) in p:
			d.add(i + n, p[x + 1, y], big)
		if (x - 1, y) in p:
			d.add(i + n, p[x - 1, y], big)
	else:
		d.add(i + n, 2 * n + 1, big)
print(sum(w) - d.calc(2 * n, 2 * n + 1))