#C2052. Longest Non-Repeating Color Pattern

    ID: 45326 Type: Default 1000ms 256MiB

Longest Non-Repeating Color Pattern

Longest Non-Repeating Color Pattern

In this problem, you are given two integers, (N) and (M), where (N) represents the number of available colors and (M) represents the number of boards. Additionally, you are given a list of (N) integers representing the colors. You must determine the longest possible color pattern that can be formed such that no color repeats within the pattern. The length of the longest pattern is given by (K = \min(N, M)), and the pattern should consist of the first (K) elements from the list.

For example, if (N = 6), (M = 4) and the colors provided are [1, 2, 3, 4, 5, 6], then (K = 4) and the corresponding pattern is [1, 2, 3, 4].

inputFormat

The input consists of two lines:
- The first line contains two space-separated integers (N) and (M).
- The second line contains (N) space-separated integers, representing the list of colors. Note that if (N = 0), the second line will be empty.

outputFormat

The output should consist of two lines:
- The first line contains the integer (K), which is the length of the longest non-repeating color pattern.
- The second line contains (K) space-separated integers representing the pattern (i.e., the first (K) colors from the input list).## sample

6 4
1 2 3 4 5 6
4

1 2 3 4

</p>