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;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int a[1105];
void fmain(int tid) {
  long double ss = 0;
  int mx = -(1 << 30);
  for (int(i) = 1; (i) <= (int)(250); (i)++) scanf("%d", a + i);
  for (int(i) = 1; (i) <= (int)(250); (i)++) {
    ss += a[i];
    mx = max(mx, a[i]);
  }
  ss /= 250;
  long double len = ss / 2;
  int ct = 0, b = 0;
  for (int(i) = 1; (i) <= (int)(250); (i)++) {
    if (a[i] > ss - len && a[i] < ss + len) ct++;
    if (a[i] <= 1) b++;
  }
  if (ct < 180 || 3 < b) {
    sort(a + 1, a + 251);
    printf("%d\n", (a[250] - a[1]) / 2);
  } else {
    printf("%d\n", (int)(ss + 0.5));
  }
}
int main() {
  int t = 1;
  scanf("%d", &t);
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}