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

#PS0000206. Đếm đoạn có trung bình trong [A,B] (Count Subarrays with Average in a Range)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn có trung bình trong [A,B] (Count Subarrays with Average in a Range)

Count Subarrays with Average in a Range

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers aia_i and two integers A≤BA\le B, count nonempty consecutive intervals [l,r][l,r] satisfying A≤∑i=lrair−l+1≤BA\le \frac{\sum_{i=l}^{r} a_i}{r-l+1}\le B. Both bounds are inclusive; 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≤2001\le n\le 200; ∣ai∣≤109|a_i|\le10^9; −109≤A≤B≤109-10^9\le A\le B\le10^9.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; ∣ai∣≤109|a_i|\le10^9; −109≤A≤B≤109-10^9\le A\le B\le10^9; A=BA=B.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; ∣ai∣≤109|a_i|\le10^9; −109≤A≤B≤109-10^9\le A\le B\le10^9.

Example 1

Input

3 2 3
1 3 2

Output

5

Explanation

The five intervals are [2,2], [3,3], [1,2], [2,3], [1,3]; their averages are 3, 2, 2, 2.5, 2.

Example 2

Input

3 0 0
-1 1 0

Output

3

Explanation

Intervals [1,2], [3,3], [1,3] sum to zero and thus have average exactly zero.