cswork / OAOpen practice workspace

MetaOA #5

Longest Subarray With Value Frequency > Threshold

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersHashing

Find the longest contiguous subarray in which at least one value occurs strictly more than the threshold k times. If none exists, output 0. The check here follows the statement's "strictly greater"; both of the original site's examples should give the full array length 7, and this site has corrected them.

Input

The first line contains n k (1≤k≤n≤100000), and the second line contains n values (0..10⁹).

Output

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

Example 1

Input:

7 3
1 1 1 2 3 1 1

Output:

7

Example 2

Input:

7 1
1 2 3 2 3 4 1

Output:

7

Example 3

Input:

2 2
1 1

Output:

0

Example notes

Example 1: in the full array, 1 occurs 5 times, strictly more than the threshold 3, so the full length 7 is valid and optimal.

Editorial

Loading solution…