Boyan is playing a computer game. In the beginning there are balls arranged in a line. Each ball has a number written on it, so that every two consecutive balls have different numbers. The game consists of the following steps:
The player removes a ball from the line.
While there are consecutive balls with equal numbers, they are automatically removed from the line.
If there are balls left in the line, go to step , otherwise the game ends.
The score is the number of balls that are automatically removed. The goal of the game is to maximize the score.
Example:
Boyan removes the ball with number . The balls left are {, , , , }.
Removing the consecutive balls with equal numbers we have {, , , , } -> {, , } -> {}. The ball left is {}.
Since there are balls left, we go to step .
Next iteration:
Boyan removes the ball with number . The balls left are {}.
There are no consecutive balls with equal numbers.
There are no balls left, so the game ends.
The number of balls that are automatically removed is . It is the maximum possible score for this game. Boyan is playing a lot, but he is still not sure when he is playing optimally. Write a program to help him to find the best score he can achieve.
The first line contains the positive integer ( ≤ ≤ ). The second line contains positive integers - the numbers written on the balls (number on a ball ≤ 10^6).
Print the maximum possible score Boyan can achieve.
Example 1
Example 2