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 minn = 1000, maxx = 0;
bool check_if_uniform(vector<int> a) {
  int n = a.size(), i, j, k, total, avg, ct;
  total = 0;
  for (auto p : a) total += p;
  avg = total / n;
  ct = 0;
  for (auto p : a) {
    if (p < avg * 0.2) ct++;
  }
  minn = min(minn, ct);
  maxx = max(maxx, ct);
  if (ct <= n / 40)
    return false;
  else
    return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t, n, i, j, k, ct, ans;
  long double maxx, total, x, avg;
  cin >> t;
  while (t--) {
    n = 250;
    vector<int> a(n);
    total = 0;
    maxx = 0;
    for (i = 0; i < n; i++) {
      cin >> x;
      total += x;
      maxx = max(maxx, x);
      a[i] = x;
    }
    bool check_uniform = check_if_uniform(a);
    if (check_uniform)
      ans = maxx / 2;
    else
      ans = total / n;
    cout << ans << "\n";
  }
  return 0;
}