The Lucky StreakMedium

The Lucky Streak

Medium+30 XP · +10 Aurasliding windowhash maparrays

Anjali, a student at UptoSkills Arena, loves finding "lucky streaks" in sequences of numbers. A lucky streak is defined as a contiguous subarray where all elements are distinct. She wants to find the longest possible lucky streak in a given sequence of integers. Help Anjali find the length of the longest lucky streak. If there are multiple streaks of the same maximum length, choose the one that starts at the earliest index.

Input

The first line contains an integer N, the size of the sequence. The second line contains N space-separated integers representing the sequence.

Output

A single integer representing the length of the longest lucky streak. If multiple streaks have the same maximum length, output the length of the one starting at the earliest index.

Constraints

1 <= N <= 200000 -10^9 <= a_i <= 10^9

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5
1 2 3 2 1
Output
3

The longest streak with distinct elements is [1, 2, 3] of length 3.

Example 2

Input
7
1 1 1 1 1 1 1
Output
1

The longest streak with distinct elements is [1] of length 1.

Hints