atcoder#ARC075C. [ARC075E] Meaningful Mean

[ARC075E] Meaningful Mean

Score : 600600 points

Problem Statement

You are given an integer sequence of length NN, a=a = {a1,a2,,aNa_1, a_2, \cdots , a_N}, and an integer KK.

aa has N(N+1)/2N(N+1)/2 non-empty contiguous subsequences, {al,al+1,,ara_l, a_{l+1}, \cdots , a_r} (1lrN)(1 \leq l \leq r \leq N). Among them, how many have an arithmetic mean that is greater than or equal to KK?

Constraints

  • All input values are integers.
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1K1091 \leq K \leq 10^9
  • 1ai1091 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN KK

a1a_1

a2a_2

::

aNa_N

Output

Print the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to KK.

3 6
7
5
7
5

All the non-empty contiguous subsequences of aa are listed below:

  • {a1a_1} = {77}
  • {a1,a2a_1, a_2} = {7,57, 5}
  • {a1,a2,a3a_1, a_2, a_3} = {7,5,77, 5, 7}
  • {a2a_2} = {55}
  • {a2,a3a_2, a_3} = {5,75, 7}
  • {a3a_3} = {77}

Their means are 77, 66, 19/319/3, 55, 66 and 77, respectively, and five among them are 66 or greater. Note that {a1a_1} and {a3a_3} are indistinguishable by the values of their elements, but we count them individually.

1 2
1
0
7 26
10
20
30
40
30
20
10
13