Little Vera really likes Advent and Christmas time. Most of all, she likes colorful Christmas lights and enjoys decorating her balcony with shining colors. To decorate her balcony, she bought a sequence of lights connected in a row, each shining in one of a thousand different colors.
Apart from lights, Vera also really likes repeating patterns, so she would like to have her balcony decorated so that a certain pattern of colors repeats times in a row. However, the lamps she bought might not satisfy her obsession of repetition and patterns, so she decided to cut off zero or more lamps from the beginning and from the end of the sequence to obtain a sequence in which a pattern of colors repeats times in a row.
Help her determine whether she can obtain such a sequence of lights by making the mentioned cuts, and if so, print the pattern that will be repeated.
Input Specification
The first line contains positive integers and described above.
The second line contains a sequence of positive integers , which denotes the colors of the lamps that Vera bought in the order they appear in her sequence.
Output Specification
If Vera can't cut out a sequence of lights that she wants, print -1
.
If Vera can cut out a sequence of lights that she wants, in the first line, print the length of the repeating pattern, and in the second line, print the sequence of colors that makes up the pattern. If there is more than one solution, you can output any one of them.
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 10 | The sequence contains a pattern of a single light repeated times in a row. |
2 | 15 | |
3 | 25 | No additional constraints. |
Sample Input 1
8 6
10 1 1 1 1 1 1 5
Sample Output 1
1
1
Sample Input 2
3 2
1 2 1
Sample Output 2
-1
Sample Input 3
10 2
1 5 1 5 2 5 6 2 5 6
Sample Output 3
2
1 5
Explanation for Sample Output 3
If Vera cuts off six lights from the end and zero from the beginning, she obtains the sequence of lights , in which the pattern repeats twice in a row. If, on the other hand, she cuts off four lights from the beginning and zero from the end, she obtains the sequence of lights , in which the pattern repeats twice, so this is also a valid solution.
Comments