#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const int maxn = 100000 + 10;
map<int, int> mp;
int k, b, n;
int rec[maxn];
int main() {
  while (scanf("%d%d%d", &k, &b, &n) == 3) {
    mp.clear();
    rec[0] = 0;
    mp[0] = 1;
    long long ans = 0, ans1 = 0;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      int x;
      scanf("%d", &x);
      if (x == 0) {
        ++cnt;
      } else {
        ans1 += (long long)cnt * (cnt + 1) / 2;
        cnt = 0;
      }
      rec[i] = (rec[i - 1] + x) % (k - 1);
      ans += mp[(rec[i] - b + k - 1) % (k - 1)];
      ++mp[rec[i]];
    }
    if (cnt) ans1 += (long long)cnt * (cnt + 1) / 2;
    if (b == 0)
      printf("%I64d\n", ans1);
    else if (b == k - 1)
      printf("%I64d\n", ans - ans1);
    else
      printf("%I64d\n", ans);
  }
  return 0;
}
