#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T& c) {
  return c.size();
}
long long T[100010];
long long S[100010];
int A[100010];
map<int, int> G;
map<long long, int> F;
int n, k, b;
long long res;
int main() {
  scanf("%d %d %d", &k, &b, &n);
  G[0]++;
  F[0]++;
  for (int i = (1), _b = (n); i <= _b; i++) {
    scanf("%d", &A[i]);
    S[i] = (S[i - 1] + A[i]) % (k - 1);
    if (b != 0) res = res + G[(S[i] - b + k - 1) % (k - 1)];
    G[S[i]]++;
    T[i] = T[i - 1] + A[i];
    if (b == 0)
      res = res + F[T[i]];
    else if (b == k - 1)
      res = res - F[T[i]];
    F[T[i]]++;
  }
  cout << res;
}
