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 PYTHON):

Solution:
def mean(seq):
    N = len(seq)
    return sum(seq)/float(N)
    
def std(seq):
    m = mean(seq)
    N = len(seq)
    return sum([(s-m)**2/N for s in seq])

def solve(seq):
    m = mean(seq)
    s = std(seq)
    
    s1 = m
    s2 = m*(m+1)/3
    
    if abs(s-s1) < abs(s-s2):
        return int(m)
    else:
        return (max(seq)+1)/2
        
V = int(raw_input())
seqs = [map(int, raw_input().split()) for i in xrange(V)]

for seq in seqs:
    print solve(seq)