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

[COCI 2015/2016 #2] VUDU

Problem Description

Young Mirko has been buying voodoo dolls lately. Considering that he is very interested in the cheapest purchase possible, he has been tracking the prices of voodoo dolls each day.His price list consists of doll prices in the last NN days, where doll price aia_i represents the price of a doll ii days ago.

Mirko thinks he has noticed a connection between the average doll price in a sequence of consecutive days and the price on the following day. He wants to test his hunch and is puzzled by a very interesting question: "For a given PP, how many different consecutive subsequences in the last NN days are there, when the average doll price was greater than or equal to PP?"

Two consecutive subsequences are considered different if their beginnings or ends are different.

Input Format

The first line of input contains the integer NN, the sequence length.

The second line of input contains NN prices aia_i.

The third line of input contains an integer PP.

Output Format

The first and only line of output must contain the answer to Mirko's question for a given PP.

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

Hint

Clarification of the first example

The only subsequence that has an average greater than or equal to 33 is {3}\lbrace 3 \rbrace.

Clarification of the second example

The subsequences that have an average greater than or equal to 22 are {1,3}\lbrace 1, 3 \rbrace, {1,3,2}\lbrace 1, 3, 2 \rbrace, {3}\lbrace 3 \rbrace, {3,2}\lbrace 3 ,2 \rbrace, {2}\lbrace 2 \rbrace.

Scoring

In test cases worth 30%30\% of the points, 1N1041\le N \le 10^4.

In test cases for all points, 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.

From COCI 2015-2016 CONTEST #2 T5 VUDU.

Organized by

/user/1074137