#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
  return out << p.first << ' ' << p.second;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {
    out << *i << ' ';
  }
  return out;
}
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &p) {
  return in >> p.first >> p.second;
}
template <class T>
istream &operator>>(istream &in, vector<T> &v) {
  for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {
    in >> (*i);
  }
  return in;
}
template <class T>
ostream &operator,(ostream &out, const T &t) {
  return out << t;
}
template <class T>
istream &operator,(istream &in, T &t) {
  return in >> t;
}
int io_init() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout, fixed, setprecision(9);
  return 1;
}
int _io_dummy = io_init();
template <class T, class U>
bool remin(T &a, const U &b) {
  return b < a ? a = b, true : false;
}
template <class T, class U>
bool remax(T &a, const U &b) {
  return b > a ? a = b, true : false;
}
long long solve(int k, int b, const vector<int> &v) {
  long long ans = 0;
  if (!b) {
    int l = 0;
    for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {
      if (!*i) {
        ans += ++l;
      } else {
        l = 0;
      }
    }
    return ans;
  }
  if (b == k) ans = -solve(k, 0, v);
  b = (-b + k) % k;
  map<int, int> cnt;
  cnt[0] = 1;
  int s = 0;
  for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {
    s = (s + *i) % k;
    ans += cnt[(s + b) % k];
    ++cnt[s];
  }
  return ans;
}
int main() {
  int k, b, n;
  cin, k, b, n;
  vector<int> v(n);
  cin, v;
  cout, solve(k - 1, b, v), '\n';
}
