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;
double getAverage(const vector<int>& v) {
  int s = 0;
  for (int i = 0; i < (int)(v.size()); i++) s += v[i];
  double avg = s / (double)(v.size());
  return avg;
}
double getVariance(const vector<int>& v) {
  double mean = getAverage(v);
  double temp = 0;
  for (double a : v) temp += (a - mean) * (a - mean);
  return temp / v.size();
}
const int INF = 0x7FFFFFFF;
void solve(int test) {
  vector<int> v(250);
  for (int i = 0; i < (int)(250); i++) scanf("%d ", &v[i]);
  int mn = INF, mx = 0;
  for (int i = 0; i < (int)(250); i++) {
    mn = min(mn, v[i]);
    mx = max(mx, v[i]);
  }
  double k = getVariance(v) / getAverage(v);
  string distribution = (k > 2.0 ? "uniform" : "poisson");
  double avg = distribution == "poisson" ? getAverage(v) : (mx + mn) / 2.0;
  int estimate = (avg + 0.5);
  cout << estimate << endl;
}
int main() {
  int n;
  scanf("%d ", &n);
  for (int i = 0; i < (int)(n); i++) solve(i);
  return 0;
}