PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000076. Bài lớn bài nhỏ (Gold) (High Card Low Card (Gold))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bài lớn bài nhỏ (Gold) (High Card Low Card (Gold))

High Card Low Card (Gold)

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

A deck has 2N2N distinct cards. Elsie’s NN cards and play order are fixed. Bessie holds the complement and chooses her order. A higher card wins in the first N/2N/2 rounds; a lower card wins in the last N/2N/2. Maximize Bessie’s wins (USACO Gold, fixed switch).

Input

Line 1: even NN. Next NN lines: Elsie’s cards in play order.

Output

Print the maximum number of rounds Bessie can win.

Subtasks

  • Subtask 1 (20 points): Exactly one dataset; 2≤N≤122\le N\le12; NN even; 1≤ei≤2N1\le e_i\le2N; Elsie’s cards are pairwise distinct.
  • Subtask 2 (30 points): Exactly one dataset; 2≤N≤20002\le N\le2000; NN even; 1≤ei≤2N1\le e_i\le2N; Elsie’s cards are pairwise distinct.
  • Subtask 3 (50 points): Exactly one dataset; 2≤N≤500002\le N\le50000; NN even; 1≤ei≤2N1\le e_i\le2N; Elsie’s cards are pairwise distinct.

Example

Input

4
1
8
4
3

Output

2

Explanation

Bessie has the complementary cards 2,5,6,7 and can score at most two wins.