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;
const long long MOD = 1e9 + 7;
const int INF = 2e9 + 10;
const long double EPS = 1e-9;
const int M = 1e2 + 12;
const int N = 4e5 + 10;
void solve() {
  int n = 250;
  vector<int> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  int p = (accumulate(a.begin(), a.end(), 0ll) / n);
  long double m1 = (long double)p / 2.;
  long double m2 = (long double)p * (3. / 2.);
  int c1 = 0, c2 = 0, c3 = 0;
  for (long long i = 0; i < n; ++i)
    if (a[i] < m1)
      c1++;
    else if (a[i] > m2)
      c3++;
    else
      c2++;
  if (c2 <= 3 * (c1 + c3)) {
    cout << (a[0] + a[n - 1]) / 2 << endl;
  } else {
    cout << round(((long double)a[(n - 1) / 2] + (long double)a[n / 2]) / 2.)
         << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int v;
  cin >> v;
  while (v--) {
    solve();
  }
}