#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 * 1000 + 10;
long long K, B, N;
long long Arr[MAX_N];
long long Sum[MAX_N];
long long Ans, TMP;
map<long long, long long> M;
int main() {
  ios::sync_with_stdio(false);
  cin >> K >> B >> N;
  for (int i = 1; i <= N; i++) {
    cin >> Arr[i];
    Sum[i] = Arr[i] + Sum[i - 1];
    Sum[i] %= (K - 1);
  }
  long long cnt = 0;
  for (int i = 1; i <= N + 1; i++) {
    if (i != N + 1 && Arr[i] == 0)
      cnt++;
    else {
      TMP += (cnt * (cnt + 1)) / 2;
      cnt = 0;
    }
  }
  for (int i = 0; i <= N; i++) {
    long long Temp = Sum[i] % (K - 1);
    long long X = (((Temp - B) % (K - 1)) + (K - 1)) % (K - 1);
    if (M.find(X) != M.end()) Ans += M[X];
    M[Temp]++;
  }
  if (B == K - 1)
    cout << Ans - TMP << endl;
  else if (B == 0)
    cout << TMP << endl;
  else
    cout << Ans << endl;
  return 0;
}
