#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long k, b, n;
  cin >> k >> b >> n;
  map<long long, long long> mp;
  mp[0] = 1;
  long long zeroes = 0, cont = 0, mod = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x == 0) {
      ++cont;
      zeroes += cont;
    } else
      cont = 0;
    mod = (mod + x) % (k - 1);
    long long temp = (mod + k - 1 - b) % (k - 1);
    ans += mp[temp];
    ++mp[mod];
  }
  if (b == 0)
    cout << zeroes << '\n';
  else if (b == k - 1)
    cout << ans - zeroes << '\n';
  else
    cout << ans << '\n';
  return 0;
}
