import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n, k;
  readf (" %d %d", &n, &k);
  auto a = new int[n];
  foreach (i; 0 .. n) {
    readf (" %d", &a[i]);
  }
  auto c = new int[n+1];
  foreach (i; 1 .. n + 1) {
    c[i] = (c[i-1] + a[i-1]) % k;
  }
  auto s = c.dup;
  debug stderr.writeln ("c = ", c);
  foreach (i; 0 .. n + 1) {
    c[i] = (c[i] - i) % k;
    if (c[i] < 0) c[i] += k;
  }
  debug stderr.writeln ("c = ", c);
  int[][int] h;
  long res;
  foreach_reverse (i; 0 .. n + 1) {
    auto ptr = c[i] in h;
    if (ptr !is null) {
      foreach (l; *ptr) {
        int o = s[l] - s[i];
        if (o < 0) o += k;
        if (o == l - i) {
          debug stderr.writefln ("%d %d", i, l);
          ++res;
        }
      }
      (*ptr) ~= i;
    } else {
      h[c[i]] = [i];
    }
  }
  writeln (res);
}

