#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
long long k, b, n;
long long a[maxn];
void work() {
  k--;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long res = 0;
  map<long long, long long> Map;
  long long sum = 0;
  Map[sum]++;
  for (int i = 1; i <= n; i++) {
    sum = (sum + a[i]) % k;
    long long x = (sum - b + k) % k;
    if (Map.find(x) != Map.end()) res += Map[x];
    Map[sum]++;
  }
  if (b == k || b == 0) {
    if (b == 0) res = 0;
    long long tmp = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] == 0)
        tmp++;
      else {
        if (b == k)
          res -= tmp * (tmp + 1) / 2;
        else
          res += tmp * (tmp + 1) / 2;
        tmp = 0;
      }
    if (b == k)
      res -= tmp * (tmp + 1) / 2;
    else
      res += tmp * (tmp + 1) / 2;
  }
  cout << res << endl;
}
int main() {
  while (cin >> k >> b >> n) work();
}
