#include <bits/stdc++.h>
using namespace std;
int a[100005];
map<int, int> s;
int main(void) {
  long long ans = 0, z = 0;
  int k, b, n;
  scanf("%d%d%d", &k, &b, &n);
  int zcnt = 0;
  s[0]++;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    zcnt = (a[i] ? 0 : zcnt + 1);
    z += zcnt;
    a[i] = (a[i] + a[i - 1]) % (k - 1);
    int P = (a[i] - b + k - 1) % (k - 1);
    ans += s[P];
    s[a[i]]++;
  }
  if (b == 0)
    ans = z;
  else if (b == k - 1)
    ans -= z;
  printf("%I64d\n", ans);
  return 0;
}
