#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int64_t k, b;
  size_t n;
  std::cin >> k >> b >> n;
  std::vector<int64_t> a(n);
  for (size_t i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  int64_t less = 0;
  if (b == 0 || b == k - 1) {
    int64_t result = 0;
    for (size_t i = 0; i < n; ++i) {
      size_t ptr = 0;
      while (i + ptr < n && a[i + ptr] == 0) {
        ptr += 1;
      }
      result += ptr * (ptr + 1) / 2;
      i += ptr;
    }
    if (b == 0) {
      std::cout << result << '\n';
      return 0;
    } else {
      less = result;
      b = 0;
    }
  }
  std::unordered_map<int64_t, int64_t> counts;
  counts[0] = 1;
  int64_t result = 0;
  int64_t sum = 0;
  for (size_t i = 0; i < n; ++i) {
    sum = (sum + a[i]) % (k - 1);
    result += counts[(sum - b + k - 1) % (k - 1)];
    counts[sum] += 1;
  }
  std::cout << result - less << '\n';
}
