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;
long long a[250LL];
int main() {
  int _;
  cin >> _;
  while (_--) {
    for (int i = 0; i < 250LL; i++) cin >> a[i];
    long long p = accumulate(a, a + 250LL, 250LL / 2) / 250LL;
    long long uni = p * p / 3;
    long long var = 0;
    for (int i = 0; i < 250LL; i++) var += (a[i] - p) * (a[i] - p);
    var /= 250LL;
    long long ans = p;
    if (abs(var - p) < abs(var - uni))
      ans = p;
    else
      ans = *max_element(a, a + 250LL) / 2;
    cout << ans << endl;
  }
}