#include <bits/stdc++.h>
using namespace std;
int n, b, m;
int a[100009], sum[100009];
map<int, int> h;
int main() {
  cin >> b >> m >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = (sum[i - 1] + a[i]) % (b - 1);
  }
  long long zero = 0, t = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0)
      t++;
    else {
      zero += 1ll * t * (t + 1) / 2;
      t = 0;
    }
  }
  if (t) zero += 1ll * t * (t + 1) / 2;
  if (m == 0) {
    cout << zero << endl;
    return 0;
  }
  long long ans = 0;
  h[0]++;
  for (int i = 1; i <= n; i++) {
    int t = ((sum[i] - m) % (b - 1) + (b - 1)) % (b - 1);
    ans += h[t];
    h[sum[i]]++;
  }
  if (m == b - 1) ans -= zero;
  cout << ans << endl;
}
