import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n, m;
    scan(n, m);
    auto a = readln.split.to!(int[]);

    int[int] asc;
    int[] b = new int[](n + 1);

    asc[0] = 1;
    b[n] = 0;

    int val;
    long sum;

    foreach_reverse (i ; 0 .. n) {
        val += a[i];
        val %= m;

        if (val in asc) {
            asc[val]++;
        }
        else {
            asc[val] = 1;
        }

        b[i] = val;
        sum += a[i];
    }

    debug {
        writeln(asc);
        writeln(b);
    }

    long ans;

    foreach (i ; 0 .. n) {
        if (sum % m in asc) {
            ans += asc[sum % m];
        }

        asc[b[i]]--;

        sum -= a[i];
    }

    writeln(ans - n);
}


























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
