#include <bits/stdc++.h>
using namespace std;
void ASS(bool bb) {
  if (!bb) {
    ++*(int*)0;
  }
}
#pragma comment(linker, "/STACK:106777216")
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int k, b, n;
  k = read();
  b = read();
  n = read();
  map<int, int> mp;
  int s = 0;
  int zer = 0;
  long long res = 0;
  for (int i = 0; i < (int)(n); i++) {
    ++mp[s];
    int x = read();
    s = (s + x) % (k - 1);
    if (x == 0)
      zer++;
    else
      zer = 0;
    if (b == 0)
      res += zer;
    else {
      res += mp[(s + k - 1 - b) % (k - 1)];
      if (b == k - 1) res -= zer;
    }
  }
  cout << res << endl;
  return 0;
}
