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() {
  srand(time(NULL));
  int v;
  scanf("%d", &v);
  for (int i = 0; i < v; i++) {
    vector<int> a(250);
    int sum = 0;
    for (int j = 0; j < a.size(); j++) {
      scanf("%d", &a[j]);
      sum += a[j];
    }
    double avg = sum / 250.0;
    int cnt = 0;
    for (int j = 0; j < a.size(); j++) {
      double val = (double)a[j] / avg;
      cnt += 0.5 <= val && val <= 1.5;
    }
    if (cnt > 250 * 0.7) {
      cout << (int)avg << "\n";
    } else {
      cout << *max_element(a.begin(), a.end()) / 2 << "\n";
    }
  }
  return 0;
}