#include <bits/stdc++.h>
using namespace std;
int K, B, N;
int in[100010];
map<int, long long> cnt;
int main() {
  scanf("%d%d%d", &K, &B, &N);
  for (int i = 0; i < N; ++i) scanf("%d", &in[i]);
  long long br0 = 0;
  long long last0 = -1;
  for (int i = 0; i < N; ++i)
    if (in[i] != 0)
      last0 = -1;
    else {
      if (last0 == -1) last0 = i;
      br0 += i - last0 + 1;
    }
  int MOD = K - 1;
  long long sbr = 0;
  int tar = B % MOD;
  ++cnt[0];
  int ost = 0;
  for (int i = 0; i < N; ++i) {
    ost = (ost + in[i]) % MOD;
    int cur = (ost - tar) % MOD;
    if (cur < 0) cur += MOD;
    sbr += cnt[cur];
    ++cnt[ost];
  }
  if (B == 0)
    cout << br0 << '\n';
  else if (B == K - 1)
    cout << sbr - br0 << '\n';
  else
    cout << sbr << '\n';
  return 0;
}
