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;
struct edge {
  int u, v;
  long long w;
};
long long MOD = 1000000007;
long long _MOD = 1000000009;
double EPS = 1e-10;
const int N = 250;
double F[10001];
double uniform(int N, vector<int> a, int p) {
  double sum = 0;
  for (int i = 0; i < N; i++) {
    if (0 <= a[i] && a[i] <= p * 2)
      sum += log(1.0 / (p * 2 + 1));
    else
      return -DBL_MAX;
  }
  return sum;
}
double poisson(int N, vector<int> a, int p) {
  double sum = 0;
  for (int i = 0; i < N; i++) {
    sum += log(p) * a[i];
    sum += -p;
    sum -= F[a[i]];
  }
  return sum;
}
int main() {
  for (int x = 1; x <= 10000; x++) F[x] = F[x - 1] + log(x);
  int T;
  cin >> T;
  while (T--) {
    vector<int> a(N);
    for (int i = 0; i < N; i++) scanf("%d", &a[i]);
    double ma = -DBL_MAX;
    int p0;
    for (int p = 10; p <= 1000; p++) {
      double q = max(uniform(N, a, p), poisson(N, a, p));
      if (q > ma) ma = q, p0 = p;
    }
    cout << p0 << endl;
  }
}