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

#TP0000052. Truyền thuyết về hai vương quốc (A Tale of Two Lands)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Truyền thuyết về hai vương quốc (A Tale of Two Lands)

A Tale of Two Lands

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A legend describes two closed intervals determined by integers xx and yy. Interval A has endpoints ∣x∣|x| and ∣y∣|y|, while interval V has endpoints ∣x−y∣|x-y| and ∣x+y∣|x+y|. Within each interval, the endpoints are understood in increasing order.

A pair is valid when the whole interval A is contained in interval V, including their endpoints.

You are given nn pairwise distinct integers. Choose two different numbers as x,yx,y. Count the valid unordered pairs; swapping xx and yy does not produce a new pair.

Input

  • The first line contains an integer nn: the number of candidate integers.
  • The second line contains exactly nn pairwise distinct integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the number of unordered pairs satisfying the interval-containment condition.

Subtasks

  • Subtask 1 (20 points): 2≤n≤252\le n\le 25; −109≤ai≤109-10^9\le a_i\le10^9 for every ii; all aia_i are pairwise distinct.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; −109≤ai≤109-10^9\le a_i\le10^9 for every ii; all aia_i are pairwise distinct.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9 for every ii; all aia_i are pairwise distinct.

Examples

Input

3
2 5 -3

Output

2

Explanation

The unordered pairs are {2,5}\{2,5\}, {2,−3}\{2,-3\}, and {5,−3}\{5,-3\}. For {2,5}\{2,5\}, the intervals are [2,5][2,5] and [3,7][3,7], so containment fails. For {2,−3}\{2,-3\} they are [2,3][2,3] and [1,5][1,5], and for {5,−3}\{5,-3\} they are [3,5][3,5] and [2,8][2,8]; both latter pairs work. The answer is 22.