#include <bits/stdc++.h>
using namespace std;
int n, b, k, a[110000], s[110000];
map<int, int> mm;
int main() {
  s[0] = 0;
  mm[0]++;
  long long res = 0;
  int pre = 0;
  scanf("%d %d %d", &b, &k, &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (s[i - 1] == 0 && a[i] == 0)
      s[i] = 0;
    else {
      s[i] = (s[i - 1] + a[i]) % (b - 1);
      if (s[i] == 0) s[i] = b - 1;
    }
    if (a[i] == 0) {
      if (k == 0) pre++;
      res += pre;
    } else {
      if (k == 0)
        pre = 0;
      else {
        int val = (s[i] - k + b - 1) % (b - 1);
        pre = mm[val];
        if (val == 0) pre += mm[b - 1];
      }
      res += pre;
    }
    mm[s[i]]++;
  }
  printf("%I64d\n", res);
  return 0;
}
