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 a[250], b[250];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    for (int i = 0; i < 250; i++) scanf("%d", &a[i]);
    double mina = a[0], maxa = a[0], minb = b[0], maxb = b[0];
    double mida = 0;
    for (int i = 0; i < 250; i++) {
      mida += a[i];
      mina = min(mina, (double)a[i]);
      maxa = max(maxa, (double)a[i]);
    }
    mida /= 250.;
    int sum = 0, sumb = 0;
    double len = mida / 2;
    for (int i = 0; i < 250; i++) {
      if (a[i] > (mida - len) && a[i] < (mida + len)) sum++;
      if (a[i] <= 1) sumb++;
    }
    if (sum < 180 || sumb > 3) {
      printf("%.0lf\n", (mina + maxa) / 2 + 0.5);
    } else {
      printf("%.0lf\n", mida + 0.5);
    }
  }
  return 0;
}