#include <iostream>
#include <vector>
#include <unordered_map>
#include <numeric>
#include <cassert>

using namespace std;

constexpr int MAX_M = 10'000;
std::array<int, MAX_M> cnt;

long long nchoose2(int n){
  return 1LL * n * (n - 1) / 2;
}

long long nchoose3(int n){
  return 1LL * n * (n - 1) * (n - 2) / 6;
}

int main(){
  ios_base::sync_with_stdio(false);

  int N, M;
  assert(cin >> N >> M);
  assert(1 <= N && N <= 200'000);
  assert(1 <= M && M <= 10'000);

  for (int i = 0; i < N; i++){
    int x;
    assert(cin >> x);
    assert(0 <= x && x <= 2'000'000'000);
    cnt[x % M]++;
  }

  long long answer = 0;

  for (int i = 0; i < M; i++){
    if (cnt[i] > 0){
      for (int j = i; j < M; j++){
        if (cnt[j] > 0){
          int sum = (i + j) % M;
          int k = (M - sum + M) % M;

          if (i <= j && j <= k){
            if (i == j && j == k){
              answer += nchoose3(cnt[i]);
            }
            else if (i == j){
              answer += nchoose2(cnt[i]) * cnt[k];
            }
            else if (j == k){
              answer += nchoose2(cnt[j]) * cnt[i];
            }
            else{
              answer += 1LL * cnt[i] * cnt[j] * cnt[k];
            }
          }
        }
      }
    }
  }

  cout << answer << "\n";

  return 0;
}
