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 P;
int g1() {
  double p = rand() / 32767.0, s = 0, g = 1;
  for (int k = 0;; k++) {
    if (k) g *= k;
    double c = pow(P, k) * exp(-P) / g;
    s += c;
    if (p <= s) return k;
  }
}
int g2() {
  double p = rand() / 32767.0, s = 0;
  for (int k = 0; k <= P + P; k++) {
    s += 1.0 / (2 * P + 1);
    if (p <= s) return k;
  }
  return P + P;
}
int main() {
  int v;
  scanf("%d", &v);
  while (v--) {
    vector<int> vs;
    for (int i = 0; i < 250; i++) {
      int x;
      scanf("%d", &x);
      vs.push_back(x);
    }
    double avr = 0, ss = 0;
    for (int i = 0; i < 250; i++) avr += (double)vs[i];
    avr /= 250;
    int mx = 0;
    for (int i = 0; i < 250; i++)
      ss += (vs[i] - avr) * (vs[i] - avr), mx = max(mx, vs[i]);
    ss /= avr;
    if (ss < 500)
      printf("%d\n", int(avr + 0.5));
    else
      printf("%d\n", int(mx / 2.0 + 0.5));
  }
}