#include <bits/stdc++.h>
using namespace std;
int k, b, n;
const int maxn = (int)1e5;
int a[maxn];
inline int mmod(int x) {
  return x < 0 ? x + k - 1 : x >= k - 1 ? x - (k - 1) : x;
}
long long count() {
  int added = 0;
  map<int, int> rs;
  int bn = mmod(b);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    added = mmod(added + mmod(a[i]));
    int toins = mmod(a[i] - added);
    if (rs.count(toins))
      rs[toins]++;
    else
      rs[toins] = 1;
    int toget = mmod(bn - added);
    if (rs.count(toget)) res += rs[toget];
  }
  return res;
}
long long countzero() {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (i && !a[i - 1]) continue;
    for (int j = i; j < n && !a[j]; j++) res += j - i + 1;
  }
  return res;
}
int main() {
  while (scanf("%d%d%d", &k, &b, &n) >= 1) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    if (!b)
      printf(
          "%lld"
          "\n",
          countzero());
    else {
      if (b == k - 1)
        printf(
            "%lld"
            "\n",
            count() - countzero());
      else
        printf(
            "%lld"
            "\n",
            count());
    }
  }
  return 0;
}
