macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
pub mod at {
    // use std;
    #[inline]
    fn rmb(k: usize) -> usize {
        (k as isize & -(k as isize)) as usize
    }
    pub trait Monoid {
        type T: Clone + PartialEq;
        fn mempty(&self) -> Self::T;
        fn mappend(&self, x: &Self::T, y: &Self::T) -> Self::T;
    }
    pub struct BinaryIndexedTree<M: Monoid> {
        bit: Vec<M::T>,
        m: M,
    }
    impl<M: Monoid> BinaryIndexedTree<M> {
        pub fn new(n: usize, m: M) -> BinaryIndexedTree<M> {
            let bit = vec![m.mempty(); n + 1];
            BinaryIndexedTree { bit: bit, m: m }
        }
        #[doc = " 1-indexed"]
        pub fn query(&self, k: usize) -> M::T {
            let mut res = self.m.mempty();
            let mut k = k;
            while k > 0 {
                res = self.m.mappend(&res, &self.bit[k]);
                k -= rmb(k);
            }
            res
        }
        #[doc = " 1-indexed"]
        pub fn update(&mut self, k: usize, x: M::T) {
            let mut k = k;
            while k < self.bit.len() {
                self.bit[k] = self.m.mappend(&self.bit[k], &x);
                k += rmb(k);
            }
        }
    }
    pub struct AnyMonoid<T: Clone, F: Fn(&T, &T) -> T> {
        id: T,
        op: F,
    }
    impl<T: Clone, F: Fn(&T, &T) -> T> AnyMonoid<T, F> {
        pub fn new(id: T, op: F) -> AnyMonoid<T, F> {
            AnyMonoid { id: id, op: op }
        }
    }
    impl<T: Clone + PartialEq, F: Fn(&T, &T) -> T> Monoid for AnyMonoid<T, F> {
        type T = T;
        fn mempty(&self) -> T {
            self.id.clone()
        }
        fn mappend(&self, x: &T, y: &T) -> T {
            (self.op)(x, y)
        }
    }
    pub trait Bisect: Copy {
        fn halve(self, other: Self) -> Self;
        fn section_end(self, other: Self) -> bool;
    }
    impl Bisect for usize {
        fn halve(self, other: Self) -> Self {
            if self > other {
                other + (self - other) / 2
            } else {
                self + (other - self) / 2
            }
        }
        fn section_end(self, other: Self) -> bool {
            (if self > other {
                self - other
            } else {
                other - self
            }) <= 1
        }
    }
    impl Bisect for i64 {
        fn halve(self, other: Self) -> Self {
            (self + other) / 2
        }
        fn section_end(self, other: Self) -> bool {
            (self - other).abs() <= 1
        }
    }
    impl Bisect for f64 {
        fn halve(self, other: Self) -> Self {
            (self + other) / 2.
        }
        fn section_end(self, other: Self) -> bool {
            (self - other).abs() <= 1e-8
        }
    }
    pub fn binary_search<T: Bisect, F: Fn(T) -> bool>(f: F, ok: T, err: T) -> T {
        let mut ok = ok;
        let mut err = err;
        while !ok.section_end(err) {
            let m = ok.halve(err);
            if f(m) {
                ok = m;
            } else {
                err = m;
            }
        }
        ok
    }
    pub fn lower_bound<T: Bisect + Ord>(v: &[T], x: T) -> usize {
        binary_search(|i| v[i as usize] >= x, v.len() as i64, -1) as usize
    }
}
use at::*;
use std::collections::BTreeSet;
fn main() {
    input! { n, k: i64, a: [i64; n] };
    let mut s = vec![0; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + a[i];
    }
    for i in 0..n + 1 {
        s[i] -= k * i as i64;
    }
    let v = s
        .iter()
        .cloned()
        .collect::<BTreeSet<_>>()
        .into_iter()
        .collect::<Vec<_>>();
    let mut bit = BinaryIndexedTree::new(n + 1, AnyMonoid::new(0i64, |&x, &y| x + y));
    let mut ans = 0;
    for i in 0..n {
        let x = lower_bound(&v, s[i]);
        bit.update(x + 1, 1);
        let y = lower_bound(&v, s[i + 1]);
        ans += bit.query(y + 1);
    }
    println!("{}", ans);
}


Measured memory_bytes: 18684