#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
long long ans, sum[100001];
int k, b, n, x, cnt[100001];
int main() {
  cin >> k >> b >> n;
  if (!b) {
    for (long long i = 1; i <= n; i++) {
      cin >> x;
      cnt[0] = (!x) ? (cnt[0] + 1) : 0;
      ans += cnt[0];
    }
    cout << ans << endl;
  } else {
    --k, --b;
    for (long long i = 1; i <= n; i++) {
      cin >> x;
      cnt[i] = (!x) ? (cnt[i - 1] + 1) : 0;
      sum[i] = (sum[i - 1] + x) % k;
    }
    m[0] = 1;
    for (long long i = 1; i <= n; i++) {
      long long tmp = (sum[i] - b - 1 + k) % k;
      ans += m[tmp];
      m[sum[i]]++;
      if (tmp == sum[i]) ans -= cnt[i];
    }
    cout << ans << endl;
  }
}
