#include <bits/stdc++.h>
template <class T>
inline T MAX(T a, T b) {
  if (a > b) return a;
  return b;
}
template <class T>
inline T MIN(T a, T b) {
  if (a < b) return a;
  return b;
}
template <class T>
inline T ABS(T x) {
  if (x < 0) return -x;
  return x;
}
using namespace std;
inline void OPEN(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
int K, B, N;
int A[100000 + 5], second[100000 + 5];
map<int, int> MAP;
int main() {
  scanf("%d%d%d", &K, &B, &N);
  int Bawel = B;
  B %= K - 1;
  for (int i = 0, _n = (N); i < _n; i++) scanf("%d", &A[i]);
  MAP[0] = 1;
  long long ret = 0;
  long long males = 0;
  int nol = 0;
  for (int i = 0, _n = (N); i < _n; i++) {
    if (i == 0)
      second[i] = A[i];
    else
      second[i] = A[i] + second[i - 1];
    second[i] %= (K - 1);
    int cari = (second[i] - B + (K - 1)) % (K - 1);
    ret += MAP[cari];
    if (A[i] == 0)
      nol++;
    else
      nol = 0;
    males += nol;
    MAP[second[i]]++;
  }
  if (Bawel == 0)
    cout << males << endl;
  else if (B == 0)
    cout << ret - males << endl;
  else
    cout << ret << endl;
  return 0;
}
