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;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int minn = 1000, maxx = 0;
bool check_if_uniform(vector<int> a) {
  int n = a.size(), i, j, k, total, avg, ct;
  total = 0;
  ct = 0;
  for (auto p : a) total += p;
  avg = total / n;
  for (auto p : a)
    if (p < avg * 0.2) ct++;
  minn = min(minn, ct);
  maxx = max(maxx, ct);
  if (ct <= n / 40)
    return false;
  else
    return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n = 0, m = 0, k = 0, ct = 0, i = 0, j = 0, p = 0, q = 0,
                  y = 0, z = 0, ans = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0,
                  hi = 0;
    string s;
    bool flag = false;
    n = 250;
    long double maxx, total, x, avg;
    vector<int> a(n);
    total = 0;
    maxx = 0;
    for (i = 0; i < n; i++) {
      cin >> x;
      total += x;
      maxx = max(maxx, x);
      a[i] = x;
    }
    bool check_uniform = check_if_uniform(a);
    if (check_uniform)
      ans = maxx / 2;
    else
      ans = total / n;
    cout << ans << endl;
  }
  return 0;
}