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 TC, w[260];
double mean, mean2;
int main() {
  srand(1879);
  int i;
  scanf("%d", &TC);
  while (TC--) {
    mean = 0.0;
    for (i = 1; i <= 250; i++) {
      scanf("%d", &w[i]);
      mean += w[i];
    }
    mean /= 250;
    sort(w + 1, w + 251);
    double res = 0.0;
    for (i = 1; i <= 250; i++) {
      if (mean - sqrt(mean) * 2 <= w[i] && w[i] <= sqrt(mean) * 2 + mean)
        res += 1.0 / 250;
    }
    if (res > 0.9) {
      printf("%.0f\n", mean);
    } else {
      printf("%d\n", (w[250] + 1) / 2);
    }
  }
}