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

#CC0000045. Đếm đoạn con có tổng trong khoảng (Count of Range Sum)

HỌC THEO LỘ TRÌNH

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

4 lộ trình
Xem thêm 1 lộ trình

Đếm đoạn con có tổng trong khoảng (Count of Range Sum)

Count of Range Sum

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array and bounds L,RL,R, count contiguous subarrays whose sums lie in the inclusive interval [L,R][L,R]. The answer is guaranteed to fit in a signed 32-bit integer.

Input

The first line contains n,L,Rn,L,R. The second line contains nn integers aia_i.

Output

Print the number of subarrays whose sum lies in [L,R][L,R].

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; −231≤ai≤231−1-2^{31}\le a_i\le 2^{31}-1; −105≤L≤R≤105-10^5\le L\le R\le10^5; đáp án vừa số nguyên 32-bit có dấu.
  • Subtask 2 (30 points): 1≤n≤4201\le n\le 420; −231≤ai≤231−1-2^{31}\le a_i\le 2^{31}-1; −105≤L≤R≤105-10^5\le L\le R\le10^5; đáp án vừa số nguyên 32-bit có dấu.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; −231≤ai≤231−1-2^{31}\le a_i\le 2^{31}-1; −105≤L≤R≤105-10^5\le L\le R\le10^5; đáp án vừa số nguyên 32-bit có dấu.

Examples

Input

3 -2 2
-2 5 -1

Output

3

Explanation

The three valid subarrays have sums -2, -1 and 2: [−2][-2], [−1][-1], and [−2,5,−1][-2,5,-1]. Both endpoints are inclusive.