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

#PS0000201. Số đoạn có tổng thuộc khoảng [A,B] (Count Subarray Sums in a Range)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Số đoạn có tổng thuộc khoảng [A,B] (Count Subarray Sums in a Range)

Count Subarray Sums in a Range

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers (possibly negative) and two bounds A≤BA\le B, count nonempty consecutive intervals [l,r][l,r] satisfying A≤∑i=lrai≤BA\le\sum_{i=l}^r a_i\le B. Intervals at different positions are counted separately.

Input

The first line contains n,A,Bn,A,B. The second line contains exactly nn integers aia_i.

Output

Print the number of qualifying intervals.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; −109≤ai≤109-10^9\le a_i\le10^9; −2⋅1014≤A≤B≤2⋅1014-2\cdot10^{14}\le A\le B\le2\cdot10^{14}.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; −2⋅1014≤A≤B≤2⋅1014-2\cdot10^{14}\le A\le B\le2\cdot10^{14}; ai≥0a_i\ge0.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; −2⋅1014≤A≤B≤2⋅1014-2\cdot10^{14}\le A\le B\le2\cdot10^{14}.

Example 1

Input

3 -2 2
-2 5 -1

Output

3

Explanation

The qualifying intervals are [1,1] (-2), [3,3] (-1), and [1,3] (2).

Example 2

Input

3 0 0
0 0 0

Output

6

Explanation

All six nonempty intervals sum to zero.