#include <bits/stdc++.h>
using namespace std;
long long a[100000];
map<int, int> s;
int main() {
  long long k, b, n;
  cin >> k >> b >> n;
  for (long long ni = 0; ni < n; ni++) cin >> a[ni];
  long long count = 0;
  long long dr = 0;
  long long zeroc = 0;
  long long seq = 0;
  for (int ni = 0; ni < n; ni++) {
    if (a[ni] == 0)
      zeroc += ++seq;
    else
      seq = 0;
  }
  for (int ni = 0; ni < n; ni++) {
    s[dr]++;
    dr = (dr + a[ni]) % (k - 1);
    count += s[(dr - b + k - 1) % (k - 1)];
  }
  if (b == 0)
    cout << zeroc << endl;
  else if (b == k - 1)
    cout << count - zeroc << endl;
  else
    cout << count << endl;
  return 0;
}
