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

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E802 solver = new E802();
        solver.solve(1, in, out);
        out.close();
    }

    static class E802 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n = in.nextInt();
            int[] a = new int[250];

            for (int v = 1; v <= n; v++) {

                double sum = 0;
                for (int i = 0; i < 250; i++) {
                    a[i] = in.nextInt();
                    sum += a[i];
                }

                double mean = sum / 250;

                double variance = 0;

                for (int i = 0; i < 250; i++) {
                    double deviation = mean - a[i];
                    variance += deviation * deviation;
                }

                variance /= 250;

                int ans = 0;

                if (2 * mean >= variance) { //gaussian
                    ans = ((int) Math.round(mean));
                } else { //uniform
                    ans = arrays.max(a) + arrays.min(a);
                    ans = ((int) Math.round(ans / 2.));
                }

                out.println(ans);

            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class arrays {
        public static int max(int[] a) {
            int ans = a[0];
            for (int i : a) {
                ans = Math.max(ans, i);
            }
            return ans;
        }

        public static int min(int[] a) {
            int ans = a[0];
            for (int i : a) {
                ans = Math.min(ans, i);
            }
            return ans;
        }

    }
}