Problem: Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.

Can you help Heidi estimate each village's population?

Input

Same as the easy version.

Output

Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.

Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.

Solution (in PYTHON3):

Solution:
v = int(input())
eps = 170

def ans(a):
    a.sort()
    if len(a) % 2 == 0:
        med = a[len(a)//2]
    else:
        med = (a[len(a)//2] + a[len(a)//2 - 1]) // 2

    l = med - med // 2
    r = med + med // 2

    c1 = c2 = 0

    for i in a:
        if i >= l and i <= r:
            c1 += 1
        else:
            c2 += 1

    if abs(c1 - c2) <= eps:
        return (med, "uniform")
    else:
        return (med, "poisson")

    

for i in range(v):
    cur = [int(i) for i in input().split()]
    b = ans(cur)
    if b[1] == "poisson":
        print(b[0])
    else:
        print((max(cur) - min(cur)) // 2)