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>
double s1, s2;
int T, n, a[255];
int main() {
  n = 250;
  scanf("%d", &T);
  double m, M;
  while (T--) {
    s1 = s2 = 0;
    m = 1e9, M = 0;
    double x;
    for (int i = 0; i < n; ++i) {
      scanf("%lf", &x);
      s1 += x, s2 += x * x;
      m = std::min(m, x);
      M = std::max(M, x);
    }
    s1 /= n;
    s2 /= n;
    s2 -= s1 * s1;
    if (s2 / s1 > 3) {
      printf("%.0f\n", 0.5 + 0.5 * (M + m));
    } else {
      printf("%.0f\n", 0.5 + (0.8 * s1 + 0.2 * s2));
    }
  }
  return 0;
}