#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 30005;
int d, m, n, lm, b[N], gen[25];
ll l, r;
struct Node {
  bitset<N> p, s, a;
  ll ans, l;
  void set(int x) {
    if (x <= b[n]) p[n] = 1;
    if (x <= b[1]) s[1] = 1;
    for (int i = 1; i <= n; i++)
      if (x <= b[i]) a[i] = 1;
    ans = (n == 1 && x <= b[1]);
    l = 1;
  }
} a[65][65];
Node merge(const Node &a, const Node &b) {
  static Node ret;
  ret.l = a.l + b.l;
  ret.p = a.p;
  if (a.l < n) ret.p |= (a.a << a.l & b.p) >> a.l;
  ret.s = b.s;
  if (b.l < n) ret.s |= (b.a >> 1 & a.s) << b.l;
  if (a.l + b.l <= n)
    ret.a = b.a >> a.l & a.a;
  else
    ret.a.reset();
  ret.ans = a.ans + b.ans + (a.s << 1 & b.p).count();
  return ret;
}
ll calc(ll x) {
  ll y = 0, p = 0;
  static Node ret;
  bool fl = 0;
  ret.ans = 0;
  for (int i = lm - 1; i >= 0; --i) {
    int j;
    for (j = 0; y + a[i][(p + gen[j]) % m].l <= x; j++) {
      if (!fl)
        ret = a[i][(p + gen[j]) % m], fl = 1;
      else
        ret = merge(ret, a[i][(p + gen[j]) % m]);
      y += a[i][(p + gen[j]) % m].l;
    }
    p = (p + gen[j]) % m;
  }
  return ret.ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> d >> m;
  for (int i = 0; i < d; i++) cin >> gen[i];
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  cin >> l >> r;
  for (int i = 0; i < m; i++) a[0][i].set(i);
  for (lm = 1; a[lm - 1][0].l <= r / d; lm++)
    for (int i = 0; i < m; i++) {
      a[lm][i] = a[lm - 1][(i + gen[0]) % m];
      for (int j = 1; j < d; j++)
        a[lm][i] = merge(a[lm][i], a[lm - 1][(i + gen[j]) % m]);
    }
  cout << calc(r) - calc(l + n - 2) << endl;
  return 0;
}
