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