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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int N = 1e6;
int a[N];
double sqr(double x) { return x * x; }
int main() {
  int cas;
  scanf("%d", &cas);
  double ret = 0;
  for (int num = 0; num < cas; ++num) {
    int n = 250;
    double ave = 0;
    double max_a = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      ave += a[i];
      max_a = max(max_a, (double)a[i]);
    }
    ave /= n;
    double V = 0;
    for (int i = 0; i < n; ++i) {
      V += sqr(ave - a[i]);
    }
    V /= n;
    double ratio = ave / V;
    ret = max(ret, abs(ratio - 1));
    if (abs(ratio - 1) < 0.5) {
      printf("%d\n", (int)(ave + 0.5));
    } else {
      printf("%d\n", (int)(max_a * 0.5 + 0.5));
    }
  }
  return 0;
}