#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int k, b, n;
vector<int> a;
long long nulCnt() {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      long long len = 0;
      for (; i < n && a[i] == 0; i++) {
        len++;
      }
      res += len * (len + 1) / 2;
    }
  }
  return res;
}
void solve() {
  long long res = 0;
  if (b == 0) {
    res = nulCnt();
  } else {
    int m = k - 1, offset = 0;
    map<int, int> cnt;
    for (int i = n - 1; i >= 0; i--) {
      offset = (offset + a[i]) % m;
      cnt[(m + a[i] - offset) % m]++;
      res += cnt[(m + b - offset) % m];
    }
    if (b == m) {
      res -= nulCnt();
    }
  }
  cout << res << endl;
}
int main() {
  while (cin >> k >> b >> n) {
    a = vector<int>(n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    solve();
  }
}
