stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define ms(a, b) memset(a, b, sizeof(a))



using namespace std;



const int Size = 26;

const int MAXN = 1e5 + 100;

const int maxn = 50 + 7;

const int MOD = 1e5;

const int INF = 0x3FFFFFFF;



set<int>s;

map<int, int>mp;

int pre[MAXN], a[MAXN];



int main()

{

    int n;

    ll m;

    ll ans = 0;

    ll temp;

    ios::sync_with_stdio(false);

    s.clear();

    mp.clear();

    cin >> n >> m;

    pre[0] = 0;

    for(int i = 1; i <= n; i++)

    {

        cin >> a[i];

        pre[i] = a[i];

    }

    for(int i = 1; i <= n; i++)

    {

        pre[i] = (pre[i - 1] + pre[i]) % m;

        mp[pre[i]]++;

        if(!s.count(pre[i]))   s.insert(pre[i]);

    }

    set<int>::iterator it;

    for(it = s.begin(); it != s.end(); it++)

    {

        temp = mp[*it];

        ans += temp * (temp - 1) / 2;

    }

    if(*s.begin() == 0)

        ans += mp[0];

    cout << ans << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1048429277791354x):
#include<stdio.h>

#include<map>

using namespace std;

typedef long long ll;

ll a[110000];

ll sum[110000];

map<ll,ll>cnt;

int main()

{

    ll n,m;

    sum[0]=0;

    scanf("%lld%lld",&n,&m);

    for(ll i=1;i<=n;i++)

    {

        scanf("%lld",&a[i]);

        sum[i]=(sum[i-1]+a[i])%m;

    }

    ll ans=0;

    for(ll i=1;i<=n;i++)

    {

            ans+=cnt[sum[i]];

            cnt[sum[i]]++;

    }

    printf("%lld\n",ans+cnt[0]);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define ms(a, b) memset(a, b, sizeof(a))



using namespace std;



const int Size = 26;

const int MAXN = 1e5 + 100;

const int maxn = 50 + 7;

const int MOD = 1e5;

const int INF = 0x3FFFFFFF;



set<int>s;

map<int, int>mp;

int pre[MAXN], a[MAXN];



int main()

{

    int n;

    ll m;

    ll ans = 0;

    ll temp;

    ios::sync_with_stdio(false);

    s.clear();

    mp.clear();

    cin >> n >> m;

    pre[0] = 0;

    for(int i = 1; i <= n; i++)

    {

        cin >> a[i];

        pre[i] = a[i];

    }

    for(int i = 1; i <= n; i++)

    {

        pre[i] = (pre[i - 1] + pre[i]) % m;

        mp[pre[i]]++;

        if(!s.count(pre[i]))   s.insert(pre[i]);

    }

    set<int>::iterator it;

    for(it = s.begin(); it != s.end(); it++)

    {

        temp = mp[*it];

        ans += temp * (temp - 1) / 2;

    }

    if(*s.begin() == 0)

        ans += mp[0];

    cout << ans << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1046360361496255x):
#include<stdio.h>

#include<map>

#define maxn 100005

using namespace std;

long long remainder[maxn];

long long a[maxn];

map<long long,long long>number_l;

int main()

{

    long long n,m,answer=0;

    scanf("%lld%lld",&n,&m);

    for(int i=1;i<=n;i++)

    {

        scanf("%lld",&a[i]);

        remainder[i]=remainder[i-1]+a[i];

        remainder[i]%=m;

        answer+=number_l[remainder[i]];

        number_l[remainder[i]]++;

    }

    answer+=number_l[0];/**自己为起点自己为终点没有算进去，要补上**/

    printf("%lld\n",answer);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;

#define repeat(i, n) for(int i = 0; i < (n); i++)





int main()

{

	int N,M;

	cin >> N >> M;



	int A[100001] = {};

	long long B[100001] = {};

	map<int, int> MAP;



	repeat(i, N) {

		cin >> A[i];

		B[i + 1] = B[i] + A[i];



		B[i + 1] %= M;



		MAP[(int)B[i + 1]]++;

	}

	MAP[0]++;



	long long result = 0;



	for (auto ITR : MAP){

		result += 1ll * ITR.second * (ITR.second - 1) / 2;

	}





	//出力

	cout << result << endl;













	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.1852208257035697x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int S[100001];

	S[0] = 0;

	rep(i, N) {

		S[i + 1] = (S[i] + getint()) % M;

	}

	sort(S, S + N + 1);



	int mae = 0;

	ll k = 1;

	ll kotae = 0;

	rep1(i, N) {

		if (mae == S[i]) k++;

		else {

			kotae += k * (k - 1) / 2;

			mae = S[i];

			k = 1;

		}

	}

	kotae += k * (k - 1) / 2;



	co(kotae);



	Would you please return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;

#define repeat(i, n) for(int i = 0; i < (n); i++)





int main()

{

	int N,M;

	cin >> N >> M;



	int A[100001] = {};

	long long B[100001] = {};

	map<int, int> MAP;



	repeat(i, N) {

		cin >> A[i];

		B[i + 1] = B[i] + A[i];



		B[i + 1] %= M;



		MAP[(int)B[i + 1]]++;

	}

	MAP[0]++;



	long long result = 0;



	for (auto ITR : MAP){

		result += 1ll * ITR.second * (ITR.second - 1) / 2;

	}





	//出力

	cout << result << endl;













	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4799789075701444x):
//#include<bits/stdc++.h>

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



void pakuripair_sort(int N, int A[], int B[]) {

	const int b = 8;

	int tmp[100001], tmp2[100001];

	rep(k, 4) {

		int kazu[1 << b] = {}, kazu2[1 << b] = {};

		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];

		for (int i = N - 1; i >= 0; i--) {

			tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];

			tmp2[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];

		}

		k++;

		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];

		for (int i = N - 1; i >= 0; i--) {

			A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];

			B[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp2[i];

		}

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int A[100001], AN[100001];

	A[0] = 0;

	rep1(i, N) {

		int a = getint();

		A[i] = (A[i - 1] + a) % M;

		AN[i] = i;

	}

	pakuripair_sort(N, A + 1, AN + 1);



	int B[100001];

	int mae = A[0];

	int k = 0;

	ll kotae = 0;

	rep(i, N + 1) {

		if (mae != A[i]) k++;

		B[AN[i]] = k;

		mae = A[i];

	}

	int C[100001] = {};

	rep(i, N + 1) {

		kotae += C[B[i]]++;

	}

	printf("%lld", kotae);



	Would you please return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;

#define repeat(i, n) for(int i = 0; i < (n); i++)





int main()

{

	int N,M;

	cin >> N >> M;



	int A[100001] = {};

	long long B[100001] = {};

	map<int, int> MAP;



	repeat(i, N) {

		cin >> A[i];

		B[i + 1] = B[i] + A[i];



		B[i + 1] %= M;



		MAP[(int)B[i + 1]]++;

	}

	MAP[0]++;



	long long result = 0;



	for (auto ITR : MAP){

		result += 1ll * ITR.second * (ITR.second - 1) / 2;

	}





	//出力

	cout << result << endl;













	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 10.301220813522203x):
//#include<bits/stdc++.h>

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



void pakuri_sort(int N, int A[]) {

	const int b = 8;

	int tmp[200001];

	rep(k, 4) {

		int kazu[1 << b] = {}, kazu2[1 << b] = {};

		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];

		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];

		k++;

		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];

		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int A[100001];

	A[0] = 0;

	rep1(i, N) {

		int a = getint();

		A[i] = (A[i - 1] + a) % M;

	}

	pakuri_sort(N, A + 1);



	//数だけでええんか

	int mae = -1;

	int k = 0;

	ll kotae = 0;

	rep(i, N + 1) {

		if (mae != A[i]) k = 0;

		kotae += k++;

		mae = A[i];

	}

	printf("%lld", kotae);



	Would you please return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int S[100001];

	S[0] = 0;

	rep(i, N) {

		S[i + 1] = (S[i] + getint()) % M;

	}

	sort(S, S + N + 1);



	int mae = 0;

	ll k = 1;

	ll kotae = 0;

	rep1(i, N) {

		if (mae == S[i]) k++;

		else {

			kotae += k * (k - 1) / 2;

			mae = S[i];

			k = 1;

		}

	}

	kotae += k * (k - 1) / 2;



	co(kotae);



	Would you please return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.714041113078604x):
//#include<bits/stdc++.h>

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



void pakuri_sort(int N, int A[]) {

	const int b = 8;

	int tmp[200001];

	rep(k, 4) {

		int kazu[1 << b] = {}, kazu2[1 << b] = {};

		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];

		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];

		k++;

		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;

		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];

		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int A[100001];

	A[0] = 0;

	rep1(i, N) {

		int a = getint();

		A[i] = (A[i - 1] + a) % M;

	}

	pakuri_sort(N, A + 1);



	//数だけでええんか

	int mae = -1;

	int k = 0;

	ll kotae = 0;

	rep(i, N + 1) {

		if (mae != A[i]) k = 0;

		kotae += k++;

		mae = A[i];

	}

	printf("%lld", kotae);



	Would you please return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;

#define rep(i,n) for(ll i=0;i<n;i++)

#define REP(i,a,n) for(ll i=a;i<n;i++)

#define ALL(s) s.begin(),s.end()

#define P pair<ll,ll>

#define vl vector<ll>

#define vl vector<ll>

#define vvl vector<vector<ll>>

#define vvl vector<vector<ll>>

#define print(n) cout<<n<<endl

const int M=100010;

const int inf=1000000007;

const long long INF=1000000000000000007;

using ll=long long;

int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



ll comb(ll x){

	ll ans=1;

	ans=x*(x-1)/2;

	return ans;

}



int main(){

	ll n,m,ans=0;

	int a,dp[M]={};

	cin>>n>>m;

	rep(i,n){

		cin>>a;

		dp[i+1]=(dp[i]+a)%m;

	}

	sort(dp+1,dp+n+1);

	REP(i,1,n+1){

		if(dp[i]==0)ans++;

		else break;

	}

	REP(i,1,n+1){

		ll cnt=1;

		REP(j,i+1,n+1){

			if(dp[i]==dp[j])cnt++;

			else break;

		}

		ans+=comb(cnt);

		i+=cnt-1;

	}

	print(ans);

}

// Faster C++ solution for the same problem (measured speedup: 1.3893530102811167x):
#include "bits/stdc++.h"

using namespace std;

#define rep(i,n) for(ll i=0;i<n;i++)

#define REP(i,a,n) for(ll i=a;i<n;i++)

#define ALL(s) s.begin(),s.end()

#define P pair<ll,ll>

#define vl vector<ll>

#define vl vector<ll>

#define vvl vector<vector<ll>>

#define vvl vector<vector<ll>>

#define print(n) cout<<n<<endl

const int M=100010;

const int inf=1000000007;

const long long INF=1000000000000000007;

using ll=long long;

int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){

	ll n,m;

	cin>>n>>m;

	ll s=0;

	map<ll,ll> mp;

	REP(i,1,n+1){

		ll x;

		cin>>x;

		s+=x;

		mp[s%m]+=1;

	}

	ll ans=0;

	for(auto v:mp) {

		if(v.first==0)ans+=v.second;

		ans+=(v.second)*(v.second-1)/2;

	}

	print(ans);

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<stdlib.h>

#include<time.h>

#include<math.h>

#include<string.h>

#include<algorithm>

#include<queue>

#include<map>

using namespace std;



int main(void){

 int l,r;

 long long int N,M,a;

 long long int ans=0;

 long long int sum=0;

 long long int A[100050]; 

 map<long long int,long long int> B;



 for(int i=0; i<=100020;i++)A[i]=0;



 cin>>N>>M;

 for(int i=0; i<N; i++){

  cin>>a;

  A[i+1]=(A[i]+a)%M;

 }



 for(int i=0; i<=N; i++){

  ans+=B[A[i]];

  B[A[i]]++;

 }

 std::cout<<ans<<std::endl; 

}

// Faster C++ solution for the same problem (measured speedup: 1.7966449489557197x):
#include<iostream>

#include<vector>

#include<stdlib.h>

#include<time.h>

#include<math.h>

#include<string.h>

#include<algorithm>

#include<queue>

#include<map>

using namespace std;



int main(void){

 int N,M,a;

 map<int,int> B; 

 long long int ans=0;



 cin>>N>>M;

 vector<long long int>A(N+1,0);

 for(int i=1; i<N+1;i++){

  cin>>a;

  A[i]=(A[i-1]+a)%M;

 }

 for(int i=0; i<N+1; i++){

  ans+=B[A[i]];

  B[A[i]]++;

 }

 std::cout<<ans<<std::endl;

}
// Slower C++ solution:
/*

    Author: Alam Khan

    AUST CSE 40th Batch



*/



#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

typedef vector<ll> vl;

typedef deque<ll> dl;

typedef stack<ll> stl;

typedef set<ll> sl;

typedef map<string, ll> msl;

typedef map<ll,ll> mll;

#define sf(n)     scanf("%lld",&n)

#define sff(n,m)     scanf("%lld %lld",&n,&m)

#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)

#define sfs(n)     scanf("%s",n)

#define pf(n)     printf("%lld\n",n)

#define pff(n,m)     printf("%lld %lld\n",n,m)

#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)

#define pfs(n)     printf("%s\n",n)

#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)

#define pb     push_back

#define prf     printf

#define inf     2e18

#define low     -1000000000000

#define PI        acos(-1.0)

#define rep1(i,n) for(i=1;i<n;i++)

#define rep0(i,n) for(i=0;i<n;i++)

#define rep(i,a,n) for(i=a;i<n;i++)

#define repe1(i,n) for(i=1;i<=n;i++)

#define repe0(i,n) for(i=0;i<=n;i++)

#define repe(i,a,n) for(i=a;i<=n;i++)

ll a[100009],arr[100009];

map<ll,ll> ma;

vector<ll> v[100009];

ll sol(ll n)

{

    return (n*(n+1))/2;

}

int main()

{

    ll i,n,t,k,j,x=0,y=0,m;

    sff(n,m);

    rep0(i,n)

    {

        sf(x);

        arr[i] = x;

        if(i==0)

            a[i] = x;

        else a[i] = a[i-1]+x;

        a[i] = a[i]%m;

    }

    ll ind = 0;

    for(i=0;i<n;i++)

    {

        if(ma.find(a[i])==ma.end())

        {

            ma[a[i]] = ind++;

        }

        v[ma[a[i]]].push_back(i);

    }

    /*map<ll,ll> :: iterator it;

    for(it=ma.begin();it!=ma.end();it++)

    {

        cout<<it->first<<endl;

        for(i=0;i<v[it->second].size();i++)

        {

            cout<<v[it->second][i]<<" ";

        }

        cout<<endl;

    }*/

    ll ans =0;

    if(ma.find(0)!=ma.end())

    {

        ans+= v[ma[0]].size();

    }

    x = 0;

    ll hi,lo,mid,temp;

    //cout<<"ans = "<<ans<<endl;

    for(i=0;i<n;i++)

    {

        x+= arr[i];

        x = x%m;

        lo = 0;

        hi = v[ma[x]].size()-1;

        temp  = -1;

        while(lo<=hi)

        {

            mid = (lo+hi)/2;

            if(v[ma[x]][mid]>i)

            {

                temp = mid;

                hi = mid-1;

            }

            else lo = mid+1;

        }

        //pff(x,temp);

        //cout<<v[ma[x]].size()<<endl;

        if(temp!=-1)

        {

            ans+= v[ma[x]].size()-temp;

        }

    }

    pf(ans);





    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 3.4722786678895377x):
#include <bits/stdc++.h>

#include<iostream>

using namespace std;

typedef long long ll;

const int N=1e5+5;

ll m[N],s[N],cum[N];

int main(){

   ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n,m;

   cin>>n>>m;

   map<ll,int>mp;

   ll ans=0;

   cum[0]=0;

   ll sum=0;

   mp[0]=1;

   for(int i=0;i<n;i++){

       int c;

   cin>>c;

    cum[i]=cum[i-1]+c;

    cum[i]%=m;

    ans+=mp[cum[i]];



    mp[cum[i]]++;



   }

   cout<<ans;











    return 0;

}
// Slower C++ solution:
/*

    Author: Alam Khan

    AUST CSE 40th Batch



*/



#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

typedef vector<ll> vl;

typedef deque<ll> dl;

typedef stack<ll> stl;

typedef set<ll> sl;

typedef map<string, ll> msl;

typedef map<ll,ll> mll;

#define sf(n)     scanf("%lld",&n)

#define sff(n,m)     scanf("%lld %lld",&n,&m)

#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)

#define sfs(n)     scanf("%s",n)

#define pf(n)     printf("%lld\n",n)

#define pff(n,m)     printf("%lld %lld\n",n,m)

#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)

#define pfs(n)     printf("%s\n",n)

#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)

#define pb     push_back

#define prf     printf

#define inf     2e18

#define low     -1000000000000

#define PI        acos(-1.0)

#define rep1(i,n) for(i=1;i<n;i++)

#define rep0(i,n) for(i=0;i<n;i++)

#define rep(i,a,n) for(i=a;i<n;i++)

#define repe1(i,n) for(i=1;i<=n;i++)

#define repe0(i,n) for(i=0;i<=n;i++)

#define repe(i,a,n) for(i=a;i<=n;i++)

ll a[100009],arr[100009];

map<ll,ll> ma;

vector<ll> v[100009];

ll sol(ll n)

{

    return (n*(n+1))/2;

}

int main()

{

    ll i,n,t,k,j,x=0,y=0,m;

    sff(n,m);

    rep0(i,n)

    {

        sf(x);

        arr[i] = x;

        if(i==0)

            a[i] = x;

        else a[i] = a[i-1]+x;

        a[i] = a[i]%m;

    }

    ll ind = 0;

    for(i=0;i<n;i++)

    {

        if(ma.find(a[i])==ma.end())

        {

            ma[a[i]] = ind++;

        }

        v[ma[a[i]]].push_back(i);

    }

    /*map<ll,ll> :: iterator it;

    for(it=ma.begin();it!=ma.end();it++)

    {

        cout<<it->first<<endl;

        for(i=0;i<v[it->second].size();i++)

        {

            cout<<v[it->second][i]<<" ";

        }

        cout<<endl;

    }*/

    ll ans =0;

    if(ma.find(0)!=ma.end())

    {

        ans+= v[ma[0]].size();

    }

    x = 0;

    ll hi,lo,mid,temp;

    //cout<<"ans = "<<ans<<endl;

    for(i=0;i<n;i++)

    {

        x+= arr[i];

        x = x%m;

        lo = 0;

        hi = v[ma[x]].size()-1;

        temp  = -1;

        while(lo<=hi)

        {

            mid = (lo+hi)/2;

            if(v[ma[x]][mid]>i)

            {

                temp = mid;

                hi = mid-1;

            }

            else lo = mid+1;

        }

        //pff(x,temp);

        //cout<<v[ma[x]].size()<<endl;

        if(temp!=-1)

        {

            ans+= v[ma[x]].size()-temp;

        }

    }

    pf(ans);





    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 3.4746210378533173x):
#include<bits/stdc++.h>

#define ll long long

#define dbg(x) cout<<#x<<": "<<x<<endl;

#define N 300005

#define M 1000000007

#define pii pair<ll,ll>

#define fast ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

main()

{

    int n,m;

    cin>>n>>m;

    map<ll,ll>mp;

    ll now=0;

    ll ans=0;

    mp[0]++;

    for(int i=0;i<n;i++)

    {

        ll x;

        cin>>x;

        now+=x;

        now%=m;

        ans+=mp[now];

        mp[now]++;

    }

    cout<<ans;

}