#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to;
  long long cost;
};
constexpr double PI = 3.14159265358979323846;
constexpr long long INF = 1 << 15;
constexpr long long MOD = (long long)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = {0, 1, 0, -1};
constexpr int dx[4] = {1, 0, -1, 0};
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (T& x : vec) os << x << " ";
  return os;
}
int main(void) {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N);
  cin >> A;
  for (long long i = (long long)0; i < (long long)N; ++i) {
    A[i] = A[i] % M;
  }
  int l = 0, r = 0;
  long long sum = A[0];
  long long ans = 0;
  while (true) {
    cout << l << ' ' << r << ' ' << sum << endl;
    if (sum % M == 0) {
      ans++;
      if (l < r) {
        sum -= A[l];
        l++;
      } else {
        if (r < N - 1) {
          r++;
          sum += A[r];
        } else {
          cout << ans << endl;
          return 0;
        }
      }
    } else {
      if (sum > M) {
        if (l < r) {
          sum -= A[l];
          l++;
        } else {
          r++;
          if (r >= N) {
            cout << ans << endl;
            return 0;
          } else {
            sum += A[r];
          }
        }
      } else {
        r++;
        if (r >= N) {
          cout << ans << endl;
          return 0;
        } else {
          sum += A[r];
        }
      }
    }
  }
  return 0;
}
