#include <bits/stdc++.h>
using namespace std;
long long ADD(long long a, long long b, int base) {
  base--;
  return (a + b + base) % base;
}
map<int, int> store;
int main() {
  store[0] = 1;
  long long base, b, n, a, csum = 0, len = 0, zeros = 0;
  long long ans = 0;
  cin >> base >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0)
      len++;
    else
      zeros += (long long)len * (len + 1) / 2, len = 0;
    csum = ADD(csum, a, base);
    a = ADD(csum, -b, base);
    ans += store[a];
    store[csum]++;
  }
  zeros += (long long)len * (len + 1) / 2;
  if (b == 0)
    cout << zeros << endl;
  else if (b == base - 1)
    cout << ans - zeros << endl;
  else
    cout << ans << endl;
  return 0;
}
