#include <bits/stdc++.h>
using namespace std;
const double PI = acos(0) * 2;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
long long k, b, n, a[100100];
map<long long, int> mm;
int main() {
  cin >> k >> b >> n;
  long long t = k - 1;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long ans = 0;
  long long sum = 0;
  mm[0] = 1;
  for (int i = 1; i <= n; i++) {
    (sum += a[i]) %= t;
    long long p = (sum + t - b) % t;
    if (mm.find(p) != mm.end()) {
      ans += mm[p];
    }
    mm[sum]++;
  }
  long long cnt = 0, mi = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0)
      cnt++;
    else {
      mi += (cnt + 1) * cnt / 2LL;
      cnt = 0;
    }
  }
  mi += (cnt + 1) * cnt / 2LL;
  if (b == 0)
    ans = mi;
  else if (b == t)
    ans -= mi;
  cout << ans;
}
