#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int k, b, n, s[N];
map<int, int> a;
long long ans, cnt;
int main() {
  cin >> k >> b >> n;
  long long t = 0;
  k--;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x == 0)
      t++;
    else
      cnt += t * (t + 1) / 2, t = 0;
    s[i] = (s[i - 1] + x) % k;
    a[s[i - 1]]++;
    ans += a[(s[i] + k - b) % k];
  }
  cnt += t * (t + 1) / 2;
  if (b == 0) {
    cout << cnt;
    return 0;
  }
  if (k == b) ans -= cnt;
  cout << ans;
}
