#include <bits/stdc++.h>
using namespace std;
const int maxK = 1000000000 + 5;
const int maxN = 100000 + 5;
int K, B, N;
long long ans = 0, sum = 0, zeroes = 0;
map<int, int> cnt;
int myMod(int a, int b) {
  if (a > 0) return a % b;
  return (b - (-a) % b) % b;
}
int main() {
  cnt[0] = 1;
  scanf("%d%d%d", &K, &B, &N);
  if (!B) {
    for (int i = 1; i <= N; i++) {
      int curr;
      scanf("%d", &curr);
      if (!curr)
        zeroes++;
      else if (zeroes) {
        ans += ((1 + (long long)zeroes) * (long long)zeroes) >> 1;
        zeroes = 0;
      }
    }
    ans += ((1 + (long long)zeroes) * (long long)zeroes) >> 1;
  } else if (B == K - 1) {
    for (int i = 1; i <= N; i++) {
      int curr;
      scanf("%d", &curr);
      sum += curr;
      sum %= K - 1;
      int need = myMod(sum - B, K - 1);
      ans += cnt[need];
      cnt[sum]++;
      if (!curr)
        zeroes++;
      else if (zeroes) {
        ans -= ((1 + (long long)zeroes) * (long long)zeroes) >> 1;
        zeroes = 0;
      }
    }
    ans -= ((1 + (long long)zeroes) * (long long)zeroes) >> 1;
  } else {
    for (int i = 1; i <= N; i++) {
      int curr;
      scanf("%d", &curr);
      sum += curr;
      sum %= K - 1;
      int need = myMod(sum - B, K - 1);
      ans += cnt[need];
      cnt[sum]++;
    }
  }
  cout << ans << endl;
  return 0;
}
