#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
int in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
long long A[101000];
long long acum[101000];
void solve() {
  int K = in();
  int B = in();
  int N = in();
  int M = K - 1;
  int i;
  long long voy = 0;
  acum[0] = 0;
  for (i = 1; i <= N; i++) {
    A[i] = in();
    if (A[i] == 0) {
      acum[i] = acum[i - 1] + 1;
    } else {
      acum[i] = 0;
    }
  }
  acum[N + 1] = 0;
  long long ceroes = 0;
  for (i = 1; i <= N + 1; i++) {
    if (acum[i] == 0) ceroes += ((acum[i - 1]) * (acum[i - 1] + 1) / 2);
  }
  if (B == 0) {
    cout << ceroes << endl;
    return;
  }
  long long ans = 0;
  map<int, long long> pref;
  pref[0] = 1;
  voy = 0;
  for (i = 1; i <= N; i++) {
    voy += A[i];
    ans += pref[(((voy % M - B) % M) + M) % M];
    pref[voy % M]++;
  }
  if (B == M) ans -= ceroes;
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
