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

#PS0000203. Đếm đoạn theo tổng và độ dài (Count Subarrays by Sum and Length)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn theo tổng và độ dài (Count Subarrays by Sum and Length)

Count Subarrays by Sum and Length

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers aia_i, length bounds L,RL,R and sum bounds A,BA,B, count nonempty consecutive intervals [l,r][l,r] satisfying both L≤r−l+1≤RL\le r-l+1\le R and A≤∑i=lrai≤BA\le\sum_{i=l}^{r}a_i\le B. Indices are 1-based; intervals at different positions are counted separately.

Input

The first line contains n,L,R,A,Bn,L,R,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≤1001\le n\le 100; ∣ai∣≤109|a_i|\le10^9; 1≤L≤R≤n1\le L\le R\le n; −1014≤A≤B≤1014-10^{14}\le A\le B\le10^{14}.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; ∣ai∣≤109|a_i|\le10^9; 1≤L≤R≤n1\le L\le R\le n; −1014≤A≤B≤1014-10^{14}\le A\le B\le10^{14}; L=RL=R.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; ∣ai∣≤109|a_i|\le10^9; 1≤L≤R≤n1\le L\le R\le n; −1014≤A≤B≤1014-10^{14}\le A\le B\le10^{14}.

Example 1

Input

4 1 2 2 3
1 2 -1 3

Output

4

Explanation

Intervals [2,2], [4,4], [1,2], [3,4] have sums 2, 3, 3, 2.

Example 2

Input

3 2 2 0 0
0 0 0

Output

2

Explanation

Both intervals of length 2 sum to zero.