#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m, k, b;
int x[100000];
map<int, int> all;
int main() {
  scanf("%d%d%d", &k, &b, &n);
  int bb = b % (k - 1);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  int cur = 0;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    all[cur]++;
    cur = (cur + x[i]) % (k - 1);
    int tmp = (cur - bb + k - 1) % (k - 1);
    ans += all[tmp];
  }
  long long ans0 = 0;
  cur = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == 0)
      cur++;
    else
      cur = 0;
    ans0 += cur;
  }
  if (b == 0)
    ans = ans0;
  else if (bb == 0)
    ans -= ans0;
  cout << ans << endl;
  return 0;
}
