#include <bits/stdc++.h>
using namespace std;
using cat = long long;
int D, M;
vector<int> gen;
vector<vector<vector<cat> > > cnt;
void solve_cnt(int max_dig) {
  vector<vector<cat> > cnt_sum(max_dig + 1, vector<cat>(M, 0));
  cnt_sum[0][0] = 1;
  for (int i = 0; i < max_dig; i++)
    for (int j = 0; j < M; j++)
      for (int k = 0; k < D; k++)
        cnt_sum[i + 1][(j + gen[k]) % M] += cnt_sum[i][j];
  cnt.resize(max_dig + 1, vector<vector<cat> >(D, vector<cat>(M, 0)));
  for (int i = 0; i < max_dig; i++)
    for (int j = 0; j < M; j++)
      for (int k = 0; k < D; k++) cnt[i][k][(j + gen[k]) % M] += cnt_sum[i][j];
  for (int i = 0; i <= max_dig; i++)
    for (int j = 0; j < M; j++)
      for (int k = 1; k < D; k++) cnt[i][k][j] += cnt[i][k - 1][j];
}
cat solve_leaf(cat A_mask, cat Xl, cat Xr) {
  cat ret = 0;
  static vector<char> Vl;
  Vl.clear();
  static vector<char> Vr;
  Vr.clear();
  while (Xl) {
    Vl.push_back(Xl % D);
    Xl /= D;
  }
  while (Xr) {
    Vr.push_back(Xr % D);
    Xr /= D;
  }
  while (!Vl.empty() && !Vr.empty() && Vl.size() == Vr.size() &&
         Vl.back() == Vr.back()) {
    int s = gen[Vl.back()];
    A_mask = (A_mask >> s) | ((A_mask & ((1LL << s) - 1)) << (M - s));
    Vl.pop_back();
    Vr.pop_back();
  }
  for (int i = (int)Vr.size() - 1, s = 0; i >= 0; i--) {
    cat mask = (A_mask >> s) | ((A_mask & ((1LL << s) - 1)) << (M - s));
    if (Vr[i])
      for (int k = 0; mask; k++, mask >>= 1)
        ret += cnt[i][Vr[i] - 1][k] * (mask & 1);
    s += gen[Vr[i]];
    if (s >= M) s -= M;
  }
  for (int i = (int)Vl.size() - 1, s = 0; i >= 0; i--) {
    cat mask = (A_mask >> s) | ((A_mask & ((1LL << s) - 1)) << (M - s));
    if (Vl[i])
      for (int k = 0; mask; k++, mask >>= 1)
        ret -= cnt[i][Vl[i] - 1][k] * (mask & 1);
    s += gen[Vl[i]];
    if (s >= M) s -= M;
  }
  return ret;
}
cat solve_recursive(vector<cat>& A_mask, cat Xl, cat Xr) {
  int N = A_mask.size();
  cat ret = 0;
  for (int i = 0; i < D; i++) {
    if (Xr - 1 - i < 0) break;
    vector<cat> A_mask_new;
    A_mask_new.reserve(A_mask.size() / D + 2);
    for (int j = 0, k = i, l = 0; j < N; j++, k++) {
      if (k == D) k = 0, l++;
      int g = gen[k];
      cat mask_new =
          (A_mask[j] >> g) | ((A_mask[j] & ((1LL << g) - 1)) << (M - g));
      if ((int)A_mask_new.size() == l) A_mask_new.push_back((1LL << M) - 1);
      A_mask_new[l] &= mask_new;
    }
    if (A_mask_new.size() == 1)
      ret += solve_leaf(A_mask_new[0],
                        (Xl - 1 - i >= 0) ? (Xl - 1 - i) / D + 1 : 0,
                        (Xr - 1 - i) / D + 1);
    else
      ret += solve_recursive(A_mask_new,
                             (Xl - 1 - i >= 0) ? (Xl - 1 - i) / D + 1 : 0,
                             (Xr - 1 - i) / D + 1);
  }
  return ret;
}
cat solve(vector<int>& B, cat Xl, cat Xr) {
  int N = B.size();
  vector<cat> A_mask(N);
  for (int i = 0; i < N; i++) A_mask[i] = (1LL << (B[i] + 1)) - 1;
  if (N == 1)
    return solve_leaf(A_mask[0], Xl, Xr);
  else
    return solve_recursive(A_mask, Xl, Xr);
}
int main() {
  cin.sync_with_stdio(0);
  cin >> D >> M;
  gen.resize(D);
  for (int i = 0; i < D; i++) cin >> gen[i];
  solve_cnt(100);
  int N;
  cin >> N;
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B[i];
  cat L, R;
  cin >> L >> R;
  L--, R--;
  cout << solve(B, L, R - N + 2) << "\n";
}
