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