K-Dimensional Grids

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

Neo was bored of always living in three-dimensional space. In order to cope with his boredom, he learned how to lucid dream, where he was able to recreate his own world with -dimensions and conveniently place himself in any corner of his world. His world can be imagined as a -dimensional grid where each dimension is located on a unique plane with a grid size of length . The drawback of Neo's dream world is that when he wakes up, he forgets most of the properties he used in order to create the world.

He is only able to remember , the number of different shortest paths there are from his starting corner to the furthest point of his starting corner, within his -dimensional grid, and a list of numbers, , which are possible side lengths he chose for each dimensions' grid length. A single value of may only correspond to the length of 1 dimensions' grid size.

Can you help Neo determine , the dimension of the world he created and , the length of each grid size?

Note: Neo will not create a world less than 2 dimensions.

Input

First line: , the number of different shortest paths from the corner located at the origin to its opposite corner modulo .

Second line: , the number of possible side lengths to construct the -dimensional grid.

Third line: space-separated integers, , the list of possible side lengths.

Output

On the first line, print , the dimension of the world.

On the second line, print numbers in non-decreasing order, the lengths of each side.

If there is no solution print -1, otherwise it is guaranteed that there is only 1 solution.

Sample Input 1

6
3
2 3 2

Sample Output 1

2
2 2

Explanation for Sample Output 1

A 2-dimensional grid of length will create a grid that has different paths. The 6 different paths are (where R is right and D is down):

RRDD
RDRD
RDDR
DRRD
DRDR
DDRR