Poly-polygonal Numbers

No attempts yetTime limit1sMemory limit128 MB

Problem

A polygonal number is a number that can be represented by a regular arrangement of equally spaced points forming a regular polygon. Some examples are shown below.

The first figure shows the first four triangular numbers 1, 3, 6, 10. The next three show the first four square, pentagonal, and hexagonal numbers, respectively. In general, the $k$-gonal numbers are those whose points form a regular $k$-gon (so triangular numbers are 3-gonal, square numbers are 4-gonal, and so on). We call $k$ the index of the polygonal number. The $m$-th $k$-gonal number is given by

$$P(k, m) = \frac{(k-2)m^2 - (k-4)m}{2}$$

In this problem you must find numbers that are $k$-gonal for two or more values of $k$. We call such numbers poly-polygonal.

Input

The input consists of several problem instances. Each instance consists of three lines.

  • The first line contains a non-negative integer $n$ ($n \le 50$), the number of kinds of polygonal numbers of interest in this instance.
  • The second line contains $n$ integers, the indices of those polygonal numbers. They are all distinct and given in increasing order, and each index $k$ satisfies $3 \le k \le 1000$. (This line may be longer than 80 characters.)
  • The third line contains a single positive integer $s$ ($s \le 10000$), the starting point for the search for poly-polygonal numbers.

A value of $n = 0$ terminates the input.

Output

For each problem instance, output the next five poly-polygonal numbers that are greater than or equal to $s$. Print each number on its own line in the following format:

num:k1 k2 k3 ...

where num is the poly-polygonal number and k1, k2, k3, ... are the indices (among the given ones), in increasing order, for which num is that $k$-gonal number. Separate consecutive indices with a single space, and separate consecutive problem instances with a single blank line. The input guarantees that the maximum value of any poly-polygonal number fits in a 64-bit signed (long) integer.