#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
int a[N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long k, b, n;
  cin >> k >> b >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (b == 0) {
    long long tot = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == 0)
        tot++, ans += tot;
      else
        tot = 0;
    }
  } else {
    map<int, int> mp;
    mp[0]++;
    long long sum = 0;
    long long tot = 0;
    for (int i = 1; i <= n; i++) {
      sum += a[i];
      sum %= k - 1;
      sum = (sum + k - 1) % (k - 1);
      long long x = (sum - b) % (k - 1);
      x = (x + k - 1) % (k - 1);
      ans += mp[x];
      mp[sum]++;
      if (b == k - 1) {
        if (a[i] == 0)
          tot++, ans -= tot;
        else
          tot = 0;
      }
    }
  }
  cout << ans << "\n";
}
