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;
signed main() {
  long long V;
  cin >> V;
  while (V--) {
    double a[250];
    for (long long i = 0; i < 250; i++) cin >> a[i];
    double exp = 0;
    for (long long i = 0; i < 250; i++) exp += a[i];
    exp /= 250;
    double var = 0;
    for (long long i = 0; i < 250; i++) var += (a[i] - exp) * (a[i] - exp);
    var /= 250;
    double k = exp / var;
    double err = 0.60;
    long long ans = round(exp);
    if (1.0 - err <= k && k <= 1.0 + err) {
    } else {
      double m = *max_element(a, a + 250);
      ans = ((250 + 1.0) / 250 * m - 1.01) / 2.0;
    }
    ans = max(ans, 10LL);
    ans = min(ans, 1000LL);
    cout << ans << endl;
  }
  return 0;
}