#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long int i=(a);i<=(b);++i)
#define NFOR(i,a,b) for(long long int i=(a);i>=(b);--i)
#define pb push_back
#define ll long long
#define F first
#define PI 3.14159265358979323846264338327
#define S second
#define all(v) v.begin(),v.end()
#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define MOD 1000000007
using namespace std;
ll brr[10004];
void solve()
{
ll t,n,m,x,y;
cin>>n>>m;
ll arr[n+1];
FOR(i,1,n)
cin>>arr[i];
FOR(i,1,n)
{
arr[i]%=m;
brr[arr[i]]++;
}
long long sum=0;
FOR(i,0,m-1)
{
if(brr[i]<=0)continue;
FOR(j,i,m-1)
{
if(brr[j]<=0)continue;
ll v1=(i+j)%m;
ll k=(m-v1)%m;
if(k>=j){
long long ans=0;
if(i==j&&i==k)
{
if(brr[i]>=2)
ans+=(1LL*brr[i]*(brr[i]-1)*(brr[i]-2))/6;
}
else if(i==j)
{
if(brr[i]>=1){
ans+=(1LL*(brr[i])*(brr[i]-1))/2;
ans*=brr[k];}
}
else if(i==k)
{
if(brr[i]>=1){
ans+=(1LL*(brr[i])*(brr[i]-1))/2;
ans*=brr[j];}
}
else if(j==k)
{
if(brr[j]>=1){
ans+=(1LL*(brr[j])*(brr[j]-1))/2;
ans*=brr[i];}
}
else
ans+=(1LL*brr[i]*brr[j]*brr[k]);
ans=max(ans,0LL);
sum+=ans;
}
}
}
cout<<sum<<endl;
}
int main()
{
fast;
solve();
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBGT1IoaSxhLGIpIGZvcihsb25nIGxvbmcgaW50IGk9KGEpO2k8PShiKTsrK2kpCiNkZWZpbmUgTkZPUihpLGEsYikgZm9yKGxvbmcgbG9uZyBpbnQgaT0oYSk7aT49KGIpOy0taSkKI2RlZmluZSBwYiBwdXNoX2JhY2s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AgICBhbnMrPSgxTEwqYnJyW2ldKihicnJbaV0tMSkqKGJycltpXS0yKSkvNjsKICAgIAkJfQogICAgCQllbHNlIGlmKGk9PWopCiAgICAJCXsKICAgIAkJCWlmKGJycltpXT49MSl7CiAgICAJCQlhbnMrPSgxTEwqKGJycltpXSkqKGJycltpXS0xKSkvMjsKICAgIAkJCWFucyo9YnJyW2tdO30KICAgIAkJfQogICAgCQllbHNlIGlmKGk9PWspCiAgICAJCXsKICAgIAkJCWlmKGJycltpXT49MSl7CiAgICAJCQlhbnMrPSgxTEwqKGJycltpXSkqKGJycltpXS0xKSkvMjsKICAgIAkJCWFucyo9YnJyW2pdO30KICAgIAkJfQogICAgCQllbHNlIGlmKGo9PWspCiAgICAJCXsKICAgIAkJICAgICAgICAgIGlmKGJycltqXT49MSl7CiAgICAJCSAgICAgICAgICBhbnMrPSgxTEwqKGJycltqXSkqKGJycltqXS0xKSkvMjsKICAgIAkJICAgICAgICAgIGFucyo9YnJyW2ldO30KICAgIAkJfQogICAgCQllbHNlCiAgICAJCWFucys9KDFMTCpicnJbaV0qYnJyW2pdKmJycltrXSk7CiAgICAJCWFucz1tYXgoYW5zLDBMTCk7CiAgICAJCXN1bSs9YW5zOwogICAgCQogICAgCQl9CiAgICAJfQogICAgfQogICAgY291dDw8c3VtPDxlbmRsOwogICAgCn0KIAppbnQgbWFpbigpCnsKICAgIGZhc3Q7CiAKICAgIHNvbHZlKCk7CnJldHVybiAwOwp9