#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int MN = 100111;
int k, b, n;
int a[MN], s[MN];
long long solve0() {
  int i = 1;
  long long res = 0;
  while (i <= n) {
    if (a[i]) {
      ++i;
      continue;
    } else {
      int j = i;
      while (j < n && a[j + 1] == 0) {
        ++j;
      }
      long long l = j - i + 1;
      res += l * (l + 1) / 2;
      i = j + 1;
    }
  }
  return res;
}
map<int, int> m;
long long solve() {
  long long res = 0;
  m.clear();
  m[0] = 1;
  b %= (k - 1);
  for (int i = (1), _b = (n); i <= _b; i++) {
    int need = s[i] - b;
    if (need < 0) need += k - 1;
    res += m[need];
    m[s[i]]++;
  }
  return res;
}
int main() {
  while (scanf("%d%d%d", &k, &b, &n) == 3) {
    for (int i = (1), _b = (n); i <= _b; i++) {
      scanf("%d", &a[i]);
      s[i] = (s[i - 1] + a[i]) % (k - 1);
    }
    long long res;
    if (b == 0)
      res = solve0();
    else if (b == k - 1)
      res = solve() - solve0();
    else
      res = solve();
    cout << res << endl;
  }
  return 0;
}
