#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 42;
int k, b, n;
int arr[nmax];
map<int, int> seen;
long long zeros() {
  long long ret = 0;
  for (int i = 1; i <= n; i++)
    if (arr[i] == 0) {
      int j = i;
      while (j <= n && arr[j] == 0) j++;
      ret = ret + 1LL * (j - i) * (j - i + 1) / 2;
      j--;
      i = j;
    }
  return ret;
}
int main() {
  cin >> k >> b >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  if (b == 0) {
    cout << zeros() << endl;
    return 0;
  }
  int sum = 0;
  seen[sum]++;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    sum = (sum + arr[i]) % (k - 1);
    ans = ans + seen[(sum - b + k - 1) % (k - 1)];
    seen[sum]++;
  }
  if (b == k - 1) ans = ans - zeros();
  cout << ans << endl;
  return 0;
}
