#include <bits/stdc++.h>
using namespace std;
const int N = 30000;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  bool f = false;
  for (; ch < '0' || ch > '9'; ch = getchar()) f |= ch == '-';
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
int d, m, n, a[20], b[N], tot;
bitset<N> all;
long long l, r;
struct Node {
  long long ans, len;
  bitset<N> pre, suf;
  Node() {
    ans = len = 0;
    pre.reset();
    suf.reset();
  }
  Node operator+(const Node &o) const {
    Node c;
    c.ans = ans + o.ans;
    c.len = len + o.len;
    c.pre = pre;
    c.suf = o.suf;
    if (len < n - 1) c.pre &= (o.pre >> len) | (all << (n - 1 - len));
    if (o.len < n - 1) c.suf &= (suf << o.len) | (all >> (n - 1 - o.len));
    if (c.len >= n) {
      bitset<N> tmp = suf & o.pre;
      if (len < n - 1) tmp &= all >> (n - 1 - len);
      if (o.len < n - 1) tmp &= all << (n - 1 - o.len);
      c.ans += tmp.count();
    }
    return c;
  }
  Node operator+=(const Node &o) { return *this = *this + o; }
} f[60][60];
long long qry(long long x) {
  Node r;
  int now = 0;
  for (int i = tot; ~i; --i)
    for (int j = 0; j < d; ++j)
      if (x >= f[i][0].len) {
        r += f[i][(now + a[j]) % m];
        x -= f[i][0].len;
      } else {
        now = (now + a[j]) % m;
        break;
      }
  return r.ans;
}
int main() {
  read(d);
  read(m);
  for (int i = 0; i < d; ++i) read(a[i]);
  read(n);
  for (int i = 0; i < n; ++i) read(b[i]);
  for (int i = 0; i < n - 1; ++i) all.set(i);
  for (int i = 0; i < m; ++i) {
    f[0][i].len = 1;
    if (n == 1)
      f[0][i].ans = i <= b[0];
    else
      for (int j = 0; j < n - 1; ++j) {
        f[0][i].pre[j] = i <= b[j + 1];
        f[0][i].suf[j] = i <= b[j];
      }
  }
  read(l);
  read(r);
  while (d * f[tot][0].len <= r) {
    ++tot;
    for (int i = 0; i < m; ++i) {
      f[tot][i] = f[tot - 1][i];
      for (int j = 1; j < d; ++j) f[tot][i] += f[tot - 1][(i + a[j]) % m];
    }
  }
  printf("%lld\n", qry(r) - qry(l + n - 2));
}
