#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using std::cerr;
using std::cin;
using std::cos;
using std::cout;
using std::endl;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::next_permutation;
using std::pair;
using std::priority_queue;
using std::queue;
using std::random_shuffle;
using std::set;
using std::sin;
using std::sort;
using std::sqrt;
using std::stack;
using std::string;
using std::stringstream;
using std::swap;
using std::vector;
const long double PI = 3.14159265358979323846;
vector<int> used;
vector<vector<int> > en;
int main() {
  int k, b, n;
  cin >> k >> b >> n;
  vector<int> data(n);
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> data[i];
  }
  long long z = 0;
  long long res0 = 0;
  for (int i = 0; i < n; ++i)
    if (data[i] == 0)
      ++z;
    else {
      res0 += z * (z + 1) / 2;
      z = 0;
    }
  res0 += z * (z + 1) / 2;
  if (b == 0) {
    cout << res0 << endl;
    return 0;
  }
  if (b == k - 1) b = 0;
  vector<int> sum(n + 1);
  map<int, int> num;
  num[0] = 1;
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) {
    sum[i] = (sum[i - 1] + data[i - 1]) % (k - 1);
    int x = (sum[i] - b + k - 1) % (k - 1);
    res += num[x];
    if (num.find(sum[i]) == num.end())
      num[sum[i]] = 1;
    else
      ++num[sum[i]];
  }
  if (b == 0) res -= res0;
  cout << res << endl;
  return 0;
}
