#include <bits/stdc++.h>
using namespace std;
long long lf[101000];
map<long long, int> mp;
int main() {
  long long k, b, n, ret, ze, cnt;
  int x;
  while (cin >> k >> b >> n) {
    lf[0] = 0;
    ret = 0;
    ze = 0;
    cnt = 0;
    mp.clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      lf[i] = (lf[i - 1] + x) % (k - 1);
      if (x == 0)
        cnt++;
      else
        ze += cnt * (cnt + 1) / 2, cnt = 0;
    }
    ze += (cnt + 1) * cnt / 2;
    long long y;
    for (int i = 0; i <= n; i++) {
      if (mp.count(lf[i]) > 0) ret += mp[lf[i]];
      y = (lf[i] + b) % (k - 1);
      if (mp.count(y) > 0)
        mp[y]++;
      else
        mp[y] = 1;
    }
    if (b == k - 1)
      ret -= ze;
    else if (b == 0)
      ret = ze;
    cout << ret << endl;
  }
  return 0;
}
