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[300];
int main() {
  int n;
  double aver, s2;
  double s;
  scanf("%d", &n);
  while (n--) {
    aver = 0.0;
    s2 = 0.0;
    for (int i = 0; i < 250; i++) {
      scanf("%d", &a[i]);
      aver += a[i];
    }
    aver = aver / 250.0;
    for (int i = 0; i < 250; i++) {
      s2 += (a[i] - aver) * (a[i] - aver);
    }
    s2 = s2 / 250.0;
    int cnt = 0;
    if (fabs(1 - (s2 / aver)) < 0.5) {
      printf("%d\n", (int)aver);
    } else {
      int mi = 100000;
      int ma = 0;
      for (int i = 0; i < 250; i++) {
        mi = min(mi, a[i]);
        ma = max(ma, a[i]);
      }
      printf("%d\n", mi + ma / 2);
    }
  }
}