iPhone 9S

Interview

Time limit1sMemory limit128 MB

Summary
Remove everyone in the line who wants one chosen capacity, then report the longest run of equal capacities that remains. Choose the capacity to maximize that run.
Level

Medium4 of 10

Topics
Array, Implementation, Brute force, Simulation
Solved
No attempts yet

Problem

Today Apple releases the iPhone 9S. NN (1≤N≤10001 \le N \le 1000) people stand in a single line in front of the Apple Store, each wanting to be the first to buy the new iPhone.

The iPhone 9S lets each buyer choose the storage capacity freely. Older iPhones came in fixed sizes such as 16/32/64GB, but for the 9S a buyer tells the clerk the desired capacity BiB_i, and an iPhone with exactly that capacity is built on the spot.

The clerk thinks the line looks nicer when people who want the same capacity stand next to each other. So the clerk picks one capacity and removes every person who wants that capacity from the line. When people leave, the remaining people keep their relative order and close the gaps.

Choose exactly one capacity, remove everyone who wants it, and look at the resulting line. Among all groups of consecutive people who want the same capacity, consider the length of the longest such group. Choose the capacity to remove so that this longest length is as large as possible, and print that maximum length.

Input

The first line contains NN. Each of the next NN lines contains one integer BiB_i, the capacity wanted by each person in line order. 0≤Bi≤1,000,0000 \le B_i \le 1{,}000{,}000. There are always at least two distinct values among the BiB_i.

Output

Print the maximum possible length of a run of consecutive people who want the same capacity, after the clerk removes everyone who wants some single chosen capacity.

Hint

Suppose 9 people are in line and the capacities they want are, in order, 2, 7, 3, 7, 7, 3, 7, 5, 7. If everyone who wants capacity 3 is removed, the line becomes 2, 7, 7, 7, 7, 5, 7, and the longest run of the same capacity is the four consecutive people who want 7. So the answer is 4.

Examples3

  1. Example 1

    Input
    9
    2
    7
    3
    7
    7
    3
    7
    5
    7
    
    Expected output
    4
    
  2. Example 2

    Input
    3
    5
    1
    5
    
    Expected output
    2
    
  3. Example 3

    Input
    6
    1
    2
    1
    2
    1
    2
    
    Expected output
    3