#include <bits/stdc++.h>
using namespace std;
int k, b, n;
int a[100100];
int s[100100];
map<int, int> m;
void input() {
  scanf("%d%d%d", &k, &b, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
}
void solve() {
  long long int ans0 = 0;
  for (int i = 0, x = 0; i < n; i++) {
    if (a[i] == 0) {
      x++;
      ans0 += x;
    } else {
      x = 0;
    }
  }
  if (b == 0) {
    cout << ans0 << endl;
    return;
  }
  k--;
  if (b == k) {
    b = 0;
  }
  long long int ans = 0;
  int now = 0, f;
  int idx = 0;
  m[0] = idx;
  s[idx++] = 1;
  for (int i = 0; i < n; i++) {
    now = (now + a[i]) % k;
    f = (now + k - b) % k;
    if (m.find(f) != m.end()) {
      ans += s[m.find(f)->second];
    }
    if (m.find(now) == m.end()) {
      m[now] = idx;
      s[idx] = 1;
      idx++;
    } else {
      s[m.find(now)->second]++;
    }
  }
  if (b == 0) {
    ans -= ans0;
  }
  cout << ans << endl;
}
int main() {
  input();
  solve();
  scanf("%d", &n);
}
