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() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  fixed(cout);
  int t, i, n;
  cin >> t;
  while (t--) {
    n = 250;
    vector<int> x(n);
    double mu = 0, a, b = 0;
    for (i = 0; i < n; ++i) {
      cin >> x[i];
      mu += x[i];
      b = max(b, 1. * x[i]);
      if (i == 0)
        a = x[i];
      else
        a = min(a, 1. * x[i]);
    }
    mu /= n;
    double v = 0;
    for (i = 0; i < n; ++i) v += (x[i] - mu) * (x[i] - mu);
    v /= n;
    if (fabs(v - (b - a) * (b - a) / 12) < fabs(v - mu)) {
      cout << ((int)(b)) / 2 << '\n';
    } else {
      cout << ((int)(mu)) << '\n';
    }
  }
  return 0;
}