#include <bits/stdc++.h>
using namespace std;
map<int, int> ha;
int k, b, n;
int u[100010] = {};
int main() {
  scanf("%d%d%d", &k, &b, &n);
  int mod = 0;
  ha[mod]++;
  long long sum1 = 0;
  long long sum2 = 0;
  int now = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &u[i]);
    if (u[i])
      now = 0;
    else {
      now++;
      sum1 += now;
    }
    mod += u[i];
    mod %= k - 1;
    sum2 += ha[(mod - b + k - 1) % (k - 1)];
    ha[mod]++;
  }
  if (b == 0)
    printf("%I64d", sum1);
  else if (b == k - 1)
    printf("%I64d", sum2 - sum1);
  else
    printf("%I64d", sum2);
  return 0;
}
