#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
long long k, b, n;
long long an[MAX];
int main() {
  scanf("%lld%lld%lld", &k, &b, &n);
  for (int i = (1); i <= (n); ++i) scanf("%lld", &an[i]);
  long long tmp = 0;
  int i = 1;
  while (i <= n) {
    if (an[i] == 0) {
      int j = i;
      while (j <= n && an[j] == 0) j++;
      long long cnt = j - i;
      tmp += cnt * (cnt - 1) / 2 + cnt;
      i = j;
    } else
      i++;
  }
  if (b == 0) {
    printf("%lld\n", tmp);
  } else {
    unordered_map<long long, int> mm;
    mm[0] = 1;
    long long cur = -1, ans = 0;
    if (b == k - 1) b = 0;
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        cur = an[i] % (k - 1);
      } else {
        cur = (cur + an[i]) % (k - 1);
      }
      long long res = ((cur - b) % (k - 1) + k - 1) % (k - 1);
      ans += mm[res];
      mm[cur]++;
    }
    if (b == 0)
      printf("%lld\n", ans - tmp);
    else
      printf("%lld\n", ans);
  }
  return 0;
}
