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

#TP0000051. Những chiếc bánh mochi hai tầng (Various Kagamimochi)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những chiếc bánh mochi hai tầng (Various Kagamimochi)

Various Kagamimochi

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn mochi, numbered from 11 to nn. The size of mochi ii is aia_i. Their sizes are given in nondecreasing order.

To make a two-layer kagamimochi, choose two different mochi. Place the smaller mochi above the larger one. The arrangement is valid if the upper mochi has size at most half the size of the lower one, meaning 2ai≤aj2a_i\le a_j.

Two arrangements are different if at least one chosen mochi is different, even when their sizes are equal. Count all valid arrangements.

Input

  • The first line contains an integer nn: the number of mochi.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in nondecreasing order.

Output

Print one integer: the number of choices of two distinct mochi forming a valid two-layer kagamimochi.

Subtasks

  • Subtask 1 (20 points): 2≤n≤252\le n\le 25; 1≤ai≤1091\le a_i\le10^9 for every ii; a1≤a2≤⋯≤ana_1\le a_2\le\cdots\le a_n.
  • Subtask 2 (30 points): 2≤n≤40002\le n\le 4000; 1≤ai≤1091\le a_i\le10^9 for every ii; a1≤a2≤⋯≤ana_1\le a_2\le\cdots\le a_n.
  • Subtask 3 (50 points): 2≤n≤5000002\le n\le 500000; 1≤ai≤1091\le a_i\le10^9 for every ii; a1≤a2≤⋯≤ana_1\le a_2\le\cdots\le a_n.

Examples

Input

6
2 3 4 4 7 10

Output

8

Explanation

The mochi sizes are 2,3,4,4,7,102,3,4,4,7,10. The mochi of size 22 can go above four mochi (4,4,7,104,4,7,10), size 33 above two (7,107,10), and each size-44 mochi above the size-1010 mochi. The total is 4+2+1+1=84+2+1+1=8. The two size-44 mochi are distinct objects.