#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
map<long long, long long> mp;
long long k, b, n;
long long mod, ans0, ans;
int main() {
  scanf("%I64d %I64d %I64d", &k, &b, &n);
  mod = 0;
  ans0 = 0;
  mp.clear();
  ans = 0;
  mp[0] = 1;
  long long num = 0;
  for (long long i = (1); i <= (n); ++i) {
    long long x;
    scanf("%I64d", &x);
    if (x == 0) {
      num++;
      ans0 += num;
    } else
      num = 0;
    mod += x;
    mod %= k - 1;
    ans += mp[(mod - b + k - 1) % (k - 1)];
    mp[mod]++;
  }
  if (b == 0)
    printf("%I64d\n", ans0);
  else if (b == k - 1)
    printf("%I64d\n", ans - ans0);
  else
    printf("%I64d\n", ans);
}
