#P3129. Bessie’s Card Game Strategy
Bessie’s Card Game Strategy
Bessie’s Card Game Strategy
Bessie the cow loves card games. In this game, 2N cards labeled \(1\ldots 2N\) are split between Bessie and her friend Elsie, each receiving N cards. The game consists of N rounds. In each round, both players play one card.
Initially, the rules are "high card wins": the player who plays the higher card earns a point. However, at one point during the game, Bessie can choose to switch the rules so that for all remaining rounds the rule becomes "low card wins" (i.e. the lower card wins the point). Bessie may decide not to change the rule at all, or even switch immediately so that every round uses the low‐card rule.
Knowing in advance the exact order in which Elsie will play her cards, determine the maximum number of points Bessie can win if she plays optimally.
Note: When matching cards, Bessie is free to choose the order in which she plays her cards from her hand, but each card can be used only once.
inputFormat
The first line contains a single integer \(N\) (the number of rounds/cards per player). The next \(N\) lines each contain a single integer, representing the order in which Elsie will play her cards.
It is guaranteed that the deck consists of the numbers \(1, 2, \ldots, 2N\), and that Elsie’s cards are distinct.
outputFormat
Output a single integer, the maximum number of points Bessie can win.
sample
4
1
8
4
3
3