#include <bits/stdc++.h>
using namespace std;
const int N(100002);
int A[N];
map<int, int> dp;
int lucky, base, n;
long long calczero() {
  long long consec = 0, all = 0;
  for (int i = 1; i <= n + 1; ++i) {
    if (A[i] == 0) {
      consec++;
    } else {
      all += ((consec * (consec + 1)) >> 1);
      consec = 0;
    }
  }
  return all;
}
int main() {
  cin >> base >> lucky >> n;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  A[n + 1] = 1;
  if (lucky == 0) {
    cout << calczero() << endl;
    return 0;
  }
  base--;
  int shift = 0;
  long long ans = 0;
  map<int, int>::iterator x;
  for (int i = 1; i <= n; ++i) {
    shift -= A[i];
    shift %= base;
    dp[(((shift + A[i]) % base) + base) % base]++;
    if ((x = dp.find((((shift + lucky) % base) + base) % base)) != dp.end())
      ans += (long long)x->second;
  }
  if (lucky == base) ans -= calczero();
  cout << ans << endl;
  return 0;
}
