#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 4;
const int K = 26;
const int inf = (int)1e9 + 7;
char s[N];
int p[N], a[N], t[N];
int main() {
  int n, b, k;
  scanf("%d%d%d", &k, &b, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int x = -1;
  for (int i = 0; i < n; ++i) {
    if (a[i] == 0 && x == -1) {
      x = i;
    }
    if (a[i] != 0) {
      x = -1;
      t[i] = i + 1;
    } else {
      t[i] = x;
    }
  }
  for (int i = 0; i < n; ++i) {
    p[i] = ((i > 0 ? p[i - 1] : 0) + a[i]) % (k - 1);
  }
  map<int, int> m;
  m[0]++;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (b == 0) {
      ans += i - t[i] + 1;
      continue;
    }
    ans += m[(p[i] - b + k - 1) % (k - 1)] -
           (b == k - 1 && a[i] == 0 ? i - t[i] + 1 : 0);
    m[p[i]]++;
  }
  printf("%lld", ans);
  return 0;
}
