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

#PS0000195. Đếm đoạn có điểm nhỏ hơn K (Count Subarrays With Score Less Than K)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn có điểm nhỏ hơn K (Count Subarrays With Score Less Than K)

Count Subarrays With Score Less Than K

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn positive integers, define the score of a nonempty consecutive interval [l,r][l,r] as (r−l+1)∑i=lrai(r-l+1)\sum_{i=l}^{r}a_i. Count pairs 1≤l≤r≤n1\le l\le r\le n whose score is strictly less than KK. Intervals at different positions are counted separately.

Input

The first line contains n,Kn,K. The second 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; 1≤ai≤1051\le a_i\le10^5; 1≤K≤10151\le K\le10^{15}.
  • Subtask 2 (30 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤1051\le a_i\le10^5; 1≤K≤10151\le K\le10^{15}; ai=a1a_i=a_1.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤1051\le a_i\le10^5; 1≤K≤10151\le K\le10^{15}.

Example 1

Input

5 10
2 1 4 3 5

Output

6

Explanation

The five singletons and interval [1,2] (score 6) qualify. Interval [2,3] has score 10 and is excluded.

Example 2

Input

3 5
1 1 1

Output

5

Explanation

Three length-one and two length-two intervals qualify; the length-three interval scores 9.