Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef had three sequences of real numbers $k_{1}, k_{2}, \ldots, k_{N}$, $c_{1}, c_{2}, \ldots, c_{N}$ and $x_{1}, x_{2}, \ldots, x_{N}$. Unfortunately, he lost the sequence $x$; the only thing he remembers about it is that
$$x_{1} \cdot k_{1} + x_{2} \cdot k_{2} + \ldots + x_{N} \cdot k_{N} = 0 \,.$$

Chef's favourite expression is
$$\sqrt{x_{1}+c_{1}} + \sqrt{x_{2}+c_{2}} + \ldots + \sqrt{x_{N}+c_{N}} \,.$$
Its value is defined only if $x_{i}+c_{i} ≥ 0$ for each valid $i$. Let's denote the maximum value of this expression$ $ (over all sequences $x$ such that it is defined) by $F$.

Help Chef find $F$ and a sequence $x_{1}, x_{2}, \ldots, x_{N}$ such that the value of Chef's expression is $F$, or determine that there is no solution (the value of Chef's expression is always undefined).

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ real numbers $k_{1}, k_{2}, \ldots, k_{N}$.
The third line contains $N$ real numbers $c_{1}, c_{2}, \ldots, c_{N}$.

All real numbers are given with exactly two digits after the decimal point.

------  Output ------
For each test case, if there is no solution, print a single line containing one integer $-1$. Otherwise, print a single line containing $N+1$ space-separated real numbers $F, x_{1}, x_{2}, \ldots, x_{N}$.

It can be proved that if a solution exists, then it is unique. Your answer will be considered correct if the absolute or relative error of each number on the output does not exceed $10^{−2}$.

------  Constraints  ------
$1 ≤ T ≤ 10^{5}$
$2 ≤ N ≤ 10^{5}$
$0 < k_{i} ≤ 2,000$ for each valid $i$
$|c_{i}| ≤ 2,000$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$

------  Subtasks ------
Subtask #1 (15 points): $N = 2$

Subtask #2 (15 points): $k_{i} = 1$ and $c_{i} = 0$ for each valid $i$

Subtask #3 (15 points): $k_{i} = 1$ for each valid $i$

Subtask #4 (15 points): $c_{i} = 0$ for each valid $i$

Subtask #5 (40 points): original constraints

----- Sample Input 1 ------ 
5
4
1.00 2.00 3.00 4.00
5.00 6.00 7.00 8.00
3
1.23 8.90 5.67
-2.34 -9.01 -6.78
3
1.00 1.00 1.00
1.23 8.90 -5.67
2
1.23 8.90
-5.67 2.34
2
1.23 8.90
5.67 -2.34
----- Sample Output 1 ------ 
12.0761472885 28.6000000000 2.4000000000 -3.2666666667 -5.9000000000
-1
3.6578682316 0.2566666667 -7.4133333333 7.1566666667
3.5802375027 15.5642936942 -2.1510203645
-1
----- explanation 1 ------ 
Example case 1: The optimal solution is $x = (28.6, 2.4, -49/15, -5.9)$. Then, $x_{1} \cdot k_{1} + x_{2} \cdot k_{2} + x_{3} \cdot k_{3} + x_{4} \cdot k_{4} = 28.6 \cdot 1 + 2.4 \cdot 2 - 49 \cdot 3 / 15 + (-5.9) \cdot 4 = 0$, and $F = \sqrt{28.6+5}+\sqrt{2.4+6}+\sqrt{-49/15+7}+\sqrt{-5.9+8} \doteq 12.076$. This is the maximum value of Chef's expression.

Example case 2: For each $i$, $c_{i}$ is negative, but $x_{i}+c_{i}$ must be non-negative, so $x_{i}$ must be positive. However, all $k_{i}$ are also positive, so $x_{1} k_{1} + x_{2} k_{2} + \ldots + x_{N} k_{N}$ cannot be $0$. There is no solution.

Difficulty: MEDIUM_HARD
Tags: Matrices

Mathematics

Starter code:

Solutions:
import sys
input = lambda : sys.stdin.readline().strip()
from math import sqrt
T = int(input())
for i in range(T):
	N = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	S1 = sum((1 / (4 * k[i]) for i in range(N)))
	S2 = sum((k[i] * c[i] for i in range(N)))
	if S2 == 0:
		print(0, end=' ')
		for i in range(N):
			print(-c[i], end=' ')
		print()
	elif S2 < 0:
		print(-1)
	else:
		multiplier = sqrt(S1 / S2)
		x = [1 / (4 * k[i] ** 2 * multiplier ** 2) - c[i] for i in range(N)]
		F = sum((sqrt(x[i] + c[i]) for i in range(N)))
		print(F, end=' ')
		for i in range(N):
			print(x[i], end=' ')
		print()


import sys
import math
T = int(sys.stdin.readline())
ans_arr = []
for t in range(T):
	N = int(sys.stdin.readline())
	k = [float(i) for i in sys.stdin.readline().split()]
	c = [float(j) for j in sys.stdin.readline().split()]
	kcheck = 1
	for g in range(N):
		if k[g] != 1:
			kcheck = 0
			break
	ccheck = 1
	for h in range(N):
		if c[h] != 0:
			ccheck = 0
			break
	s = ''
	if kcheck == 1 and ccheck == 1:
		s += '0 '
		for e in range(N):
			s += '0 '
	elif N == 2:
		c1 = c[0]
		c2 = c[1]
		k1 = k[0]
		k2 = k[1]
		x2 = (c1 * k1 * k1 - c2 * k2 * k2) / (k2 * k2 + k1 * k2)
		x1 = -(x2 * k2 / k1)
		if x1 + c1 >= 0 and x2 + c2 >= 0:
			F = math.sqrt(x1 + c1) + math.sqrt(x2 + c2)
			s += str(F) + ' ' + str(x1) + ' ' + str(x2)
		else:
			s += '-1'
	else:
		tmp = 0
		for w in range(1, N):
			tmp += 1 / k[w]
		sumofall = 0
		for p in range(1, N):
			sumofall += c[p] * k[p]
		x1 = (-c[0] * pow(k[0], 2) * tmp + sumofall) / (k[0] + pow(k[0], 2) * tmp)
		x_arr = [x1]
		for p in range(1, N):
			val = (x_arr[0] + c[0]) * (pow(k[0], 2) / pow(k[p], 2)) - c[p]
			x_arr.append(val)
		F = 0
		cond = 1
		for w in range(N):
			if x_arr[w] + c[w] >= 0:
				F += math.sqrt(x_arr[w] + c[w])
			else:
				cond = 0
				break
		if cond == 0:
			s += '-1'
		else:
			s += str(F) + ' '
			for e in range(N):
				s += str(x_arr[e]) + ' '
	ans_arr.append(s)
print('\n'.join(ans_arr))


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	(s1, s2) = (0, 0)
	for i in range(n):
		s1 += c[i] * k[i]
		s2 += 1 / k[i]
	t = s1 / s2
	if t < 0:
		print(-1)
	else:
		f = sqrt(s1 * s2)
		l = []
		for i in range(n):
			l.append(t * (1 / (k[i] * k[i])) - c[i])
		print(str(f) + ' ' + ' '.join(list(map(str, l))))


from decimal import *
from math import *
getcontext().prec = 15
t = int(input())
while t:
	n = int(input())
	k = []
	c = []
	kstring = input()
	k = kstring.split(' ')
	k_counter = 1
	for i in range(0, n):
		k[i] = Decimal(k[i])
		if k[i] != 1:
			k_counter = 0
	cstring = input()
	c = cstring.split(' ')
	c_counter = 1
	for i in range(0, n):
		c[i] = Decimal(c[i])
		if c[i] != 0:
			c_counter = 0
	if k_counter == 1 and c_counter == 1 or c_counter == 1:
		print('0.0000000000', end=' ')
		for i in range(0, n):
			print('0.0000000000', end=' ')
		print('')
		t -= 1
		continue
	num = Decimal(0)
	den = Decimal(0)
	for i in range(0, n):
		num += Decimal(1 / k[i])
		den += Decimal(k[i] * c[i])
	if den == 0 and c_counter == 0 and (k_counter == 1):
		print('0.0000000000', end=' ')
		for i in range(0, n):
			print(Decimal(-1 * c[i] / 10000 * 10000), end=' ')
		print('')
		t -= 1
		continue
	frac = Decimal(num / den)
	if frac < 0:
		print('-1')
		t -= 1
		continue
	_lamda = Decimal(num / den)
	_lamda = Decimal(_lamda / 4)
	x = []
	for i in range(0, n):
		res = Decimal(1 / Decimal(4 * _lamda * k[i] * k[i]))
		res = res - c[i]
		x.append(res)
	_max = 0
	for i in range(0, n):
		_max += Decimal(sqrt(x[i] + c[i]))
	print(_max, end=' ')
	for i in range(0, n):
		print(x[i], end=' ')
	print('')
	t -= 1


import numpy as np
import sys
import warnings
warnings.filterwarnings('ignore', category=RuntimeWarning)

def output(x):
	return '{:.10f}'.format(x)

def solve():
	k = np.array(sys.stdin.readline().strip().split(' ')).astype('float64')
	c = np.array(sys.stdin.readline().strip().split(' ')).astype('float64')
	l = np.sqrt(sum(1 / k) / sum(c * k)) / 2
	x = 1 / (4 * k ** 2 * l ** 2) - c
	if np.isnan(x).any():
		print('-1')
	else:
		T = sum(np.sqrt(x + c))
		print(output(T), end='', flush=False)
		for X in x:
			print(' ', end='', flush=False)
			print(output(X), end='', flush=False)
		print('')
T = int(sys.stdin.readline())
for i in range(T):
	n = int(sys.stdin.readline())
	solve()


import math
t = int(input())
while t:
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	summ_prod = 0
	summ_div = 0
	flag = 0
	f = 0
	x = [0] * n
	for i in range(1, n):
		summ_prod += k[i] * c[i]
		summ_div += 1 / k[i]
	a = summ_div * (c[0] * k[0] * k[0])
	b = summ_div * k[0] * k[0]
	x[0] = (summ_prod - a) / (b + k[0])
	for i in range(1, n):
		x[i] = k[0] * k[0] * (x[0] + c[0]) / (k[i] * k[i]) - c[i]
	for i in range(n):
		if c[i] + x[i] < 0:
			flag = 1
			break
		f += math.sqrt(c[i] + x[i])
	if flag:
		print('-1')
	else:
		print(f, *x)
	t -= 1


from math import sqrt
for t in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	findX = lambda l2, k, c, i: 1 / (4 * l2 * k[i] * k[i]) - c[i]
	try:
		num = sum([1 / (4 * i) for i in k])
		den = sum([c[i] * k[i] for i in range(n)])
		if den == 0:
			isNeg = False
			for i in c:
				if i < 0:
					isNeg = True
					break
			if True:
				print('{0:.10f}'.format(0), end=' ')
				for i in range(n):
					print('{0:.10f}'.format(-c[i]), end=' ')
				print()
				continue
			else:
				den = den / 0
		l2 = num / den
		x = [findX(l2, k, c, i) for i in range(n)]
		f = sum([sqrt(x[i] + c[i]) for i in range(n)])
		print('{0:.10f}'.format(f), end=' ')
		for i in x:
			print(i, end=' ')
		print()
	except Exception as e:
		print(-1)


def solve(n, k, c):
	ck = [ki * ci for (ci, ki) in zip(c, k)]
	sck = sum(ck)
	if sck < 0:
		return (-1, None)
	ik = [1 / ki for ki in k]
	sik = sum(ik)
	F = (sck * sik) ** 0.5
	x = [sck / (k[i] ** 2 * sik) - c[i] for i in range(n)]
	return (F, x)
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	k = list(map(float, input().strip().split()))
	c = list(map(float, input().strip().split()))
	(F, x) = solve(n, k, c)
	if F == -1:
		print(F)
	else:
		print(F, ' '.join(map(str, x)))


import numpy as np

def program():
	n = int(input())
	kstr = input()
	cstr = input()
	klist = list(kstr.split(' '))
	clist = list(cstr.split(' '))
	K = np.array(klist, dtype='float64')
	C = np.array(clist, dtype='float64')
	Kinv = 1 / K
	s1 = np.sum(Kinv)
	KC = K * C
	s2 = np.sum(KC)
	if s2 < 0:
		print('-1')
		return
	F = np.sqrt(s1 * s2)
	p = s2 / s1
	x = np.empty(n)
	K2 = K ** 2
	x = p / K2 - C
	print(F, end=' ')
	for i in range(n):
		print(x[i], end=' ')
	print()
T = int(input())
while T:
	program()
	T -= 1


for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	p = sum((x * y for (x, y) in zip(k, c)))
	if p < 0:
		print(-1)
		continue
	x = [1.0 / i / i for i in k]
	q = sum((i * j for (i, j) in zip(x, k)))
	x = [i * p / q for i in x]
	f = sum((i ** 0.5 for i in x))
	x = [i - j for (i, j) in zip(x, c)]
	print(f, *x)


def fun():
	n = int(input())
	K = list(map(float, input().split()))
	C = list(map(float, input().split()))
	A = 0
	B = 0
	for (k, c) in zip(K, C):
		A += k * c
		B += 1 / k
	if A < 0:
		print(-1)
		return
	print((A * B) ** 0.5, end=' ')
	for (k, c) in zip(K, C):
		print(A / (B * k * k) - c, end=' ')
	print()
t = int(input())
while t:
	t -= 1
	fun()


from math import *
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	(SUMck, SUM_k) = (0.0, 0.0)
	for i in range(n):
		SUMck += c[i] * k[i]
		SUM_k += 1 / k[i]
	F2 = SUMck * SUM_k
	if F2 < 0:
		print(-1)
	else:
		print(sqrt(F2), end=' ')
		t = SUMck / SUM_k
		for i in range(n):
			print(t / k[i] / k[i] - c[i], end=' ')
		print()


import math
for _ in range(int(input())):
	N = int(input())
	K = list(map(float, input().split()))
	C = list(map(float, input().split()))
	kInverse = 0
	kc = 0
	for i in range(N):
		kc += K[i] * C[i]
		kInverse += 1 / K[i]
	F_square = kc * kInverse
	if F_square < 0:
		print(-1)
	else:
		alpha = kc / kInverse
		X = []
		for i in range(N):
			X.append(alpha / (K[i] * K[i]) - C[i])
		print(math.sqrt(F_square), end=' ')
		print(*X)


from math import *
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	(a, b) = (0.0, 0.0)
	for i in range(n):
		a += c[i] * k[i]
		b += 1 / k[i]
	F = a * b
	if F < 0:
		print(-1)
	else:
		print(sqrt(F), end=' ')
		for i in range(n):
			print(a / (k[i] ** 2 * b) - c[i], end=' ')
		print()


def ii():
	return int(input())

def miff():
	return map(float, input().split())

def liff():
	return list(miff())
for _ in range(ii()):
	n = ii()
	k = liff()
	c = liff()
	A = sum((K * C for (K, C) in zip(k, c)))
	if A < 0:
		print(-1)
		continue
	B = sum((1 / K for K in k))
	max_f = (A * B) ** (1 / 2)
	print(max_f, end=' ')
	C = A / B
	for (Q, W) in zip(k, c):
		ti = C / (Q * Q)
		xi = ti - W
		print(xi, end=' ')
	print()


def solve(karr, carr, n):
	sm1 = 0
	sm2 = 0
	sm3 = 0
	for i in range(n):
		k = karr[i]
		c = carr[i]
		sm1 += k * c
		sm2 += 1 / k
	if sm1 * sm2 < 0:
		return -1
	else:
		li = [''] * (n + 1)
		li[0] = str(pow(sm1 * sm2, 0.5))
		for i in range(n):
			k = karr[i]
			c = carr[i]
			li[i + 1] = str(sm1 / (sm2 * k ** 2) - c)
		return ' '.join(li)
for case in range(int(input())):
	n = int(input())
	karr = list(map(float, input().split()))
	carr = list(map(float, input().split()))
	print(solve(karr, carr, n))


import sys, os, re, random, itertools, collections, copy

def read_int():
	return int(input())

def read_num_list():
	return [float(x) for x in input().split()]
T = read_int()
while T > 0:
	T -= 1
	n = read_int()
	k = read_num_list()
	c = read_num_list()
	(a, b) = (0, 0)
	for i in range(n):
		a += k[i] * c[i]
		b += 1.0 / k[i]
	ff = a * b
	if ff < 0:
		print(-1.0)
	else:
		ans = [ff ** 0.5]
		sk = sum([1.0 / x for x in k])
		for i in range(n):
			x = ff / (k[i] * sk) ** 2 - c[i]
			ans += [x]
		print(' '.join(map(str, ans)))


from decimal import *
getcontext().prec = 12
from sys import stdin, stdout
from math import sqrt

def P(k, c):
	num = Decimal('0')
	den = Decimal('0')
	for i in range(len(k)):
		num += k[i] * c[i]
		den += 1 / k[i]
	return num / den

def F(x, c):
	ans = Decimal('0')
	for i in range(len(x)):
		ans += Decimal.sqrt(x[i] + c[i])
	return ans

def X(k, c):
	p = P(k, c)
	x = [p / (k[i] * k[i]) - c[i] for i in range(len(k))]
	return x

def solve(inp, out):
	try:
		n = int(inp())
		k = list(map(float, inp().split()))
		c = list(map(float, inp().split()))
		for i in range(n):
			k[i] = Decimal(k[i])
			c[i] = Decimal(c[i])
		x = X(k, c)
		f = F(x, c)
		print(f, end=' ')
		for i in x:
			print(i, end=' ')
		print()
	except:
		print(-1)

def main():
	inp = stdin.readline
	out = stdout.write
	for _ in range(int(inp())):
		solve(inp, out)
main()


import math as m
t = int(input())
while t > 0:
	n = int(input())
	arr1 = list(map(float, input().split()))
	arr2 = list(map(float, input().split()))
	ind = -1
	ax = 0.0
	ay = 0.0
	a = 0
	b = 0
	arr3 = [0.0 for i in range(n)]
	arr4 = [0.0 for i in range(n + 1)]
	count = 0.0
	minn = -100000000.0
	for i in range(n):
		if arr1[i] > minn:
			minn = arr1[i]
			ind = i
	for i in range(n):
		ax = minn / arr1[i]
		ax = ax * ax
		ay = ax * arr2[ind] - arr2[i]
		a += arr1[i] * ax
		b += arr1[i] * ay
	count = b * -1.0 / a
	a = 0
	b = 0
	f1 = 0
	for i in range(n):
		ax = minn / arr1[i]
		ax = ax * ax
		ay = ax * arr2[ind] - arr2[i]
		arr3[i] = count * ax + ay
		ax = arr3[i] + arr2[i]
		if ax < 0:
			f1 = 1
		else:
			b += m.sqrt(ax)
		a += arr3[i] * arr1[i]
	arr4[0] = b
	for i in range(1, n + 1):
		arr4[i] = arr3[i - 1]
	if f1 == 0:
		print(*arr4)
	else:
		print('-1')
	t = t - 1


import math
t = int(input())
for _ in range(t):
	n = int(input())
	num = list(map(float, input().split()))
	c = list(map(float, input().split()))
	xnew = []
	suml = 0
	sumr = 0
	for i in range(0, n):
		sumr = sumr + num[i] / (num[i] * num[i] * 4)
		suml = suml + num[i] * c[i]
	if suml == 0:
		ansinv = 0
	else:
		ansinv = sumr / suml
	for i in range(0, n):
		if ansinv != 0:
			send = 1 / (num[i] ** 2 * 4 * ansinv)
			send = send - c[i]
			xnew.append(send)
		else:
			xnew.append(0 - c[i])
	F = 0
	flag = 0
	for i in range(0, n):
		if xnew[i] + c[i] >= 0:
			flag = 1
			F = F + (xnew[i] + c[i]) ** 0.5
		else:
			flag = 0
			print(-1)
			break
	if flag == 1:
		print(F, end=' ')
		print(*xnew)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	k = [float(x) for x in input().split()]
	c = [float(x) for x in input().split()]
	lda = 0
	kx_sum = 0
	alpha = 0
	for i in range(n):
		alpha += 1 / k[i]
	c_zero = c.count(0)
	beta = 0
	for i in range(n):
		beta += k[i] * c[i]
	z = 0
	if beta > 0:
		lda = math.sqrt(alpha / beta) / 2
	elif beta < 0:
		print(-1)
		continue
	else:
		z = 1
	x = []
	for i in range(n):
		if z == 0:
			x.append(1 / (4 * lda * lda * k[i] * k[i]) - c[i])
		else:
			x.append(-c[i])
			kx_sum = kx_sum + k[i] * x[i]
	if kx_sum != 0:
		print(-1)
		continue
	f = 0
	temp = 0
	for i in range(n):
		if x[i] + c[i] >= 0:
			f += math.sqrt(x[i] + c[i])
		else:
			temp = 1
	if c_zero == n:
		for i in range(n + 1):
			print('{0:.10f}'.format(0), end=' ')
		print()
	elif temp == 0:
		print(f, end=' ')
		for i in range(n):
			print('{0:.10f}'.format(x[i]), end=' ')
		print()
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	K = list(map(float, input().split()))
	C = list(map(float, input().split()))
	x_1 = [(C[i] * K[i], 1 / K[i]) for i in range(n)]
	(eq_1, eq_2) = (sum([x[0] for x in x_1]), sum([x[1] for x in x_1]))
	x_2 = [eq_1 / (eq_2 * pow(K[i], 2)) - C[i] for i in range(n)]
	pred = [eq_1 / (eq_2 * pow(K[i], 2)) for i in range(n)]
	try:
		ans = [math.sqrt(eq_1 / (eq_2 * pow(K[i], 2))) for i in range(n)]
	except:
		pass
	d = sum((1 for number in pred if number < 0))
	if d >= 1:
		print(-1)
	else:
		print(sum(ans), *x_2)


def su(arr1):
	m = 0
	for i in arr1[1:]:
		m += 1 / i
	return m
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr1 = list(map(float, input().split()))
	arr2 = list(map(float, input().split()))
	total = 0
	arr3 = [0, 0]
	for i in range(n):
		total += arr1[i] * arr2[i]
	arr3[1] = total / (arr1[0] * (1 + arr1[0] * su(arr1))) - arr2[0]
	for i in range(1, n):
		g = arr1[0] ** 2 / arr1[i] ** 2 * (arr3[1] + arr2[0]) - arr2[i]
		arr3.append(g)
	flag = True
	for i in range(1, n + 1):
		if arr3[i] + arr2[i - 1] < 0:
			flag = False
			break
		else:
			arr3[0] += (arr3[i] + arr2[i - 1]) ** (1 / 2)
	if not flag:
		print(-1)
	else:
		print(*arr3)


t = int(input())
for _ in range(t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	sum1 = sumk = 0
	k1 = k.copy()
	for i in range(n):
		sum1 += k[i] * c[i]
		k[i] = k[i] * (1 / (k[i] * 2) ** 2)
		sumk += k[i]
	if sum1 != 0:
		res = sumk / sum1
		res = 1 / res
	else:
		res = 0
	x = list()
	max1 = 0
	temp = 0
	for i in range(n):
		x.append(res * k[i] / k1[i] - c[i])
		if x[i] + c[i] < 0:
			print(-1)
			temp = 1
			break
		max1 += (x[i] + c[i]) ** 0.5
	if temp == 1:
		continue
	print(max1, end=' ')
	print(*x)


import math
t = int(input())
for xyz in range(t):
	n = int(input())
	k = [float(x) for x in input().split()]
	c = [float(x) for x in input().split()]
	ka = []
	s = 0.0
	for i in range(n):
		ka.append(1 / k[i])
		s += k[i] * c[i]
	if s < 0:
		print(-1)
	else:
		lamda = math.sqrt(s / sum(ka))
		mxx = 0.0
		ans = []
		for i in range(n):
			y = lamda * ka[i]
			mxx += y
			ans.append(y ** 2 - c[i])
		print(mxx, *ans)


import math
t = int(input())
for i in range(t):
	s = 0.0
	up = 0.0
	ans = 0.0
	x = []
	n = int(input())
	k = [float(x) for x in input().split()]
	c = [float(x) for x in input().split()]
	flag = 0
	flag1 = 0
	for j in range(n):
		if c[j] != 0:
			flag = 1
	for j in range(n):
		if k[j] != 1:
			flag1 = 1
	for j in range(n):
		s += k[j] * c[j]
	if s < 0:
		print(-1)
	elif flag == 1 and s != 0:
		for j in range(n):
			up += 1 / k[j]
		lamda = math.sqrt(up / (4 * s))
		for j in range(n):
			m = 1 / (4 * lamda ** 2 * k[j] ** 2) - c[j]
			x.append(m)
		for j in range(n):
			ans += math.sqrt(x[j] + c[j])
		print(ans, end=' ')
		for j in range(n):
			if j != n - 1:
				print(x[j], end=' ')
			else:
				print(x[j])
	elif flag == 0:
		print(0, end=' ')
		for j in range(n):
			if j != n - 1:
				print(0, end=' ')
			else:
				print(0)
	elif s == 0:
		print(0, end=' ')
		for j in range(n):
			if j != n - 1:
				print(-c[j], end=' ')
			else:
				print(-c[j])


from math import sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	k = list(map(lambda s: float(s), input().split()))
	c = list(map(lambda s: float(s), input().split()))
	ck = sum((ke * ce for (ke, ce) in zip(k, c)))
	if ck < 0:
		print(-1)
		continue
	gamma = ck / sum((1 / ke for ke in k))
	x = [gamma / (ke * ke) - ce for (ke, ce) in zip(k, c)]
	print(str(sum((sqrt(xe + ce) for (xe, ce) in zip(x, c)))), ' '.join((str(float(xe)) for xe in x)))


import math
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
inp = lambda : int(stdin.readline())
sip = lambda : stdin.readline()
mulip = lambda : map(int, stdin.readline().split())
lst = lambda : list(map(float, stdin.readline().split()))
slst = lambda : list(sip())
M = pow(10, 9) + 7
for _ in range(inp()):
	N = inp()
	(f1, ans, f2, f3, k) = (0, 0, 0, 0, 0)
	K = lst()
	C = lst()
	numK = list(set(K))
	for i in range(N):
		f2 += K[i] * C[i]
		k += 1 / K[i]
	f3 = f2 / k
	for i in range(N):
		temp = f3 / pow(K[i], 2)
		if temp < 0:
			print(-1)
			f1 = 1
			break
		ans += pow(temp, 0.5)
	if f1 != 1:
		print(ans, end=' ')
		for i in range(N):
			temp = f3 / pow(K[i], 2)
			temp -= C[i]
			print(temp, end=' ')
			(K[i], C[i]) = (0, 0)
		print()


import sys
input = sys.stdin.readline
t = int(input())
import math
import statistics
for i in range(t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	sum1 = 0
	num = 0
	yo = True
	for j in range(n):
		if k[j] != 1:
			yo = False
	if yo == False:
		for j in range(n):
			sum1 += c[j] * k[j]
			num += 1 / k[j]
		sum1 = sum1 * 4
		deno = sum1
		flaggg = True
		if deno != 0:
			result = num / deno
			x = []
			flag = True
			F = 0
			for j in range(n):
				x_temp = -c[j]
				value = result * k[j] ** 2
				if value != 0:
					x_temp += 1 / (4 * value)
				else:
					flag = False
					break
				if x_temp + c[j] >= 0:
					F += (x_temp + c[j]) ** 0.5
					x.append(x_temp)
				else:
					flag = False
					break
			if flag == True:
				s = ''
				s += str(F)
				if len(x) == n:
					for j in range(len(x)):
						s += ' ' + str(x[j])
					print(s)
				else:
					print(-1)
			else:
				print(-1)
		else:
			s = ''
			s += str(0)
			for j in range(n):
				s += ' ' + str(0)
			print(s)
	else:
		x = []
		F = 0
		flag = True
		avg = statistics.mean(c)
		for j in range(n):
			x_temp = avg - c[j]
			x.append(x_temp)
			if x_temp + c[j] >= 0:
				F += (x_temp + c[j]) ** 0.5
			else:
				flag = False
				break
		if flag == True:
			s = ''
			s += str(F)
			if len(x) == n:
				for j in range(len(x)):
					s += ' ' + str(x[j])
				print(s)
			else:
				print(-1)
		else:
			print(-1)


import sys
import math
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	kc = 0
	divk = 0
	for i in range(n):
		kc += k[i] * c[i]
		divk += 1 / k[i]
	ans = 0
	f = 0
	x = []
	for i in range(n):
		x.append(kc / divk / (k[i] * k[i]) - c[i])
		if x[i] + c[i] < 0:
			f = 1
			break
		ans += math.sqrt(x[i] + c[i])
	if f:
		print(-1)
	else:
		print(ans, end=' ')
		print(*x)


for _ in range(int(input())):
	n = int(input())
	a = list(map(float, input().split()))
	b = list(map(float, input().split()))
	s = 0.0
	for i in range(n):
		s += a[i] * b[i]
	if s < 0.0:
		print(-1)
		continue
	x = 0.0
	for i in a:
		x += 1 / (2 * i)
	s *= 2
	lam = float(pow(s / x, 0.5))
	f = float(x * lam)
	ans = []
	ans.append('%.10f' % f)
	for i in range(n):
		k = 0.0
		k = float(float(pow(1 / (2 * a[i]) * lam, 2)) - b[i])
		ans.append('%.10f' % k)
	print(*ans)


from math import *
t = int(input())
for y in range(t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	kc = []
	sumk = 0
	for i in range(n):
		kc.append(k[i] * c[i])
		sumk += pow(k[i], -1)
	sumkc = sum(kc)
	x = []
	for i in range(n):
		num = sumkc - k[i] * c[i] - k[i] * k[i] * c[i] * (sumk - 1 / k[i])
		den = k[i] * k[i] * sumk
		x.append(num / den)
	cx = []
	flag = 0
	for i in range(n):
		cx.append(c[i] + x[i])
		if cx[i] < 0:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		root = 0
		for i in range(n):
			root += sqrt(cx[i])
		print(root, end=' ')
		for i in range(n):
			print(x[i], end=' ')
	print('\n')


import math
test = int(input())
for i in range(0, test):
	n = int(input())
	krr = list(map(float, input().split(' ')))
	crr = list(map(float, input().split(' ')))
	prod = 0
	sum1 = 0
	ans = 0
	drr = []
	for i in range(0, n):
		prod = prod + krr[i] * crr[i]
	if prod < 0:
		print('-1')
		continue
	for i in range(0, n):
		sum1 = sum1 + 1 / krr[i]
	for i in range(0, n):
		drr.append(prod / (krr[i] * krr[i] * sum1) - crr[i])
	for i in range(0, n):
		ans = ans + math.sqrt(drr[i] + crr[i])
	print(str.format('{0:.10f}', ans), end=' ')
	for i in range(0, n):
		print(str.format('{0:.10f}', drr[i]), end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	temp1 = 0.0
	for i in range(n):
		temp1 += c[i] * k[i]
	temp1 = temp1 * 4
	temp2 = 0.0
	for i in range(n):
		temp2 += 1 / k[i]
	inv_lambda = temp1 / temp2
	arr = []
	for i in range(n):
		t1 = 1 / (4 * k[i] ** 2)
		t1 = t1 * inv_lambda
		t1 = t1 - c[i]
		arr.append(t1)
	count = 0.0
	for i in range(n):
		count += arr[i] * k[i]
	flag = 0
	for i in range(n):
		if arr[i] + c[i] >= 0.0:
			pass
		else:
			flag = 1
	if (count >= 0.0 or count <= 0.0) and flag == 0:
		f = 0.0
		for i in range(n):
			f += (arr[i] + c[i]) ** 0.5
		arr = [f] + arr
		print(*arr)
	else:
		print(-1)


import math
t = int(input())
for i in range(0, t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	x = [0] * n
	sum1 = 0
	sum2 = 0
	sum3 = 0
	for j in range(0, n):
		sum1 += c[j] * k[j]
		sum2 += 1 / k[j]
	fl = 1
	for j in range(0, n):
		p = sum1 / (k[j] * k[j] * sum2)
		if p < 0:
			fl = 0
			break
		x[j] = p - c[j]
		sum3 += math.sqrt(p)
	if fl == 0:
		print('-1')
		continue
	print(sum3, end=' ')
	for o in x:
		print(o, end=' ')
	print()


import math
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	right = 0
	left = 0
	for i in range(n):
		right += k[i] * c[i]
		left += 1 / k[i]
	ans = []
	lamb = right / left * 4
	count = 0
	f = 0
	for i in range(n):
		h = lamb / (4 * k[i] * k[i])
		if h < 0:
			count = 1
			break
		else:
			h -= c[i]
			ans.append(h)
			f += math.sqrt(h + c[i])
	if count == 1:
		print(-1)
	else:
		print(f, *ans)


for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	possible = [-c[i] for i in range(n)]
	s = 0
	for i in range(n):
		s += k[i] * possible[i]
	if s > 0:
		print('-1')
	else:
		r = [1] * n
		for i in range(1, n):
			r[i] = k[0] ** 2 / k[i] ** 2
		sc = 0
		sr = 0
		for i in range(n):
			sc += k[i] * c[i]
			sr += k[i] * r[i]
		x = sc / sr
		ans = [0] * n
		lol = 0
		for i in range(n):
			r[i] *= x
			ans[i] = r[i] - c[i]
			lol += r[i] ** 0.5
		print(lol, *ans)


t = int(input())
for _ in range(t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	oneoverk = sum([1 / x for x in k])
	sumck = sum([c[i] * k[i] for i in range(n)])
	lamb = sumck / oneoverk
	if lamb < 0:
		print(-1)
	else:
		x = [lamb / k[i] ** 2 - c[i] for i in range(n)]
		opti = sum([(x[i] + c[i]) ** (1 / 2) for i in range(n)])
		x = [opti] + x
		print(' '.join(list(map(str, x))))


for _ in range(int(input())):
	n = int(input())
	k = [float(x) for x in input().split()]
	c = [float(x) for x in input().split()]
	const = sum([i * j for (i, j) in zip(k, c)]) / sum([1 / i for i in k])
	x = [const / j ** 2 - i for (i, j) in zip(c, k)]
	if any((i + j < 0 for (i, j) in zip(x, c))):
		print(-1)
	else:
		res = sum([(i + j) ** 0.5 for (i, j) in zip(x, c)])
		print(res, *x)


from functools import reduce
from operator import add
from math import sqrt

def main():
	for test_Case in range(int(input())):
		n = int(input())
		k = list(map(float, input().split()))
		c = list(map(float, input().split()))
		numer = reduce(add, map(lambda i: k[i] * c[i], range(n)))
		x = [0] * n
		value = 0
		Count = k.count(0)
		if Count != 0:
			print(-1)
			continue
		denom = 0
		for i in range(n):
			denom += 1 / k[i]
		lamb = numer / denom
		if lamb < 0:
			print(-1)
			continue
		for i in range(n):
			x[i] = lamb / pow(k[i], 2) - c[i]
			value += sqrt(x[i] + c[i])
		print(value, *x, sep=' ')
main()


import math as m
import numpy as np
import pandas as pd
testcase = int(input())
for i in range(testcase):
	a = int(input())
	b = [float(x) for x in input().split()]
	d = [float(x) for x in input().split()]
	v = []
	cnt = 0.0
	for i in range(a):
		v.append(1 / b[i])
		cnt += b[i] * d[i]
	if cnt < 0:
		print(-1)
	else:
		lm = m.sqrt(cnt / sum(v))
		M = 0.0
		xx = []
		for j in range(a):
			y = lm * v[j]
			M += y
			xx.append(y ** 2 - d[j])
		print(M, *xx)


from math import sqrt

def get_input_line():
	return input()

def f(x1, x2, c1, c2):
	return sqrt(x1 + c1) + sqrt(x2 + c2)

def wrap(result):
	return ' '.join([str(_) for _ in result])

def solve_n_equals_two_small(n, ks, cs):
	(k1, k2) = ks
	(c1, c2) = cs
	factor = -k2 / k1
	x1 = -c1
	(max_f, max_x1, max_x2) = (-1, x1, x1 / factor)
	while x1 / factor >= -c2:
		x2 = x1 / factor
		curr_f = f(x1, x2, c1, c2)
		if curr_f > max_f:
			max_f = curr_f
			max_x1 = x1
			max_x2 = x2
		x1 += 0.01
	if max_f == -1:
		return wrap([-1])
	else:
		return wrap([max_f, max_x1, max_x2])

def solve_n_equals_two_big(n, ks, cs):
	(k1, k2) = ks
	(c1, c2) = cs
	fc = k1 / k2
	x1 = (c2 - c1 * fc ** 2) / (fc ** 2 + fc)
	x2 = -fc * x1
	if x1 + c1 < 0 or x2 + c2 < 0:
		return wrap([-1])
	return wrap([f(x1, x2, c1, c2), x1, x2])

def solve_k_equals_one(n, ks, cs):
	positive_sum = 0
	negative_sum = 0
	for c in cs:
		if c < 0:
			negative_sum += abs(c)
		else:
			positive_sum += c
	if negative_sum > positive_sum:
		return wrap([-1])
	target_value = (positive_sum - negative_sum) / n
	max_f = sqrt(target_value) * n
	xs = []
	for c in cs:
		x = target_value - c
		xs.append(x)
	return wrap([max_f] + xs)

def solve_c_equals_zero(n, ks, cs):
	result = [0] * (n + 1)
	return wrap(result)

def solve_big(n, ks, cs):
	sum_ci_times_ki = 0
	sum_one_over_ki = 0
	for (ki, ci) in zip(ks, cs):
		sum_ci_times_ki += ci * ki
		sum_one_over_ki += 1 / ki
	if sum_ci_times_ki <= 0:
		return wrap([-1])
	lambda_factor = sum_one_over_ki / sum_ci_times_ki
	xs = []
	f_ = 0
	for i in range(n):
		ki = ks[i]
		ci = cs[i]
		xi = 1 / (ki * ki * lambda_factor) - ci
		if xi + ci < 0:
			return wrap(-1)
		xs.append(xi)
		f_ += sqrt(xi + ci)
	return wrap([f_] + xs)

def main():
	t = int(get_input_line())
	for i in range(t):
		n = int(get_input_line())
		ks = list(map(float, get_input_line().strip().split()))
		cs = list(map(float, get_input_line().strip().split()))
		result = '-1'
		all_c_zeroes = True
		for c in cs:
			if c != 0:
				all_c_zeroes = False
				break
		all_k_ones = True
		for k in ks:
			if k != 1:
				all_k_ones = False
				break
		if all_c_zeroes:
			result = solve_c_equals_zero(n, ks, cs)
		elif all_k_ones:
			result = solve_k_equals_one(n, ks, cs)
		elif n == 2:
			result = solve_n_equals_two_big(n, ks, cs)
		else:
			result = solve_big(n, ks, cs)
		print(result)
main()


import math
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	x = []
	ans = 0.0
	temp = 0.0
	deno = 0.0
	for i in range(n):
		temp = k[i] * c[i] + temp
		deno = deno + 1 / k[i]
	if temp >= 0:
		for i in range(n):
			a = temp / (deno * k[i] * k[i])
			x.append(a - c[i])
			ans = ans + math.sqrt(a)
		print(ans, end=' ')
		for i in range(n):
			print(x[i], end=' ')
		print()
	else:
		print(-1)


t = int(input())
for ijk in range(0, t):
	n = int(input())
	k = list(map(float, input().strip().split()))
	c = list(map(float, input().strip().split()))
	ans1 = 0
	ans2 = 0
	for i in range(0, n):
		ans1 += 1 / k[i]
		ans2 += k[i] * c[i]
	if ans1 * ans2 < 0:
		print(-1)
	else:
		F = pow(ans1 * ans2, 0.5)
		m = F / ans1
		x = []
		for i in range(0, n):
			xi = m * m / (k[i] * k[i]) - c[i]
			x.append(xi)
		print(F, end=' ')
		print(*x, sep=' ')


T = int(input())
for t in range(T):
	n = int(input())
	k = [float(x) for x in input().strip().split()]
	c = [float(x) for x in input().strip().split()]
	sumkc = sum((k[i] * c[i] for i in range(n)))
	if sumkc < 0:
		print(-1)
	else:
		try:
			sumkc_by_sum_1_by_k = sumkc / sum((1 / k[i] for i in range(n)))
			y = [sumkc_by_sum_1_by_k / k[i] ** 2 for i in range(n)]
			f = sum((y[i] ** 0.5 for i in range(n)))
			x = [y[i] - c[i] for i in range(n)]
			print(f, ' '.join(map(str, x)))
		except:
			print(-1)


t = [int(k) for k in input().strip().split(' ')][0]
from math import sqrt
for nt in range(t):
	n = [int(k) for k in input().strip().split(' ')][0]
	k = [float(_) for _ in input().strip().split(' ')]
	c = [float(_) for _ in input().strip().split(' ')]
	cani = sum([-k[i] * c[i] for i in range(n)])
	if cani > 0:
		print(-1)
	else:
		ut = sum([0.25 / i for i in k])
		tdr = sqrt(-ut / cani) if cani else 100000000
		x = [0.25 / k[i] / k[i] / tdr / tdr - c[i] for i in range(n)]
		print(' '.join(['{:.6f}'.format(_) for _ in [sum([sqrt(x[i] + c[i]) for i in range(n)])] + x]))


t = int(input())
while t > 0:
	n = int(input())
	k = input().strip().split()
	for i in range(n):
		k[i] = float(k[i])
	c = input().strip().split()
	for i in range(n):
		c[i] = float(c[i])
	x1 = 0
	p = 0
	for i in range(1, n):
		p = p + (c[i] * k[i] * k[i] - c[0] * k[0] * k[0]) / k[i]
	q = k[0]
	for i in range(1, n):
		q = q + k[0] * k[0] / k[i]
	x1 = p / q
	ans = []
	ans.append(x1)
	temp = k[0] * k[0] * (x1 + c[0])
	for i in range(1, n):
		xx = temp / (k[i] * k[i]) - c[i]
		ans.append(xx)
	flag = 1
	ans1 = [0] * n
	for i in range(n):
		ans1[i] = ans[i] + c[i]
		if ans1[i] < 0:
			flag = 0
	if flag == 1:
		total = 0
		for i in ans1:
			total = total + i ** 0.5
		print('%.10f' % total, end=' ')
		for i in ans:
			print('%.10f' % i, end=' ')
		print()
	else:
		print(-1)
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	k = list(map(eval, input().strip().split()))
	c = list(map(eval, input().strip().split()))
	(a, b) = (0, 0)
	try:
		cnt = 0
		for i in range(n):
			if c[i] != 0:
				a += k[i] * c[i]
				cnt += 1
			b += 1 / k[i]
		if a == 0 and cnt > 0:
			print(0, *[-1 * x for x in c])
			continue
		else:
			l = b ** (1 / 2) / (2 * a ** (1 / 2))
		m = 0
		x = [0] * n
		for i in range(n):
			x[i] = 1 / (4 * l * l * k[i] * k[i]) - c[i]
			m += (x[i] + c[i]) ** (1 / 2)
		if type(m) == type(1 + 1j):
			print(-1)
		else:
			print(m, *x)
	except:
		print(0, *[0] * n)


import numpy as np

def main():
	for _ in range(int(input())):
		N = int(input())
		K = np.array([float(i) for i in input().split()])
		C = np.array([float(i) for i in input().split()])
		if np.sum(K * C) < 0:
			print(-1)
		else:
			k_2 = K[0] ** 2
			K_2 = k_2 / K
			numer = np.sum(C * K) - np.sum(K_2) * C[0]
			denom = np.sum(K_2)
			x1 = numer / denom
			l = (x1 + C[0]) * (K[0] * K[0]) / (K * K) - C
			mx = np.sum(np.sqrt(l + C))
			print(mx, *list(l))
main()


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	k = [float(s) for s in input().split()]
	c = [float(s) for s in input().split()]
	w2 = sum([k[i] * c[i] for i in range(1, n)])
	w3 = sum([1 / k[i] for i in range(1, n)])
	if w2 + k[0] * c[0] < 0:
		print(-1)
		continue
	x1 = (w2 - c[0] * k[0] ** 2 * w3) / (k[0] * (1 + k[0] * w3))
	x = [0 for i in range(n)]
	x[0] = x1
	for i in range(1, n):
		x[i] = (x[0] + c[0]) * k[0] ** 2 / k[i] ** 2 - c[i]
	F = sum([sqrt(x[i] + c[i]) for i in range(n)])
	print(round(F, 3), end=' ')
	for i in x:
		print(round(i, 3), end=' ')
	print()


import sys
import math
t = int(input())
while t > 0:
	n = int(input())
	k = list(map(float, input().split(' ')))
	c = list(map(float, input().split(' ')))
	lembda = 0
	sum = 0
	altermul = 0
	mul = 0
	cn = 0
	chsum = 0
	x = []
	for i in range(n):
		mul = mul + 1 / k[i]
	for i in range(n):
		if c[i] == 0:
			cn = cn + 1
	for i in range(n):
		sum = sum + k[i] * c[i]
		altermul = altermul + mul / k[i]
	z = 0
	if sum > 0:
		lembda = math.sqrt(mul / sum) / 2
	elif sum < 0:
		print(-1)
		t = t - 1
		continue
	else:
		z = 1
	for i in range(n):
		if z != 1:
			x.append(1 / (4 * lembda * lembda * k[i] * k[i]) - c[i])
		else:
			x.append(-c[i])
			chsum = chsum + k[i] * x[i]
	if chsum != 0:
		print(-1)
		t = t - 1
		continue
	fmax = 0
	wr = 0
	for i in range(n):
		if x[i] + c[i] >= 0:
			fmax = fmax + math.sqrt(x[i] + c[i])
		else:
			wr = 1
	if cn == n:
		temp = 0.0
		print(temp, end=' ')
		for i in range(n):
			print(temp, end=' ')
		print()
	elif wr == 0:
		print(fmax, end=' ')
		for i in range(n):
			print(x[i], end=' ')
		print()
	else:
		print(-1)
	k.clear()
	c.clear()
	t = t - 1


import math
t = int(input())
for ii in range(t):
	n = int(input())
	k = list(map(float, input().rstrip().split()))
	c = list(map(float, input().rstrip().split()))
	dp = [0] * n
	if k.count('1') == n and c.count(0) == n:
		print(0, *dp)
		continue
	if c.count(0) == n:
		print(0, *dp)
		continue
	if n == 2:
		c1 = c[0]
		c2 = c[1]
		k1 = k[0]
		k2 = k[1]
		x1 = (c2 * k2 * k2 - k1 * k1 * c1) / (k1 * k1 + k1 * k2)
		x2 = -1 * (x1 * k1) / k2
		if c1 + x1 < 0 or c2 + x2 < 0:
			print(-1)
		else:
			value = math.sqrt(c1 + x1) + math.sqrt(c2 + x2)
			print(value, x1, x2)
		continue
	sum1 = 0
	sum2 = 0
	flag = 0
	for i in range(n):
		sum1 += 1 / k[i]
		sum2 += c[i] * k[i]
	if sum2 == 0:
		print(-1)
		continue
	l = sum1 / sum2
	l = l / 4
	for i in range(n):
		p = 4.0 * l * k[i] * k[i]
		if p == 0:
			flag = 1
			break
		p = 1 / p
		dp[i] = p - c[i]
		if dp[i] + c[i] < 0:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		ans = 0
		for i in range(n):
			ans += math.sqrt(dp[i] + c[i])
		print(ans, *dp)


import math
for _ in range(int(input())):
	n = int(input())
	kList = list(map(float, input().split()))
	cList = list(map(float, input().split()))
	found = False
	for i in cList:
		if i != 0:
			found = True
	upUp = 1 / kList[0]
	downUp = cList[0] * kList[0]
	downDown = 0.0
	for i in range(1, n, 1):
		upUp += 1 / kList[i]
		downUp += cList[i] * kList[i]
	if downUp == 0 and found == True:
		print(0, end=' ')
		for i in range(n):
			print(-1 * cList[i], end=' ')
		print()
		continue
	if downUp == 0:
		for _ in range(n + 1):
			print(0, end=' ')
		print()
		continue
	if downUp < 0:
		print(-1)
		continue
	lambdaConstant = math.sqrt(upUp / downUp)
	lambdaConstant /= 2
	ls = []
	result = 0.0
	for i in range(n):
		down = 2 * kList[i] * lambdaConstant
		down *= down
		x = 1 - cList[i] * down
		x /= down
		ls.append(x)
		result += math.sqrt(x + cList[i])
	print('%0.10f ' % result, end=' ')
	for i in range(n):
		print('%0.10f ' % ls[i], end=' ')
	print()


for _ in range(0, int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	cc = 0
	dd = 0
	for i in c:
		if i == 0:
			cc = cc + 1
		if i < 0:
			dd = dd + 1
	if cc == n:
		c.append(0)
		print(*c, sep=' ')
	elif dd == n:
		print(-1)
	else:
		v1 = 0
		v2 = 0
		for i in range(0, n):
			v1 += 1 / k[i]
			v2 += c[i] * k[i]
		if v2 == 0:
			print(0, end=' ')
			for i in range(0, n):
				c[i] = -1 * c[i]
			print(*c, sep=' ')
		else:
			lm = v1 / (4 * v2)
			sol = []
			s = 0
			chk = 1
			for i in range(0, n):
				d = 4 * lm * k[i] * k[i]
				x = 1 / d
				x = x - c[i]
				sol.append(round(x, 10))
				if sol[i] + c[i] >= 0:
					s += pow(sol[i] + c[i], 0.5)
				else:
					chk = 0
					break
			if chk == 0:
				print(-1)
			else:
				print(round(s, 10), end=' ')
				print(*sol, sep=' ')


import math

def calc(y, n):
	z = 0
	for i in range(n):
		z = z + math.sqrt(y[i])
	return z
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	sum_ki = 0
	sum_kc = 0
	for i in range(n):
		sum_ki += 1 / k[i]
		sum_kc += k[i] * c[i]
	if sum_kc >= 0:
		D = sum_kc / sum_ki
		y = []
		for i in range(n):
			y.append(D / k[i] ** 2)
		F = calc(y, n)
		print('{0:.10f}'.format(F), end=' ')
		for i in range(n):
			print('{0:.10f}'.format(y[i] - c[i]), end=' ')
		print()
	else:
		print('-1')


import math
t = int(input())
for l in range(0, t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	ciki = 0
	ciki2 = 0
	ciki3 = 0
	for i in range(0, n):
		ciki += c[i] * k[i]
	for i in range(0, n):
		ciki3 += k[0] * k[0] / k[i]
	x = list()
	x.append(ciki / ciki3 - c[0])
	for i in range(1, n):
		x.append((x[0] + c[0]) * (k[0] * k[0]) / (k[i] * k[i]) - c[i])
	t = 0
	f = 0
	for i in range(0, n):
		if x[i] + c[i] < 0:
			print(-1)
			break
		else:
			t += 1
			f += math.sqrt(x[i] + c[i])
	if t < n:
		continue
	print(f, end=' ')
	for i in range(0, n):
		print(x[i], end=' ')
	print('')


t = int(input())
for nt in range(t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	s1 = 0
	for i in range(1, n):
		s1 += k[i] * c[i]
	s2 = 0
	for i in range(1, n):
		s2 += 1 / k[i]
	subtract = c[0] * k[0] * k[0] * s2
	rhs = s1 - subtract
	s3 = 1
	for i in range(1, n):
		s3 += k[0] / k[i]
	lhs = s3 * k[0]
	x1 = rhs / lhs
	ans = []
	ans.append(x1)
	x1 = x1 + c[0]
	x1 = x1 * k[0] * k[0]
	for i in range(1, n):
		ans.append(x1 / k[i] ** 2 - c[i])
	answer = 0
	flag = 0
	for i in range(n):
		if ans[i] + c[i] >= 0:
			answer += (ans[i] + c[i]) ** 0.5
		else:
			print(-1)
			flag = 1
			break
	if flag == 0:
		print(answer, end=' ')
		print(*ans)


for t in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	kr = list(map(lambda e: 1 / e, k))
	kc = [k[i] * c[i] for i in range(n)]
	y = 1 / sum(kr) * sum(kc)
	x = []
	flag = False
	F = 0
	for i in range(n):
		xi = (y * kr[i] - kc[i]) / k[i]
		if xi + c[i] < 0:
			flag = True
			break
		F += (xi + c[i]) ** 0.5
		x.append(xi)
	if flag:
		print(-1)
	else:
		print(F, end=' ')
		print(' '.join(map(str, x)))


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(float, input().split()))
mapin = lambda : map(int, input().split())

def kc(i):
	return k[i] ** 2 * c[i]
for _ in range(int(input())):
	n = int(input())
	k = listin()
	c = listin()
	skc = 0
	for i in range(n):
		skc += k[i] * c[i]
	skin = 0
	for i in k:
		skin += 1 / i
	if skc < 0:
		print(-1)
	else:
		x = []
		if skc == 0:
			s = sum(c)
			ans = [s / n for i in range(n)]
			val = n * (s / n) ** 0.5
			for i in range(n):
				ans[i] -= c[i]
			print(val, end=' ')
			print(*ans)
		else:
			fourlambdasquare = skin / skc
			for i in range(n):
				x.append(1 / (fourlambdasquare * k[i] ** 2) - c[i])
			val = 0
			for i in range(n):
				val += (x[i] + c[i]) ** 0.5
			print(val, end=' ')
			print(*x)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr_k = list(map(float, stdin.readline().split()))
	arr_c = list(map(float, stdin.readline().split()))
	s = 0
	for i in range(n):
		s += arr_k[i] * (0 - arr_c[i])
	if s > 0:
		print(-1)
	elif arr_k.count(1) == n:
		t = sum(arr_c) / n
		f = (n * sum(arr_c)) ** 0.5
		print(round(f, 10), end=' ')
		for i in range(n - 1):
			print(round(t - arr_c[i], 10), end=' ')
		print(round(t - arr_c[n - 1], 10))
	else:
		(D, P) = (0, 0)
		for i in range(n):
			D += arr_k[i] * arr_c[i]
			P += 1 / arr_k[i]
		F = (D * P) ** 0.5
		print(round(F, 10), end=' ')
		for i in range(n - 1):
			d = D - arr_k[i] * arr_c[i]
			p = P - 1 / arr_k[i]
			num = d - p * arr_c[i] * arr_k[i] ** 2
			den = arr_k[i] * (1 + p * arr_k[i])
			print(round(num / den, 10), end=' ')
		d = D - arr_k[n - 1] * arr_c[n - 1]
		p = P - 1 / arr_k[n - 1]
		num = d - p * arr_c[n - 1] * arr_k[n - 1] ** 2
		den = arr_k[n - 1] * (1 + p * arr_k[n - 1])
		print(round(num / den, 10))


from numpy import inner

def f(x, c):
	total = 0
	for i in range(len(x)):
		if x[i] + c[i] < 0:
			return -1
		total += (x[i] + c[i]) ** 0.5
	return total
for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	x = [0] * len(k)
	k_ = sum([1 / ki for ki in k])
	kc = inner(k, c)
	for i in range(len(k)):
		k_i = k_ - 1 / k[i]
		x[i] = (kc - k[i] * c[i] - k[i] ** 2 * c[i] * k_i) / (k[i] + k[i] ** 2 * k_i)
	ans = f(x, c)
	if ans == -1:
		print(-1)
	else:
		print(ans, end=' ')
		print(*x)


from math import sqrt
from decimal import Decimal
t = int(input())
for _ in range(t):
	n = int(input())
	k = list(map(Decimal, input().split()))
	c = list(map(Decimal, input().split()))
	G = 0
	for i in range(n):
		G += k[i] * c[i]
	P = 1
	for i in range(n):
		P *= k[i]
	y = []
	for i in range(n):
		y.append(P / k[i])
	Y = sum(y)
	if G < 0:
		print(-1)
	else:
		res = []
		for i in range(n):
			res.append(G * y[i] / (Y * k[i]))
		m = 0
		for i in range(n):
			m += sqrt(res[i])
			res[i] -= c[i]
		print(m, end=' ')
		for i in range(n):
			print(res[i], end=' ')
		print()


def kmpsearch(out, pat):
	n = len(out)
	m = len(pat)
	p = [0] * m
	compute(pat, m, p)
	q = 0
	i = 0
	while i < n:
		if pat[q] == out[i]:
			q = q + 1
			i = i + 1
		elif q != 0:
			q = p[q - 1]
		else:
			i = i + 1
		if q == m:
			print('pattern occurs at ' + str(i - q))
			q = p[q - 1]

def redoximi(vector1, vector2):
	ans = 0
	for i in range(len(vector1)):
		ans += vector1[i] * vector2[i]
	return ans

def compute(pat, m, p):
	k = 1
	l = 0
	while k < m:
		if pat[k] <= pat[l]:
			l = l + 1
			p[k] = l
			k = k + 1
		elif l != 0:
			l = p[l - 1]
		else:
			p[k] = 0
			k = k + 1

def bottle_neck(list):
	ans = 0
	for i in list:
		ans += 1 / i
	return ans

def solveit(dic):

	def create_ST(arr, st, low, high, pos):
		if low == high:
			st[pos] = arr[low]
			return st
		mid = int((low + high) / 2)
		create_ST(arr, st, low, mid, 2 * pos + 1)
		create_ST(arr, st, mid + 1, high, 2 * pos + 2)
		st[pos] = min(st[2 * pos + 1], st[2 * pos + 2])
		return st

	def next_power_of_2(x):
		f = 1 if x == 0 else 2 ** (x - 1).bit_length()
		return f * 2 - 1

	def query(st, ql, qh, low, high, pos):
		if ql <= low and qh >= high:
			return st[pos]
		if ql > high or qh < low:
			return math.inf
		mid = (low + high) / 2
		return min(query(st, ql, qh, low, mid, 2 * pos + 1), query(st, ql, qh, mid + 1, high, 2 * pos + 2))
	final = 0
	for (oppo, vivo) in dic.items():
		for casio in range(len(vivo)):
			final += vivo[casio] * casio
			final -= vivo[casio] * (len(vivo) - casio - 1)
		final -= len(vivo) * (len(vivo) - 1) // 2
		if oppo == 0:
			for prime in vivo:
				final += prime
	return final

def waarida(list):
	ans = 0
	for i in list:
		ans += i ** 0.5
	return ans

def search(pat, str):
	m = len(pat)
	n = len(str)
	for i in range(n - m + 1):
		j = 0
		for j in range(0, m):
			if str[i + j] != pat[j]:
				break
		if j == m - 1:
			print('Pattern found at', i)

def float_input():
	list = [float(i) for i in input().split()]
	return list

def insert(word):
	current = root
	for i in range(len(word)):
		if word[i] not in current.children:
			node = TrieNode()
			current.children[word[i]] = node
		else:
			node = current.children[word[i]]
		current = node
		current.endofword = True
		current.count += 1
t = int(input())

def search(word, root):
	current = root
	for i in range(len(word)):
		if word[i] not in current.children:
			return False
		else:
			node = current.children[word[i]]
		current = node
	return {'The word exists': current.endofword, 'No of times word occurs': current.count}
for tt in range(t):
	(matter, mojner) = ([], [])
	size = int(input())
	K = float_input()
	C = float_input()
	pried = bottle_neck(K)
	dire = redoximi(K, C)
	possible_or_not = True
	all_knowing = dire / pried
	for i in range(size):
		matter.append(all_knowing / pow(K[i], 2))
		if matter[i] < 0:
			possible_or_not = False
			break
		else:
			mojner.append(matter[i] - C[i])
	if possible_or_not:
		mojner = [waarida(matter)] + mojner
		print(*mojner)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [float(x) for x in input().split()]
	B = [float(x) for x in input().split()]
	p = 0
	q = 0
	for i in range(n - 1):
		p += A[i] * B[i]
		q += 1 / A[i]
	q *= A[-1] ** 2
	Xn = (p - B[-1] * q) / (q + A[-1])
	if Xn + B[-1] >= 0:
		flag = 0
		D = []
		for i in range(n - 1):
			l = (Xn + B[-1]) * (A[-1] / A[i]) ** 2 - B[i]
			if l + B[i] >= 0:
				D.append(l)
			else:
				flag = 1
				break
		if flag:
			print(-1)
		else:
			F = (Xn + B[-1]) ** 0.5
			for i in range(n - 1):
				F += (D[i] + B[i]) ** 0.5
			print(F, end=' ')
			for i in D:
				print(i, end=' ')
			print(Xn)
	else:
		print(-1)


import math
t = int(input())
for ti in range(t):
	n = int(input())
	l1 = list(map(float, input().split()))
	l2 = list(map(float, input().split()))
	l3 = []
	a1 = 0
	for i in range(n):
		a1 += l1[i] * l2[i]
	a2 = 0
	for i in range(n):
		a2 += 1 / l1[i]
	f = a1 * a2
	if f < 0:
		print(-1)
		continue
	l = a1 / a2
	for i in range(n):
		x = l / (l1[i] * l1[i]) - l2[i]
		l3.append(x)
	f = math.sqrt(f)
	print(f, end=' ')
	for i in range(n - 1):
		print(l3[i], end=' ')
	print(l3[-1])


for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	multi = 0
	divi = 0
	for i in range(n):
		multi += k[i] * c[i]
		divi += 1 / k[i]
	const = multi / divi
	ans = []
	f = 0
	for i in range(n):
		cur_ans = const / pow(k[i], 2) - c[i]
		ans.append(cur_ans)
		f += (cur_ans + c[i]) ** 0.5
	if isinstance(f, complex):
		print(-1)
		continue
	else:
		print(f, end=' ')
	print(' '.join((str(v) for v in ans)))


from math import sqrt

def solve2(k, c):
	G = 0
	for (ke, ce) in zip(k, c):
		G += ke * ce
	if G:
		k_inv = [1 / ke for ke in k]
		L_sq = 1 / (4 * G) * sum(k_inv)
		if L_sq <= 0:
			return False
		L = sqrt(L_sq)
		X = [1 / (2 * L * ke) for ke in k]
	else:
		X = [0 for i in range(len(k))]
	s = sum(X)
	x = [Xe ** 2 - ce for (Xe, ce) in zip(X, c)]
	return [s] + x
t = int(input())
for __ in range(t):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	ans = solve2(k, c)
	if ans:
		print(*ans)
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	k = [float(x) for x in input().split()]
	c = [float(x) for x in input().split()]
	temp = 0.0
	k1 = []
	sc = 0.0
	for i in range(n):
		k1.append(1 / k[i])
		sc += k[i] * c[i]
	if sc < 0:
		print(-1)
	else:
		lam = math.sqrt(sc / sum(k1))
		mx = 0.0
		x = []
		for i in range(n):
			y = lam * k1[i]
			mx += y
			x.append(y ** 2 - c[i])
		print(mx, *x)


from math import *
for i in range(int(input())):
	N = int(input())
	K = list(map(float, input().split()))
	C = list(map(float, input().split()))
	p = 0
	num = 0
	den = 0
	for i in range(N):
		num = num + C[i] * K[i]
		den = den + 1 / K[i]
	p = num / den
	if p < 0:
		print(-1)
		continue
	else:
		ma = 0
		x = [0] * N
		for i in range(N):
			x[i] = p / K[i] ** 2 - C[i]
			ma = ma + sqrt(x[i] + C[i])
		print(ma, end=' ')
		print(*x)


for _ in range(int(input())):
	n = int(input())
	k = list(map(float, input().split()))
	c = list(map(float, input().split()))
	reci = sum([1 / elem for elem in k])
	ck = sum([i * j for (i, j) in zip(c, k)])
	lam = ck / reci
	x = [round(lam / j ** 2 - i, 10) for (i, j) in zip(c, k)]
	try:
		f = round(sum([(i + j) ** 0.5 for (i, j) in zip(x, c)]), 10)
		print(f, *x)
	except Exception as e:
		print(-1)


from math import sqrt
t = int(input())
for i in range(t):
	n = int(input())
	k = [float(j) for j in input().split()]
	c = [float(j) for j in input().split()]
	x = [0] * n
	sumi = 0
	for j in range(n):
		x[j] = -c[j]
		sumi += x[j] * k[j]
	sumi = -sumi
	if sumi < 0:
		print(-1)
		continue
	factor = 1
	f2 = 0
	for j in k:
		f2 += 1 / j
	factor /= f2
	X = [0] * n
	f = 0.0
	for j in range(n):
		s = sumi * factor / k[j] ** 2
		if s > 0:
			f += sqrt(s)
		X[j] = x[j] + s
	print(f, end=' ')
	for j in X:
		print(j, end=' ')
	print()