#P7868. [COCI 2015/2016 #2] VUDU

[COCI 2015/2016 #2] VUDU

Description

Young Mirko has recently been buying Voodoo dolls. Since he is interested in the cheapest things, he tracks the prices of Voodoo dolls every day. He already knows the prices over the last NN days, where the price on day ii is denoted by aia_i.

Mirko believes that there is some connection between the average price over several consecutive days and the price on the next day. He wants to verify his idea, but he is stuck on a problem: “For a given PP, how many different contiguous subarrays within these NN days have an average price greater than or equal to PP?”

Two contiguous subarrays are different if and only if their starting positions or ending positions are different.

Input Format

The first line contains an integer NN.

The next line contains NN integers, where the ii-th integer represents aia_i.

The last line contains an integer PP.

Output Format

Output one integer on a single line, representing how many different contiguous subarrays within these NN days have an average price greater than or equal to PP.

3
1 2 3
3
1
3
1 3 2
2
5
3
1 3 2
3
1

Hint

[Sample 1 Explanation]

There are only 3 subarrays whose average is greater than or equal to 3.

[Sample 2 Explanation]

There are 5 subarrays whose average is greater than or equal to 2, and they are:

1 3

1 3 2

3

3 2

2

[Constraints]

For 30%30\% of the testdata, 1N1041 \le N \le 10^4.

For 100%100\% of the testdata, 1N1061 \le N \le 10^6, 1ai1091 \le a_i \le 10^9, 1P1091 \le P \le 10^9.

[Notes]

The scoring for this problem follows the original problem, with a full score of 140140.

Translated from COCI 2015-2016 CONTEST #2 T5 VUDU.

Translated by ChatGPT 5