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 char get(void) {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline void read(int &x) {
  x = 0;
  static char c;
  for (; !(c >= '0' && c <= '9'); c = get())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = get())
    ;
}
int T, a[260];
double avg, cnt;
inline void solve(void) {
  avg = cnt = 0;
  for (int i = 1; i <= 250; i++) read(a[i]), avg += a[i];
  avg /= 250.0;
  for (int i = 1; i <= 250; i++) {
    double x = a[i] / avg;
    if (x >= 0.5 && x <= 1.5) cnt++;
  }
  cnt /= 250.0;
  if (cnt > 0.7) {
    printf("%d\n", (int)(avg + 0.5));
  } else {
    int t = *max_element(a, a + 250);
    printf("%d\n", t / 2);
  }
}
int main(void) {
  for (read(T); T--;) solve();
  return 0;
}