#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 123, inf = 1e9, mod = 1e9 + 7, N = 360360;
long long k, b, n, ans, cur, a[maxn];
map<long long, long long> cnt;
int main() {
  cin >> k >> b >> n;
  cnt[0]++;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cur = (cur + a[i]) % (k - 1);
    ans += cnt[(cur - b % (k - 1) + (k - 1)) % (k - 1)];
    cnt[cur]++;
  }
  if (b == 0) {
    cur = 0;
    ans = 0;
    for (int i = 0; i < n; i++)
      if (a[i] == 0)
        cur++, ans += cur;
      else
        cur = 0;
  }
  if (b == k - 1) {
    cur = 0;
    for (int i = 0; i < n; i++)
      if (a[i] == 0)
        cur++, ans -= cur;
      else
        cur = 0;
  }
  cout << ans;
}
