#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
map<int, int> M;
int main() {
  int k, b, n;
  scanf("%d%d%d", &k, &b, &n);
  int cur = 0;
  long long z = 0;
  for (int j = 0; j < (int)n; j++) {
    scanf("%d", &a[j]);
    if (a[j] == 0) {
      cur++;
      z += cur;
    } else
      cur = 0;
  }
  if (b == 0) {
    cout << z;
    exit(0);
  }
  int sum_suff = 0;
  long long ans = 0;
  M[0] = 1;
  for (int pos = n - 1; pos >= 0; pos--) {
    sum_suff = (sum_suff + a[pos]) % (k - 1);
    int need = (-b + sum_suff + k - 1) % (k - 1);
    int to_add = M[need];
    ans += to_add;
    M[sum_suff] += 1;
  }
  if (b == k - 1) ans -= z;
  cout << ans;
}
