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;
inline int readInt() {
  int n = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
  return n;
}
const int MAX_N = 250 + 3, MAX_P = 2000 + 3;
int n, a[MAX_N], cnt[MAX_P];
inline double E(int a[]) { return accumulate(a, a + 250, 0.0) / 250; }
inline double D(int a[]) {
  double avg = E(a), s = 0;
  for (int i = 0; i < 250; ++i) s += (a[i] - avg) * (a[i] - avg);
  s /= 250;
  return s;
}
int main() {
  int caseNum = readInt();
  while (caseNum--) {
    n = 250;
    for (int i = 0; i < 250; ++i) a[i] = readInt();
    double e = E(a), d = D(a), val = (e - d) / e;
    if (fabs(val) < 0.5) {
      printf("%d\n", int(round(e)));
    } else {
      printf("%d\n", *max_element(a, a + n) / 2);
    }
  }
  return 0;
}