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 main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    double sm = 0.0;
    vector<double> d(250);
    for (int i = 0; i < 250; i++) {
      scanf("%lf", &d[i]);
      sm += d[i];
    }
    double mu = sm / 250.0;
    double sigma2 = 0;
    for (int i = 0; i < 250; i++) {
      sigma2 += pow(d[i] - mu, 2);
    }
    sigma2 /= 250.0;
    if (min(mu, sigma2) / max(mu, sigma2) >= 0.6) {
      cout << int(mu) << endl;
    } else {
      sort(d.begin(), d.end());
      cout << int(d[0] + d[249]) / 2 << endl;
    }
  }
  return 0;
}