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 t;
int a[257];
double hfahuwef[3007];
long double calc(int p, int k) {
  if (k == 0) return -p;
  return k * log(p) - p - hfahuwef[k];
}
long double poisson(int p) {
  long double res = 0;
  for (int i = 0; i < 250; ++i) {
    res += calc(p, a[i]);
  }
  return res;
}
long double uniform(int p) {
  long double res = 0;
  if (a[0] > 2 * p) return -1e9;
  return 250 * log(double(1) / (2 * p + 1));
}
void solve() {
  for (int i = 0; i < 250; ++i) {
    cin >> a[i];
  }
  sort(a, a + 250);
  reverse(a, a + 250);
  int ans = -1;
  long double best = -1e9;
  for (int i = 10; i <= 1000; ++i) {
    long double p = poisson(i);
    if (p > best) {
      best = p;
      ans = i;
    }
    long double u = uniform(i);
    if (u > best) {
      best = u;
      ans = i;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  srand(time(NULL));
  hfahuwef[0] = log(1);
  for (int i = 1; i <= 3000; ++i) {
    hfahuwef[i] = hfahuwef[i - 1] + log(i);
  }
  cin >> t;
  while (t--) solve();
}