Problem:
Score : 600 points

Problem Statement

You are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.

a has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal to K?

Constraints

All input values are integers.

1 ≤ N ≤ 2 \times 10^5

1 ≤ K ≤ 10^9

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N K
a_1
a_2
:
a_N

Output

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

Sample Input 1

3 6
7
5
7

Sample Output 1

5

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

{a_1} = {7}

{a_1, a_2} = {7, 5}

{a_1, a_2, a_3} = {7, 5, 7}

{a_2} = {5}

{a_2, a_3} = {5, 7}

{a_3} = {7}

Their means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of their elements, but we count them individually.

Sample Input 2

1 2
1

Sample Output 2

0

Sample Input 3

7 26
10
20
30
40
30
20
10

Sample Output 3

13

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;
int a[101010];
LL rui[101010];
vector<LL>v;

//[1,n],size
int bit[101010 + 1];

int sum(int i) {
	int s = 0;
	while (i > 0) {
		s += bit[i];
		//i&-iはiの最後の1ビット
		i -= i&-i;
	}
	return s;
}

void add(int i, int x) {
	while (i <= n) {
		bit[i] += x;
		i += i&-i;
	}
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		rui[i] = rui[i - 1] + a[i];
	}
	for (int i = 1; i <= n; i++) {
		v.emplace_back( rui[i] - k*i);
	}
	v.emplace_back(0);
	sort(ALL(v));
	UNIQ(v);
	LL ans = 0;
	add(lower_bound(ALL(v), 0) - v.begin() + 1, 1);
	for (int i = 1; i <= n; i++) {
		int num = lower_bound(ALL(v), rui[i] - k*i) - v.begin() + 1;
		ans += sum(num);
		add(num, 1);
	}
	cout << ans << endl;
}