#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1e5;
const int mod=1234567;
long long n,k,a[5*maxn+10],s[5*maxn+10],num[5*maxn+10],c[5*maxn+10][10];
inline long long read(){
long long num=0; char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
return num;
}
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
a[i]=read();
s[i]=s[i-1]+a[i];
num[s[i]%k]++;
}
c[0][0]=1; c[1][0]=c[1][1]=1; c[2][0]=c[2][2]=1; c[2][1]=2;
for(int i=3;i<=n;i++){
for(int j=0;j<=2;j++){
c[i][j]=(c[i-1][j]%mod+c[i-1][j-1]%mod)%mod;
}
}
/*for(int i=1;i<=n;i++){
for(int j=0;j<=2;j++){
cout<<c[i][j]<<' ';
}
cout<<endl;
}*/
long long ans=0;
for(int i=0;i<k;i++){
if(num[i]>=2) ans=ans%mod+c[num[i]][2]%mod;
ans%=mod;
}
cout<<(ans%mod+num[0]%mod)%mod<<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1e5;
const int mod=1234567;
long long n,k,a[5*maxn+10],s[5*maxn+10],num[5*maxn+10],c[5*maxn+10][10];
inline long long read(){
long long num=0; char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
return num;
}
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
a[i]=read();
s[i]=s[i-1]+a[i];
num[s[i]%k]++;
}
c[0][0]=1; c[1][0]=c[1][1]=1; c[2][0]=c[2][2]=1; c[2][1]=2;
for(int i=3;i<=n;i++){
for(int j=0;j<=2;j++){
c[i][j]=(c[i-1][j]%mod+c[i-1][j-1]%mod)%mod;
}
}
/*for(int i=1;i<=n;i++){
for(int j=0;j<=2;j++){
cout<<c[i][j]<<' ';
}
cout<<endl;
}*/
long long ans=0;
for(int i=0;i<k;i++){
if(num[i]>=2) ans=ans%mod+c[num[i]][2]%mod;
ans%=mod;
}
cout<<(ans%mod+num[0]%mod)%mod<<endl;
return 0;
}