#include <bits/stdc++.h>
using namespace std;
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
long long A[100005], B[100005], C[100005];
int main() {
  int k = getnum() - 1, b = getnum(), n = getnum();
  long long ans = 0, z = 0, zero = 0;
  for (int i = 1; i <= n; i++) {
    A[i] = getnum();
    if (A[i] == 0)
      zero++;
    else
      z += zero * (zero + 1) / 2, zero = 0;
  }
  z += zero * (zero + 1) / 2, zero = 0;
  if (b == 0) {
    cout << z;
    return 0;
  }
  for (int i = 1; i <= n; i++) A[i] = (A[i - 1] + A[i]) % k, B[i] = A[i];
  sort(B + 1, B + n + 1);
  int lim = unique(B + 1, B + n + 1) - B - 1;
  for (int i = n; i >= 0; i--) {
    long long x = (A[i] + b) % k;
    int l = lower_bound(B + 1, B + lim + 1, x) - B;
    if (B[l] == x) ans += C[l];
    l = lower_bound(B + 1, B + lim + 1, A[i]) - B;
    C[l]++;
  }
  if (b == k) ans -= z;
  cout << ans;
}
