#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, M;
  cin >> N >> M;
  long long int a[N];
  long long int tmp;
  long long int sum = 0;
  long long int ans = 0;
  long long int ans2 = 1;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    a[i] = tmp % M;
  }
  for (int i = 0; i < N; i++) {
    sum += a[i];
    if (sum % M == 0) {
      sum = 0;
      ans += 1;
    }
  }
  while (ans > 0) {
    ans2 = ans * ans2;
    ans -= 1;
  }
  ans2 = 0.5 * ans2 * (ans2 + 1);
  cout << ans2 << endl;
  ;
}
