use std::io::stdin;
use std::collections::HashMap;


fn main() {
    let mut nm = String::new();
    stdin().read_line(&mut nm).unwrap();
    let nm: Vec<usize> = nm.trim().split_whitespace().flat_map(str::parse).collect();
    let (n, m) = (nm[0], nm[1]);

    let mut candies = String::new();
    stdin().read_line(&mut candies).unwrap();
    let candies: Vec<usize> = candies.trim().split_whitespace().flat_map(str::parse).collect();

    println!("{}", solve(n, m, candies));
}

fn solve(n :usize, m: usize, candies: Vec<usize>) -> usize {
    let mut ca = Vec::with_capacity(n + 1);
    ca.push(0);
    candies.into_iter().fold(0, |acc, v|{
        let v = (acc + v) % m;
        ca.push(v);
        v
    });

    let mut res = 0;
    let mut memo: HashMap<usize, usize> = HashMap::new();
    for i in ca.into_iter() {
        if let Some(p) = memo.get_mut(&i) {
            res += *p;
            *p += 1;
        } else {
            memo.insert(i, 1);
        }
    }
    res
}
