High Card Low Card

Time limit2sMemory limit512 MB

Summary
Order Bessie's cards against Elsie's known sequence to win the most rounds under high-card-first-half and low-card-second-half scoring.
Level

Medium6 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

Bessie the cow loves card games, which is a surprising hobby for an animal with no opposable thumbs. The trouble is that none of the other cows in the herd make decent opponents. They play so badly that their order of play is completely predictable. Even then, finding a winning line is not easy for Bessie.

Bessie and her friend Elsie play a simple card game. They take a deck of 2N2N cards numbered 11 through 2N2N and split it so that Bessie holds NN cards and Elsie holds NN cards. They play NN rounds, and in each round each player puts down one card. In the first N/2N/2 rounds the player with the higher card scores one point. In the last N/2N/2 rounds the rule flips and the player with the lower card scores one point. All card numbers are distinct, so no round is a tie.

Bessie knows in advance the order in which Elsie will play her cards. Bessie may play her own cards in any order she likes. Write a program that computes the maximum number of points Bessie can score.

Input

The first line contains NN (2≤N≤500002 \le N \le 50000, and NN is even).

Each of the next NN lines contains one card that Elsie plays, given in round order. The cards missing from this list are exactly Bessie's hand.

Output

Print the maximum number of points Bessie can score on a single line.

Hint

In the example with N=4N = 4 where Elsie plays 11, 88, 44, 33, Bessie holds 22, 55, 66, and 77. She beats the 11 with her 55 in the first round, then saves the 22 for one of the last two rounds, where it beats the 44 or the 33. Two points is the most she can get.

Examples2

  1. Example 1

    Input
    4
    1
    8
    4
    3
    
    Expected output
    2
    
  2. Example 2

    Input
    2
    4
    1
    
    Expected output
    0