#TP0000050. Đếm cặp phần tử cần xóa (Counting Pairs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đế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 positive integers and two integers with . Array positions are numbered from to .
Choose two distinct positions and remove both elements simultaneously. The remaining sum is the sum of the other elements, regardless of how positions would be renumbered afterwards.
An index pair is valid if the remaining sum is at least and at most , both bounds inclusive.
Count all valid pairs . Different pairs of positions are counted separately.
Input
- The first line contains three integers : the array length and the lower and upper bounds on the remaining sum.
- The second line contains exactly positive integers in original positional order.
Output
Print one integer: the number of pairs for which the remaining sum lies in the inclusive interval .
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
4 8 10
4 6 3 6
Output
4
Explanation
The array has total sum ; the remaining sum must belong to . Removing positions or leaves . Removing or leaves . The other two choices leave sums and , outside the interval. Therefore, exactly pairs are valid.