10321: CF EDU - Suffix Array - Step 5 - E. Refrain
[Creator : ]
Description
Consider an array of $n$ integers from $1$ to $m$. A subsequence of consecutive elements of this array is called refrain if the product of its length and the number of occurrences in the array is maximum possible.
Given an array, your task is to find its refrain.
Input
First line contains two integers: $n, m\ (1≤n≤150,000,\ 1≤m≤10)$.
Second line contains $n$ integers from $1$ to $m$.
Output
In the first line of print the maximal product of refrain length and the number of its occurrences in array.
In the second line print its length.
In the third line print the refrain itself.
Sample 1 Input
8 3
1 2 1 2 1 1 2 1
Sample 1 Output
9
3
1 2 1
Sample 2 Input
1 1
1
Sample 2 Output
1
1
1
Sample 3 Input
6 2
1 2 1 2 1 2
Sample 3 Output
8
4
1 2 1 2