#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
map<long long, long long> num;
long long k, b, n;
long long now;
long long z, sz;
int main() {
  cin >> k >> b >> n;
  long long ans = 0;
  now = 0;
  num[0] = 1;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x != 0)
      z = 0;
    else
      sz += (++z);
    now += x;
    now %= (k - 1);
    ans += num[((now - b) % (k - 1) + (k - 1)) % (k - 1)];
    num[now]++;
  }
  if (b == 0)
    cout << sz << endl;
  else if (b == k - 1)
    cout << ans - sz << endl;
  else
    cout << ans << endl;
  return 0;
}
