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;
  cin >> t;
  while (t--) {
    int cc[2101];
    int sum = 0;
    memset(cc, 0, sizeof cc);
    int mnv = 1e9, mxv = -1;
    for (int i = 0; i < 250; i++) {
      int x;
      cin >> x;
      cc[x]++;
      sum += x;
      mnv = min(mnv, x);
      mxv = max(mxv, x);
    }
    double rmean = sum / 250.0;
    int mn = rmean * 0.75;
    int mx = rmean * 1.25;
    int dd = 0;
    for (int i = mn; i <= mx; i++) {
      if (cc[i]) {
        dd += cc[i];
      }
    }
    if (dd / 250.0 > 0.45) {
      cout << (int)rmean << '\n';
    } else {
      cout << (int)(0.5 * (mxv + mnv)) << '\n';
    }
  }
}