Problem: Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request.

Also, there are now villages with as few as a single inhabitant, meaning that <image>.

Can you help Heidi find out whether a village follows a Poisson or a uniform distribution?

Input

Same as for the easy and medium versions. But remember that now 1 ≤ P ≤ 1000 and that the marmots may provide positive as well as negative integers.

Output

Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answers came from a uniform distribution.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
int a[250];
bool is_poisson() {
  int sum = 0;
  for (int j = 0; j < (250); ++j) sum += a[j];
  double P = sum / 250.;
  double dd = 0;
  for (int j = 0; j < (250); ++j) {
    dd += (P - a[j]) * (P - a[j]);
  }
  dd /= 250.;
  if (dd < P * 2) return true;
  return false;
}
vector<double> ana, anb, xna[50], xnb[50];
int main() {
  int(V);
  scanf("%d", &V);
  for (int i = 0; i < (V); ++i) {
    int sum = 0;
    for (int j = 0; j < (250); ++j) {
      scanf("%d", &(a[j]));
      sum += a[j];
    }
    double P = sum / 250.;
    int x = *min_element(a, a + 250);
    int y = *max_element(a, a + 250);
    map<int, int> d;
    for (int j = 0; j < (250); ++j) d[a[j]]++;
    vector<int> v;
    for (auto &&w : d) {
      v.push_back(w.second);
    }
    sort(v.begin(), v.end());
    if (y - x <= 20) {
      int freq[30] = {};
      for (int j = 0; j < (250); ++j) {
        int d = (a[j] - x);
        freq[d]++;
      }
      if (-x >= 5) {
        double smax = freq[-x];
        double smin = (freq[0] + freq[y - x]) / 2;
        double s = smax / smin;
        if (i < 1000)
          xna[y - x].push_back(s);
        else
          xnb[y - x].push_back(s);
        if (s >= 3) {
          puts("poisson");
        } else {
          puts("uniform");
        }
        continue;
      }
      int fmax = *max_element(freq, freq + y - x + 1);
      int fmin = *min_element(freq, freq + y - x + 1);
      double thr[30] = {
          2, 2, 2, 2,   5, 2, 5,  2,  5,  2,  5,
          5, 7, 5, 7.5, 5, 8, 12, 20, 12, 20, 20,
      };
      if (fmax > thr[y - x] * fmin) {
        puts("poisson");
      } else {
        puts("uniform");
      }
    } else {
      int freq[7] = {};
      for (int j = 0; j < (250); ++j) {
        int d = (a[j] - x) * 7 / (-2 * x);
        if (d < 7) freq[d]++;
      }
      double fmax = (freq[3]);
      double fmin = (freq[0] + freq[6]) / 2.0;
      if (i < 1000) {
        ana.push_back(fmax / (double)fmin);
      } else
        anb.push_back(fmax / (double)fmin);
      if (fmax > 2.05 * fmin) {
        puts("poisson");
      } else {
        puts("uniform");
      }
    }
  }
  return 0;
}