Under construction

Still being built. Things may change

Lampice

Interview

Time limit1sMemory limit512 MB

Summary
Given a sequence of n colors, cut any prefix and suffix so that the remaining block is some pattern repeated exactly k times, and print that pattern.
Level

Medium4 of 10

Topics
Brute force, Implementation, String matching, Array
Solved
No attempts yet

Problem

Vera loves Advent and Christmas time. Above all she likes colorful Christmas lights and enjoys decorating her balcony with shining colors. To decorate her balcony she bought a sequence of nn lights connected in a row, each shining in one of a thousand different colors.

Vera also likes repeating patterns, so she wants her balcony decorated so that a certain pattern of colors repeats kk times in a row. The lamps she bought might not satisfy her love 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 kk times in a row.

Determine whether she can obtain such a sequence of lights by making these cuts, and if so, print the pattern that will be repeated.

Input

The first line contains positive integers nn and kk (1≤k≤n≤501 ≤ k ≤ n ≤ 50) described above.

The second line contains a sequence of positive integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10001 ≤ a_i ≤ 1000) which denotes the colors of the lamps that Vera bought, in the order they appear in her sequence.

Output

If Vera cannot 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.

Hint

Clarification of the third example: If Vera cuts off six lights from the end and zero from the beginning, she obtains the sequence of lights 1 5 1 5, in which the pattern 1 5 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 2 5 6 2 5 6, in which the pattern 2 5 6 repeats twice, so this is also a valid solution.

Examples3

  1. Example 1

    Input
    8 6
    10 1 1 1 1 1 1 5
    
    Expected output
    1
    1
    
  2. Example 2

    Input
    3 2
    1 2 1
    
    Expected output
    -1
    
  3. Example 3

    Input
    10 2
    1 5 1 5 2 5 6 2 5 6
    
    Expected output
    2
    1 5