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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;
const int n = 250;
bool is_uniform(const vector<int>& a) {
  int mn = *min_element((a).begin(), (a).end());
  int mx = *max_element((a).begin(), (a).end());
  int len = mn + mx;
  int start = 0, finish = 0;
  for (int(i) = 0; (i) < ((int)(a).size()); (i)++) {
    if (a[i] <= len / 5) {
      ++start;
    }
    if (a[i] >= 4 * len / 5) {
      ++finish;
    }
  }
  return (start + finish) * 100 / n > 20;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tst;
  cin >> tst;
  for (int(_) = 0; (_) < (tst); (_)++) {
    vector<int> a(n);
    for (int(i) = 0; (i) < ((int)(a).size()); (i)++) cin >> a[i];
    if (is_uniform(a)) {
      cout << (*min_element((a).begin(), (a).end()) +
               *max_element((a).begin(), (a).end())) /
                  2
           << endl;
    } else {
      int sum = 0;
      for (int x : a) sum += x;
      cout << (sum / n) << endl;
    }
  }
  return 0;
}