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

Solution:
#include <bits/stdc++.h>
using namespace std;
int T, x, n;
double s, a[300], s1, maxx;
int main() {
  scanf("%d", &T);
  while (T--) {
    s = 0, maxx = 0, s1 = 0;
    n = 250;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      s += a[i], maxx = std::max(maxx, a[i]);
    }
    s /= n;
    for (int i = 1; i <= n; i++) {
      s1 += (a[i] - s) * (a[i] - s);
    }
    s1 /= n;
    if (s1 < 2 * s)
      printf("%d\n", (int)s);
    else
      printf("%d\n", int(*max_element(a + 1, a + 1 + n) / 2));
  }
  return 0;
}