#include<iostream> #include<cstdio> #include<iomanip> #include<algorithm> #define maxn 110 #define ll long long #define ull unsigned long long usingnamespacestd;
int n, m;
ll a[maxn], L, R;
ull check(ll x){ ull s = 0; for (int i = 0; i < n; ++i) { if (x >> i & 1) s += a[i + 1]; if (s > R) return s; } return s; }
ll f[maxn][maxn]; int d[maxn]; ll dfs(int pos, int limit, int k){ if (!pos) return k == m; if (!limit && ~f[pos][k]) return f[pos][k]; int up = limit ? d[pos] : 1; ll ans = 0; for (int i = 0; i <= up; ++i) ans += dfs(pos - 1, limit && i == d[pos], k + (i == 1)); if (!limit) f[pos][k] = ans; return ans; }
ll solve(ll x){ int l = 0; while (x) d[++l] = x % 2, x /= 2; return dfs(l, 1, 0); }
intmain(){ cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); cin >> L >> R; ll l = 1, r = (1ll << n) - 1, mid, ans = -1; while (l <= r) { mid = l + r >> 1; if (check(mid) >= L) ans = mid, r = mid - 1; else l = mid + 1; } l = 1, r = (1ll << n) - 1; ll Ans = -1; while (l <= r) { mid = l + r >> 1; if (check(mid) <= R) Ans = mid, l = mid + 1; else r = mid - 1; } fill(f[0], f[0] + maxn * maxn, -1); if (~ans && ~Ans) cout << solve(Ans) - solve(ans - 1) << "\n"; elsecout << "0\n"; return0; }