#include <bits/stdc++.h>
using namespace std;
int a[255];
double f[2010];
double solve1(int p) {
  double sum = 0;
  for (int i = 1; i <= 250; i++) {
    if (a[i] >= 0 && a[i] <= p * 2)
      sum += log(1.0 / (p * 2 + 1));
    else
      return -1e20;
  }
  return sum;
}
double solve2(int p) {
  double sum = 0;
  for (int i = 1; i <= 250; i++) {
    sum += a[i] * log(p) - p - f[a[i]];
  }
  return sum;
}
int main() {
  for (int i = 1; i <= 2000; i++) f[i] = f[i - 1] + log(i);
  int t;
  scanf("%d", &t);
  while (t--) {
    for (int i = 1; i <= 250; i++) scanf("%d", &a[i]);
    double m1 = -1e20, ans;
    int pp;
    for (int p = 10; p <= 1000; p++) {
      ans = max(solve2(p), solve1(p));
      if (ans > m1) {
        m1 = ans;
        pp = p;
      }
    }
    cout << pp << endl;
  }
  return 0;
}

### Prompt

In CPP, your task is to solve the following 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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[255];
double f[2010];
double solve1(int p) {
  double sum = 0;
  for (int i = 1; i <= 250; i++) {
    if (a[i] >= 0 && a[i] <= p * 2)
      sum += log(1.0 / (p * 2 + 1));
    else
      return -1e20;
  }
  return sum;
}
double solve2(int p) {
  double sum = 0;
  for (int i = 1; i <= 250; i++) {
    sum += a[i] * log(p) - p - f[a[i]];
  }
  return sum;
}
int main() {
  for (int i = 1; i <= 2000; i++) f[i] = f[i - 1] + log(i);
  int t;
  scanf("%d", &t);
  while (t--) {
    for (int i = 1; i <= 250; i++) scanf("%d", &a[i]);
    double m1 = -1e20, ans;
    int pp;
    for (int p = 10; p <= 1000; p++) {
      ans = max(solve2(p), solve1(p));
      if (ans > m1) {
        m1 = ans;
        pp = p;
      }
    }
    cout << pp << endl;
  }
  return 0;
}

```