#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, tmp, mod;
  long long sum, res;
  map<int, int> MOD{};
  for (int i = 0; i <= N; i++) {
    cin >> tmp;
    sum += tmp;
    mod = sum % M;
    MOD[mod] += 1;
  }
  res = 0;
  for (const auto& [key, value] : MOD) {
    int factorial = 1;
    for (int i = 1; i <= value; i++) {
      factorial *= i;
    }
    res += factorial;
  }
  cout << res << endl;
  return 0;
}
