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

#BS0000121. Đếm cặp có tổng trong khoảng (Count the Number of Fair Pairs)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm cặp có tổng trong khoảng (Count the Number of Fair Pairs)

Count the Number of Fair Pairs

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array a1,…,ana_1,\ldots,a_n and bounds L≤UL\le U, a pair of distinct positions (i,j)(i,j) is fair if 1≤i<j≤n1\le i<j\le n and L≤ai+aj≤UL\le a_i+a_j\le U. Equal values at different positions still correspond to different pairs. Count all fair pairs.

Input

The first line contains n,L,Un,L,U. The second line contains nn integers a1,…,ana_1,\ldots,a_n.

Output

Print the number of fair position pairs.

Subtasks

  • Subtask 1 (20 points): 1≤n≤351\le n\le 35; −109≤ai≤109; −109≤L≤U≤109-10^9\le a_i\le 10^9;\ -10^9\le L\le U\le 10^9, 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤25001\le n\le 2500; −109≤ai≤109; −109≤L≤U≤109-10^9\le a_i\le 10^9;\ -10^9\le L\le U\le 10^9, 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; −109≤ai≤109; −109≤L≤U≤109-10^9\le a_i\le 10^9;\ -10^9\le L\le U\le 10^9, 1≤i≤n1\le i\le n.

Examples

Input

6 3 6
0 1 7 4 4 5

Output

6

Explanation

The six fair one-based pairs are (1,4)(1,4), (1,5)(1,5), (1,6)(1,6), (2,4)(2,4), (2,5)(2,5), and (2,6)(2,6). Their sums are 4,4,5,5,5,64,4,5,5,5,6, all in [3,6][3,6]. The two occurrences of 44 are at distinct positions, so count separately. Print 6.