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 = 1e6 + 5;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    vector<int> V(250);
    int sum = 0;
    for (int j = 0; j < 250; j++) {
      cin >> V[j];
      sum += V[j];
    }
    double P = double(sum) / 250;
    sum = 0;
    double cnt = 0;
    int mx = 0;
    for (int j = 0; j < 250; j++) {
      if (0.499 * P <= V[j] and V[j] <= 1.501 * P) {
        cnt++;
        sum += V[j];
      }
      mx = max(mx, V[j]);
    }
    cnt /= 250;
    P = double(sum) / 250;
    int Pi = round(P);
    if (cnt > 0.75)
      ;
    else {
      Pi = max(Pi, (mx + 1) / 2);
    }
    cout << Pi << "\n";
  }
  return 0;
}