LogiQuest

446. Degree of an Array

EasyHash Map

The degree is the highest frequency of any value. Print the length of the shortest contiguous subarray with the same degree as the whole array.

Input format

Line 1: n Line 2: n integers

Output format

The length.

Example 1

Input

5
1 2 2 3 1

Output

2

Example 2

Input

7
1 2 2 3 1 4 2

Output

6

Constraints

1 ≤ n ≤ 5 × 10⁴

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…