N-Rock-Paper-Scissors
Time limit1sMemory limit1024 MB
Given the opponent's card sequence, play each card 1 to N exactly once to maximize rounds where your card is not cyclically adjacent to theirs.
Problem
Dohun, a game enthusiast, wanted to make rock-paper-scissors more fun, so he invented a new game called N-Rock-Paper-Scissors. The rules are as follows.
- players each start with cards numbered from to , one card each.
- Each player plays one round against each of the other players, for rounds in total. In each round, the two players each play one of their cards.
- If two players play cards and , the player who played card wins, and the player who played card loses.
- If two players play card and card , the player who played card wins, and the player who played card loses.
- All other matchups are draws.
- Once a round is decided as a win, loss, or draw, the played card is discarded, and the next round is played with the remaining cards.
Dohun designed these rules. He wants to know the maximum number of draws possible in the next rounds, given the list of cards the opponent will play in those rounds.
Input
The first line contains the number of rounds .
The second line contains the cards that the opponent will play in order, separated by spaces.
Output
Print the maximum number of draws you can get by playing cards appropriately in the rounds.