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
  import bisect
  
  
  def main():
      N, K = map(int, input().split())
      cum = [0]
      for _ in range(N):
          cum.append(cum[-1] + int(input()) - K)
  
      s_cum = sorted(cum)
  
      def invNumCount(A):
          l = len(A)
          res = 0
          BIT = [0] * (l + 1)
  
          def BIT_query(idx):
              res_sum = 0
              while idx > 0:
                  res_sum += BIT[idx]
                  idx -= idx & (-idx)
              return res_sum
  
          def BIT_update(idx, x):
              while idx <= l:
                  BIT[idx] += x
                  idx += idx & (-idx)
              return
  
          Ai = [None] * l
          for i, e in enumerate(A):
              Ai[e] = i
          for i, e in enumerate(Ai):
              res += i - BIT_query(e + 1)
              BIT_update(e + 1, 1)
          return res
  
      d = {}
      pos = [None] * (N + 1)
      for i, num in enumerate(cum):
          ind = bisect.bisect_left(s_cum, num)
          if num not in d:
              d[num] = 1
          else:
              ind += d[num]
              d[num] += 1
          pos[i] = N - ind
  
      print(invNumCount(pos))
  
  
  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"}]