#include <bits/stdc++.h>
int main(void) {
  long int N, M, i, j, *A, count = 0, *B;
  scanf("%ld %ld", &N, &M);
  A = (long int*)malloc(sizeof(long int) * N);
  B = (long int*)malloc(sizeof(long int) * N);
  for (i = 0; i < N; i++) {
    scanf("%ld", &A[i]);
    B[i] = A[i];
    if (A[i] % M == 0) count++;
  }
  for (i = N - 1; i > 0; i--) {
    for (j = 0; j < i; j++) {
      B[j] = B[j + 1] + A[j];
      printf("%ld\n", B[j]);
      if (B[j] % M == 0) count++;
    }
  }
  printf("%ld\n", count);
  return 0;
}
