output_description: Print the number of the non-empty contiguous subsequences with an arithmetic
  mean that is greater than or equal to K.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      a_1
      a_2
      :
      a_N
attempt: import sys
  
  input = sys.stdin.buffer.readline
  sys.setrecursionlimit(10**7)
  from collections import defaultdict
  
  con = 10**9 + 7
  INF = float("inf")
  
  
  def getlist():
      return list(map(int, input().split()))
  
  
  class SegmentTree(object):
      # N:処理する区間の長さ
      def __init__(self, N):
          self.N = N
          self.N0 = 2 ** (N - 1).bit_length()
          self.initVal = 0
          self.data = [self.initVal] * (2 * self.N0)
  
      # 区間クエリの種類
      def calc(self, a, b):
          return a + b
  
      # k番目の値にxを加算
      def add(self, k, x):
          k += self.N0 - 1
          self.data[k] += x
          while k > 0:
              k = (k - 1) // 2
              self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])
  
      # 区間[l, r]の演算値
      def query(self, l, r):
          L = l + self.N0
          R = r + self.N0 + 1
          m = self.initVal
          while L < R:
              if R & 1:
                  R -= 1
                  m = self.calc(m, self.data[R - 1])
              if L & 1:
                  m = self.calc(m, self.data[L - 1])
                  L += 1
              L >>= 1
              R >>= 1
  
          return m
  
  
  # 処理内容
  def main():
      N, K = getlist()
      A = []
      for i in range(N):
          a = int(input())
          A.append(a)
  
      # K引く
      for i in range(N):
          A[i] -= K
  
      # 累積和
      B = [0]
      for i in range(N):
          B.append(B[-1] + A[i])
  
      # 座圧
      C = list(set(B))
      C.sort()
      D = defaultdict(int)
      for i in range(len(C)):
          D[C[i]] = i
  
      # 座標変換
      for i in range(N + 1):
          B[i] = D[B[i]]
  
      # セグ木
      ans = 0
      Seg = SegmentTree(N)
      for i in range(N + 1):
          b = B[i]
          val = Seg.query(0, b)
          ans += val
          Seg.add(b, 1)
  
      print(ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: 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?
samples: [{"input": "3 6\n    7\n    5\n    7", "output": "5\n    \n\nAll the non-empty contiguous subsequences of a are listed below:\n\n  * {a_1} = {7}\n  * {a_1, a_2} = {7, 5}\n  * {a_1, a_2, a_3} = {7, 5, 7}\n  * {a_2} = {5}\n  * {a_2, a_3} = {5, 7}\n  * {a_3} = {7}\n\nTheir means are 7, 6, 19/3, 5, 6 and 7, respectively, and five among them are\n6 or greater. Note that {a_1} and {a_3} are indistinguishable by the values of\ntheir elements, but we count them individually.\n\n* * *"}, {"input": "1 2\n    1", "output": "0\n    \n\n* * *"}, {"input": "7 26\n    10\n    20\n    30\n    40\n    30\n    20\n    10", "output": "13"}]