One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.

The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.

A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi, yi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers,  - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits after the decimal point, 0 ≤ pi ≤ 1). No two targets may be at the same point.

Output

Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6.

Examples

Input

1
0 0 0 0.5


Output

0.5000000000


Input

2
0 0 0 0.6
5 0 5 0.7


Output

1.3000000000

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Probability


Solutions:
from collections import Counter

def nCk(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
import math
inf = 10 ** 20
n = int(input())
c = []
dp = [0] * (n + 1)
for i in range(n):
	(x, y, t, p) = map(float, input().split())
	c.append([int(x), int(y), int(t), p])
c.sort(key=lambda x: x[2])
for i in range(n):
	dp[i] = c[i][3]
	for j in range(i):
		if (c[i][0] - c[j][0]) ** 2 + (c[i][1] - c[j][1]) ** 2 <= (c[i][2] - c[j][2]) ** 2:
			dp[i] = max(dp[i], dp[j] + c[i][-1])
print(max(dp))


F = lambda : map(float, input().split())
n = int(input())
arr = []
for i in range(n):
	(x, y, t, s) = F()
	arr.append([int(x), int(y), int(t), s])
arr.sort(key=lambda x: x[2])
dp = [0] * n
for i in range(n):
	dp[i] = arr[i][-1]
	for j in range(i):
		if (arr[i][0] - arr[j][0]) ** 2 + (arr[i][1] - arr[j][1]) ** 2 <= (arr[i][2] - arr[j][2]) ** 2:
			dp[i] = max(dp[i], dp[j] + arr[i][-1])
print(max(dp))


n = int(input())
b = []
for i in range(n):
	(x, y, t, p) = map(float, input().split())
	b.append([t, x, y, p])
b.sort()
dp = [0 for j in range(n)]
dp[0] = b[0][3]
ans = 0
for i in range(1, n):
	(t, x, y, p) = b[i]
	j = i - 1
	while j >= 0:
		(t1, x1, y1, p1) = b[j]
		if ((x1 - x) ** 2 + (y1 - y) ** 2) ** 0.5 <= t - t1:
			dp[i] = max(dp[i], dp[j])
		j += -1
	dp[i] += p
print(max(dp))


import heapq

def is_reachable(from_state, target):
	return (from_state[0] - target[0]) ** 2 + (from_state[1] - target[1]) ** 2 <= (target[2] - from_state[2]) ** 2
num_iter = int(input())
targets = sorted([list(map(float, input().strip().split(' '))) for dummy in range(0, num_iter)], key=lambda single_target: single_target[2])
states = []
for (i, target) in enumerate(targets):
	score_estimate = target[3]
	sorted_states = heapq.nlargest(len(states), states)
	for j in range(len(sorted_states)):
		if is_reachable(sorted_states[j][1], target):
			score_estimate += sorted_states[j][1][3]
			break
	target[3] = score_estimate
	heapq.heappush(states, (score_estimate, target))
max_score = heapq.nlargest(1, states)[0][1][3]
print(max_score)


def is_reachable(from_state, target):
	return (from_state[0] - target[0]) ** 2 + (from_state[1] - target[1]) ** 2 <= (target[2] - from_state[2]) ** 2
num_iter = int(input())
targets = sorted([list(map(float, input().strip().split(' '))) for dummy in range(0, num_iter)], key=lambda single_target: single_target[2])
states = []
for (i, target) in enumerate(targets):
	states.append(target[3])
	for j in range(i):
		if is_reachable(targets[j], target):
			score_estimate = states[j] + target[3]
			if states[i] < score_estimate:
				states[i] = score_estimate
max_score = max(states)
print(max_score)


def dist_square(p_1, p_2):
	return (p_1[0] - p_2[0]) ** 2 + (p_1[1] - p_2[1]) ** 2
n = int(input())
events = []
for _ in range(n):
	(x, y, t, p) = input().split()
	(x, y, t, p) = (int(x), int(y), int(t), float(p))
	events += [(t, (x, y), p)]
events.sort()
A = [0 for _ in range(n)]
for i in range(n):
	A[i] = 0
	for j in range(i):
		if dist_square(events[i][1], events[j][1]) <= (events[i][0] - events[j][0]) ** 2:
			A[i] = max([A[i], A[j]])
	A[i] += events[i][2]
print(max(A))


I = lambda : map(float, input().split())
n = int(input())
li = sorted((list(I()) for i in range(n)), key=lambda x: x[2])
d = {}
ans = 0
for i in range(n):
	x1 = li[i][0]
	y1 = li[i][1]
	t1 = li[i][2]
	p1 = li[i][3]
	d[i] = p1
	for j in range(i):
		x = li[j][0]
		y = li[j][1]
		t = li[j][2]
		p = li[j][3]
		if (y1 - y) ** 2 + (x1 - x) ** 2 <= (t1 - t) ** 2:
			d[i] = max(d[i], d[j] + p1)
	ans = max(ans, d[i])
print(ans)


import sys
import math
sys.setrecursionlimit(100000)

def solve():
	(n,) = rv()
	targets = list()
	for i in range(n):
		(x, y, t, p) = input().split()
		x = int(x)
		y = int(y)
		t = int(t)
		p = float(p)
		targets.append((t, x, y, p))
	targets.sort()
	mem = [[-2] * (n + 2) for _ in range(n + 1)]
	res = dp(0, -1, targets, mem)
	print(res)

def dp(index, previndex, targets, mem):
	if index == len(targets):
		return 0
	if mem[index][previndex + 1] > -1:
		return mem[index][previndex + 1]
	(x, y) = (targets[previndex][1], targets[previndex][2])
	distance = 0 if previndex == -1 else math.sqrt((x - targets[index][1]) * (x - targets[index][1]) + (y - targets[index][2]) * (y - targets[index][2]))
	dont = dp(index + 1, previndex, targets, mem)
	take = 0
	if previndex == -1 or distance <= targets[index][0] - targets[previndex][0]:
		take = targets[index][3] + dp(index + 1, index, targets, mem)
	mem[index][previndex + 1] = max(take, dont)
	return max(take, dont)

def prt(l):
	return print(''.join(l))

def rv():
	return map(int, input().split())

def rl(n):
	return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


n = int(input())
targets = [input() for _ in range(n)]
targets = [line.split() for line in targets]
targets = [(int(x), int(y), int(t), float(p)) for (x, y, t, p) in targets]
targets = sorted(targets, key=lambda x: x[2])
max_scores = [0] * n
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		if (targets[j][2] - targets[i][2]) ** 2 >= (targets[j][0] - targets[i][0]) ** 2 + (targets[j][1] - targets[i][1]) ** 2:
			max_scores[i] = max(max_scores[i], max_scores[j])
	max_scores[i] += targets[i][3]
print(max(max_scores))


n = int(input())
ts = sorted((list(map(float, input().strip().split())) for _ in range(n)), key=lambda x: x[2])
d = [0] * n
ans = 0
for i in range(n):
	d[i] = ts[i][3]
	for j in range(i):
		if (ts[i][0] - ts[j][0]) ** 2 + (ts[i][1] - ts[j][1]) ** 2 <= (ts[i][2] - ts[j][2]) ** 2:
			d[i] = max(d[i], d[j] + ts[i][3])
	ans = max(ans, d[i])
print('%.9f' % ans)


class Target:

	def __init__(self, x, y, t, p):
		self.x = x
		self.y = y
		self.t = t
		self.p = p
		self.best = 0
n = int(input())
targets = n * [None]
for i in range(n):
	parts = input().split()
	(x, y, t) = map(int, parts[:3])
	p = float(parts[3])
	targets[i] = Target(x, y, t, p)
targets.sort(key=lambda target: target.t)
best = 0
for (i, a) in enumerate(targets):
	a.best += a.p
	best = max(best, a.best)
	for j in range(i + 1, n):
		b = targets[j]
		if (b.t - a.t) ** 2 < (b.x - a.x) ** 2 + (b.y - a.y) ** 2:
			continue
		b.best = max(b.best, a.best)
print(best)