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 warning(disable : 4996)
using namespace std;
class solve {
  long long n, l, k, a, b, c, m, r;
  vector<long long> v;

 public:
  solve() {
    v.resize(250);
    for (auto &x : v) cin >> x;
    ;
    n = 250;
    a = -1, b = 1e9;
    for (int i = 0; i < 250; i++) {
      a = max(v[i], a);
      b = min(v[i], b);
    }
    double mean = accumulate(v.begin(), v.end(), 0) / 250.0, var = 0;
    for (int i = 0; i < 250; i++) {
      var += (v[i] - mean) * (v[i] - mean);
    }
    var /= 250;
    double Pm = mean, Pv = mean, Umean = (a + b) / 2,
           Uvar = ((a - b) * (a - b)) / 12.0;
    if (abs(Pv - var) < abs(Uvar - var)) {
      cout << int(mean) << endl;
    } else {
      cout << (int)((a - b - 1) / 2.0) << endl;
    }
  }
};
int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) new solve;
  return 0;
};