#include <bits/stdc++.h>
using namespace std;
int cnt, len, n, m, pt, gen[209], p[209], b[30009];
long long l, r, ans, dp[209][209];
map<long long, int> mp;
int read() {
  int x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
long long readll() {
  long long x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
int calc(long long x) {
  if (mp[x]) return mp[x];
  mp[x] = ++pt;
  static int p[209];
  static long long f[209][209][2];
  int len = 0;
  for (; x; x /= cnt) p[++len] = x % cnt;
  memset(f, 0, sizeof(f));
  f[0][0][1] = 1;
  int i, j, k, l;
  for (i = 1; i <= len; i++)
    for (j = 0; j < m; j++)
      for (k = 0; k < 2; k++)
        for (l = 0; l <= (k ? cnt - 1 : p[i]); l++)
          f[i][(j + gen[l]) % m][k] += f[i - 1][j][k | (l < p[i])];
  for (i = 0; i < m; i++) dp[pt][i] = f[len][i][0];
  return pt;
}
void work(vector<long long> f, int k, bool flag) {
  int i;
  if (f.size() == 1) {
    if (f[0]) {
      long long tmp = 0;
      for (i = len; i >= k; i--) tmp = tmp * cnt + p[i];
      int now = calc(tmp + flag);
      for (i = 0; i < m; i++)
        if (f[0] >> i & 1) ans += dp[now][i];
    }
    return;
  }
  if (k > len && !flag) return;
  vector<long long> g;
  for (i = 0; i < cnt; i++) {
    g.clear();
    int j = i;
    long long now = (1ll << m) - 1;
    for (long long x : f) {
      long long y = x >> gen[j] | (x & (1ll << gen[j]) - 1) << m - gen[j];
      if (!j)
        now = y;
      else
        now &= y;
      j = (j + 1) % cnt;
      if (!j) {
        g.push_back(now);
        now = -1;
      }
    }
    if (now != -1) g.push_back(now);
    work(g, k + 1, i == p[k] ? flag : i < p[k]);
  }
}
void solve(long long t) {
  int i;
  len = 0;
  for (; t; t /= cnt) p[++len] = t % cnt;
  vector<long long> f;
  f.clear();
  for (i = 1; i <= n; i++) f.push_back((1ll << b[i] + 1) - 1);
  work(f, 1, 0);
}
int main() {
  scanf("%d%d", &cnt, &m);
  int i;
  for (i = 0; i < cnt; i++) scanf("%d", &gen[i]);
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  scanf("%lld%lld", &l, &r);
  r -= n - 1;
  if (l > r) {
    puts("0");
    return 0;
  }
  long long t = 0;
  solve(r);
  t += ans;
  ans = 0;
  solve(l - 1);
  t -= ans;
  printf("%lld\n", t);
  return 0;
}
