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;
const int N = 10005;
int n, a[N];
int cnt[N];
int main() {
  int T;
  srand(time(0));
  scanf("%d", &(T));
  while (T--) {
    memset(cnt, 0, sizeof(cnt));
    double ex = 0;
    for (int i = 1; i <= 250; i++)
      scanf("%d", &(a[i])), cnt[a[i]]++, ex += a[i];
    ex /= 250;
    int tot = 0;
    for (int i = 1; i <= ex / 3; i++) tot += cnt[i];
    if (tot < 250 / 6 - 25) {
    } else {
      ex = 0;
      for (int i = 1; i <= 250; i++) ex = max(ex, (double)a[i]);
      ex /= 2.0;
    }
    printf("%.0lf\n", ex);
  }
  return 0;
}