The Magical Color PaletteMedium

The Magical Color Palette

Medium+30 XP · +10 Aurabinary searchgreedy

An artist is painting houses along a street. There are n houses in a row, and each house i has a pre-assigned color c_i. The artist wants to repaint some houses. The rule is that for any two adjacent houses, they must have different colors after repainting. The artist also has a magical palette with k distinct colors. What is the minimum possible value of k such that all n houses can be painted satisfying the adjacent house rule, using only colors from the magical palette, and without changing the color of any house that is already satisfactory (i.e., c_i and c_{i+1} are different)?

Input

The first line contains an integer n (2 <= n <= 200000). The second line contains n space-separated integers c_1, c_2, ..., c_n (1 <= c_i <= n).

Output

Print a single integer: the minimum k.

Constraints

2 <= n <= 200000 1 <= c_i <= n

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

Example 1

Input
5
1 1 2 2 1
Output
2

Houses 1 and 2 must differ. Houses 3 and 4 must differ. The longest sequence of identical adjacent colors is length 2 (1,1 or 2,2). Thus, we need 2+1=3 colors. E.g., Colors: 1 2 1 3 1.

Example 2

Input
6
1 2 3 1 2 3
Output
1

All adjacent houses have different colors. The longest sequence of identical adjacent colors has length 0. Thus, we need 0+1=1 color. E.g., Color: 1 1 1 1 1 1.

Hints