#include <bits/stdc++.h>
using namespace std;
long long int a[100005];
int main() {
  long long int n, b, k;
  cin >> k >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int ans = 0;
  if (b == 0) {
    for (int i = 0; i < n;) {
      long long int now = a[i];
      long long int cnt = 0;
      while (i < n && a[i] == now) {
        i++;
        cnt++;
      }
      if (now == 0) {
        ans += (cnt * (cnt + 1) / 2);
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (b == k - 1) b = 0;
  long long int ans2 = 0;
  if (b == 0) {
    for (int i = 0; i < n;) {
      long long int now = a[i];
      long long int cnt = 0;
      while (i < n && a[i] == now) {
        i++;
        cnt++;
      }
      if (now == 0) {
        ans2 += (cnt * (cnt + 1) / 2);
      }
    }
  }
  map<long long int, long long int> mp;
  mp[0]++;
  for (int i = 0; i < n; i++) {
    if (i > 0) a[i] += a[i - 1];
    long long int mod = a[i] % (k - 1);
    long long int need = (mod - b + k + k - 2) % (k - 1);
    if (mp.find(need) != mp.end()) {
      ans += mp[need];
    }
    mp[mod]++;
  }
  cout << ans - ans2 << endl;
  return 0;
}
