#include <bits/stdc++.h>
using namespace std;
map<long long, int> cnt;
long long sum[100100], a[100100];
int main() {
  int k, b, n;
  long long ans = 0, rans = 0;
  cin >> k >> b >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  int pl = 0;
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = (sum[i - 1] + a[i]) % (k - 1);
    if (a[i])
      pl = 0;
    else
      pl++, ans += pl;
  }
  if (!b) {
    cout << ans << endl;
    return 0;
  }
  cnt[0] = 1;
  for (int i = 1; i <= n; i++) {
    rans += cnt[(sum[i] - b + k - 1) % (k - 1)];
    cnt[sum[i]]++;
  }
  if (b != k - 1) {
    cout << rans << endl;
    return 0;
  }
  cout << rans - ans << endl;
  return 0;
}
