module MultiSet = struct
  module type OrderedType =
    sig
      type t
      val compare: t -> t -> int
    end

  module type S =
    sig
      type elt
      type t
      val empty : t
      val add : elt -> t -> t
      val count_gt : elt -> t -> int
    end

  module Make (Ord : OrderedType)
  (* : S with type elt = Ord.t *) =
    struct
      type elt = Ord.t

      type t =
        | Empty
        | Node of body
      and body = 
        { left : t;
          data : elt;
          count : int;
          right : t;
          height : int;
          cardinal : int }
      

      let height = function
        | Empty -> 0
        | Node { height } -> height

      let cardinal = function
        | Empty -> 0
        | Node { cardinal } -> cardinal

      let create ~left ~data ~count ~right =
        Node
          { left; data; count; right;
            height = 1 + max (height left) (height right);
            cardinal = count + cardinal left + cardinal right }

    let balance ~left:l ~data:x ~count:d ~right:r =
      let hl = height l in
      let hr = height r in
      if hl > hr + 2 then begin
        match l with
        | Empty -> invalid_arg "MultiSet.balance" | Node { left = ll; data = lv; count = ld; right = lr } ->
            if height ll >= height lr then
              create ll lv ld (create lr x d r)
            else begin
              match lr with
              | Empty -> invalid_arg "MultiSet.balance"
              | Node { left = lrl; data = lrv; count = lrd; right = lrr } ->
                  create (create ll lv ld lrl) lrv lrd (create lrr x d r)
            end
      end else if hr > hl + 2 then begin
        match r with
        | Empty -> invalid_arg "MultiSet.balance"
        | Node { left = rl; data = rv; count = rd; right = rr } ->
            if height rr >= height rl then
              create (create l x d rl) rv rd rr
            else begin
              match rl with
              | Empty -> invalid_arg "Map.bal"
              | Node { left = rll; data = rlv; count = rld; right = rlr } ->
                  create (create l x d rll) rlv rld (create rlr rv rd rr)
            end
      end else create l x d r

    let empty = Empty

    let rec add x = function
      | Empty -> create Empty x 1 Empty
      | Node { left; data = y; count; right } ->
          match Ord.compare x y with
          | 0 ->
              create left x (count + 1) right
          | c when c < 0 ->
              balance (add x left) y count right
          | _ ->
              balance left y count (add x right)

    let rec count_gt x = function
      | Empty -> 0
      | Node { left; data = y; count; right } ->
          match Ord.compare x y with
          | 0 ->
              cardinal right
          | c when 0 < c ->
              (* y < x *) 
              count_gt x right
          | _ ->
              (* x < y *)
              count_gt x left + count + cardinal right
    end
end

module IntMultiSet = MultiSet.Make (struct
  type t = int
  let compare = compare
end)


let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  (* [a_i, ... a_j]の平均値がk iff [a_i - k, ... , a_j - k]の合計値が0 *)
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun a -> a - k in
  Printf.printf "%d\n" @@ snd @@ Array.fold_left (fun ((m, offset), acc) a ->
    (* mの全ての要素にaを加算する代わりに，offsetにaを加算する *)
    (* x∈mの真の値はx+offsetになる *)
    let offset = offset + a in
    let m = IntMultiSet.add (a - offset) m in
    (m, offset),
    (* 真の値が0以上，つまり-offset - 1 < xなるx∈mの数を数える *)
    acc + IntMultiSet.count_gt (~-offset - 1) m) ((IntMultiSet.empty, 0), 0) as_