class Hypergeometric {

  public double phyper(int x, int N, int M, int n, boolean lowerTail) {
    int i;
    int up;
    double p;

    up = Math.min(n, M);
    p = 0;

    if (x < up / 2) {
      for (i = x; i >= 0; i--)
        p += dhyper(i, N, M, n);

      if (lowerTail) return p;
      else return 1 - p;
    } else {
      for (i = x + 1; i <= up; i++)
        p += dhyper(i, N, M, n);

      if (lowerTail) return 1 - p;
      else return p;
    }
  }

  public  Hypergeometric();

}