#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

struct Bit {
    tree: Vec<isize>,
}
impl Bit {
#[allow(dead_code)]
    fn new(n: usize) -> Self {
        Bit { tree: vec![0; n] }
    }
#[allow(dead_code)]
    fn from(vec: Vec<isize>) -> Self {
        let mut bit = Bit::new(vec.len() + 1);
        for i in 1..(vec.len() + 1) {
            bit.add(i, vec[i - 1]);
        }
        bit
    }
#[allow(dead_code)]
    fn add(&mut self, a: usize, w: isize) {
        let mut x = a as isize;
        while x < self.tree.len() as isize {
            self.tree[x as usize] += w;
            x += x & (-x);
        }
    }
#[allow(dead_code)]
    fn sum(&self, n: usize) -> isize {
        let mut x = n as isize;
        let mut ret = 0;
        while x > 0 {
            ret += self.tree[x as usize];
            x -= x & (-x);
        }
        ret
    }
#[allow(dead_code)]
    fn sum_with(&self, l: usize, r: usize) -> isize {
        self.sum(r) - self.sum(l - 1)
    }
}

fn solve() {
    let (n,k) = get!(usize,isize);
    let a = get!(isize;n);

    let mut sum = 0;
    let mut count = 0;
    let mut vec = Vec::new();
    vec.push(0);
    for &e in &a {
        sum += e-k;
        vec.push(sum);
    }
    vec.sort();
    let mut map = BTreeMap::new();
    for i in 0..vec.len() {
        map.entry(vec[i]).or_insert(VecDeque::new()).push_back(i);
    }

    let mut bit = Bit::new(n+2);
    let mut sum = 0;
    if let Some(v) = map.get(&sum) {
        let i = v.iter().next().cloned().unwrap();
        bit.add(i+1,1);
    }
    for &e in &a {
        sum += e-k;
        if let Some(v) = map.get(&sum) {
            let i = v.iter().next().cloned().unwrap();
            let j = v.iter().rev().next().cloned().unwrap();
            count += bit.sum(j+1);
            bit.add(i+1,1);
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 43388