import std;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
  int n = scan!int;
  long k = scan!long;
  long[] as = scan!long(n);
  long[] bs = as.map!(x => (x - 1) % k).array;
  long[] sums = [0];
  foreach(b; bs) sums ~= (sums[$ - 1] + b) % k;
  log("as:", as);
  log("bs:", bs);
  log("sums:", sums);
  
  long ans = 0;
  long[long] cnt;
  foreach(i; 0 .. n + 1){
    if(i >= k) cnt[sums[i - k]] -= 1;
    long s = sums[i];
    if(s !in cnt) cnt[s] = 0;
    ans += cnt[s];
    cnt[s] += 1;
    log("i:", i, "s:", s, "cnt:", cnt, "ans:", ans);
  }
  
  ans.writeln;
}