Nathan is preparing for the Dash marathon. He has N training plans. The i-th plan has an effectiveness of A_{i}, but requires that at least B_{i} other training plans must be performed before it. A training plan cannot be repeated. 

If he performs some K > 0 distinct trainings - P_{1}, P_{2}, \ldots , P_{K} (1 ≤ P_{i} ≤ N, P_{i} \neq P_{j}) then his training score is \frac{\sum_{j=1}^{K} A_{P_{j}}}{K}. If Nathan does not perform any training plan (K = 0), then his score is 0.

What is the highest score that Nathan can get by performing zero or more training plans, if he can perform them in any order?

------ Input Format ------ 

- The first line of the input contains a single integer T - the number of test cases. The description of T test cases follows.
- The first line of each test case contains N - the number of training plans.
- The second line contains N integers A_{1}, A_{2}, \ldots, A_{N} where A_{i} is the effectiveness of the i-th training plan.
- The third line contains N integers B_{1}, B_{2}, \ldots, B_{N} where B_{i} is the number of pre-requisite training plans for the i-th training plan.

------ Output Format ------ 

- For each test case, output a single real number - the highest score that Nathan can get by performing zero or more training plans.
- Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be X, and the jury's answer be Y. Your answer is accepted if and only if \frac{|X - Y|}{\max{(1, |Y|)}} ≤ 10^{-6}.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{5}$
$-10^{5} ≤ A_{i} ≤ 10^{5}$
$0 ≤ B_{i} ≤ N - 1$
- Sum of $N$ over all test cases does not exceed $5\cdot 10^{5}$.

----- Sample Input 1 ------ 
3
4
-9 -21 -4 -43
0 0 0 0
5
10 14 5 9 1
4 1 3 0 0
7
-1 101 5 63 -7 -88 59
0 1 6 2 3 4 5

----- Sample Output 1 ------ 
0.000000
11.500000
54.333333
----- explanation 1 ------ 
Test case 1: It is optimal for Nathan to not perform any training plans as all the plans have negative $A_{i}$ value.

Test case 2: It is optimal for Nathan to:
- First, perform the $4$-th training plan (for which $B_{i} = 0$).
- Then perform the $2$-nd training plan (for which $B_{i} = 1$ which is satisfied as he has already performed $1$ training plan)

Test case 3: It is optimal for Nathan to:
- First, perform the $1$-st training plan (for which $B_{i} = 0$).
- Then perform the $2$-nd training plan (for which $B_{i} = 1$ which is satisfied as he has already performed $1$ training plan)
- Then perform the $4$-th training plan (for which $B_{i} = 2$ which is satisfied as he has already performed $2$ training plans)

Difficulty: HARD

Solutions:
import heapq
for _ in range(int(input())):
	numberOfSessions = int(input())
	efficiencySessionList = list(map(int, input().split()))
	sessionsRequiredList = list(map(int, input().split()))
	mappedEfficiencyRequired = [(sessionsRequiredList[i], i) for i in range(numberOfSessions)]
	mappedEfficiencyRequired.sort(reverse=True)
	heap = []
	highestScore = sumVal = 0
	for minK in range(numberOfSessions):
		while mappedEfficiencyRequired and mappedEfficiencyRequired[-1][0] <= minK:
			index = mappedEfficiencyRequired[-1][1]
			mappedEfficiencyRequired.pop()
			heapq.heappush(heap, -efficiencySessionList[index])
		if heap:
			sumVal += -heapq.heappop(heap)
			highestScore = max(highestScore, sumVal / (minK + 1))
		else:
			break
	print('{:.6f}'.format(highestScore))


import heapq
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	nums = sorted(zip(b, a))
	heap = []
	(ans, temp, count) = (0.0, 0, 0)
	(i, j) = (0, 0)
	while j < n:
		while i < n and nums[i][0] <= j:
			heapq.heappush(heap, -1 * nums[i][1])
			i += 1
		if heap:
			temp += -1 * heapq.heappop(heap)
			count += 1
			ans = max(ans, temp / count)
			j += 1
		else:
			break
	print('%.6f' % ans)


from queue import PriorityQueue
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = [[] for i in range(n + 1)]
	dp = [0 for i in range(n + 1)]
	for i in range(n):
		ans[b[i]].append(l[i])
	lis = PriorityQueue()
	for i in range(1, n + 1):
		li = ans[i - 1]
		for x in li:
			lis.put(-x)
		if not lis.empty():
			dp[i] = dp[i - 1]
			dp[i] += -lis.get()
		else:
			break
	maxe = 0
	for i in range(1, n + 1):
		dp[i] /= i
		maxe = max(dp[i], maxe)
	maxe = max(dp)
	print('{:6f}'.format(maxe))


import collections, heapq
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	preq = collections.defaultdict(list)
	for i in range(n):
		preq[b[i]].append(a[i])
	heap = []
	for i in preq[0]:
		heapq.heappush(heap, -i)
	i = 1
	ans = 0
	sm = 0
	while heap:
		cand = -heapq.heappop(heap)
		sm += cand
		ans = max(ans, sm / i)
		for j in preq[i]:
			heapq.heappush(heap, -j)
		i += 1
	print('{:.6f}'.format(max(ans, 0)))


from heapq import heappush, heappop
from sys import stdin
input = stdin.readline

class Plan:
	__slots__ = ['effectiveness', 'index']

	def __init__(self, effectiveness, index):
		self.effectiveness = effectiveness
		self.index = index

def solve(N, training):
	answer = 0
	count = 0
	training = sorted(training, key=lambda x: x.index)
	usable = []
	first = 0
	for k in range(1, N + 1):
		while first < N and training[first].index == k - 1:
			heappush(usable, -training[first].effectiveness)
			first += 1
		if not usable:
			break
		count += -heappop(usable)
		answer = max(answer, count / k)
	return answer
T = int(input().strip())
for problem in range(1, T + 1):
	N = int(input().strip())
	A = [int(x) for x in input().strip().split()]
	B = [int(x) for x in input().strip().split()]
	training = [Plan(a, b) for (a, b) in zip(A, B)]
	print('{0:.6f}'.format(solve(N, training)))


import heapq
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	req = list(map(int, input().split()))
	ans = 0
	dit = {}
	for i in range(n):
		if req[i] in dit:
			dit[req[i]].append(arr[i])
		else:
			dit[req[i]] = [arr[i]]
	hp = []
	i = 0
	count = 0
	s = 0
	while True:
		if i not in dit:
			if not hp:
				break
			else:
				s += -heapq.heappop(hp)
		else:
			m = max(dit[i])
			if not hp or (hp and -hp[0] < m):
				s += m
				dit[i].remove(m)
				for e in dit[i]:
					heapq.heappush(hp, -e)
			else:
				s += -heapq.heappop(hp)
				for e in dit[i]:
					heapq.heappush(hp, -e)
		count += 1
		curr = s / count
		ans = max(ans, curr)
		i += 1
	print('%.6f' % ans)


N = 10
tree = [0] * (2 * N)

def build(arr):
	for i in range(n):
		tree[n + i] = arr[i]
	for i in range(n - 1, 0, -1):
		tree[i] = tree[i << 1] + tree[i << 1 | 1]

def updateTreeNode(p, value):
	tree[p + n] = value
	p = p + n
	i = p
	while i > 1:
		tree[i >> 1] = tree[i] + tree[i ^ 1]
		i >>= 1

def query(l, r):
	res = 0
	l += n
	r += n
	while l < r:
		if l & 1:
			res += tree[l]
			l += 1
		if r & 1:
			r -= 1
			res += tree[r]
		l >>= 1
		r >>= 1
	return res
from heapq import heappop, heappush, heapify
for i in range(int(input())):
	heap = []
	heapify(heap)
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append([B[i], A[i]])
	l = sorted(l)
	j = 0
	cs = 0.0
	ms = 0.0
	for req in range(n):
		while j < n and l[j][0] <= req:
			heappush(heap, -l[j][1])
			j += 1
		if heap == []:
			break
		else:
			cs -= heappop(heap)
			ms = max(ms, cs / (req + 1))
	print('{0:.6f}'.format(ms))


from heapq import heappush, heappop
for tcase in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	la = [[] for i in range(n + 1)]
	for (i, k) in enumerate(b):
		la[k].append(-a[i])
	pq = []
	k = 0
	s = 0
	ans = 0.0
	while len(la[k]) > 0 or len(pq) > 0:
		while len(la[k]) > 0:
			heappush(pq, la[k].pop())
		s -= heappop(pq)
		k += 1
		ans = max(ans, s / k)
	print('{:.6f}'.format(ans))


from heapq import heappop, heappush, heapify
for i in range(int(input())):
	heap = []
	heapify(heap)
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append([B[i], A[i]])
	l = sorted(l)
	j = 0
	cs = 0.0
	ms = 0.0
	for req in range(n):
		while j < n and l[j][0] <= req:
			heappush(heap, -l[j][1])
			j += 1
		if heap == []:
			break
		else:
			cs -= heappop(heap)
			ms = max(ms, cs / (req + 1))
	print('{0:.6f}'.format(ms))


import heapq
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append([b[i], a[i]])
	c.sort(key=lambda x: (x[0], -x[1]))
	ans = [0]
	h = []
	x = 0
	i = 0
	while i < n:
		if c[i][0] <= x:
			if x == 0:
				ans.append(c[i][1])
				i += 1
			else:
				while i < n and c[i][0] <= x:
					heapq.heappush(h, c[i][1] * -1)
					i += 1
				ans.append((ans[-1] * x + heapq.heappop(h) * -1) / (x + 1))
			x += 1
		elif c[i][0] > x:
			if len(h) == 0:
				break
			ans.append((ans[-1] * x + heapq.heappop(h) * -1) / (x + 1))
			x += 1
	if x < n - 1:
		while x < n - 1:
			if len(h) == 0:
				break
			ans.append((ans[-1] * x + heapq.heappop(h) * -1) / (x + 1))
			x += 1
	print('{0:.6f}'.format(max(ans)))