#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
vector<bool> v;
int main() {
  int k, b, n;
  cin >> k >> b >> n;
  vector<int> v(n + 1);
  vector<std::pair<int, int> > s(n + 1);
  s[0] = make_pair(0, 0);
  long long int res = 0;
  int zeros = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    if (v[i]) {
      res -= zeros * 1ll * (zeros + 1) / 2;
      zeros = 0;
    } else
      zeros++;
    s[i].first = (s[i - 1].first + v[i]) % (k - 1);
    s[i].second = i;
  }
  res -= zeros * 1ll * (zeros + 1) / 2;
  if (b == 0) {
    cout << -res;
    return 0;
  } else if (b != k - 1)
    res = 0;
  sort(s.begin(), s.end());
  for (int i = 1; i <= n; i++) {
    auto iter1 = lower_bound(s.begin(), s.end(),
                             make_pair((s[i].first - b + k - 1) % (k - 1), 0));
    auto iter2 = upper_bound(
        s.begin(), s.end(),
        make_pair((s[i].first - b + k - 1) % (k - 1), s[i].second - 1));
    res += iter2 - iter1;
  }
  cout << res;
}
