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