#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ll;
typedef vector<long long> vl;
typedef vector<ll> vll;
typedef vector<vl> vvl;
template <typename T>
ostream &operator<<(ostream &o, vector<T> v) {
  if (v.size() > 0) o << v[0];
  for (unsigned i = 1; i < v.size(); i++) o << " " << v[i];
  return o << "\n";
}
template <typename U, typename V>
ostream &operator<<(ostream &o, pair<U, V> p) {
  return o << "(" << p.first << ", " << p.second << ") ";
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (unsigned i = 0; i < v.size(); i++) in >> v[i];
  return in;
}
template <typename T>
istream &operator>>(istream &in, pair<T, T> &p) {
  in >> p.first;
  in >> p.second;
  return in;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  long long k, b, n;
  cin >> k >> b >> n;
  vl a(n);
  cin >> a;
  map<long long, long long> ma;
  ma[0]++;
  long long tot = 0;
  long long ans = 0;
  long long z = 0;
  for (long long i = (0); i < (long long)n; i++) {
    tot += a[i];
    tot %= (k - 1);
    if (a[i] == 0)
      z++;
    else
      z = 0;
    long long tmp = (tot + k - 1 - b) % (k - 1);
    if (b == k - 1 or b == 0) {
      if (b == 0)
        ans += z;
      else
        ans += ma[tmp] - z;
    } else
      ans += ma[tmp];
    ma[tot]++;
  }
  cout << ans << "\n";
  return 0;
}
