#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int a[100005];
int sum[100005];
int main() {
  int k, b, n;
  cin >> k >> b >> n;
  int m = k - 1;
  int i, j;
  int pre = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    pre = (pre + a[i]) % m;
    sum[i] = pre;
  }
  long long ans = 0;
  mp.clear();
  mp[0] = 1;
  for (i = 0; i < n; i++) {
    int tmp = (m + sum[i] - b) % m;
    if (mp.find(tmp) != mp.end()) ans += (long long)mp[tmp];
    mp[sum[i]]++;
  }
  long long res = 0;
  for (i = 0; i < n; i = j) {
    j = i;
    int cnt = 0;
    while (j < n && a[i] == a[j] && a[i] == 0) {
      cnt++;
      j++;
    }
    if (cnt > 0) {
      res += (long long)(1 + cnt) * cnt / 2;
    } else
      j++;
  }
  if (b == 0)
    cout << res << endl;
  else if (b == k - 1)
    cout << ans - res << endl;
  else
    cout << ans << endl;
  return 0;
}
