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

#TP0000050. Đếm cặp phần tử cần xóa (Counting Pairs)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm cặp phần tử cần xóa (Counting Pairs)

Counting 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 x,yx,y with x≤yx\le y. Array positions are numbered from 11 to nn.

Choose two distinct positions i<ji<j and remove both elements simultaneously. The remaining sum is the sum of the other n−2n-2 elements, regardless of how positions would be renumbered afterwards.

An index pair is valid if the remaining sum is at least xx and at most yy, both bounds inclusive.

Count all valid pairs (i,j)(i,j). Different pairs of positions are counted separately.

Input

  • The first line contains three integers n,x,yn,x,y: the array length and the lower and upper bounds on the remaining sum.
  • The second line contains exactly nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n in original positional order.

Output

Print one integer: the number of pairs 1≤i<j≤n1\le i<j\le n for which the remaining sum ∑k≠i,jak\sum_{k\ne i,j}a_k lies in the inclusive interval [x,y][x,y].

Subtasks

  • Subtask 1 (20 points): 3≤n≤253\le n\le 25; 1≤x≤y≤2⋅10141\le x\le y\le2\cdot10^{14}; 1≤ai≤1091\le a_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 3≤n≤25003\le n\le 2500; 1≤x≤y≤2⋅10141\le x\le y\le2\cdot10^{14}; 1≤ai≤1091\le a_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 3≤n≤2000003\le n\le 200000; 1≤x≤y≤2⋅10141\le x\le y\le2\cdot10^{14}; 1≤ai≤1091\le a_i\le10^9 for every 1≤i≤n1\le i\le n.

Examples

Input

4 8 10
4 6 3 6

Output

4

Explanation

The array [4,6,3,6][4,6,3,6] has total sum 1919; the remaining sum must belong to [8,10][8,10]. Removing positions (1,2)(1,2) or (1,4)(1,4) leaves 19−4−6=919-4-6=9. Removing (2,3)(2,3) or (3,4)(3,4) leaves 19−6−3=1019-6-3=10. The other two choices leave sums 1313 and 77, outside the interval. Therefore, exactly 44 pairs are valid.