#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using VI = vector<int>;
using pii = pair<int, int>;
template <typename A, typename B>
void smin(A &a, const B &b) {
  if (a > b) a = b;
}
template <typename A, typename B>
void smax(A &a, const B &b) {
  if (a < b) a = b;
}
int a[101010], dp[101010];
map<int, int> num;
int main() {
  int k, b, n;
  scanf("%d %d %d", &k, &b, &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  if (!b) {
    INT ans = 0;
    for (int i = 1, j = 1; i <= n; i = j) {
      for (; j <= n && a[i] == a[j]; j++)
        ;
      if (!a[i]) {
        ans += (INT)(j - i + 1) * (j - i) >> 1;
      }
    }
    printf("%I64d", ans);
    return 0;
  }
  k--, b %= k;
  INT ans = 0;
  if (!b) {
    for (int i = 1, j = 1; i <= n; i = j) {
      for (; j <= n && a[i] == a[j]; j++)
        ;
      if (!a[i]) {
        ans -= (INT)(j - i + 1) * (j - i) >> 1;
      }
    }
  }
  num[0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i - 1] + a[i]) % k;
    int first = (dp[i] - b + k) % k;
    ans += num[first];
    num[dp[i]]++;
  }
  printf("%I64d", ans);
}
