#include <iostream>
#include <vector>
#include <unordered_map>
#include <numeric>
#include <cassert>
using namespace std;
constexpr int MAX_M = 10'000;
std::array<int, MAX_M> cnt;
long long nchoose2(int n){
return 1LL * n * (n - 1) / 2;
}
long long nchoose3(int n){
return 1LL * n * (n - 1) * (n - 2) / 6;
}
int main(){
ios_base::sync_with_stdio(false);
int N, M;
assert(cin >> N >> M);
assert(1 <= N && N <= 200'000);
assert(1 <= M && M <= 10'000);
for (int i = 0; i < N; i++){
int x;
assert(cin >> x);
assert(0 <= x && x <= 2'000'000'000);
cnt[x % M]++;
}
long long answer = 0;
for (int i = 0; i < M; i++){
if (cnt[i] > 0){
for (int j = i; j < M; j++){
if (cnt[j] > 0){
int sum = (i + j) % M;
int k = (M - sum + M) % M;
if (i <= j && j <= k){
if (i == j && j == k){
answer += nchoose3(cnt[i]);
}
else if (i == j){
answer += nchoose2(cnt[i]) * cnt[k];
}
else if (j == k){
answer += nchoose2(cnt[j]) * cnt[i];
}
else{
answer += 1LL * cnt[i] * cnt[j] * cnt[k];
}
}
}
}
}
}
cout << answer << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDxjYXNzZXJ0PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0ZXhwciBpbnQgTUFYX00gPSAxMCcwMDA7CnN0ZDo6YXJyYXk8aW50LCBNQVhfTT4gY250OwoKbG9uZyBsb25nIG5jaG9vc2UyKGludCBuKXsKICByZXR1cm4gMUxMICogbiAqIChuIC0gMSkgLyAyOwp9Cgpsb25nIGxvbmcgbmNob29zZTMoaW50IG4pewogIHJldHVybiAxTEwgKiBuICogKG4gLSAxKSAqIChuIC0gMikgLyA2Owp9CgppbnQgbWFpbigpewogIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoKICBpbnQgTiwgTTsKICBhc3NlcnQoY2luID4+IE4gPj4gTSk7CiAgYXNzZXJ0KDEgPD0gTiAmJiBOIDw9IDIwMCcwMDApOwogIGFzc2VydCgxIDw9IE0gJiYgTSA8PSAxMCcwMDApOwoKICBmb3IgKGludCBpID0gMDsgaSA8IE47IGkrKyl7CiAgICBpbnQgeDsKICAgIGFzc2VydChjaW4gPj4geCk7CiAgICBhc3NlcnQoMCA8PSB4ICYmIHggPD0gMicwMDAnMDAwJzAwMCk7CiAgICBjbnRbeCAlIE1dKys7CiAgfQoKICBsb25nIGxvbmcgYW5zd2VyID0gMDsKCiAgZm9yIChpbnQgaSA9IDA7IGkgPCBNOyBpKyspewogICAgaWYgKGNudFtpXSA+IDApewogICAgICBmb3IgKGludCBqID0gaTsgaiA8IE07IGorKyl7CiAgICAgICAgaWYgKGNudFtqXSA+IDApewogICAgICAgICAgaW50IHN1bSA9IChpICsgaikgJSBNOwogICAgICAgICAgaW50IGsgPSAoTSAtIHN1bSArIE0pICUgTTsKCiAgICAgICAgICBpZiAoaSA8PSBqICYmIGogPD0gayl7CiAgICAgICAgICAgIGlmIChpID09IGogJiYgaiA9PSBrKXsKICAgICAgICAgICAgICBhbnN3ZXIgKz0gbmNob29zZTMoY250W2ldKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmIChpID09IGopewogICAgICAgICAgICAgIGFuc3dlciArPSBuY2hvb3NlMihjbnRbaV0pICogY250W2tdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYgKGogPT0gayl7CiAgICAgICAgICAgICAgYW5zd2VyICs9IG5jaG9vc2UyKGNudFtqXSkgKiBjbnRbaV07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICBhbnN3ZXIgKz0gMUxMICogY250W2ldICogY250W2pdICogY250W2tdOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgfQoKICBjb3V0IDw8IGFuc3dlciA8PCAiXG4iOwoKICByZXR1cm4gMDsKfQo=