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 in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline void priv(vector<int> a) {
  for (int i = 0; i < ((int)(a).size()); ++i)
    printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < ((int)(v).size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
const int MX = 100005, INF = 1e9;
const long long int LINF = 1e18;
const double eps = 1e-10;
random_device _rd;
mt19937 _mt(_rd());
inline int rnd(unsigned n) {
  unsigned res = _mt();
  if (res >= n) return rnd(n);
  return res;
}
inline int rnd(int l, int r) { return _mt() % (r - l + 1) + l; }
double rnd() { return rnd(1e9) / 1e9; }
int gen_p(int p) {
  double s = 0;
  int res = 0;
  while (s < 1) {
    s += -log(1 - rnd()) / p;
    ++res;
  }
  return res;
}
void poisson(vector<int>& a, int p) {
  for (int i = 0; i < ((int)(a).size()); ++i) {
    a[i] = gen_p(p);
  }
}
void uniform(vector<int>& a, int p) {
  for (int i = 0; i < ((int)(a).size()); ++i) {
    a[i] = rnd(0, p * 2);
  }
}
int main() {
  int ts;
  scanf("%d", &ts);
  for (int ti = 0; ti < (ts); ++ti) {
    int n = 250;
    vector<int> a(n);
    cin >> a;
    double av = 0;
    for (int i = 0; i < (n); ++i) av += a[i];
    av /= n;
    double s = 0;
    for (int i = 0; i < (n); ++i) {
      s += (a[i] - av) * (a[i] - av);
    }
    s /= n;
    int ans;
    if (s / av < 2) {
      ans = av + 0.4;
    } else {
      int r = 0;
      for (int i = 0; i < (n); ++i) r = max(r, a[i]);
      ans = r / 2 / 0.97 + 0.5;
      if (ans < 30) ans = r / 2;
    }
    cout << ans << endl;
  }
  return 0;
}