#include <bits/stdc++.h>
using namespace std;
map<int, int> mymap;
int vet[100010], sum[100010];
int main() {
  int n, b, k, aux;
  long long res, p, last;
  scanf("%d%d%d", &k, &b, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &vet[i]);
  if (!b) {
    res = p = 0LL;
    for (int i = 1; i <= n; i++) {
      if (vet[i]) {
        res += (p * (p + 1)) / 2;
        p = 0LL;
      } else
        p++;
    }
    res += (p * (p + 1)) / 2;
    cout << res << endl;
    return 0;
  }
  k--;
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = (vet[i] + sum[i - 1]) % k;
  }
  res = 0;
  mymap.clear();
  mymap[0] = 1;
  last = 0LL;
  for (int i = 1; i <= n; i++) {
    aux = (sum[i] - b + k) % k;
    if (vet[i])
      res += mymap[aux];
    else
      res += last;
    if (vet[i]) last = mymap[aux];
    mymap[sum[i]]++;
  }
  cout << res << endl;
  return 0;
}
