#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
void xmax(long long& a, long long b) { a = max(a, b); }
void xmin(long long& a, long long b) { a = min(a, b); }
void print(vc<long long>& a, string second) {
  cerr << "prinitng " << second << "\n";
  for (long long i = 0; i < a.size(); i++) {
    cerr << a[i] << " ";
  }
  cerr << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long k, b, n;
  map<long long, long long> anz;
  map<long long, long long> anz_null;
  anz_null[0] = 1;
  anz[0] = 1;
  cin >> k >> b >> n;
  k--;
  long long bb = b;
  b = b % k;
  long long sum = 0;
  long long cur = 0;
  vc<long long> aa(n);
  for (long long i = 0; i < n; i++) {
    cin >> aa[i];
  }
  long long cur_sum = 0;
  long long null_sum = 0;
  for (long long i = 0; i < n; i++) {
    long long a = aa[i];
    cur = (cur + a) % k;
    cur_sum += a;
    long long last = (cur + k - b) % k;
    long long add = anz[last];
    sum += add;
    long long add_null = anz_null[cur_sum];
    null_sum += add_null;
    anz[cur]++;
    anz_null[cur_sum]++;
  }
  if (bb == k) {
    cout << sum - null_sum << "\n";
  } else if (bb == 0) {
    cout << null_sum << "\n";
  } else
    cout << sum << "\n";
}
