#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;

/*-----------------------------------------------------------------------------
　メイン
 -------------------------------------------------------------------------------*/
int main()
{
	ll N, M;
	cin >> N >> M;
	map<ll, ll> mp;
	vector<ll> A(N);
	vector<ll> sum(N + 1, 0);
	REP(i, N) {
		cin >> A[i];
		A[i] %= M;
		sum[i + 1] = sum[i] + A[i];
		sum[i + 1] %= M;
		mp[sum[i + 1]]++;
	}
	
	ll ans = 0;
	for (int i = 0; i <= (M + 1) / 2; i++) {
		ll amari = i;
 		ll amariRev = (M - i) % M;
		ll amariPtn = mp[amari] * (mp[amari] + 1) / 2;
 		ll amariPtnRev = mp[amariRev] * (mp[amariRev] + 1) / 2;
		if (amari == 0) {
			ans += amariPtn;
		} else if (amari == amariRev) {
			ans += (amariPtn / 2) * (amariPtn / 2);
		} else {
			ans += amariPtn * amariPtnRev;
		}
	}
	cout << ans << endl;
	return 0;
}

