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

#TP0000047. Đếm cặp có tổng thuộc đoạn (Number of Pairs)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm cặp có tổng thuộc đoạn (Number of Pairs)

Number of Pairs

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n and two integers l,rl,r with l≤rl\le r. Array positions are numbered from 11 through nn.

A pair (i,j)(i,j) is valid when 1≤i<j≤n1\le i<j\le n and the sum of the corresponding values lies in the inclusive interval [l,r][l,r]:

l≤ai+aj≤r.l\le a_i+a_j\le r.

Count all valid pairs of positions. Two pairs are distinct if at least one index differs. Equal values at different positions are counted separately.

Input

  • The first line contains three integers n,l,rn,l,r: the length of the array and the lower and upper sum bounds.
  • The second line contains exactly nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n in order.

Output

Print one integer: the number of index pairs (i,j)(i,j) satisfying i<ji<j and l≤ai+aj≤rl\le a_i+a_j\le r.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 1≤l≤r≤1091\le l\le r\le10^9; 1≤ai≤1091\le a_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤25001\le n\le 2500; 1≤l≤r≤1091\le l\le r\le10^9; 1≤ai≤1091\le a_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤l≤r≤1091\le l\le r\le10^9; 1≤ai≤1091\le a_i\le10^9 for every 1≤i≤n1\le i\le n.

Examples

Input

3 4 7
5 1 2

Output

2

Explanation

The array is a=[5,1,2]a=[5,1,2], and the inclusive sum interval is [4,7][4,7]. The three index pairs are: (1,2)(1,2) with sum 5+1=65+1=6 (valid); (1,3)(1,3) with sum 5+2=75+2=7 (valid because the upper bound is inclusive); and (2,3)(2,3) with sum 1+2=31+2=3 (invalid). Exactly 22 pairs qualify, so the output is 2.