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

#BS0000329. Xếp bánh mochi thành cặp (Simultaneous Kagamimochi)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Xếp bánh mochi thành cặp (Simultaneous Kagamimochi)

Simultaneous Kagamimochi

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn mochi rice cakes in nondecreasing order of size; cake ii has size aia_i.

A kagamimochi is a stack of two cakes, with a cake of size xx placed on one of size yy exactly when 2x≤y2x\le y. Each cake may be used in at most one stack, whether as its top or bottom.

Determine the maximum number of stacks that can be formed simultaneously.

Input

The first line contains integer nn, the number of cakes.

The second line contains nn integers a1,…,ana_1,\ldots,a_n in nondecreasing order, their sizes.

Output

Print one nonnegative integer: the maximum number of stacks.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le12; 1≤ai≤1091\le a_i\le10^9; ai≤ai+1 (1≤i<n)a_i\le a_{i+1}\ (1\le i<n).
  • Subtask 2 (30 points): 2≤n≤5⋅1052\le n\le5\cdot10^5; 1≤ai≤1091\le a_i\le10^9; ai≤ai+1 (1≤i<n)a_i\le a_{i+1}\ (1\le i<n); at most two distinct sizes.
  • Subtask 3 (50 points): 2≤n≤5⋅1052\le n\le5\cdot10^5; 1≤ai≤1091\le a_i\le10^9; ai≤ai+1 (1≤i<n)a_i\le a_{i+1}\ (1\le i<n).

Examples

Input 1

6
2 3 4 4 7 10

Output 1

3

Explanation

Create stacks with top and bottom sizes (2,4), (3,7), (4,10), using six distinct cakes. Four stacks would require eight cakes, so three is optimal.

Example 1

Input 2

3
5 6 7

Output 2

0

Explanation

Twice the smallest size 5 is 10, greater than the largest size 7. No valid stack exists.

Input 3

3
387 388 389

Output 3

0

Explanation

Twice the smallest size is 774, exceeding the largest size 389. No pair is valid.

Input 4

24
307 321 330 339 349 392 422 430 477 481 488 537 541 571 575 602 614 660 669 678 712 723 785 792

Output 4

6

Explanation

Use pairs (307,614), (321,660), (330,669), (339,678), (349,712), (392,785). The largest bottom size is 792, so every top must have size at most 396. Only six cakes meet that bound, proving optimality.