#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int a[100100], s[100100];
map<int, int> mp;
int main() {
  int k, b, n;
  cin >> k >> b >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  INT ans = 0;
  for (int i = 1; i <= n; i++) s[i] = (s[i - 1] + a[i]) % (k - 1);
  for (int i = n; i >= 1; i--) {
    mp[s[i]]++;
    int d = (s[i - 1] + b) % (k - 1);
    ans += mp[d];
  }
  INT cnt = 0, ct = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i]) {
      cnt += ct * (ct + 1) / 2;
      ct = 0;
      continue;
    }
    ct++;
  }
  cnt += ct * (ct + 1) / 2;
  if (b % (k - 1)) {
    cout << ans << endl;
    return 0;
  }
  if (b) {
    ans -= cnt;
    cout << ans << endl;
    return 0;
  }
  cout << cnt << endl;
  return 0;
}
