#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long MOD = 1e9 + 7;
const int N = 1e5 + 7;
long long k, b, n;
long long a[N], c[N];
map<int, int> mp;
long long calc(long long n) {
  int l = 0;
  long long ret = 0;
  int pr = 1;
  while (pr <= n) {
    if (c[pr]) {
      ret += (1LL * l + 1) * (long long)l / 2LL;
      l = 0;
      pr++;
      continue;
    } else {
      pr++;
      l++;
    }
  }
  ret += (1LL * l + 1) * (long long)l / 2LL;
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> k >> b >> n;
  for (int i = int(1); i <= int(n); ++i) cin >> a[i], c[i] = a[i];
  long long ans = 0;
  if (!b) {
    ans = calc(n);
    cout << ans << endl;
    return 0;
  }
  if (k == 2) {
    ans = n * (n + 1LL) / 2 - calc(n);
    cout << ans << endl;
    return 0;
  }
  b %= (k - 1);
  for (int i = int(1); i <= int(n); ++i) a[i] %= (k - 1);
  mp[0] = 1;
  long long pre = 0;
  for (int i = int(1); i <= int(n); ++i) {
    (pre += a[i]) %= (k - 1);
    ans += mp[(pre - b + k - 1) % (k - 1)];
    mp[pre] = mp[pre] + 1;
  }
  if (b == 0) ans -= calc(n);
  cout << ans << endl;
}
