#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<utility>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef set<int> si;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define pp(x)               push_back(x)
#define isodd(x) (x&1)
#define iseven(x) (!(x&1))
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define INF                   1000000000
#define PI             3.141592653589793
#define rep(i, v)       for(int i=0;i<sz(v);++i)
void fastInOut() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); }
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
int  n, m; string str1, str2; char C;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int arr[10000]; int sum = 0;    int l, r, x;
vi gemy; bool f = 0;
int rec(int i, int s){

    if (s>=l&& s <= r){
        sort(all(gemy));
        if (gemy.size()>=2&&f!=1&&gemy[gemy.size() - 1] - gemy[0] >= x)
        {
            f = 1;
            sum++;
        }
    }
    if (i == n)return 0;
    rec(i + 1, s);
    f = 0;
    gemy.push_back(arr[i]);
    rec(i + 1, s + arr[i]);
    gemy.pop_back();
}
int main(){

    cin >> n >> l >> r >> x;
    lop(i, n){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int a = 0, b = 0;

    rec(0, 0); cout << sum;
}

# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MMAXN = (1LL << 10);
const ll MMAXM = (1LL << 10);
const ll MAXN = ll(5e5);

ll bit(ll x, ll i){
    return (x >> i) & 1;
}

ll n, l, r, x, c[MAXN], rr;

int main(){
    cin >> n >> l >> r >> x;
    for(ll i = 1; i <= n; ++i){
        cin >> c[i];
    }
    for(ll i = 0; i < (1LL << n); ++i){
        ll s = 0, mn = ll(1e7), mx = -ll(1e7);
        for(ll j = 0; j < 32; ++j){

            if(((i >> j) & 1) == 1){

                s += c[j + 1];
                mn = min(mn, c[j + 1]);
                mx = max(mx, c[j + 1]);
            }
        }
        if(s >= l && s <= r && mx - mn >= x){
            ++rr;
        }
    }
    cout << rr;

    return 0;
}

// In the name of God
#include<bits/stdc++.h>
using namespace std;

const int N = 13 + 3;
int n, x, l, r, a[N];

void input() {
	cin >> n >> l >> r >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

bool check(int id) {
	int mn = 10000 * 1000, mx = -1, sum = 0, num = 0;
	for (int i = 0; i < n; i++)
		if (id >> i & 1) {
			num++;
			mn = min(a[i], mn);
			mx = max(a[i], mx);
			sum += a[i];
		}
	return sum <= r && sum >= l && mx - mn >= x && num >= 2;
}

void solve() {
	int ans = 0;
	for (int i = 0; i < (1 << n) + 1; i++)
		if (check(i))
			ans++;
	cout << ans << endl;
}

int main() {
	input(), solve();
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
__int64 c[20],dp[20][20];
int ans;
__int64 n,l,r,x;
void dfs(__int64 sum, int a, int li, int an)
{
	if(sum>=l && sum<=r && a>=x) ans++;
	if(sum>r) return;
	for(int i=li;i<=n;i++)
	{
		dfs(sum+c[i], c[i]-an, i+1, an);
	}
}
int main()
{
	cin>>n>>l>>r>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
	}
	ans=0;
	sort(c+1,c+n+1);
	for(int i=1;i<n;i++)
		dfs(c[i],0,i+1,c[i]);
	cout<<ans<<endl;
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 2000005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
int n,a[20],l,r,x;
int main()
{
    int i,j,k;
    scanf("%d%d%d%d",&n,&l,&r,&x);
    for(i = 0;i<n;i++)
        scanf("%d",&a[i]);
    int s = (1<<n)-1,ans = 0;
    for(i = 1;i<=s;i++)
    {
        int cnt=0,sum=0,minn = 99999999,maxn = 0;
        for(j = 0;j<n;j++)
        {
            if((1<<j)&i)
            {
                cnt++;
                sum+=a[j];
                minn = min(minn,a[j]);
                maxn = max(maxn,a[j]);
            }
        }
        if(cnt>=2 && maxn-minn>=x && sum>=l && sum<=r)
            ans++;
    }
    printf("%d\n",ans);

    return 0;
}

/*          IT IS GOING TO HAPPEN !
                because
                 I AM GOING TO MAKE IT HAPPEN !      */

// all you need is to be consistent , even in your darkest times

// あきらめない -- Uzumaki Naruto !

// When something is important enough, you do it even if the odds are not in your favor.

#include "bits/stdc++.h"

#define DIEHOD ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ld long double
#define ll long long
#define all(A) begin(A) , end(A)
#define sf(x)  scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define REP(i , n) for (int i = 0; i < n; i++)
#define pf(x)  printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pii    pair<lld , lld>
#define rep(i , a , b)  for(lld i = a; i < b ; i++)
#define reps(i , a , b) for(lld i = a ; i >= b ; i--)
#define ftc(x)  cerr << #x << ": " << x << " \n" ;
#define vvi   vector < pair <lld , lld> >
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define mem(a , b) memset(a , b , sizeof(a))
#define lld long long int
#define ulld unsigned long long int
#define input lld* arr = new lld [n]
#define input1 lld* brr = new lld [n]
#define vec vector < lld >
#define pb push_back
#define ss second
#define ff first
#define inf (lld)(1e18)
#define fin -999999999999999999
#define mod 1000000007
#define umap unordered_map
#define mpp make_pair
#define finish(x) cout << x << " ";
#define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

using namespace std;

// map <lld , vector<lld>> g;
// vec v;
// map<lld , bool> vis ; lld siz = 0 , ans = 0 ;

// void dfs(lld x) {

//   vis[x] = 1;

//   for (auto i : g[x]) {
//     if (!vis[i]) {
//       dfs(i);
//     }
//   }

//   return;
// }

// lld pow1(int  a , int y) {
//   a %= mod;
//   lld  ans = 1;

//   while (y > 0) {

//     if (y & 1)
//       ans = (ans * a) % mod;

//     y = y >> 1;
//     a = (a * a) % mod;
//   }
//   return ans;
// }

// lld power(int a, int b) {
//   lld ans = 1;
//   while (b > 0) {
//     if (b & 1) ans = ans * a;
//     b = b >> 1;
//     a = a * a;
//   }
//   return ans;
// }

// bool isPrime(lld n) {
//   if (n <= 1)  return false;
//   if (n <= 3)  return true;
//   if (n % 2 == 0 || n % 3 == 0) return false;

//   lld p = sqrt(n);

//   for (lld i = 5; i <= p ; i = i + 6)
//     if (n % i == 0 || n % (i + 2) == 0)
//       return false;
//   return true;
// }

// bool sortbysec(const pair<lld , lld > &a, const pair<lld , lld > &b) {
//   return (a.ss < b.ss);
// }

// Do SMTH instead of sitting mofo

// BINARY SEARCH zarur dekh lena (kaafi useful)

// String ka question hai to y zarur dekh lena kahi Dsu ya Graph se solve ho jae
// ya fir STACK se bhi ho sakta hai ...

// CONSTRUCTIVE ALGOS ke case mai pattern ke alava brute force bhi karke dekh lena
// jese digits hai to ek extra 0 se 9 tk ka ya agar character hai to ek 'a' se 'z' tak
// for loop laga kar check karo ki kahi
// ek particular X mil jae jo pattern crack kar de....

// keep in mind apna best dena ki zarurat tabhi sabse zada hoti hai
// jab aap sabse zada kharab state mai ho tabhi kuch hoga

// BHAI  .... DP with recurrance contest 672 nuksaan ho gaya tha dp na soch kar

void sober() {
  lld n , x = 0 , a = 0 , b = 0 , y = 0 , k = 0 , m = 0 , c = 0 , d = 0 , ans = 0;

  cin >> n >> a >> b >> x;

  vec v(n) ; REP(i , n) cin >> v[i];

  sort(all(v));

  for (int mask = 1 ; mask < (1 << n) ; mask++) {

    lld sum = 0 , maxx = 0 , minn = inf;

    REP(i , n) {

      if ((mask >> i) & 1) {
        sum += v[i];
        maxx = max(maxx , v[i]);
        minn = min(minn , v[i]);
      }

    }

    // cout << maxx << "  " << minn << "\n";

    if (sum >= a and sum <= b and maxx - minn >= x)
      ans++;
  }

  cout << ans << "\n";

}

signed main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt" , "r" , stdin) ;
  freopen("output.txt" , "w" , stdout) ;
#endif

  DIEHOD;
  lld t = 1;
  // cin >> t;
  while (t--) {
    sober();
  }
}

//  c0ded by :
// - - - - - - - - - - - - - - - - - - - - - - s 0 b e r and s i m r a n

#include<iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
ll sum;
ll n, l, r, x;
vector<ll>vc,vc2,vc3;
void solve(int num,ll*arr)
{
	sum = 0;
	for (int i = 0; i < n; i++)
	{
		if (num&(1 << i))
		{
			sum += arr[i];
			vc.push_back(arr[i]);
		}
	}
}

int main()
{
	cin >> n >> l >> r >> x;
	ll*arr = new ll[n];
	for (int i = 0; i < n; i++)
         cin >> arr[i];
	sort(arr, arr + n);
	for (int i = 1; i < (1 << n); i++)
	{

		solve(i,arr);
		int z = abs(vc[0]-vc[vc.size()-1]);
		if (sum >= l&&sum <= r&&z >= x)
			vc2.push_back(vc.size());
		vc = vc3;
	}
	cout << vc2.size();

	return 0;
}

/*          IT IS GOING TO HAPPEN !
                because
                 I AM GOING TO MAKE IT HAPPEN !      */

// all you need is to be consistent , even in your darkest times

// あきらめない -- Uzumaki Naruto !

// When something is important enough, you do it even if the odds are not in your favor.

#include "bits/stdc++.h"

#define DIEHOD ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ld long double
#define ll long long
#define all(A) begin(A) , end(A)
#define sf(x)  scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define REP(i , n) for (int i = 0; i < n; i++)
#define pf(x)  printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pii    pair<lld , lld>
#define rep(i , a , b)  for(lld i = a; i < b ; i++)
#define reps(i , a , b) for(lld i = a ; i >= b ; i--)
#define ftc(x)  cerr << #x << ": " << x << " \n" ;
#define vvi   vector < pair <lld , lld> >
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define mem(a , b) memset(a , b , sizeof(a))
#define lld long long int
#define ulld unsigned long long int
#define input lld* arr = new lld [n]
#define input1 lld* brr = new lld [n]
#define vec vector < lld >
#define pb push_back
#define ss second
#define ff first
#define inf (lld)(1e18)
#define fin -999999999999999999
#define mod 1000000007
#define umap unordered_map
#define mpp make_pair
#define finish(x) cout << x << " ";
#define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });

using namespace std;

// map <lld , vector<lld>> g;
// vec v;
// map<lld , bool> vis ; lld siz = 0 , ans = 0 ;

// void dfs(lld x) {

//   vis[x] = 1;

//   for (auto i : g[x]) {
//     if (!vis[i]) {
//       dfs(i);
//     }
//   }

//   return;
// }

// lld pow1(int  a , int y) {
//   a %= mod;
//   lld  ans = 1;

//   while (y > 0) {

//     if (y & 1)
//       ans = (ans * a) % mod;

//     y = y >> 1;
//     a = (a * a) % mod;
//   }
//   return ans;
// }

// lld power(int a, int b) {
//   lld ans = 1;
//   while (b > 0) {
//     if (b & 1) ans = ans * a;
//     b = b >> 1;
//     a = a * a;
//   }
//   return ans;
// }

// bool isPrime(lld n) {
//   if (n <= 1)  return false;
//   if (n <= 3)  return true;
//   if (n % 2 == 0 || n % 3 == 0) return false;

//   lld p = sqrt(n);

//   for (lld i = 5; i <= p ; i = i + 6)
//     if (n % i == 0 || n % (i + 2) == 0)
//       return false;
//   return true;
// }

// bool sortbysec(const pair<lld , lld > &a, const pair<lld , lld > &b) {
//   return (a.ss < b.ss);
// }

// Do SMTH instead of sitting mofo

// BINARY SEARCH zarur dekh lena (kaafi useful)

// String ka question hai to y zarur dekh lena kahi Dsu ya Graph se solve ho jae
// ya fir STACK se bhi ho sakta hai ...

// CONSTRUCTIVE ALGOS ke case mai pattern ke alava brute force bhi karke dekh lena
// jese digits hai to ek extra 0 se 9 tk ka ya agar character hai to ek 'a' se 'z' tak
// for loop laga kar check karo ki kahi
// ek particular X mil jae jo pattern crack kar de....

// keep in mind apna best dena ki zarurat tabhi sabse zada hoti hai
// jab aap sabse zada kharab state mai ho tabhi kuch hoga

// BHAI  .... DP with recurrance contest 672 nuksaan ho gaya tha dp na soch kar

lld n , a , b , x; vec v , ans;

bool check(lld sum){

  lld maxx = fin , minn = inf;

  REP(i , ans.size()){
    maxx = max(maxx , ans[i]);
    minn = min(minn , ans[i]);
  }

  return (sum >= a and sum <= b and maxx - minn >= x);

}

lld itachi = 0;

void rec(lld i , lld sum){

  if(i == n){
    if(check(sum)){
      itachi++;
    }
    return;
  }

  lld cnt = 0;

  ans.pb(v[i]);

  rec(i + 1 , sum + v[i]);
  ans.pop_back();
  rec(i + 1 , sum);
}

void sober() {
  lld y = 0 , sum = 0 , k = 0 , m = 0 , c = 0 , d = 0;

  cin >> n >> a >> b >> x;

  v.resize(n); REP(i , n) cin >> v[i];

  rec(0 , 0);
  cout << itachi << "\n";
  return;
}

signed main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt" , "r" , stdin) ;
  freopen("output.txt" , "w" , stdout) ;
#endif

  DIEHOD;
  lld t = 1;
  // cin >> t;
  while (t--) {
    sober();
  }
}

//  c0ded by :
// - - - - - - - - - - - - - - - - - - - - - - s 0 b e r and s i m r a n

#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>

using namespace std;

long n,l,r,x;
long * c,*rn, len=0;

long VarCount(long st,long sum){

    long count = 0;

    for(long i=st; i<n; i++){
        if (sum+*(c+i)>r) continue;
        *(rn+len) = *(c+i); len++;
        if (len>=2 && sum+*(c+i)>=l) {
            long min=*rn, max=*rn;
            for(long j=0; j<len; j++) {
              if (*(rn+j)>max) max=*(rn+j);
              else if (*(rn+j)<min) min=*(rn+j);
            }
            if (abs(max-min)>=x) count++;
        }
        count += VarCount(i+1,sum+*(c+i));
        len--;
    }

    return count;
}

void main()
{
    cin>>n>>l>>r>>x;
    c = (long*)calloc(n,sizeof(long));
    rn = (long*)calloc(n,sizeof(long));
    for(long i = 0; i<n; i++)
    {
        cin>>*(c+i);
    }

    cout<<VarCount(0,0);
    return;
}

#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, l, r, x;
	cin >> n >> l >> r >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int mask = 0; mask < (1 << n); mask++) {
		int hard = 0, simple = 0, sum = 0;
		for (int i = 0; i < n; i++)
			if (mask & (1 << i)) {
				sum += a[i];
				if (a[i] > hard)
					hard = a[i];
				if (a[i] < simple || !simple)
					simple = a[i];
			}
		if (hard - simple >= x && sum >= l && sum <= r)
			ans++;
	}
	cout << ans;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_i=(b);i<_i;i++)
int n,l,r,x;
int p[15];
int bt(int i, int sum, vector<int> dif){
    if(i==n){
        if(sum>=l && sum<=r){
            int _min=0x3f3f3f3f,_max=0,s=0;
            FOR(i,0,dif.size()){
                _min=min(_min,dif[i]);
                _max=max(_max,dif[i]);
                s+=dif[i];
            }
            return dif.size()>=2 && (abs(_min-_max)>=x) && s>=1;
        }else
            return 0;
    }
    vector<int> d=dif;
    d.push_back(p[i]);
    if(sum+p[i]<=r){
        return bt(i+1,sum+p[i],d)+bt(i+1,sum,dif);
    }else{
        return bt(i+1,sum,dif);
    }
}
int main() {

    cin>>n>>l>>r>>x;
    FOR(i,0,n){
        cin>>p[i];
    }
    sort(p,p+n);
    vector<int> v;
    cout<<bt(0,0,v)<<endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <bitset>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define e exp(1.0)
typedef long long ll;
#define MAXN 105
#define mod 1000000007
#define INF 0x3f3f3f3f
#define fe(i,st,en) for(i = (st);i <= (en);++i)
#define fne(i,st,en) for(i = (st);i < (en);++i)
#define ri register int
int a[16], p[16];
int main(){
	int n, l, r, x;
	ri i, j;
	p[0] = 1;
	fe(i,1,15) p[i] = p[i - 1] << 1;
	while (cin >> n >> l >> r >> x) {
		fne(i,0,n) scanf("%d", a + i);
		int ans = 0;
		fne(i, 0, p[n]) {
			int s = 0, MAX, MIN;
			MAX = 0, MIN = 1000005;
			fne(j, 0, n) if (i & p[j]) s += a[j], MAX = max(MAX, a[j]), MIN = min(MIN, a[j]);
			if (s >= l && s <= r && MAX - MIN >= x) ++ans;
		}
		cout << ans << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
int a[200005];
vector<ll>v[1000000];
int main()
{
    fastread;
    ll n,i,j,k,l,m,r,x;
	cin>>n>>l>>r>>x;
	for(i=0;i<n;i++)
	cin>>a[i];
	ll gun=2;
	ll start=0;
	v[1].pb(a[0]);
	ll kola=2;
	for(i=1;i<n;i++)
	{
	   	for(j=start;j<gun;j++)
	   	{
	   	   ll sz=v[j].size();
		   for(k=0;k<sz;k++)
		   v[kola].pb(v[j][k]);
		   v[kola].pb(a[i]);
		   kola++;
		}
		gun*=2;
	}
	ll res=0;
	for(i=0;i<gun;i++)
	{
	   ll sz=v[i].size();
	   ll mini=-1,maxi=-1;
	   ll sum=0;
	   for(j=0;j<sz;j++)
	   {
	   	    sum+=v[i][j];
	   	    if(j==0)
	        {
	           mini=v[i][j];
			   maxi=v[i][j];
		     }
			 else
			 {
			 	mini=min(mini,v[i][j]);
			 	maxi=max(maxi,v[i][j]);
			 }
	   }
	   if(sum>=l&&sum<=r&&maxi-mini>=x)
	   res++;
	}
	cout<<res<<endl;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100

typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n;
ll a[110],L,R,X;
int vis[110];
int ans=0;
void DFS(int pos,ll sum,ll mn,ll mx){
    if(mx>R) return ;
    if(mx-mn>=X && sum>=L && sum<=R) ans++;
    for(int i=pos+1;i<=n;i++){
        if(!vis[i]){
            vis[i]=1;
            DFS(i,sum+a[i],min(mn,a[i]),max(mx,a[i]));
            vis[i]=0;
        }
    }
}
int main(){
    scanf("%d",&n);
    scanf("%I64d%I64d%I64d",&L,&R,&X);
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]);
    for(int i=1;i<=n;i++){
        vis[i]=1;
        DFS(i,a[i],a[i],a[i]);
        vis[i]=0;
    }
    cout<<ans<<endl;
    return 0;
}

#include<stdio.h>
#include<algorithm>
using namespace std;
#define N 20
int c[N], a[N];
int main(){
	//freopen("B.in", "r", stdin);
	int n, l, r, x;
	scanf("%d%d%d%d", &n, &l, &r, &x);
	for(int i=0; i<n; i++)scanf("%d", &c[i]);
	int m = 1<<n;
	int ans = 0;
	for(int i=1; i<m; i++){
		for(int j=0; j<n; j++){
			if(i&(1<<j))a[j] =1;
			else a[j] = 0;
		}
		int sum =0;
		for(int j=0; j<n; j++)sum+=a[j];
		if(sum<2)continue;
		sum = 0;
		int mn = 1000000;
		int mx = 0;
		for(int j=0; j<n; j++){
			if(a[j]){
				sum+=c[j];
				if(mn >c[j])mn = c[j];
				if(mx < c[j])mx = c[j];
			}
		}
		if(mx -mn<x)continue;
		if(sum<l)continue;
		if(sum>r)continue;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

/*
     _              ,_,
    / \   _ __, ___,| |__   __ _,_ __
   / ^ \ | '_ \/ _ \| '_ \ / _` | /_/
  /-/-\-\|-| |--| |-|-|_)-|-(_|-|-|
 /_/   \_\_| |__| |_|_.__/ \__,_|_|

*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(ll i=a ; i<n ; i++)

typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;

int main(){
    ios_base :: sync_with_stdio (false);
	cin.tie(NULL);

	ll TESTS=1;
	// cin>>TESTS;
	while(TESTS--){
		ll n, l, r, x;
		cin>>n>>l>>r>>x;
		vi c(n);
		rep(i, 0, n)cin>>c[i];
		sort(all(c));
		ll z=(1<<n), ans=0;
		for(int i=1; i<=z; i++){
			vi v(n, 0), a;
			ll p=i;
			for(int j=0; j<n; j++){
				if(p%2==1)v[j]=1;
				p/=2;
			}
			reverse(all(v));
			for(int j=0; j<n; j++){
				if(v[j]==1)a.pb(c[j]);
			}
			if(a.size()<2)continue;
			else if(a[a.size()-1]-a[0]<x)continue;
			else{
				ll sum=0;
				for(auto u:a)sum+=u;
				if(sum>=l&&sum<=r)ans++;
			}

		}
	cout<<ans;

	}
    return(0);
}

#include<bits/stdc++.h>
using namespace std;
int n,l,r,x,ans=0;
int a[20],b[20];
int main(){
    cin>>n>>l>>r>>x;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int bit=0;bit<pow(2,n);bit++){
        int sum=0,mx=-1,mn=1000005,cnt=0;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                sum+=a[i];
                mx=max(mx,a[i]);
                mn=min(mn,a[i]);
                cnt++;
            }
        }
        if(sum<=r&&sum>=l&&mx-mn>=x&&cnt>=2) ans++;
    }
    cout<<ans;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int n, a[15], i, l, r, x, ans, k;
void recu(int s,int d,int j,int b,bool q) {
	if (s <= r&&s >= l&&a[d] - a[b] >= x&&q) ans++;
	if (s > r||j==n) return;
	if(b>-1)recu( s + a[j], j, j + 1,b,1);
	else recu(s + a[j], j, j + 1, j,1);
	recu( s, d, j + 1,b,0);
}
int main(){
	cin >> n>>l>>r>>x;
	while (i < n)cin >> a[i++];
	sort(a, a + n);
	recu(0, 0, 0, -1,0);
	cout << ans;
}

#include <iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
long long int arr[15], lefto, righto, x, answ = 0;

void pick(int zero, int l, int r, long long int sum,int last)
{
	if (l < r)
	{
		pick(zero, l + 1, r, sum,last);
		pick(zero, l + 1, r, sum + arr[l],l);
	}
	else
		if ((sum >= lefto) && (sum <= righto) && ((arr[last] - arr[zero]) >= x) && (sum>arr[zero])) answ++;
}

int main() {
	int n,howmany=0;
	cin >> n >> lefto >> righto >> x;
	for (int i = 0; i < n; i++)  cin >> arr[i];
	sort(arr, arr + n);
	for (int i = 0; i < n; i++)
		pick(i,i+1, n,arr[i],i);
	cout << answ; return 0;
}

#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <bitset>
#include <string>
#include <string.h>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <list>
#include <algorithm>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> ii;
#define FOR(i, j, n) for (int i = j; i < n; i++)
#define ROF(i, j, n) for (int i = j; i >= n; i--)
#define pp(a, b) make_pair(a, b)
#define SC(n) scanf("%d", &n)
#define SC2(n, m) scanf("%d%d", &n, &m)
#define SCf(n) scanf("%lf", &n)
#define SCs(s) scanf("%s", s);
#define MAX 100010

int n, l, r, x, a[20];

int main() {
	scanf("%d%d%d%d", &n, &l, &r, &x);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int p2 = 1, ans = 0;
	for (int i = 0; i < n; i++) p2 *= 2;
	for (int i = 2; i < p2; i++) {
		int mn = 1e9, mx = 0, sm = 0;
		for (int j = 0; j < n; j++)
			if ((i >> j) & 1) {
				sm += a[j];
				mn = min(a[j], mn);
				mx = max(a[j], mx);
			}
		if (sm >= l && sm <= r && (mx - mn >= x)) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<iomanip>
#include<queue>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef int me;
#define andrew ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v)(int)(s.size())
#define all(v) v.begin(),v.end()

/*ll vaild(ll mi, ll n, ll a, ll b, ll c)
{

}*/
int main()
{

	ll n, l, r, d;
	cin >> n >> l >> r >> d;
	vector<ll>v(n);
	for (me i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	int x = 0;
	sort(all(v));
	for (int i = 2; i < (1 << n); i++)
	{
		ll sum = 0;
		ll m = 0;
		ll b = LLONG_MAX;
		bitset<64> bit(i);
		for (int j = 0; j <= n; j++)
		{
			if (bit[j])
			{
				sum += v[j];
				if (v[j] >= m)
				{
					m = v[j];
				}
				if (v[j] <= b)
				{
					b = v[j];
				}
			}
		}
		int y = m - b;
		if (bit.count() > 1)
		{
			if (sum >= l && sum <= r && y >= d)
			{
				x++;
			}
		}
	}
	cout << x;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1

#ifndef ONLINE_JUDGE
#define watch(x)		cerr << #x << " = " << x << "\n"
#else
#define watch(x)		42
#endif

mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
#endif
}

bool valid(int set, int l, int r, int d, int n, int a[])
{
	int s=0;
	int mn = inf;
	int mx = -inf;

	int sb = 0;

	for(int i=n-1; i>=0; i--)
	{
		if(set & (1 << i))
		{
			s += a[i];
			mn = min(mn, a[i]);
			mx = max(mx, a[i]);
			sb++;
		}
	}

	// cout << s << " " << mn << " " << mx << " " << sb << "\n";

	// int i=1;

	// while(i < set)
	// {
	// 	if(set & i != 0)
	// 	{
	// 		s += a[n-i];
	// 		mn = min(mn, a[n-i]);
	// 		mx = max(mx, a[n-i]);
	// 		sb++;
	// 	}

	// 	i = i<<1;
	// }

	if(sb < 2)
		return 0;

	return s >=l && s <= r && (mx -mn) >= d;
}

int32_t main()
{
	c_p_c();

	int n,l,r,d; cin>>n>>l>>r>>d;

	int a[n];

	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}

	int ans=0;

	for (int i = 0; i < pow(2,n); ++i)
	{
		bool v = valid(i, l, r, d, n, a);

		// cout << i << " " << v << "\n";
		if(v)
			ans++;
	}

	cout << ans;

	return 0;
}

#include<iostream>
#include<fstream>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<iterator>
#include<cmath>
#include<algorithm>
using namespace std;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define repi(n)  for(int i = 0; i < (int)(n); ++i)
#define repj(n)  for(int j = 0; j < (int)(n); ++j)
#define reprng(i,a,b) for(int i = a; i <= (int)(b); ++i)
#define reprngr(i,n,a) for(int i = n;i >= (int)(a); --i)
//#define in(a, b) (string(a).find(b) != string::npos)
#define clr(a, x) memset(a, x, sizeof(a))
#define fast_scan() (ios_base::sync_with_stdio(false),cin.tie(NULL))
#define mp make_pair
#define pb push_back
#define PI 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<bool> vb;
ifstream in("input.txt");
ofstream out("output.txt");
const ll OO = 0x3f3f3f3f;
vb taken(17);
ll n, l, r, x;
int solve(vi &c, ll sum = 0, int e = 0)
{
	if (e == sz(c))
	{
		if (sum < l || sum > r) return 0;
		int mini = OO, maxi = 0;
		repi(n) { if (taken[i]) mini = min(mini, c[i]), maxi = max(maxi, c[i]); }
		if (maxi - mini >= x) return 1;
		return 0;
	}
	int without = solve(c, sum, e + 1);
	taken[e] = true;
	int with = solve(c, sum + c[e], e + 1);
	taken[e] = false;
	return with + without;

}
int main()
{
	fast_scan();
	cin >> n >> l >> r >> x;
	vi c(n); repi(n) cin >> c[i];
	cout << solve(c);
	getchar(); getchar();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
	int n, l, r, x;
	cin >> n >> l >> r >> x;

	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	ll ans = 0;

	for (int i = 0; i < (1 << n); ++i) {
		ll sum = 0;
		int mn = 1e9+1, mx = 0;
		for (int j = 0; j < n; ++j) {
			if ((i >> j) & 1) {
				sum += a[j];
				mn = min(mn, a[j]);
				mx = max(mx, a[j]);
			}
		}
		if (l <= sum && sum <= r && mx - mn >= x) ++ans;
	}

	cout << ans << "\n";

	return 0;
}

#include <iostream>
#include <cstring>
using namespace std;

long long d[1<<17];

int p[16];

int n,l,r,x;

int gmin(int m){
    int mn= 1000000000;
    for(int i=0; i<n;i++){
        if(!(m&(1<<i)))
            continue;
        mn = min(mn,p[i]);
    }
    return mn;
}

int gmax(int m){
    int mx= 0;
    for(int i=0; i<n;i++){
        if(!(m&(1<<i)))
            continue;
        mx = max(mx,p[i]);
    }
    return mx;
}

int gsum(int m){
    int s= 0;
    for(int i=0; i<n;i++){
        if(!(m&(1<<i)))
            continue;
        s += p[i];
    }
    return s;
}

long long ways(int m){

    if(d[m]==-1){
        //cout<<m<<endl;
        int mn = gmin(m);
        int mx = gmax(m);
        int s = gsum(m);
        int c=0;
        int w = 0;
        for(int i=0; i<n;i++){
            if(!(m&(1<<i)))
                continue;
            c++;
        }
        if(c>=2 && s >= l && s <= r && (mx-mn)>=x)
            w++;
        for(int i=0; i<n;i++){
            if(m&(1<<i))
                continue;
            ways(m|(1<<i));
        }
        d[m]=w;
    }
    return d[m];
}

int main() {

    cin >> n >> l >> r >> x;
    for (int i=0; i<n; i++){
        cin >> p[i];
    }

    memset(d,255,sizeof d);
    ways(0);
    int t=0;
    for(int i=0;i<(1<<n);i++)
        t+=d[i];
    cout<<t<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);
#define MAXN 20

using namespace std;
typedef long long ll;

ll p[MAXN];

int main(){_
	ll n, l, x, r, maior, menor, cont = 0;
	ll soma;
	cin >> n >> l >> r >> x;
	for(int i=0; i<n; i++)
		cin >> p[i];

	for(int i=1; i<(1<<n); i++){
		soma = 0;
		maior = -1;
		menor = 1000000000;
		for(int j=0; j<n; j++)
			if((1<<j) & i){
				soma += p[j];
				maior = max(maior, p[j]);
				menor = min(menor, p[j]);
			}
		if(soma >= l && soma <= r && (maior-menor) >= x)
			cont++;
	}
	cout << cont << endl;

	return 0;
}
// 1486828130240

#include<iostream>
#include<algorithm>
#define fastScan ios::sync_with_stdio(0)
#define ll long long

using namespace std;

ll a[16],d[40000],vis[40000];
int main()
{
    fastScan;
    int n,x,i,j,k,l0,m,m0,m1,c;
    ll l,r,v,ans=0;
    cin>>n>>l>>r>>x;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(i=1,m=1;i<=n;i++)
    {
        m0=m;
        for(j=0;j<m0;j++,m++)
        {
            m1=m;
            c=1;
            while(!(m1&1))
                c++,m1=m1>>1;
            d[m]=a[i]+d[j];
            if(j&&a[i]-a[c]>=x)
                vis[m]=1;
            if(vis[m]&&d[m]>=l&&d[m]<=r)
                ans++;
        }
    }
    cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
int n,l,r,x,c[109],minc,maxc,dem,s;
short Getbit(int k1,int n1)
{
    return (n1>>k1)&1;
}
int main(){
 //   freopen("CONTEST.INP","r",stdin);
 //   freopen("CONTEST.OUT","w",stdout);
    cin>>n>>l>>r>>x;
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    for(int j=0;j<=pow(2,n)-1;j++)
    {
        s=0;
        minc=999999999;
        maxc=-999999999;
        for(int q=0;q<=n-1;q++)
        {
            if(Getbit(q,j)==1)
            {
                s=s+c[n-q];
                minc=min(minc,c[n-q]);
                maxc=max(maxc,c[n-q]);
            }
        }
        if(s>=l&&s<=r&&maxc-minc>=x) dem++;
    }
    cout<<dem;
    return 0;
}

#include<iostream>
#include<stdlib.h>
using namespace std;
int n,min_sum,max_sum,inter;
int *my_data;
int digui(int total, int now_id,int min_sol,int max_sol);
int compare(const void * a, const void * b);

int main(){
	int sum = 0;
	cin>>n>>min_sum>>max_sum>>inter;
	my_data = (int*)malloc(sizeof(int)*n);
	for(int i=0;i<n;i++){
		cin>>my_data[i];
	}
	qsort(my_data,n,sizeof(int),compare);
	for(int i=0;i<n-1;i++){
		sum+=digui(my_data[i],i,my_data[i],my_data[i]);
	}
	cout<<sum;
}

int digui(int total, int now_id,int min_sol,int max_sol){
	int sum = 0;
	for(int i = now_id+1;(i<n)&&(total+my_data[i]<=max_sum);i++){
			if(min_sol>my_data[i]){
				sum+=digui(total+my_data[i],i,my_data[i],max_sol);
			}
			else if(max_sol<my_data[i]){
				sum+=digui(total+my_data[i],i,min_sol,my_data[i]);
			}
			else{
				sum+=digui(total+my_data[i],i,min_sol,max_sol);
			}
		}
	if (total>=min_sum&&total!=my_data[now_id]&&(max_sol-min_sol>=inter)){
		return 1+sum;
	}
	return sum;
}

int compare(const void * a, const void * b){
	return *(int*)a-*(int*)b;
}

/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define start1 ll t = 1; while(t--)
#define F first
#define S second
#define br "\n"

void solve(){
    ll n, l, r, x;
    cin>>n>>l>>r>>x;
    ll c[n];
    for(ll i=0; i<n; i++) cin>>c[i];

    sort(c, c+n);

    ll cost = 0, cnt = 0, ans = 0, last = 1e18, first = 1e18;

    for(ll i=0; i<(1<<n); i++){
        cost = 0;
        last = 1e18;
        first = 1e18;
        cnt = 0;
        for(ll j=0; j<n; j++){
            if((i & (1<<j)) != 0){
                cost += c[j];
                if(first==1e18) first = c[j];
                else last = c[j];
                if(cost > r) break;
                last = c[j];
                cnt++;
            }
        }

        if(cost <= r && cost >= l && cnt > 1 && last - first >= x) ans++;
    }

    cout<<ans<<br;
}

int main(){
    FIO;
    start1{
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#define task "CONTEST"
#define MAX 20
using namespace std;
int n,c[MAX],l,r,x,tong,d;
short GetBit(int k,int n){
    return (n >> k) & 1;
}
main(){
  //  freopen(task".INP","r",stdin);
  //  freopen(task".OUT","w",stdout);
    cin >> n >> l >> r >> x;
    for(int i=0;i<=n-1;i++) cin >> c[i];
    for(int j=3;j<=pow(2,n)-1;j++){

        int maxx=INT_MIN,minn=INT_MAX,t=0,tong=0;
        for(int i=0;i<=n-1;i++){
            if(GetBit(i,j) == 1){
                tong+=c[i];
                t++;
                maxx=max(maxx,c[i]);
                minn=min(minn,c[i]);
                if(tong > r) break;
            }
        }
        if(l <= tong && tong <=r && t>=2 && maxx-minn >=x) d++;
    }
    cout << d;
}

#include<bits/stdc++.h>
using namespace std;
#define fn "CONTEST"
int n,l,r,x,a[1009],s,mx,de,mn,dem=0;
short Getbit(int k, int n){
    return (n>>k)&1;
}
int main(){
  //  freopen(fn".INP","r",stdin);
  //  freopen(fn".OUT","w",stdout);
    cin>>n>>l>>r>>x;
    for(int st=0;st<n;st++) cin>>a[st];
    for(int j=0;j<=pow(2,n)-1;j++){
        s=0;
        mx=-99999999;mn=1000005;
        for(int m=0;m<=n-1;m++){
            if(Getbit(m,j)==1){
                s=s+a[m];
                mx=max(mx,a[m]);
                mn=min(mn,a[m]);
            }
        }
        if(s>=l&&s<=r&&mx-mn>=x) dem++;
    }
    cout<<dem<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll , ll>
#define pci pair<char,int>
#define fi first
#define se second
//cout << fixed << setprecision(5) << f << '\n';
/*
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    //ascending
    return (a.second < b.second);
}
bool comp(pii a , pii b)
{ // descending
    if(a.second == b.second)return(a.first > b.first);
    return(a.second > b.second);
}

 // Inserts str2 in str1 starting
    // from 6th index of str1
    str1.insert(6, str2);
*/
//map<pii,int> m; m[mp(0,0)]=0; pii ans=mp(1,1e9); ans.x , ans.y
//template<class T>
//using min_heap = priority_queue<T , vector<T> , greater<T>>;
//template<class T>
//using max_heap = priority_queue<T>;
//sort(B.begin() , B.end() , [](const box &l , const box &r){return l.x1 < r.x1;});
//min_heap<pair<ll , size_t>> byx2;
//max_heap<pair<ll , size_t>> byy1;
//using vll = vector<ll>
//vi gone(n , 0);
//sortdesc(arr, arr+n, greater<int>());
// x | (1 << n) returns x with nth bit set
//  x & (-x) returns the rightmost 1 of x
//getline(cin , s);
// vector<vector<int>> dist(size of the outer vector = n , vector<int>(size of EACH VECTOR in the vector = 10));
/*for(int k=0;k<4;k++)
use this for four adjacent ;
                {
                    int ni = i + int (k = 0) - int (k = 1);
                    int nj = j + int (k = 2) - int (k = 3);
                    if(ni < 0 || nj < 0 || ni >= n || nj >= m )continue;
                }
                */

/*
-----------BFS----------------

           // was[][] is for visited
            int was[n][m];
            for(int i=0;i<n;i++)
            {
                for(int j = 0; j < m ; j++)
                {
                 was[i][j] = 0;
                }
             }
              pii q[n*m];

             was[n-1][m-1] = 1; // n,m is starting node
              q[0] = mp(n-1 , m-1);
              int l = 0 , r = 1;
              while(l < r )
            {
                int i = q[l].fi;
                int j = q[l].se;
                for(int k = 0; k < 4;k++)
                {
                    int ni = i + int (k == 0) - int (k == 1); // for this disable int long long
                    int nj = j + int (k == 2) - int (k == 3);
                    if(ni < 0 || nj < 0 || ni >= n || nj >= m|| was[ni][nj])continue;
                    q[r++] = mp(ni , nj);
                    was[ni][nj] = 1;
                }
                l+=1;
            }

-----------BFS----------------
*/
/*
-------------DFS--------------
bool visit[N];
int par[N];
vector<int> g[N];
void dfs1(int v)
{
    visit[v] = true;
    for(auto child : g[v])
    {
         if(!visit[child])
              dfs1(child);
    }

}

void dfs2(int v, int p)
{
    par[v] = p;
    for(auto child : g[v])
    {
          if(child == par[v])
                continue;
          dfs(child,v);
    }

}
-------------DFS--------------
*/
/*
----------------DFS for calculating depth of each element as well as number of children---------------
#define maxn 200005
#define pb push_back
vector<int>adj[maxn];
int depth[maxn] , size[maxn] , det[maxn];
int dfs(int u , int f)
{
    depth[u] = depth[f] + 1;
    size[u] = 1;
    for(auto i : adj[u])
    {
        size[u] += dfs(i , u);
    }
    det[u] = size[u] - depth[u];
    return size[u];
}
dfs(1 , 0);
---------------------DFS---------------------------
*/
#define pb push_back
//#define int long long
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

/*int dfs(string s , char c)
{
    int n = s.length();
    if(n == 1)
    {
        if(c == s[0]) return 0;
        else return 1;

    }
    int lc = 0;

    for(int i=0;i<n/2;i++)
    {
        if(s[i] != c){lc += 1;}
    }
int rc = 0;
    for(int i=n/2;i<n;i++)
    {
        if(s[i] != c){rc += 1;}
    }
    return min(dfs(s.substr(0 , n/2) , c + 1) + rc , dfs(s.substr(n/2 , n) , c + 1) + lc);
}
*/
//cout<<sum==1?"Carrots":sum==2?"Kiwis":"Grapes"
//printf("%s\n",sum==1?"Carrots":sum==2?"Kiwis":"Grapes");
#define float double
float distance(int x1, int y1, int x2, int y2)
{
    // Calculating distance
    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}
const int mod = 1e9 + 7;
int factorial(int n)
{
    // single line to find factorial
    return (n == 1 || n == 0) ? 1 : (n+mod)%mod * factorial(n - 1);
}
bool comp(pair<int , float>a , pair<int , float>b)
{
    if(a.se == b.se)return a.fi < b.fi;
    return a.se > b.se;
}
const int X[]={1,0,-1,0,1,1,-1,-1};
const int Y[]={0,1,0,-1,1,-1,1,-1};
/*bool dista(int x ,int y)
{
    for (int i = 0; i<n; i++)
    {
        int l = (x-data[i].x)*(x-data[i].x) + (y-data[i].y)*(y-data[i].y);
        if ( l <= data[i].r * data[i].r )
        {
            return false;
        }
    }
    return true;
}
*/
//const int mxn=1e6+9;
//int divv[mxn];
//for(i=1;i<mxn;i++) for(j=i;j<mxn;j+=i) divv[j]++;
const int maxn = 200005;
#define int long long
int n , l , r , x;
int gg = 0;
int nas = 0;
int arr[20];
void dfs(int u , int i)
{
    for(int j = i+1;j<n;j++)
    {
        if(gg - arr[j] >= x && (u + arr[j]) >= l && (u + arr[j]) <= r)
                {  nas += 1;}
                if(u + arr[j] <= r)
                    {dfs(u + arr[j] , j);}
    }
}
signed main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    //cin>>t;
    while(t--){

       //----------------------------------------------/    /

        cin>>n>>l>>r>>x;
        //int nas =0;

        int pre[n+1] = {0};
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            //pre[i+1] = pre[i] + arr[i];
        }
        sort(arr , arr + n , greater<int>());
        for(int i=0;i<n;i++)
        {
            pre[i+1] = pre[i] + arr[i];
        }
        for(int i=0;i<n;i++)
        {

                gg = 0;
                gg = arr[i];

                    dfs(arr[i], i);

            }

        cout<<nas;

        //---------------------------------------------//

    }
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int problems (vector<unsigned int> v,int l,int r, int x);

int main(){

	int n,l,r,x;
	cin >> n;
	cin >> l;
	cin >> r;
	cin >> x;

	vector<unsigned int> input;
	int flash;
	for (int nn = 0; nn < n; nn++) {
		cin >> flash;
		input.push_back(flash);
	}

	cout << problems(input,l,r,x) << "\n";

	input.clear();

    return 0;
}

int problems (vector<unsigned int> v,int l,int r, int x)
{
	int s = v.size(), totalLR=0, min, max, combinaciones=0;

	bool primerJ;

	for (int i=0; i<(1<<s); i++)
	{
		primerJ=false;

		for (int j=0; j<s; j++)
		{
			if ( (i&(1<<j)) != 0)
			{
				if (!primerJ)
				{
					min=max=v[j];
					totalLR+=v[j];
					primerJ=true;
				}
				else
				{
					if (v[j]<min)
						min=v[j];
					if (v[j]>max)
						max=v[j];
					totalLR+=v[j];
				}
			}
		}

		if(totalLR>=l && totalLR<=r && max-min>=x)
			combinaciones+=1;
		totalLR=0;
	}
	return combinaciones;
}

#include<bits/stdc++.h>
using namespace std;
const int MAXN=20;
int ans,n,l,r,x,mn,mx,sm;
int a[MAXN];
int main()
{
	cin>>n>>l>>r>>x;
	for (int i=0;i<n;i++)cin>>a[i];
	for (int i=0;i<(1<<n);i++){
		mn=(int)1e9,mx=-mn;
		sm=0;
		for(int j=0;j<n;j++) {
			if(i&(1<<j)){
				mn=min(mn,a[j]);
				mx=max(mx,a[j]);
				sm+=a[j];
			}
		}
		if(sm>=l && sm<=r && mx-mn>=x)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n,l,r,x,c[1000000],a,k,dem,maxx,minn,ok[10000000];
void TRY(){
	k=0;
	minn=999999999;
	maxx=-1;
	for(int p=1;p<=n;p++){
		if(ok[p]==1){
			k+=c[p];
			minn=min(c[p],minn);
			maxx=max(c[p],maxx);
	}
}}

void GETBIT(int y){
	for(int p=1;p<=n;p++){
		a=(y>>(p-1))&1;
		ok[p]=a;
	}
}
int main(){
	//freopen("CONTEST.INP","r",stdin);
	//freopen("CONTEST.OUT","w",stdout);
	cin>>n>>l>>r>>x;
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=3;i<=pow(2,n)-1;i++){
		GETBIT(i);
		TRY();
		if((maxx-minn)>=x&&k>=l&&k<=r)dem++;
	}
	cout<<dem;
}

#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<pair<int,int>>
#define ll long long
#define fastio std::ios::sync_with_stdio(false); cin.tie(NULL);
#define lim 200005
using namespace std;

int main(){
fastio;
int n,l,r,x;
cin >> n >> l >> r >> x;
int t[n];
for(int i=0;i<n;i++) cin >> t[i];
int ans=0;
for(int m=0;m<(1<<n);m++){
int mn=INT_MAX,mx=INT_MIN,cnt=0,sum=0;
for(int i=0;i<n;i++){
if(((m) & (1<<i))!=0){
cnt++;
mn=min(mn,t[i]);
mx=max(mx,t[i]);
sum+=t[i];
}

}

if(cnt>1 && mx-mn>=x && sum <=r && sum>=l) ans++;
}
cout << ans;
return 0;
}

#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0);
#define ll long long
#define endl '\n'
using namespace std;
const int N = 15+ 5;
int n, l, r, x;
int main()
{
	IO
		cin >> n >> l >> r >> x;
	int  arr[N];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int  ms = (1 << n);
	int  ans = 0;
	for (int mask = 0; mask < ms; mask++)
	{
		int  mn = 1e7, mx = -1, dif = 0,sum=0;
		for (int i = 0; i < n; i++)
		{
			if ((mask&(1 << i)))
			{
				mn = min(mn, arr[i]);
				mx = max(arr[i], mx);
				sum += arr[i];
			}
		}
		dif = mx - mn;
		if (sum >=l && sum <=r && dif >= x)
			ans++;
	}
	cout << ans << "\n";

}

#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <map>
#include <list>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <fstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MAXPRIME 1000000007

bool compare(int a, int b)
{
	return a > b;
}

class Compare
{
	public:
		bool operator()(int a, int b)
		{
			return a > b;
		}
};

int mod(int a, int b)
{
	return ((a % b) + b) % b;
}

int main()
{
	int n,l,r,x,c[20],cnt = 0, limit = 0;
	scanf("%d %d %d %d",&n,&l,&r,&x);
	for(int i=0;i<n;i++)
		scanf("%d",&c[i]);
	sort(c, c+n);
	for(int i=0;i<n;i++)
		limit |= (1 << i);
	for(int i=0;i<=limit;i++)
	{
		bool flag = false;
		ll tn = 0, first, last, tc = 0, mask = i, j=0;
		while(mask > 0)
		{
			if(mask & 1)
			{
				tn++;
				tc += c[j];
				if(!flag)
					first = c[j],flag = true;
				last = c[j];
			}
			mask >>= 1;
			j++;
		}
		if(tn >= 2 && tc >= l && tc <= r && last - first >= x)
			cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1};
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++)
#define LB lower_bound
#define UP upper_bound
#define INF 999999999999
const double PI = acos(-1.0);
int n;
ll c[15];
ll l,r,x;
ll mn,mx;
int ans;
int cnt;
ll ret;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w".stdout);
    cin >> n >> l >> r >> x;
    rep1(i,0,n) cin >> c[i];

    for(int i = 0; i < (1 << n); i++){
        cnt = ret = 0;
        mx = 1; mn = 1e9;
        for(int j = 0; j < n; j++){
            if(i & (1 << j)){
                cnt++;
                ret += c[j];
                mx = max(mx,c[j]);
                mn = min(mn,c[j]);
            }
        }
        if(cnt >= 2 && ret <= r && ret >= l && (mx-mn) >= x) ans++;
    }
    cout << ans;
    return 0;
}

#include<bits/stdc++.h>
int n,left,right,x,a[20];
int f(int i,int sum,int l,int h,int c)
{
    if(i>=n)
    return 0;
        int pl=l,ph=h;
        if(a[i]<l)
            l=a[i];
        if(a[i]>h)
            h=a[i];
            int f1,f2;
            f1=f(i+1,sum+a[i],l,h,c+1);
             f2=f(i+1,sum,pl,ph,c);
            if(sum+a[i]>=left&&sum+a[i]<=right&&(h-l)>=x&&c+1>=2)
            return 1+f1+f2;
            return f1+f2;
        }
int main()
{
    scanf("%d %d %d %d",&n,&left,&right,&x);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    printf("%d",f(0,0,INT_MAX,INT_MIN,0));
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,l,r,x,arr[30],ans = 0;
    cin >> n >> l >> r >> x;
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    for(int mask = 0; mask < (1<<n) ; mask++)
    {   int mn = 10000000,mx = -1230134 , c = 0,sum = 0;
        for(int i = 0; i <n; ++i)
        {
            if ((mask& (1<<i)) != 0)
            {

                c++;
                sum+=arr[i];
                mn = min(mn , arr[i]);
                mx = max(mx , arr[i]);
            }
        }
        if(mx - mn >=x && sum >=l && sum <=r && c >=2)
        {   ans++;

                    }
    }
    cout << ans;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
//           Allah_Almost3aan
//*{ربى.. كنْ لىِ خيرَ مدبر فإنى لا احسنُ التدبير}*
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int lli;
typedef  long long ll;
typedef  unsigned long long ull;
typedef  long double ld;
#define ed "\n"
#define INF 1e9
#define SZ 1000007
#define ff first
#define ss second
#define sz(a) a.size()
#define RT(v) return cout<<v<<ed,0
#define stpr(n) fixed<<setprecision(n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
string ys = "YES", no = "NO", st;
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dj[8] = { 0, -1, 0, 1, 1, 1, -1, -1 };
const int N = 1.5 * 10000000 + 16;
const lli  OO = 1e18;
lli mod = 1e9 + 7;
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
int n, l, r, x;
vector<int>v;
int Tryall(int i, int sum, int mx, int mn)
{
	if (i == n || sum >= r)
	{
		if (sum >= l&&sum <= r&&mx - mn >= x)
			return 1;
		else return 0;
	}
	return Tryall(i + 1, sum + v[i], max(mx, v[i]), min(mn, v[i]))
		+ Tryall(i + 1, sum, mx, mn);
}
int main()
{
	fast();
	int q;	//cin >> q;
	q = 1;
	while (q--)
	{
		 cin >> n >> l >> r >> x;
		 v.resize(n);
		 for (auto &i : v) cin >> i;
		 cout << Tryall(0, 0, 0, 1e9) << ed;
	}
}

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fastio              ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int                 long long
#define ll                  long long
#define ld                  long double
#define vi                  vector<int>
#define pii                 pair<int,int>
#define vpii                vector< pair<int,int> >
#define uset                unordered_set
#define umap                unordered_map
#define maxpq               priority_queue<int>
#define minpq               priority_queue<int,vi,greater<int>()>

#define all(v)              v.begin(),v.end()
#define part(v,s,e)         v.begin()+s,v.begin()+e
#define rev(v)              reverse(v.begin(),v.end())
#define sz(x)               (int)x.size()
#define def(v)              memset(v,-1,sizeof(v));
#define def0(v)             memset(v,0,sizeof(v));
#define minv(a)             *min_element(all(a))
#define maxv(a)             *max_element(all(a))
#define sumv(a)             accumulate(all(a),0)

#define lb                  lower_bound         //returns the index of the next smallest number just greater than or equal to that number.
#define ub                  upper_bound         //returns the index of the first element in the range [first, last) that is greater than value, or last if no such element is found.
#define desc                greater<int>()
#define pb                  emplace_back
#define mp                  make_pair
#define F                   first
#define S                   second

#define mod                 1000000007
#define inf                 1000000000000000
#define infty               1000000000000000000LL
#define md                  998244353
#define PI                  acos(-1.0)
#define endl                "\n"
#define rr                  return
#define br                  cout<<"\n";
#define hr                  for(int i=0;i<40;i++)    cout<<"-";cout<<endl;

#define gcd(a,b)            __gcd(a,b)
#define lcm(a,b)            (a/(__gcd(a,b)))*b

#define setbits(x)          __builtin_popcountll(x)
#define leadzero(x)         __builtin_clzll(x)
#define trailzero(x)        __builtin_ctzll(x)

#define ip(v)               for(auto& i:v)    cin>>i;
#define op(v)               for(auto i:v)    cout<<i<<" ";cout<<endl;
#define deb(x)              cout <<"Value of " #x << " : " << x << endl;

#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

#ifndef ONLINE_JUDGE
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {cout << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << "  ";
    __f(comma + 1, args...);
}
#else
#define dbg(...) 50
#endif

void solve()
{

    int n,l,r,x;
    cin>>n>>l>>r>>x;

    vi c(n);
    ip(c);

    int ans=0;

    for(int i=0;i<(1<<n);i++)   // iterating over all the possible 2^n subsets.
    {
        int mn=INT_MAX,mx=INT_MIN,cnt=0,sum=0;

        for(int j=0;j<n;j++)
        {
            if((i>>j)&1)    // checking if the jth bit is set(1) in i or not. i.e. we should inculde this number in the current subset or not.
            {
                cnt++;
                sum+=c[j];
                mx=max(mx,c[j]);
                mn=min(mn,c[j]);
            }
        }

        if(cnt>=2 and sum>=l and sum<=r and mx-mn>=x)
            ans++;

    }

    cout<<ans<<endl;

}

int32_t main()
{

    fastio
    cout<<setprecision(15)<<fixed;

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif

    int t=1;
    // cin>>t;

    for(int i=1;i<=t;i++)
    {
        // cout<<"Case #"<<i<<" : "<<endl;
        solve();
    }

    #ifndef ONLINE_JUDGE
        cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    #endif

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
const int oo = 1e9;
const ll OO = 1ll << 62;
const int M = 1 << 15;
int n, l, r, x;
int a[15];
int dp[15][M];
int calc(int msk, int i) {
    if (i == n)
        return 0;
    int &ret = dp[i][msk];
    if (ret != -1)
        return ret;
    ret = 0;
    vector<int> v;
    ll sum = 0;
    int nmsk = msk;
    nmsk |= (1 << i);
    for (int j = 0; j < n; ++j) {
        if ((nmsk >> j) & 1) {
            v.pb(a[j]);
            sum += a[j];
        }
    }
    sort(v.begin(), v.end());
    if (v.size() >= 2) {
        ll d = v[v.size() - 1] - v[0];
        if (d >= x && sum >= l && sum <= r)
            ret += 1;
    }
    ret += calc(nmsk, i + 1);
    ret += calc(msk, i + 1);
    return ret;

}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    scanf("%d%d%d%d", &n, &l, &r, &x);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    memset(dp, -1, sizeof(dp));
    printf("%d\n", calc(0, 0));
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long n ,  l , r , x;
long long a[20];

long long solve(long long ind , long long sum , long long smallest , long long biggest){
    if(ind == n){
        if(sum <= r && sum >= l && biggest - smallest >= x)return 1;
        return 0;
    }

    long long ans = solve(ind+1 , sum , smallest , biggest);
    smallest = min(smallest , a[ind]);
    biggest = max(biggest , a[ind]);
    ans += solve(ind+1 , sum+a[ind] , smallest , biggest);
    return ans;

}

int main(){
    cin >> n >> l >> r >> x;
    for(long long i  = 0 ; i < n ; ++i){
        cin >> a[i];
    }
    cout << solve(0 , 0 , 1e9 , -1e9);
    return 0;
}

#include<bits/stdc++.h>
#define MAX 10000
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long l64d;
typedef unsigned long int ud;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
l64d n,l,r,x,diff[10000001];
l64d cnt=0;
void cek(int first,l64d sum,int last)
{
    if(sum>r) return;
    if(sum<=r && sum>=l && first!=last && diff[last]-diff[first]>=x)cnt++;
    for(int i=last+1;i<n;i++)
    {
        cek(first,sum+diff[i],i);
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    std::ios::sync_with_stdio(false);
    cin>>n>>l>>r>>x;
    for(int i=0;i<n;i++) cin>>diff[i];
    sort(diff,diff+n);
    for(int i=0;i<n;i++) cek(i,diff[i],i);
    cout<<cnt<<endl;
}

/*
->>Kartheek Bellamkonda
*/
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<cmath>
 using namespace std;
 #pragma GCC optimize("O3")
 #define lli long long int
 #define ull  unsigned long long int
 #define yes cout<<"YES\n"
 #define no cout<<"NO\n"
 #define endll '\n'
 #define space " "
 #define rs(n) string n;cin>>n;
 #define read(n) lli n;cin>>n;
 #define ra(a,n) lli a[n];for(lli i=0;i<n;i++){cin>>a[i];}
 #define print(n) cout<<n<<end;
 #define pa(a,n) for(lli i=0;i<n;i++){cout<<a[i]<<space;} cout<<end;
 #define ld long double
 #define pb push_back
 #define fi first
 #define sec second
 #define db pop_back
 #define si size()
 #define bk back()
 #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
 #define beg begin()
 #define en end()
 #define pll pair <long long,long long>
 #define pli pair <long long , int>
 #define pii pair <int,int>
 #define pil pair <int,long long>
 #define forf(i,a,n) for(lli i=a;i<n;i++)
 #define forfe(i,a,n) for(lli i=a;i<=n;++i)
 #define test lli t; cin>>t;while(t--)

 lli powm(lli x,lli y,lli m){
    lli ans=1,r=1;
    x%=m;
    while(r>0&&r<=y){
        if(r&y){
            ans*=x;
            ans%=m;
        }
        r<<1;
        x*=x;
        x%=m;
    }
    return ans;
}

 bool isPrime(lli n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (lli i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
 lli lcm(lli a, lli b){
    return a / __gcd(a, b) * b;
}
 //***********************************************************************************
 // **********************************************************************************
 const lli INF = 1e9+5;

 int main(){
  fastio;
  read(n);
  read(l);
  read(r);
  read(x);
  ra(c,n);
  lli ans = 0;
  for(lli mask=0;mask<pow(2,n);mask++){
     vector<lli>v;
     lli sum =0;
    for(lli i =0 ;i<n;i++){
      if(mask&(1<<i)){
        v.pb(c[i]);
        sum+=c[i];
      }
    }
    sort(v.begin(),v.end());
    if(sum>=l && sum<=r && v[v.size()-1]-v[0]>=x){
      ans++;
    }
    v.clear();
  }
  cout<<ans<<endl;
 }

#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
int n,l,r,x;
int a[15];
int p[15];
int q[15];
void binary(int k,int n)
{
    int i=0,j=0;
    while(k)
    {
        if(k%2==0)
        p[i++]=0;
        else
        p[i++]=1;
        k=k/2;
    }
    for(j=i;j<n;j++)
    p[i]=0;
    /*for(i=0;i<n;i++)
    printf("%d  ",p[n-i-1]);
    printf("\n");*/
}
int hardest(int k)
{
  int i=0,j=0;
    while(k)
    {
        if(k%2==0)
        q[i++]=0;
        else
        q[i++]=1;
        k=k/2;
    }
    for(j=i;j<n;j++)
    q[i]=0;
    //printf("%d\n",i-1);
    return (i-1);

}

int main()
{
    scanf("%d %d %d %d",&n,&l,&r,&x);
    int i=0,j=0,k=0,min=0,max=0,sum=0,flag=0,total=0;
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    std::sort(a,a+n);
    k=(int)pow(2,n);
    for(i=0;i<k;i++)
    {
      sum=0;
      min=0;
      max=hardest(i);
      if(max)
      max=a[max];
      flag=0;
      binary(i,n);

      for(j=0;j<n;j++)
      {
        if(p[j]!=0)
        {
            if(flag==0)
            {
                min=a[j];
                flag=1;
            }
          sum+=a[j];
        }
      }

        if(max-min>=x && sum>=l && sum<=r)
        {
            //printf("AA %d   %d   %d\n",min,max,sum);
        total++;
        }
    }
      printf("%d",total);
      return 0;
}

#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll n , l , r , x ;
ll arr[20] ;
//map<ll,ll> res ;
ll res=0 ;
ll fact[25] ;

bool isvalid(vector<ll> temp)
{
    ll maxx=0 ;
    ll minn=1e18 ;
    for(int i=0 ; i<temp.size() ; i++){
        if(arr[temp[i]]>maxx){maxx=arr[temp[i]] ;}
        if(arr[temp[i]]<minn){minn=arr[temp[i]] ;}
    }
    if(abs(minn-maxx)>=x){return true ;}
    return false ;
}

bool notused(vector<ll> temp , ll idx)
{
    for(int i=0 ; i<temp.size() ; i++){
        if(temp[i]==idx){return false ;}
    }
    return true ;
}

void solve(vector<ll> temp , ll num , ll idx)
{
    if(isvalid(temp)==true && temp.size()>=2 && num>=l){
       // res[temp.size()]++ ;
       res++ ;
    }
    for(int i=idx ; i<n ; i++){
        if(num+arr[i]<=r && notused(temp,i)){
            vector<ll> ay7aga = temp ;
            ay7aga.push_back(i) ;
            solve(ay7aga,num+arr[i],i+1) ;
        }
    }
}

ll fac(ll num)
{
    ll res=1 ;
    for(int i=1 ; i<=num ; i++){res*=i ;}
    return res ;
}

int main()
{
    ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;

   // for(int i=1 ; i<=15 ; i++){fact[i]=fac(i) ;}

    cin>>n>>l>>r>>x ;
    for(int i=0 ; i<n ; i++){cin>>arr[i] ;}
    for(int i=0 ; i<n ; i++){
        vector<ll> vec ;
        vec.push_back(i) ;
        solve(vec,arr[i],i+1) ;
    }
   /* ll ans=0 ;
    for(int i=2 ; i<=15 ; i++){
        ans+=(res[i]/fact[i]) ;
    }
    cout<<ans<<endl;  */

    cout<<res<<endl;

    return 0;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#define N 100005
using namespace std;
int a[20];
int n, l, r, x;

int main(){
    cin>>n>>l>>r>>x;
    for(int i=0; i<n; ++i)
        cin>>a[i];
    int s = 1<<n;
    int cnt = 0;
    for(int i=1; i<s; ++i){
        int sum = 0, minn = 10000000, maxn = -1;
        for(int j=0; j<n; ++j)
            if((1<<j)&i){
                sum += a[j];
                minn = min(minn, a[j]);
                maxn = max(maxn, a[j]);
            }
        if(sum>=l && sum<=r && maxn-minn>=x)
            ++cnt;
    }
    cout<<cnt<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define y1 asdfghjkl
#define int long long
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll N = 1e6 + 500;

int n, l,r, x, c[22],ans;
main()
{
	cin >> n >> l >> r >> x;
	for(int i = 0; i < n; ++i)
		cin >> c[i];
	for(int i= 0; i < (1<<n);++i)
	{
		int sum = 0, cnt = 0, mn=mod,mx=0;
		for(int j = 0; j <n;++j)
		{
			if(( (i >> j) & 1 ))
			{
				sum += c[j];
				cnt++;
				mx=max(c[j], mx);
				mn = min(c[j],mn);
			}
		}
//		cout << sum << " "<<cnt<<endl;
		if(mx - mn >= x&&cnt >= 2 && l <= sum && sum <= r)
			ans++;
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
#define mod  1000000007
#define mp make_pair
#define pb push_back
#define sd second
#define mod  1000000007
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
ll i, j, k;
void solve(){
       ll n,l,r,x; cin >> n >> l >> r >> x; vl v(n);
       for(i = 0; i < n; i++) cin >> v[i];
        sort(all(v));
        ll cnt = pow(2,n);
        ll ans =0;
        for(i = 0; i < cnt ; i++){
          vl subsets;
          ll sum = 0;
           for(j = 0; j < n; j++){
             if((i & (1<<j)) > 0) subsets.pb(v[j]), sum = sum +v[j];
            }
            if((int)subsets.size()>=2){
                ll  y = (int)subsets.size();
                y--;
                if((subsets[y]-subsets[0]) >= x and sum >=l and sum <= r ) ans++;
              }
        }
        cout<< ans << endl;

     return ;
}
    signed main(){
    #ifndef ONLINE_JUDGE
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
    #endif
    //CASET
    solve();

    return 0;
  }

#define _CRT_SECURE_NO_WARNINGS
#include<bits\stdc++.h>
using namespace std;

const long long OO = 1e6;
const long long mod = 1e9 + 7;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

void fast(){
#ifndef ONLINE_JUDGE
	freopen("F:\\solving\\input.txt", "r", stdin);
	freopen("F:\\solving\\output.txt", "w", stdout);

#endif
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
vector<int>v;
int n, l, r, x, mn, mx, a[16];
int rec(int i, int cnt, int sum)
{
	if (i > n)
	{
		mn = 1000000, mx = -1;
		for (int j = 0; j < v.size(); j++)
		{
			if (v[j] < mn)mn = v[j];
			if (v[j] > mx)mx = v[j];
		}
		if (cnt >= 2 && mx - mn >= x&&sum >= l&&sum <= r)
			return 1;
		else
			return 0;
	}
	int ret = 0;
	v.push_back(a[i]);
	ret += rec(i + 1, cnt + 1, sum + a[i]);
	v.pop_back();
	ret += rec(i + 1, cnt, sum);
	return ret;
}
int main()
{
	fast();

	cin >> n >> l >> r >> x;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	cout << rec(1, 0, 0) << endl;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
/*
int main(){
const int Size = 3;
    int a [Size] = {5,8,13};
    for (int i =0 ; i < (1 << Size ); i++)
    {
        // (i) in Binary , represent one of  possible sub-sequance
        for (int j =0 ; j < Size ;j++)
        {
            // Check Bits of number i
            // If bit is set ,clr
            // set mean this element in current sub-sequance
            // if j bit is set
            if (i &(1 << j))
            {
                cout << a[j] <<" ";
            }
        }
        cout <<"\n";
    }
}
*/
int main()
{
int n, l, r, x ,ans=0;
cin>>n>>l>>r>>x;
int a[n];
for (int i =0 ; i < n ; i++)
    cin>>a[i];
for (int i =2 ; i < (1 << n ); i++)
      {
          int mn = 1e9+10 , mx =-1, c=0,sum =0;
  for (int j =0 ; j < n ;j++)
        {

        if (i &(1 << j))
        {
            sum+=a[j];
            c++;
            mn = min(mn,a[j]);
            mx = max(mx,a[j]);

        }

             }
if(sum>=l && sum <=r && c>=2 && mx-mn>=x)
            ans++;
      }
      cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
int ara[33];
int a,b,n,x;
int cnt=0;
int call(int i,int mn,int sum)
{
    cnt++;
//    cout<<i<<"  "<<mn<<"  "<<sum<<endl;
    if(sum>b)return 0;
    if(i==n)return 0;
    int inc=0,exc=0;
    int temp=ara[i]+sum;
    inc=call(i+1,min(mn,ara[i]),temp);
    if(temp>=a&&temp<=b)
    {
        if(ara[i]-mn>=x)inc++;
    }
    exc=call(i+1,mn,sum);
    return inc+exc;
}

int main()
{
    cin>>n>>a>>b>>x;
    for(int i=0;i<n;i++)cin>>ara[i];
    sort(ara,ara+n);
//    for(int i=0;i<n;i++)cout<<ara[i]<<" ";cout<<endl;
    int ans=call(0,9999999,0);
    cout<<ans<<endl;
//    cout<<" cnt = "<<cnt<<endl;
}

#include<iostream>
using namespace std;

int ans, n, l, r, x;
int a[16];
int cnt;

void dfs(int index, int now, int sum, int minn, int maxn) {
	if (now == cnt) {
		if (sum >= l && sum <= r && maxn - minn >= x) {
			ans++;
		}
		return;
	}
	if (index >= n) return;
	int min = minn < a[index] ? minn : a[index];
	int max = maxn > a[index] ? maxn : a[index];
	dfs(index + 1, now + 1, sum + a[index], min, max);
	dfs(index + 1, now, sum, minn, maxn);
}

int main() {
	ans = 0;
	cin >> n >> l >> r >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 2; i <= n; i++) {
		cnt = i;
		dfs(0, 0, 0, 99999999, -1);
	}
	cout << ans << endl;
	return 0;
}

#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<cctype>
#include <iomanip>
#include <string>
#include <sstream>

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>=    b;i--)
#define sz(a) ((int)a.size())
#define all(c) c.begin(), c.end()

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;

struct sp{ bool operator() (const string &left, const string &right){ return right < left; } };

ll stoi(string &str) { istringstream ss(str); ll i; ss >> i;    return i; }

string itos(ll i) { stringstream ss; ss << i;   return ss.str(); }

ll numBits(ll n) {  ll c = 0;   while (n){  n &= (n - 1);   c++; }  return c; }

int main(){

    ll n, l, r, x;
    cin >> n >> l >> r >> x;
    vll v;
    for (ll i = 0; i < n; i++) {
        int x; cin >> x; v.pb(x);
    }

    ll c = 0;
    for (ll i = (1 << n) - 1; i >= 0;  i--) {

        ll mn = (2e9), mx = 0, sum = 0;

        for (ll j = 0; j < n; j++) if (i & (1 << j)){

            sum += v[j];
            mn = min(mn, v[j]), mx = max(mx, v[j]);

        }

        if (sum >= l && sum <= r && mx - mn >= x) c++;

    }

    cout << c << endl;
    return 0;
}

#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include<iostream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <sstream>
//#define lp(i,n)    for(int i=0;(int)i<n;++i)
typedef long long ll;
using namespace std;
const int MAX = 1e18+9;
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
void fast() {
	std::ios_base::sync_with_stdio(0);
}
int n, l, r, x;
int difficulty[15];
bool vis[15];
int ans = 0;
int layer = 1;
void backtraking(int mi, int sum,int pos, int mx)
{
	layer++;

	if (sum >= l && sum <= r && mx - mi >= x&&layer!=2)
	{
		ans++;
	}
	if (pos == n) {

		return;
	}

	for (int i = pos; i < n; i++)
	{

		backtraking(mi, sum+difficulty[i], i + 1, difficulty[i]);

	}

}

int main()
{
	cin >> n >> l >> r >> x;
	if (n == 1)
	{
		cout << 0;
		return 0;
	}
	for (int i = 0 ; i < n; i++)
	{
		cin >> difficulty[i];
	}
	sort(difficulty, difficulty + n);

	for (int i =0 ; i < n-1; i++)
	{
		layer = 1;
		backtraking(difficulty[i], difficulty[i], i + 1,difficulty[i+1]);
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 100;
ll n, l, r, x, ans;
ll a[15], b[15];
ll run() {
    ll sum = 0, mn = 1e12, mx = 0;
    for (ll i = 0; i < n; i++) {
        if(b[i] == 0) continue;
        mx = max(b[i], mx);
        mn = min(b[i], mn);
        sum += b[i];
    }
    if (mx - mn >= x && l <= sum && sum <= r) ans++;
}

void go(ll i) {
    if(i == n) {
        run();
        return;
    }
    b[i] = 0;
    go(i + 1);
    b[i] = a[i];
    go(i + 1);
}

void solve(){
    cin >> n >> l >> r >> x;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    go(0);
    cout << ans << '\n';
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    //ll t; cin >> t; while(t--)

    solve();
}

#include<bits/stdc++.h>
using namespace std;
int N,L,R,X;
int A[16],ans;
void dfs(int n,int sum,int mn,int mx)
{
	if(n>N)
	{
		if(L<=sum&&sum<=R&&mx-mn>=X)ans++;
		return;
	}
	dfs(n+1,sum,mn,mx);
	dfs(n+1,sum+A[n],min(mn,A[n]),max(mx,A[n]));
}
int main()
{
	cin>>N>>L>>R>>X;
	for(int i=1;i<=N;i++)cin>>A[i];
	sort(A+1,A+N+1);
	dfs(1,0,2e9,0);
	cout<<ans;
	return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

const int maxn = 20;
int n, l, r, x, sum, lo, hi, cnt, c;
int problems[maxn];
int vis[maxn];

void dfs(int s) {
	if (sum > r || c > n)return;
	if (sum >= l && c <= n && c >= 2 && hi - lo >= x)cnt++;
	for (int i = s; i < n; i++) {
		if (!vis[i]) {
			vis[i] = 1;
			c++;
			sum += problems[i];
			hi = problems[i];
			dfs(i);
			sum -= problems[i];
			c--;
			vis[i] = 0;
		}
		if (!c)lo = problems[i + 1];
	}
}

int main() {
	while (cin >> n >> l >> r >> x) {
		sum = 0, cnt = 0, c = 0;
		for (int i = 0; i < n; i++)
			cin >> problems[i];
		sort(problems, problems + n);
		lo = problems[0];
		dfs(0);
		cout << cnt << endl;
	}
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n , l , r , x ;
	cin >> n >> l >> r >> x ;

	int c[16];
	for (int i = 0 ; i < n ; i++) cin >> c[i] ;

	int ans = 0;
	int sum ;
	int lc , rc;
	for (int b = 3 ; b < (1 << n) ; b++) {
		if ( (b & (b - 1)) == 0) continue;
		sum = 0;
		lc = 1000000; rc = 0;
		for (int i = 0 ; i < n && sum <= r; i++) {
			if ( (1 << i) & b) {
				sum += c[i];
				lc = min(lc , c[i]);
				rc = max(rc , c[i]);
			}
		}
		if ( rc - lc >= x && sum <= r && sum >=l) ans++;
	}
	cout << ans << endl;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n , l , r , x ;
	cin >> n >> l >> r >> x ;

	int c[16];
	for (int i = 0 ; i < n ; i++) cin >> c[i] ;

	int ans = 0;
	int sum ;
	int lc , rc;
	for (int b = 3 ; b < (1 << n) ; b++) {
		if ( (b & (b - 1)) == 0) continue;
		sum = 0;
		lc = 1000000; rc = 0;
		for (int i = 0 ; i < n; i++) {
			if ( (1 << i) & b) {
				sum += c[i];
				lc = min(lc , c[i]);
				rc = max(rc , c[i]);
			}
		}
		if ( rc - lc >= x && sum <= r && sum >=l) ans++;
	}
	cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define mod                   1000000007
#define ll                    long long
#define Author                std::ios_base::sync_with_stdio(0);
#define NIKHIL_SETHI          cout.tie(0);
#define MNNIT_ALLAHABAD       cin.tie(0);
#define umii                  unordered_map<ll,ll>
#define mii                   map<ll,ll>
#define pii                   pair<ll,ll>
#define all(v)                v.begin(),v.end()
#define forP(i,j,k)           for(i=j; i<k; i++)
#define forN(i,j,k)           for(i=j; i>k; i--)
#define pb(a)                 push_back(a)
#define lb(v,t)               lower_bound(all(v),t)-v.begin()
#define ub(v,t)               upper_bound(all(v),t)-v.begin()
#define inf 1e18

//mainly used functions
bool prime[10000001];
ll abst(ll a){if(a<0)return -a; return a;}
ll power(ll a, ll b){ll res=1;while(b){if(b&1)res=res*a;a=a*a;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}
ll lcm(ll a, ll b){return a*b/__gcd(a,b);}
ll ncr(ll n, ll r){ll p=1;ll i;for(i=1; i<=r; i++){p*=(n-i+1);p*=i;}return p;}
void sieve(){ll i;ll j;memset(prime,true,10000000);prime[0]=prime[1]=false;for(i=2; i*i<=10000000; i++){if(prime[i]){for(j=2*i; j<=10000000; j+=i){prime[j]=false;}}}}

int main()
{
    ll n,l,r,x;
    cin>>n>>l>>r>>x;
    ll i,mask;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll c = 0;
    for(mask=0;mask<(1ll<<n);mask++)
    {
        ll c1 = 0;
        ll sum = 0;
        ll mn = 1e7;
        ll mx = -1;
        for(i=0;i<n;i++)
        {
            if(mask&(1ll<<i))
            {
                c1++;
                sum += a[i];
                mn = min(mn,a[i]);
                mx = max(mx,a[i]);
            }
        }
        if(c1>=2&&sum>=l&&sum<=r&&(mx-mn)>=x)
        {
            c++;
        }
    }
    cout<<c<<"\n";
}

#include<bits/stdc++.h>
#define  p5         100005
#define  p6         1000007
#define  PI         acos(-1)
#define  M          1000000007
#define  sc         scanf
#define  ss         second
#define  ff         first
#define  pf         printf
#define  scin(x)    sc("%d",&x)
#define  scin2(x,y) sc("%d%d",&x,&y)
#define  READ(f)    freopen(f, "r", stdin)
#define  WRITE(f)   freopen(f, "w", stdout)
#define  ll         long long
#define  pp         pair < int, int>
#define  pq         priority_queue
#define  pb         push_back
#define OK          pf("YES\n")
#define _OK         pf("NO\n")
#define all(v)      v.begin(), v.end()
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
vector<ll>v[p5+2],v1;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,i,j,k,l,r,x;
    cin>>n>>l>>r>>x;
    ll ar[n];
    for(i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    k=0;
    for(i=1; i<(1<<n); i++)
    {
        ll tmp;
        tmp=i;
        j=0;
        while(tmp>0)
        {
            if(tmp&1)
            {
                v[k].pb(v1[j]);
            }
            j++;
            tmp/=2;
        }
        k++;
    }
    ll cnt=0;
    for(i=0; i<k; i++)
    {
        ll s=0,si=v[i].size(),mx=INT_MIN,mi=INT_MAX;
        for(j=0; j<si && si>1; j++)
        {
            s=s+v[i][j];
            mi=min(mi,v[i][j]);
            mx=max(mx,v[i][j]);
        }
        if(si>1 && s>=l && s<=r && (mx-mi)>=x){
            cnt++;
        }

    }
    cout<<cnt<<endl;
    return 0;
}
//https://github.com/me-shaon/bangla-programming-resources

#include <bits/stdc++.h>
using namespace std;

int main(){

  int n,l,r,x;
       scanf("%d%d%d%d",&n,&l,&r,&x);
       int c[n];
        for(int i=0; i<n; i++)
           scanf("%d",c+i);

        int ans = 0;
        for(int m=0; m<(1<<n); m++) {
            int mn = (int) 1e6,mx = 0,cnt = 0,sum = 0;
            for(int i=0; i<n; i++) {
                if((m & (1<<i))!=0) {
                    cnt++;
                    sum += c[i];
                    mn = min(mn, c[i]);
                    mx = max(mx, c[i]);
                }
            }

            if(mx-mn >= x && sum>=l && sum<=r && cnt>=2) ans++;
        }

        printf("%d",ans);

return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[20];
int main(){
	int n,l,r,x;
	cin>>n>>l>>r>>x;
	for(int i=0;i<n;i++)cin>>a[i];
	int ans=0;
	for(int i=1;i<(1<<n);i++){
		int k=i;
		int mx=0;
		int mn=1e9;
		int cnt=0;
		int res=0;
		for(int j=0;j<n;j++){
			if(k%2==1){
				cnt+=a[j];
				mx=max(mx,a[j]);
				mn=min(mn,a[j]);
				res++;
			}
			k/=2;
		}
		if(res>1&&cnt>=l&&cnt<=r&&mx-mn>=x)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define PI 3.141592653589793
#define INF 0x3f3f3f3f
#define MAX 1000010
#define mod 100000000
#define eps 1e-6
#define N 123456
#define M 12345678
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
using namespace std;

int n,m,l,r,x;
int flag,sum,ave,ans,res;
int a[N],b[N];
//int f[N][N];
//int g[N][N];
//int dp[N][N];
//bool vis[N];
char s[101];
struct node
{
    int x,y;
    int r,w;
    int to,next;
    void init()
    {
        r=0;
    }
    friend bool operator < (node a, node b)
    {
//        if(a.y==b.y)return a.x > b.x;
        return a.r > b.r;
    }
}tn;
//node edge[M];
//int head[N];

int main()
{
    int i,j,k,kk,t,xx,yy,d;
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
//    scanf("%d",&k);
//    kk=0;
//    while(k--)
    while(scanf("%d%d%d%d",&n,&l,&r,&x)!=EOF&&n)
    {
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        res=0;
        for(i=0;i<(1<<n);i++)
        {
//            for(k=0;k<4;k++)
//                    printf("%d ",i&(1<<k));
//                printf("\n");
            sum=0;
            t=-INF;
            xx=INF;
            yy=0;
            ans=0;
            for(j=0;j<n;j++)
            {

                if((1<<j)&i)
                {
//                    printf("xx=%d yy=%d a[%d]=%d\n",xx,yy,j,a[j]);
                    xx=min(xx,a[j]);
                    yy=max(yy,a[j]);
                    sum+=a[j];
                    t=a[j];
                    ans++;
                }
            }
//            printf("yy=%d xx=%d res=%d\n",yy,xx,res);
            if(sum<=r&&sum>=l&&yy-xx>=x&&ans>1)
            {
                res++;
//                printf("res=%d\n",res);
            }
        }
        printf("%d\n",res);
    }
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
const int AKA =  1e5+5;
int arr[AKA] ;
int getFirstset(int n )
{
    for(int i =31 ; i>=0 ; i--)
        if(n & (1<<i))
            return i;
}
int getLastSet(int n)
{
    return (int)(log2(n & -n));
}
int main()
{
    //10 ,30  --- 20  , 30.
  int n, l, r, x, c=0;
    scanf("%d%d%d%d", &n, &l, &r, &x);
    for(int i = 0 ; i < n ; ++i)
        scanf("%d", arr+i);
    sort(arr, arr+n);
    for(int m = 0 ; m <(1<< n) ; ++m)
    {
        int total = 0, cnt=0 , diffire  , dif1 , dif2;
        for(int i = 0 ; i < m ; ++i)
            if((m & (1 << i)))
                total+=arr[i], cnt++;
            dif1 =getFirstset(m) , dif2=getLastSet(m);
            diffire = arr[dif1] - arr[dif2];
        if(total >= l && total <=r &&  cnt >=2 && diffire>=x)
            ++c;
    }
    printf("%d", c);
}

#include<bits/stdc++.h>
using namespace std;

long long n, l, r, x;
long long ins[15];
int cnt = 0;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> l >> r >> x;

	for (int i = 0; i < n; i++)
	{
		cin >> ins[i];
	}

	for (int i = 0; i < (1 << n); i++)
	{
		if (__builtin_popcount(i) == 1)
				continue;

		long long sum = 0;
		int mini = 1e9;
		int maxi = -1;
		bool was = true;

		for (int j = 0; j < n; j++)
		{
			if ((i & (1 << j)))
			{
				sum += ins[j];
				if (ins[j] < mini)
				{
					mini = ins[j];
				}
				if (ins[j] > maxi)
				{
					maxi = ins[j];
				}
			}
			if (sum > r)
			{
				was = false;
				break;
			}
		}
		if (was and sum >= l and sum <= r and maxi - mini >= x)
		{
			cnt++;
		}
	}
	cout << cnt;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	//freopen("in1","r",stdin);
 long long  n,l,r,x,a[20];

cin>>n>>l>>r>>x;

for(int i=0;i<n;i++)cin>>a[i];
long long  cnt=0;
long long sum=0;
long long  max1=0,min1=INT_MAX;
for(int   mask=1;mask<(1<<n);mask++){
	sum=0,min1=INT_MAX,max1=0;
		for(int i=0;i<n;i++){
	if((mask>>i) & 1){
		sum+=a[i];
		max1=max(max1,a[i]);
		min1=min(min1,a[i]);

		}
	}
	if(max1-min1>=x&&sum>=l&&sum<=r){
	cnt++;
	}
}
cout<<cnt<<endl;
	return 0;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Name:- OMHARI
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ull unsigned long long
#define ll long long
#define ul unsigned long
#define db double
#define ST string
#define pb push_back
#define mp make_pair
#define el "\n"
#define vll vector <ll>
#define vl vector <long int>
#define vi vector <int>
#define all(v) (v.begin(), v.end())
#define rall(v) (v.rbegin(), v.rend())
#define is_sort(v) is_sorted all(v)
#define max_of(v) *max_element all(v)
#define min_of(v) *min_element all(v)
#define itos(s) to_string(s)
#define cntone(x) __builtin_popcountll(x)
#define cntzro(x) __builtin_clz(x)
const ll mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    /***************-Code starts from here-***************/
    int n,l,r,x,cnt=0;
    cin>>n>>l>>r>>x;
    vi v(n);

    for(int i=0; i<n; i++) cin>>v[i];

    for(int i=1; i< 1<<n; i++)
    {
        if(cntone(i)>1)
        {
            //vi temp;
            int sum=0,mn=INT_MAX,mx=INT_MIN;
            for(int j=0; j<n; j++)
            {
                if(i & 1<<j)
                {
                    sum+=v[j];
                    if(mn>v[j])
                    mn=v[j];
                    if(mx<v[j])
                    mx=v[j];
                }
            }
            if(sum>=l && sum<=r && (mx-mn)>=x)
            cnt++;
        }
    }
    cout<<cnt;

    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long N,start,endd,dif,count1=0,res=0;
long long Arr[1000];
vector<long long> v;
void result(long long x,long long ans)
{

    if (x==N)
    {

    if (v.size()>=2 && ans>=start && ans<=endd && v[v.size()-1]-v[0]>=dif){
        count1++;
        res++;
    }
       /* if ((v[v.size()-1]-v[0])>=dif && ans>=start  && ans<=endd && v.size()>=2)
        {
            count1++;

        }*/
        return;
    }

    result(x+1,ans);
    v.push_back(Arr[x]);
    result(x+1,Arr[x]+ans);
    v.pop_back();
}
int main()
{
    cin>>N>>start>>endd>>dif;
    for (int i=0 ; i<N ; i++)
    {
        cin>>Arr[i];
    }
    sort(Arr,Arr+N);
    result(0,0);
    cout<<count1<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define Rawan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lln long long int
#define random srand(time(NULL));
#define mod 1000000007
#define memset(arr,value)  memset(arr, value , sizeof arr)

using namespace std;

lln arr[16]={};
lln a,b,c,d,cnt=0;
vector<lln>v;
void chk(lln ind){
	lln l=0;
	if(ind==a){
		if(v.size()>1){
			sort(v.begin(), v.end());
			for (int i=0 ; i<v.size() ; i++){
				l+=v[i];
			}
			if(l>=b&&l<=c&&(v[v.size()-1]-v[0])>=d){
				cnt++;
			}
		}
		return;
	}
	chk(ind+1);
	v.push_back(arr[ind]);
	chk(ind+1);
	v.pop_back();
}
int main() {
	cin>>a>>b>>c>>d;
	for (int i=0 ; i<a ; i++){
		cin>>arr[i];
	}
	sort(arr, arr+a);
	chk(0);
	cout<<cnt<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int n,l,r,x,ans;
int a[100];

int main()
{
	cin>>n>>l>>r>>x;
	for(int i=0;i<n;i++) cin>>a[i];

	int ans=0;

	for( int mask=0 ; mask < (1<<n) ; mask++ )
	{
		int s=0;
		int mn=  1e9;
		int mx= -1e9;

	 //each subset
	// vector<int>subset;

	for( int i=0;i<n;i++)
	{

	   	if( mask & (1<<i) )
	   	{

		   mn=  min( mn,a[i] );
	   	   mx= max(  mx,a[i] );
		   s= s+ a[i];
		  // subset.push_back( a[i] );

    	}

	}
	   /*
	   cout<<" subset_print "<<endl;

	   for( auto u : subset ) cout<<u<<" ";
	   cout<<endl;
	   cout<<"mx "<<mx<<" mn "<<mn<<" s "<<s<<endl;
	   */

	   if( mx-mn>=x && s>=l && s<=r ) ans++;

	}

//	cout<<"ans"<<endl;
	cout<<ans<<endl;

}

 ///IN THE NAME OF ALLAH
 #include<bits/stdc++.h>
 using namespace std;
 int arr[20];
 int main(){
  int n,l,r,diff,ans=0;
  cin >> n >> l >> r >> diff;
  int limit = (1<<n);
  for(int i=0;i<n;i++)
    cin >> arr[i];
  for(int i=0;i<limit;i++){
   int sum=0,mn=1e9,mx=-1;
   for(int j=0;j<n;j++)
     if(i&(1<<j)){
      sum+=arr[j];
      mn=min(mn,arr[j]);
      mx=max(mx,arr[j]);
     }
   if(sum>=l&&sum<=r&&mx-mn>=diff)
      ans++;
  }
  cout<<ans;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, l, x, r, ans, sum, maxi, mini, problem[20];
    scanf("%d %d %d %d", &n, &l, &r, &x);
    for(int i = 0; i < n; i++)scanf("%d", &problem[i]);
    ans = 0;
    for(int i = 0; i <= 1<<n; i++){
        maxi = sum = 0;
        mini = INFINITY;
        for(int j = 0; j < n; j++){
            if(1<<j & i){
                sum += problem[j];
                mini = min(mini, problem[j]);
                maxi = max(maxi, problem[j]);
            }
        }
        if((sum >= l && sum <= r) && (maxi - mini >= x))ans++;
    }
    printf("%d\n", ans);
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, l, r, x, ans = 0;
	cin >> n >> l >> r >> x;
	vector<int> c(n);
	for (int i = 0; i < n; ++i)
		cin >> c[i];
	int k = 1 << n;
	for (int i = 0; i < k; ++i) {
		int sum = 0, mn = 1000000000, mx = 0;
		for (int j = 0; j < n; ++j)
			if (i & (1 << j)) {
				sum += c[j];
				mn = min(mn, c[j]);
				mx = max(mx, c[j]);
			}
		if (l <= sum && sum <= r && mx - mn >= x)
			++ans;
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

main(){
	int problems, minDiff, maxDiff, minDiffProb, ans = 0, mind, maxd, sum, prob[20];
	scanf("%d %d %d %d", &problems, &minDiff, &maxDiff, &minDiffProb);

	for(int i = 0; i < problems; i++)scanf("%d", &prob[i]);

	for(int i = 0; i <= (1<<problems); i++){
		sum = maxd = 0;
		mind = INT_MAX;
		for(int j = 0; j < problems; j++){
			if(i & 1<<j){
				sum += prob[j];
				mind = min(mind, prob[j]);
				maxd = max(maxd, prob[j]);
			}
		}
		if(sum >= minDiff && sum <= maxDiff && maxd - mind >= minDiffProb)ans++;
	}
	printf("%d\n", ans);
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <memory.h>
using namespace std;
const int N=1e5+10;
int num[N];
int n,m,q,t,l,r;
int top,ans,cnt;
void dfs(int sum,int d,int x,int minn)
{
    if(sum>=l&&sum<=r&&d>=q) ans++;
    if(sum>r) return;
    for(int i=x;i<=n;++i)
    {
        dfs(sum+num[i],num[i]-minn,i+1,minn);
    }
}
int main()
{
    while(cin>>n>>l>>r>>q)
    {
        ans=0;
        memset(num,0,sizeof(num));
        for(int i=1; i<=n; ++i) scanf("%d",&num[i]);
        sort(num+1,num+1+n);
        for(int i=1; i<=n; ++i)
        {
            dfs(num[i],0,i+1,num[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include<iostream>
using namespace std;
long long n,l,r,x,c=0;
long long A[15];
bool B[16];
void b(long long x)
{
    int i=0;
    while(x)
    {
        if(x&1)B[i]=1;
        ++i;
        x>>=1;
    }
}
bool C(bool b[])
{
    long long s=0,mn=1e9,mx=0,c=0;
    for(int i=0; i<15; ++i)
    {
        if(b[i])
        {
            s+=A[i]; ++c;
            mn=min(mn,A[i]);
            mx=max(mx,A[i]);
        }
    }
    if(c<2||s<l||s>r||mx-mn<x)
        return 0;
    return 1;
}
void Z()
{
    for(int i=0; i<16; ++i)
        B[i]=0;
}
int main()
{

    cin>>n>>l>>r>>x;
    for(int i=0; i<n; ++i)
        cin>>A[i];
    for(long long i=3; i<(1<<n); ++i)
    {
        b(i);
        if(C(B))++c;
        Z();
    }
    cout<<c;
    return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <memory.h>
using namespace std;
const int N=1e5+10;
int num[N];
int n,m,q,t,l,r;
int ans;
void dfs(int sum,int d,int x,int minn)
{
    if(sum>=l&&sum<=r&&d>=q) ans++;
    if(sum>r) return;
    for(int i=x;i<=n;++i)
    {
        dfs(sum+num[i],num[i]-minn,i+1,minn);
    }
}
int main()
{
    while(cin>>n>>l>>r>>q)
    {
        ans=0;
        memset(num,0,sizeof(num));
        for(int i=1; i<=n; ++i) scanf("%d",&num[i]);
        sort(num+1,num+1+n);
        for(int i=1; i<=n; ++i)
        {
            dfs(num[i],0,i+1,num[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <set>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <ctime>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bl> vbl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair
#define pb push_back
#define ft first
#define sd second
#define forn(i, y, x) for(int i = y; i < x; i++)
#define ford(i, y, x) for(int i = y; i >= x; i--)
#define sz(x) (int)x.size()
const int mod = (int)1e9 + 9;
const int inf = (int)1e9;
const int base = 10;

ll ans = 0;
vi c;
int n, l, r, x;
void dfs(int i, ll sum, int m)
{
	if (sum > r) return;
	forn(j, i + 1, sz(c)){
		if (c[j] - m >= x && sum + c[j] >= l && sum + c[j] <= r) ans++;
		dfs(j, sum + c[j], m);
	}
}

int main()
{
	cin >> n >> l >> r >> x;
	c.resize(n);
	forn(i, 0, n) cin >> c[i];
	sort(c.begin(), c.end());
	forn(i, 0, n) dfs(i, c[i], c[i]);
	cout << ans;
	return 0;
}

///IN THE NAME OF ALLAH
#include<bits/stdc++.h>
using namespace std;
int n,mn,mx,x;
int Arr[20];
int Recur(int i,int mxx,int mnn,int ne,int me)
 {
   if(i==n&&mnn>=mn&&mxx>=0&&me-ne>=x){
    // cout<<me<<" "<<ne<<endl;
     return 1;
   }

   if(i==n)
     return 0;
   int c=Recur(i+1,mxx,mnn,ne,me);
   ne = min(ne,Arr[i]);
   me = max(me,Arr[i]);
   if(mxx-Arr[i]>=0)
       c+=Recur(i+1,mxx-Arr[i],mnn+Arr[i],ne,me);
     return c;
  }
int main(){
 cin >> n >> mn >> mx >> x;
for(int i=0;i<n;i++)
 cin >> Arr[i];
 cout << Recur(0,mx,0,1e9,0);
}

#include <bits/stdc++.h>
#define ll long long
#define getbit(x,i) ((x >> i) & 1)
using namespace std;
const ll N=16;
ll A[N],n,l,r,x;
int main()
{
    cin>>n>>l>>r>>x;
    ll res=0;
    for(int i=1;i<=n;i++) cin>>A[i];

    for(int mask=0;mask < (1 << n);mask++)
    {
        if(__builtin_popcount(mask) >=2)
        {
            ll sum=0,min1=1e18,max1=-1e18;
            for(int i=0;i<n;i++) if(getbit(mask,i)==1)
            {
                sum=sum+A[i+1];
                max1=max(max1,A[i+1]);
                min1=min(min1,A[i+1]);
            }
            if(sum >= l && sum <= r && max1-min1>=x) res++;
        }
    }
    cout<<res;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int a[20], n, l, r, x;
int ans;
void dfs(int index, int num, int mx, int mi) {
	if (num >= 2 && index == n && mx - mi >= x && num >= l && num <= r) ans++;
	if (index == n||num>r) return;
	int m1 = min(mi, a[index + 1]);
	int m2 = max(mx, a[index + 1]);
	dfs(index + 1, num + a[index + 1], m2, m1);
	dfs(index + 1, num, mx, mi);
}
int main() {
	cin >> n >> l >> r >> x;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a, a + n);
	dfs(0, 0, -1e9, 1e9);
	cout << ans << '\n';
}

#include<iostream>
using namespace std;

int permutation(int l,int r,int x,int position,int limit,int now_difficulty,int* h,int min){
    now_difficulty+=h[position];
if(position!=limit){
    if(now_difficulty<l){
        return permutation(l,r,x,position+1,limit,now_difficulty,h,min)+permutation(l,r,x,position+1,limit,now_difficulty-h[position],h,min);
    }else if(now_difficulty<=r){
        if((h[position]-min)>=x){
//          cout<<"now_difficulty="<<now_difficulty<<endl;
            return 1+permutation(l,r,x,position+1,limit,now_difficulty,h,min)+permutation(l,r,x,position+1,limit,now_difficulty-h[position],h,min);
        }else{
            return permutation(l,r,x,position+1,limit,now_difficulty,h,min)+permutation(l,r,x,position+1,limit,now_difficulty-h[position],h,min);
        }
    }else if(now_difficulty>r){
        return 0;
    }
}else{
    if(now_difficulty<=r&&now_difficulty>=l&&(h[position]-min)>=x){
//      cout<<"now_difficulty="<<now_difficulty<<endl;
        return 1;
    }else{
        return 0;
    }
}
}

int main(void){
        int n,l,r,x;
        cin>>n>>l>>r>>x;
        int h[n];
        for(int i=0;i<n;i++){
            cin>>h[i];
        }
/************sort*********/
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(h[i]>h[j]){
                    swap(h[i],h[j]);
                }
            }
        }
/************finish********/
        int sum=0;
        for(int i=0;i<n-1;i++){
            sum+=permutation(l,r,x,i+1,n-1,h[i],h,h[i]);
        }
        cout<<sum<<endl;
}

# include <bits/stdc++.h>

// C

using namespace std;

typedef long long ll;

const ll MMAXN = (1LL << 10);
const ll MMAXM = (1LL << 10);
const ll MAXN = ll(5e5);

string u[MAXN];

string it(ll t){
    string x = "";
    while(t){
        x += (t % 2 == 0 ? '0' : '1');
        t /= 2;
    }
    return x;
}

ll bit(ll x, ll i){
    string z = u[x];
    if(i > z.size() - 1){
        return 0;
    }
    return (max(0, z[i] - 48));
}

ll n, l, r, x, c[MAXN], rr;

int main(){
    cin >> n >> l >> r >> x;
    for(ll i = 1; i <= n; ++i){
        cin >> c[i];
    }
    for(ll i = 0; i < (1LL << n); ++i){
        u[i] = it(i);
    }
    for(ll i = 0; i < (1LL << n); ++i){
        vector<ll>z;
        ll s = 0, mn = ll(1e7), mx = -ll(1e7);
        for(ll j = 0; j < 32; ++j){
            z.push_back(bit(i, j));
            if(bit(i, j) == 1){

                s += c[j + 1];
                mn = min(mn, c[j + 1]);
                mx = max(mx, c[j + 1]);
            }
        }

        if(s >= l && s <= r && mx - mn >= x){
            ++rr;
        }
    }
    cout << rr;

    return 0;
}

#include <iostream>
#include <fstream>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <vector>
#include <algorithm>

#define fi "c.inp"
#define fo "c.out"

using namespace std;

int da, a[20], tong, l, r, xp, x, n;

void dq(int vt){

	int i;

	if (tong >= l && tong <= r && a[vt]-a[xp] >= x)
	{
		da++;
	}

	for(i=vt+1;i<=n;i++){
		tong += a[i];
		dq(i);
		tong -= a[i];
	}
}

void solve(){
	int i;
	da = 0;
	tong = 0;

	for(i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++){
		xp=i;
		tong = a[i];
		dq(i);
	}
	cout<<da<<endl;
}

int main(){

	//freopen(fi,"r",stdin);
	//freopen(fo,"w",stdout);
//	int i;
//	cout<<3000<<endl;
//	for(i=1;i<=3000;i++){
//		cout<<3000<<" ";
//	}

	while(cin>>n>>l>>r>>x){
		solve();
	}

	return 0;
}

#include <iostream>
#include <climits>
using namespace std;
int n, l, r, x, i, o = 0, k = 0, c, mi, ma, j;
int a[16];
int main()
{
	cin >> n >> l >> r >> x;
	for (i = 0; i< n; i++)
		cin >> a[i];
	for (i = 0; i< (1 << n); i++)
	{
		c = 0;
		o = 0;
		ma = INT_MIN;
		mi = INT_MAX;
		for (j = 0; j < n; j++)
		{
			if ((i >> j) & 1 == 1)
			{
				if (a[j] > ma) ma = a[j];
				if (a[j] < mi) mi = a[j];
				c++;
				o += a[j];
			}
		}
		if (c > 1 && o >= l && o <= r && ma - mi >= x) k++;
	}
	cout << k << endl;
//	system("PAUSE");
	return 0;
}

 #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
main ()
{int n,i,j;
unsigned long long y, x,r,l,s,p,min,max;
 vector<unsigned long long >v;
    cin>>n>>l>>r>>x;
    for (i=0;i<n;i++)
    {cin >>y;
    v.push_back(y);}

    p=0;
    max=0;
    min=powl(10,6);

    for (i=0;i<(1<<n);i++)
    {s=0;
    for (j=0;j<n;j++)
       {if (i&(1<<j)==1) { if (max>v[j]) {max=v[j];}
                          if (min < v[j]) {min=v[j];}
                          s=s+v[j];}}
       if ((s<=r)&&(s>=l)&&(max-min>=x))
       {p=p+1;}}
       cout<<p;}

#include <bits/stdc++.h>

using namespace std;
const int MAX=11;
int arr[MAX][MAX];
int main() {

    vector <int> arr;
    vector <int> ans;
    int n,l,r,x;
    int counter = 0;
    int s;

    cin >> n >> l >> r >> x;

    for (int k=0;k<n;k++){
            cin >> s;
            arr.push_back(s);
       }

    for (long long i=0;i<(1LL<<n);i++){
        long long sum = 0;
        for (int j=0;j<n;j++){
            if ((i>>j)&1){
                sum+=arr[j];
            }
        }
        if ((sum>=l) && (sum<=r)){
            counter+=1;
            }
        }

        cout << counter-1;
        arr.clear();

    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define mod 100000000
#define pb push_back
#define mp make_pair
#define N 1000000
//#define endl '\n'
int a[20];
using namespace std;
int n,l,r,x;
int ans(int i,int sum,int pr,int least,int most)
{
    if(i==n){
        if(sum>=l && sum<=r && pr>1 && most-least>=x)
        return 1;
        else return 0;
    }
    int least_temp = min(least,a[i]);
    int most_temp = max(most,a[i]);
    return ans(i+1,sum+a[i],pr+1,least_temp,most_temp)
    +      ans(i+1,sum,pr,least,most);
}
//cout<<i<<" "<<sum<<" "<<pr<<" "<<least<<" "<<most<<endl;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>l>>r>>x;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<ans(0,0,0,INT_MAX,a[0])<<endl;
}

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n;
    long long int l,r,x,b=0;
    cin>>n>>l>>r>>x;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            long long int d=abs(a[i]-a[j]);
            if(d>=l || d<=r || d>=x)
            b++;
        }
    }
    cout<<b;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    typedef unsigned long long ull;
    ull n,mins,maxs,mindiff;
    cin >> n >> mins >> maxs >> mindiff;
    int points[n];
    for(ull i=0;i<n;++i){
        cin >> points[i];
    }
    ull c=0;
    ull res=1<<n;
    for(int i=3;i<res;++i){
        if((i & (i - 1)) == 0)continue;
        ull sum=0,temp=i,j=0,thismaxs=0,thismin=10000;
        //     cout << bitset<32>(temp);
        while(temp!=0){
            if(temp&1){
              //  cout << "points id==>" << j << "points[j]==>" << points[j] << endl;
                if(points[j]>thismaxs)thismaxs=points[j];
                if(points[j]<thismin) thismin=points[j];
                sum+=points[j];
            }
            ++j;
            temp>>=1;
        }
       // cout << "max==>" << thismaxs << "min==>" << thismin << endl;
      //  cout << sum << endl;
        //cout << (sum>=mins && sum<=maxs && (thismaxs-thismin)>=mindiff);
        if(sum>=mins && sum<=maxs && (thismaxs-thismin)>=mindiff){
            ++c;
        }
       // cout << endl;
    }
    cout << c;
}

#include<bits/stdc++.h>
using namespace std ;

// #define int long long

int problemset(vector<int> &vect, int l, int r, int x, vector<int> &final ){

	if(vect.size()+final.size() < 2){
		return 0;
	}
	if(vect.size() == 0){
		int sum = 0;
		for(int i = 0; i < final.size(); i++){
			sum += final[i];
		}
		if(sum >= l && sum <= r && final[final.size()-1]-final[0] >= x){
			return 1;
		}else{
			return 0;
		}
	}

	int ans = 0;
	for(int i = vect.size()-1; i >= 0; i--){
		int num = vect[i];
		vect.pop_back();
		ans += problemset(vect, l, r, x, final);
		final.push_back(num);
		ans += problemset(vect, l, r, x, final);
	}
	return ans;
}

int32_t main(){

	int n, l , r , x;
	cin >> n >> l >> r >> x;
	vector<int> vect;
	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		vect.push_back(num);
	}
	sort(vect.begin(), vect.end(), greater<int>() );

	vector<int> final;
	int ans = problemset(vect, l , r, x, final);
	cout << ans;

	return 0 ;
}

# include <bits/stdc++.h>

using namespace std ;

int n, l, r, x, vc[20], ans ;

void solve( int i, int sum, int ok, int pre ) {

    if( sum >= l && sum <= r && ok == 1) {
        ans ++ ;
    }
    if( i == n ) return ;

    if( pre == 0 ) solve( i + 1, sum + vc[i+1], 1, vc[i+1]) ;
    else if( abs(pre-vc[i+1]) >= x ) solve( i + 1, sum + vc[i+1], 1, vc[i+1]) ;
    solve( i + 1, sum, 0, pre) ;
}

int main() {
    cin >> n >> l >> r >> x ;
    for( int i = 1 ; i <= n ; i ++ ) {
        cin >> vc[i] ;
    }

    solve(1, vc[1], 1, vc[1]) ;
    solve(1, 0, 0, 0) ;
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define fn "CONTEST"
int n,l,r,x,a[20],ed=1,tg,s,mx=0,de,mn=1000005,dem=0;
short Getbit(int k, int n){
    return (n>>k)&1;
}
int main(){
  //  freopen(fn".INP","r",stdin);
  //  freopen(fn".OUT","w",stdout);
    cin>>n>>l>>r>>x;
    for(int st=1;st<=n;st++) cin>>a[st];
    for(int st=1;st<=n;st++) ed=ed<<1;
    for(int st=0;st<=ed-1;st++){
        s=0;
        de=0;mx=0;mn=1000005;
        for(int m=1;m<=n;m++){
            tg=Getbit(m,st);
            //cout<<tg;
            if(tg==1){
                de++;
                s+=a[m];
                mx=max(mx,a[m]);
                mn=min(mn,a[m]);
            }
        }
        if(s>=l&&s<=r&&((mx-mn)>=x)&&de>1) dem++;
    }
    cout<<dem<<endl;
    return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <stack>
#include <fstream>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int n , l, r , x;
	ifstream file ("Text.txt");
	file>>n>>l>>r>>x;
	vector<int> vec(n);
	for (int i = 0;i<n;i++)
		file>>vec[i];
	int kil = 0;
	for (int i =0;i<n-1;i++)
	{
		int sum = vec[i];
		int pos = 0;
		int j= i+1;
		while (j<n)
		{
			sum+=vec[j];
			if ((sum>=l)&&(sum<=r)&&abs(vec[j]-vec[i])>=x)
			{
				kil++;
				pos++;
			}
			else
			if (sum > r)
			{
				sum=vec[i];
				j-=pos;
				pos = 0;
			} else pos++;
			j++;
		}
	}
	cout<<kil;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
int main(){
	ll asize,b,c,d;
	cin>>asize>>b>>c>>d;
	ll a[20];
	FOR(i,0,asize) cin>>a[i];
	ll allforone = 0;
	FOR(i,0,(1<<asize)){
		ll min = 10000;
		ll max = 0;
		ll total = 0;
		FOR(j,0,asize) if(i & (1<<j)){
			if(a[j]<=min) min = a[j];
			if(a[j]>=max) max = a[j];
			total += a[j];
		}
		if(total >= b and total <= c and max-min >= d){
			allforone++;
		}
	}
	cout<<allforone;
	return 0;
}

#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int n, l, r, x;
vector<ll> C;
int main() {
  cin >> n >> l >> r >> x;
  C.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> C[i];
  }
  int result = 0;
  for (int mask = 0; mask < 1 << n; mask++) {
    ll sum = 0;
    ll easy = 1L << 50LL;
    ll hard = 0;
    int res = 0;
    for (int j = 0; j < n; j++) {
      if (mask >> j & 1) {
        sum += C[j];
        easy = min(easy, C[j]);
        hard = max(hard, C[j]);
        res++;
      }
    }
    if (res < 2)
      continue;
    if (l <= sum and sum <= r and (hard - easy) >= x) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

 #include<bits/stdc++.h>
#define ll long long

using namespace std;

ll l,r,x,c[20],n;
set<ll>res;
void f(ll s , int i , ll a , ll b, int p){
    if(i == n){
        if(s >= l && s <= r && b-a >= x){
            res.insert(p);
        }
        return;
    }
    f(s+c[i] , i+1 , min(a,c[i]) , max(b,c[i]), p+1);
    f(s , i+1 , a,b,p);
}

int main(){
    cin>>n>>l>>r>>x;
    for(int i=0 ; i<n ; i++){
        cin>>c[i];
    }
    f(0,0,10000000000,0,0);
res.insert(0);
    cout<<*res.end();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
main()
{
int n,l,r,x,i=0,flag=0,sum=0,a1,a2;
long a[15];
cin>>n>>l>>r>>x;
for(i=0;i<n;i++)
	cin>>a[i];
for(int mask=0; mask<(1ll<<n); mask++)
{
	sum=0;
	for(int j=0; j<n; j++)
			if(mask & (1ll<<j))
			{
				if (sum==0)
					a1=a[j];
				sum+=a[j];
				a2=a[j];
			}
	if ((sum>=l && sum<=r) && ((a2-a1)>=x))
				flag++;
}
cout<<flag<<endl;
}

#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <list>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>

#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define forn(i,n) for(int i = 0; i < int(n); ++i)
#define sz(a) int(a.size())

using namespace std;

typedef long long li;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-9;

typedef pair<int, int> pt;
#define sqr(x) ((x) * (x))
#define ft first
#define sc second
#define x first
#define y second

int n, l, r, x;
int a[16];

bool read() {
    if (!(cin >> n >> l >> r >> x))
        return false;
    forn (i, n) {
        cin >> a[i];
    }
    return true;
}

int ex(vector<int> &v, int d) {
    int res = v[0] * d;

    forn (i, v.size()) {
        if (v[i] * d > res)
            res = v[i] * d;
    }

    return res * d;
}

void solve() {
    int ans = 0;

    forn (i, 1 << n) {
        vector<int> cur;
        int sum = 0;
        int cnt = 0;

        forn (j, n) {
            if (i & (1 << j)) {
                cur.pb(a[j]);
                sum += a[j];
                cnt++;
            }
        }
        if (cnt > 1 && sum >= l && sum <= r) {
            if (ex(cur, 1) - ex(cur, -1) <= x)
                ans++;
        }
    }

    cout << ans << endl;
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    while(read())
        solve();

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define S(x) scanf("%d",&x)
#define P(x) printf("%d",x)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000010
#define ll long long
#define mp make_pair
#define pb push_back
typedef pair<int,int> pp;
typedef pair<ll,ll> ppl;
ll a[1234567];
ll final =0 ;
ll  n , l , r, x;
std::vector<ll> v;
int  j ;
void fun(int i)
{
    ll sum = 0;
    for (int k = 0; k < v.size(); ++k)
    {
        sum+=v[k];
    }
    if(sum>r)
        return ;
    if(sum>=l && sum<=r)
    {
        if(v.size()>=2)
        {
            std::vector<ll> tmp;
            for ( j = 0; j < v.size(); ++j)
            {
                tmp.pb(v[j]);
            }
            sort(tmp.begin(), tmp.end());
            if((tmp.back() - tmp[0])>=x)
            {
                final++;
            }
        }
        return ;
    }
    if(i>=n)
        return ;
    v.pb(a[i]);
    fun(i+1 );
    v.pop_back();
    fun(i+1);
    return ;
}
int main()
{
    cin>>n>>l>>r>>x;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    fun( 0);
    cout<<final<<endl;
    return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <numeric>
#define INF -999999
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//共有n个题，要选其中的一些题作为比赛题，比赛题的难度总和最低是l，最高是r，最难和最容易的题
//之间的难度差距至少是x，至少要选择2道题目
int c[20];  //存储各个题目难度
int sel[20];   //当前选的题目
int vis[20];  //题目有没有被选中过
long long ans;  //方案数
long long diff;  //方案难度总和
int n,l,r,x;
void dfs(int cur,int num){  //当前已经遍历到了第几个题目
	diff = accumulate(sel,sel+num,0);  //题目难度总和
	int maxn = *max_element(sel,sel+num);
	int minn = *min_element(sel,sel+num);
	if(num>=2&&(maxn-minn)>=x&&diff>=l&&diff<=r){   //题目难度总和和难易题的差值以及题目数量都满足条件的情况下，方案数加一
		ans++;
		return;
	}
	if(cur==n) return;
	for(int i=cur;i<n;i++){
		if(vis[i]!=1){  //当前题目还未被选中过
			vis[i] = 1;  //标记
			sel[num] = c[i];   //记录到结果数组
			num+=1;
			dfs(i,num);
			vis[i] = 0;
			num-=1;  //回溯
			sel[num] = -1;
		}
	}

}
int main(int argc, char** argv) {
	while(cin>>n>>l>>r>>x){
		for(int i=0;i<n;i++){
			cin>>c[i];  //初始化各题目的难度
		}
		ans = 0;
		diff = 0;
		dfs(0,0);

		cout<<ans<<endl;
	}
	return 0;
}

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1e5 + 300;
const int INF = 0x3f3f3f3f;
typedef long long  LL;
typedef unsigned long long ULL;
LL a[20];
LL l, r, x;
int n;
bool jud(LL sum, LL Min, LL Max){
    if(l <= sum && sum <= r && Max - Min >= x){
        return true;
    }
    return false;
}
int ans = 0;
void dfs(int cur, LL Min, LL Max, LL sum){
    if(cur > n) return;
//    printf("%d %lld %lld %lld\n",cur, Min, Max, sum);
    if(jud(sum,Min,Max) == true){
        ans++;
    }else if(sum > r){
        return ;
    }else if(Max - Min > x){
        return ;
    }
    for(int i = cur+1; i <= n; i++){
        LL tmin = Min > a[i]? a[i] : Min;
        LL tmax = Max < a[i]? a[i] : Max;
        LL tsum = sum + a[i];
//        printf("%d %lld %lld %lld+++\n",i,tmin,tmax,tsum);
        dfs(i,tmin,tmax,tsum);
    }
}
int main(){
    while(scanf("%d%lld%lld%lld",&n,&l,&r,&x)!=EOF){
        for(int i = 1; i <= n; i++){
            scanf("%lld",&a[i]);
        }
        for(int i = 1; i <= n; i++){
            dfs(i, a[i], a[i], a[i]);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

int a[26],t,c,s,mi,ma;

int main()
{
	int n,l,r,x,con[26];
	cin >> n >> l >> r >> x;
	for(int i = 0;i < n;++i)
		cin >> con[i];
	cout << pow(2,n);
	for(int i = 0;i < pow(2,n);++i)
	{
		c = s = ma = 0;
		mi = 1000001;
		++a[0];
		for(int j = 0;j < n;++j)
			if(a[j] == 2)
				a[j] = 0,++a[j + 1];
		for(int j = 0;j < n;++j)
		{
			if(a[j] == 1)
			{
				++c;
				s += con[j];
				if(con[j] < mi)
					mi = con[j];
				if(con[j] > ma)
					ma = con[j];
			}
		}
		if(c > 1 && s >= l && s <= r && (ma - mi) >= x)
			++t;
	}
	cout << t;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
const int MAX=11;
int arr[MAX][MAX];
int main() {

    vector <int> arr;
    vector <int> ans;
    int n,l,r,x;
    int counter = 0;
    int s;

    cin >> n >> l >> r >> x;

    for (int k=0;k<n;k++){
            cin >> s;
            arr.push_back(s);
       }

    for (long long i=0;i<(1LL<<n);i++){
        long long sum = 0;
        for (int j=0;j<n;j++){
            if ((i>>j)&1){
                sum+=arr[j];
            }
        }
        if ((sum>=l) && (sum<=r)){
            counter+=1;
            }
        }

        cout << counter;
        arr.clear();

    return 0;
}

#include <iostream>

#include <vector>

using namespace std;

int main() {
  string str;

  cin >> str;

  size_t n = str.size();

  int max_index_ab = -1;
  int max_index_ba = -1;

  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'A' && str[i + 1] == 'B')
      max_index_ab = i;
    if (str[i] == 'B' && str[i + 1] == 'A')
      max_index_ba = i;
  }

  int min_index_ab = n;
  int min_index_ba = n;

  for (int i = n - 1; i > 0; i--) {
    if (str[i - 1] == 'A' && str[i] == 'B')
      min_index_ab = i;
    if (str[i - 1] == 'B' && str[i] == 'A')
      min_index_ba = i;
  }

  if (min_index_ab < max_index_ba || min_index_ba < max_index_ab)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <sstream>
#define M_PI 3.14159265358979323846
#define powerIn freopen("power.in", "r", stdin)
#define powerOut freopen("power.out", "w", stdout)
#define taskIn freopen("input.txt", "r", stdin)
#define taskOut freopen("output.txt", "w", stdout)
typedef long double ld;
typedef long long ll;
using namespace std;
const int INF = (int)1e9;
const ll INF64 = (ll)1e18;
const ld EPS = 1e-9;
const int NEUTRALMIN = INF;
const int NEUTRALMAX = -INF;
const ll MAXN = (ll)1e5;
const int P = 239017;
const int MOD = 1000000007;

int a[25];
int n, l, r, x;
int cnt;
void get(int how, int from, int now)
{
	int locsum = now; int maxi = now; int mini = now; int to = from + how; bool flag = false;
	to = min(how, n - 1);
	for (int i = from; i < to + from; i++)
	{
			locsum += a[i];
			maxi = max(maxi, a[i]); mini = min(mini, a[i]);
			flag = true;
	}
	if (flag == true)
		if ((locsum <= r) && (locsum >= l) && (maxi - mini >= x))
			cnt++;
}

int main()
{
	//powerIn; powerOut;
	cin >> n >> l >> r >> x;
	fill(a, a + 25, INF);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + 25);
	for (int i = 0; i < n; i++)
	{
		int cur = a[i];
		for (int j = 1; j <= n - 1; j++)
		{
			for (int k = i + 1; k <= n - 1; k++)
			{
				get(j, k, cur); // j - скок чисел брать допо // k - с какого индекса
			}
		}
	}
	cout << cnt;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int n,l,r,x;
	cin>>n>>l>>r>>x;
	int c[n];
	for(int i=0;i<n;i++) cin>>c[i];
	int ans=0;
	for(int m=0;m<(1<<n);m++){
		int mx = INT_MIN,mn = INT_MAX,cnt=0,sum=0;
		for(int i=0;i<n;i++){
			if((m & (1<<i))!=0){
				cnt++;
				sum+=c[i];
				mn = min(mn,c[i]);
				mx = max(mx,c[i]);
			}
		}
		if(sum>=l && sum<=r && (mx-mn)<=x && cnt>=2){
			ans++;
		}
	}
	cout<<ans<<endl;

	return ;
}

int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();

	}

	return 0;
}

/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define PI					acos(-1.0)
#define vi					vector<int>
#define vii					vector<vi>
#define vll					vector<ll>
#define mid(s,e)			(s+(e-s)/2)
#define clz(n)				__builtin_clzll(n))

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template<typename T>
void printVec(const T &v, char sep=' ') {for (auto &i: v) cout << i << sep;}
template<typename T>
void printVecPair(const T &v, char sep=' ') {for (auto &i: v) cout << i.first <<" " << i.second<< sep;}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
vll c;
ll n,l,r,x;
int choose(int i, vi e) {
		ll s=0,mn=MAX,mx=MIN;
		for(int a: e) {
				s+=a;
				mn=min((int)mn,a);
				mx=max((int)mx,a);
		}
		s+=c[i];
		mn = min(mn,c[i]);
		mx = max(mx,c[i]);
		int valid = 0;
		if(s>=l && s<=r && mx-mn>=x && e.size() > 1) {
				valid = 1;
		}
		debug(e);
		if(i==n) return valid;

		vi ee = e;
		ee.push_back(c[i]);
		return valid + choose(i+1,ee) + choose(i+1,e);

}
int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	// n >= 2 l<=sum(ci)<=r    max - min >= x
	cin>>n>>l>>r>>x;
	c.resize(n+10);
	for(ll& i: c) cin>>i;

	int ans = choose(0,{});
	cout<<ans-1;

	return 0;
}

#include <iostream>
#include <conio.h>
#include <algorithm>
#include <math.h>
using namespace std;
long long n,l,r,x;
int a[15];
int main()
{
    long long g=0,sum=0;
    int min0=10000000,max0=0;
    cin>>n>>l>>r>>x;
    for (int i=1;i<=n;i++)
    cin>>a[i];
    int b[n];
    for(int i=1;i<=n;i++)
    b[i]=0;
    int z=pow(2,n);
    for(int i=1;i<=z-1;i++)
    {
        b[1]++;
        for (int j=1;j<=n;j++)
        if(b[j]==2)
        {
            b[j]=0;
            b[j+1]++;
        }
        for(int j=1;j<=n;j++)
            if(b[j]==1)
            {
            max0=max(max0,a[j]);
            min0=min(min0,a[j]);
            sum=sum+a[j];
            }
            if(sum>=l&&sum<<r&&max0-min0>=x)
            g++;
            sum=0;
            min0=10000000;
            max0=0;
    }
    cout<<g;
}

#include<bits/stdc++.h>
using namespace std;
int n,l,r,x;
int a[3232];
int calc(int S){
    int sum=0,cnt=0;
    int mn=INT_MAX,mx=0;
    for(int i=0;i<(1<<n);i++)
    if(S>>i&1)sum+=a[i],mx=max(mx,a[i]),mn=min(mn,a[i]),cnt++;
    return sum>=l&&sum<=r&&mx-mn>=x&&cnt>=2?1:0;
}
int main(){
    cin>>n>>l>>r>>x;
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<(1<<n);i++)
        ans+=calc(i);
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,l,r,x,max,min,c,s=0,k=0;
    vector <int> v;
    cin>>n>>l>>r>>x;
    for (i=0;i<n;i++)
    {
        v.push_back(c);
    }
    for(i=0;i<pow(2,n);i++)
    {
        for(j=0;j<32;j++)
        {
            if (i&(1<<j))
            {if (__builtin_popcount(i)<2)
                continue;

             max=0; min=pow(10,10);
             if (v[j]<min)
                min=v[j];
            else
            {
                if (v[j]>max)
                max=v[j];

            }

             s+=v[j];

            }
        }
    if ((s<r)&&(s>l)&&((max-min)>=x))
        k++;
    }

    cout<<k;

    return 0;
}

#include<bits/stdc++.h>
#define  p5         100005
#define  p6         1000007
#define  PI         acos(-1)
#define  M          1000000007
#define  sc         scanf
#define  ss         second
#define  ff         first
#define  pf         printf
#define  scin(x)    sc("%d",&x)
#define  scin2(x,y) sc("%d%d",&x,&y)
#define  READ(f)    freopen(f, "r", stdin)
#define  WRITE(f)   freopen(f, "w", stdout)
#define  ll         long long
#define  pp         pair < int, int>
#define  pq         priority_queue
#define  pb         push_back
#define OK          pf("YES\n")
#define _OK         pf("NO\n")
#define all(v)      v.begin(), v.end()
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
vector<ll>v[p5+2],v1;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,i,j,k,l,r,x;
    cin>>n>>l>>r>>x;
    ll ar[n];
    for(i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    sort(all(v1));
    v1.erase(unique(all(v1)),v1.end());
    k=0;
    for(i=1; i<(1<<n); i++)
    {
        ll tmp;
        tmp=i;
        j=0;
        while(tmp>0)
        {
            if(tmp&1)
            {
                v[k].pb(v1[j]);
            }
            j++;
            tmp/=2;
        }
        k++;
    }
    /*cout<<endl;
    for(i=0;i<k;i++){
        for(j=0;j<v[i].size();j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }*/
    ll cnt=0;
    for(i=0; i<k; i++)
    {
        ll s=v[i][0],si=v[i].size(),mx=-1;
        for(j=1; j<si && si>1; j++)
        {
            s=s+v[i][j];
            ll xx=v[i][j]-v[i][j-1];
            mx=max(mx,xx);
        }
        if(si>1 && s>=l && s<=r && mx>=x){
            cnt++;
        }

    }
    cout<<cnt<<endl;
    return 0;
}
//https://github.com/me-shaon/bangla-programming-resources

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, l, r, x;
    cin >> n >> l >> r >> x;
    if (n < 2) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[n];
    sort(arr.begin(), arr.end());
    int num = 0;
    //vector<int> set;
    for (int i = 0; i < n-1; i++) {
        int sum = arr[i];
        //set.push_back(arr[i]);
        for (int j = i+1; j < n; j++) {
            if (sum + arr[j] > r) break;
            if (arr[i] + x <= arr[j]) {
                //set.push_back(arr[j]);
                sum += arr[j];
                if (sum >= l) num++;
            }
        }

    }
    cout << num << endl;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>

using namespace std;

int main() {
    int n, l, r, x;

    cin >> n >> l >> r >> x;

    vector<int> problems(n);
    for (int i = 0; i < n; i++) cin >> problems[i];
    sort(problems.begin(), problems.end());

    int ans = 0;

    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            if (abs(problems[j] - problems[i]) >= x) {
                int sum = problems[i] + problems[j];

                if (sum >= l && sum <= r)
                    ans++;

                for (int k = i+1; k < j; k++) {
                    sum += problems[k];

                    if (sum >= l && sum <= r)
                        ans++;

                    if (sum > r)
                        break;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

# include <bits/stdc++.h>

using namespace std ;

int n, l, r, x, vc[20], ans ;

void solve( int i, int sum  ) {

    if( sum >= l && sum <= r ) ans ++ ;
    if( i == n ) return ;

    solve( i + 1, sum + vc[i+1] ) ;
    solve( i + 1, sum ) ;
}

int main() {
    cin >> n >> l >> r >> x ;
    for( int i = 1 ; i <= n ; i ++ ) {
        cin >> vc[i] ;
    }

    solve(1, vc[0]) ;
    solve(1, 0) ;
    cout << ans << endl;
}

#include<iostream>
#include<algorithm>
#define fastScan ios::sync_with_stdio(0)
#define ll long long

using namespace std;

ll a[16],d[40000];
int main()
{
    fastScan;
    int n,x,i,j,k,l0,m,m0;
    ll l,r,v,ans=0;
    cin>>n>>l>>r>>x;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(i=2;i<=n;i++)
    {
        j=i-1;
        while(a[i]-a[j]<x&&j)
            j--;
        for(k=1,m=1;k<=j;k++)
        {
            m0=m;
            for(l0=0;l0<m0;l0++,m++)
            {
                d[m]=a[k]+d[l0];
                v=d[m]+a[i];
                if(v>=l&&v<=r)
                    ans++;
            }
        }
        /*
        for(k=0;k<m;k++)
            cout<<d[k]<<" ";
        cout<<endl;
        /*/
    }
    cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll l,r,x;
ll v[20];
ll answer(ll lower, ll sum, int pos){
    if(pos>=n)return 0;
    if(v[pos]+sum>r)return 0;
    //cout<<lower<<" "<<sum<<" "<<v[pos]<<endl;
    ll val=0;
    if(lower==0){
        val+=answer(v[pos],sum+v[pos],pos+1);
    }
    else{
        val+=answer(lower,sum+v[pos],pos+1);
    }
    val+=answer(lower,sum,pos+1);
    if(v[pos]-lower>=x && sum+v[pos]>=l){
        //cout<<lower<<" "<<sum+v[pos]<<" "<<v[pos]<<endl;
        val++;
    }
    return val;
}
int main(){
    cin >> n >> l >> r >> x;
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    sort(v,v+n);
    cout << answer(0,0,0);
}

#include<iostream>
#include<string>

using namespace std;
int n,x,l,r,a[20];

int fun(int sum,int diff,int i,int min,int max){
          int ans=0;
          if(i==(n-1)){
                    if(sum+a[i]<=r&&sum+a[i]>=l){
                              if(a[i]<min){
                                        diff=max-a[i];
                                        min=a[i];
                              }
                              if(a[i]>max){
                                        diff=a[i]-min;
                                        max=a[i];
                              }

                              if(diff>=x)
                              ans+=1;
                    }
                    if(sum<=r&&sum>=l&&diff>=x){
                              ans+=1;
                    }
                    return ans;
          }

                  ans+=fun(sum,diff,i+1,min,max);

                              if(a[i]<min){
                                        diff=max-a[i];
                                        min=a[i];
                              }
                              if(a[i]>max){
                                        diff=a[i]-min;
                                        max=a[i];
                              }
                              sum+=a[i];

                    ans+=fun(sum,diff,i+1,min,max);

                    return ans;

}

int main(){

int i;
          cin>>n>>l>>r>>x;

          for(i=0;i<n;i++){
                    cin>>a[i];
          }

          cout<<fun(0,0,0,1000005,0);
          return 0;
}

 #include<bits/stdc++.h>
#define ll long long

using namespace std;

ll l,r,x,c[20],n;
set<ll>res;
void f(ll s , int i , ll a , ll b, int p){
    if(i == n){
        if(s >= l && s <= r && b-a >= x){
            res.insert(p);
        }
        return;
    }
    f(s+c[i] , i+1 , min(a,c[i]) , max(b,c[i]), p+1);
    f(s , i+1 , a,b,p);
}

int main(){
    cin>>n>>l>>r>>x;
    for(int i=0 ; i<n ; i++){
        cin>>c[i];
    }
    f(0,0,10000000000,0,0);
res.insert(0);
    cout<<*res.end();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long n,l,r,x,a[16];

long long f(long long mn,long long sum,long long num,long long last)
{
    if(num>=2&&sum>=l&&sum<=r&&a[last]-mn>=x&&num<=n)
    {
        //cout<<mn<<" "<<sum<<" "<<num<<" "<<last<<endl;
        return 1;
    }
    if(sum>r)
        return 0;
    long long ans=0;
    for(long long i=last+1;i<n;i++)
    {
        ans+=f(mn,sum+a[i],num+1,i);
    }
    return ans;
}

int main()
{
    cin>>n>>l>>r>>x;
    for(long long i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    long long ans=0;
    for(long long i=0;i<n;i++)
    {
        ans+=f(a[i],a[i],1,0);
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,l,r,x;
	while(scanf("%d %d %d %d",&n,&l,&r,&x) != EOF){
		int v[n];
		for(int i = 0; i < n; i++) scanf("%d",&v[i]);
		int ans = 0;
		vector<int> bolsa;
		int m = 1<<n;
		for(int i = 0; i < m; i++){
			int sum = 0;
			bolsa.clear();
			// printf("Subconj: %d { ",i);
			for(int j = 0; j < n; j++){
				if((i&(1<<j))>0){
					bolsa.push_back(v[j]);
					sum += v[j];
					// printf("%d ",v[j]);
				}
			}
			// printf(" }\n");
			// printf("suma: %d\n",sum);
			if(sum <= r && sum >= l){
				bool sw = 0;
				for(int b = 0; b < bolsa.size()-1; b++){
					if(abs(bolsa[b] - bolsa[b+1]) >= x){
						// printf("bolsaaaaaa: %d %d\n", bolsa[b] , bolsa[b+1]);
						sw = 1;
						break;
					}
				}
				if(sw) ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

#include <bits/stdc++.h>
#define INF 200000000
using namespace std;
typedef long long ll;
ll v[16];
vector<ll> v2;
ll n, l, r, x;

void count(ll pos, ll prev, ll currSum)
{
    v2.push_back(currSum);
    for (ll i = pos; i < n; i++)
    {
        if (v[i] - prev >= x)
            count(i, v[i], currSum + v[i]);
    }
}

int main()
{
    while (scanf("%lld %lld %lld %lld", &n, &l, &r, &x) == 4)
    {
        v2.clear();
        for (ll i = 0; i < n; i++)
            scanf("%lld", &v[i]);

        sort(v, v + n);
        count(0, -INF, 0);
        sort(v2.begin(), v2.end());
        ll n2 = v2.size();
        ll res = 0;
        for (ll i = 0; i < n2; i++)
        {
            if (v2[i] > r)
                break;
            if (v2[i] >= l)
                res++;
        }
        printf("%lld\n", res);
    }
}

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)=..
#define rev(s)           reverse(s.begin(),s.end())
#define Heart              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair<int,int>                   PII;
void solve()
{
    int n , l , r , x ;
    cin >> n >> l >> r >> x ;
    int arr[n + 5] ;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i] ;
    }
    int res = 0 ;
    for(int i = 0 ; i < (1 << n) ; i++)
    {
        int mn = INT_MAX ;
        int mx = -1 ;
        int tot = 0 ;
        int cur = 0 ;
        for(int j = 0 ; j < n ; j++)
        {
            if((i >> j) & 1)
            {
                tot += arr[j] ;
                cur++ ;
                mn = min(mn , arr[j]) ;
                mx = max(mx , arr[j]) ;
            }
        }
        if(cur >= 2 && tot >= l && tot <= r && (r - l) >= x)
        {
            res++ ;
        }
    }
    cout << res << endl ;

}
int main()
{
    Heart
    //  READ("0test.txt");
    // WRITE("");
    solve() ;

}

    /* asif_mak
    APRIL15 */

    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <map>
    #include <queue>
    #include <stack>
    #include <cstring>
    #include <algorithm>
    #include <cstdlib>
    #include <cmath>
    #include <limits.h>
    #include <iomanip>
    using namespace std;
    typedef long long ll;
    #define MP make_pair
    #define pb push_back
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define REP(i,a,b) for(ll i=a;i<=b;i++)
    #define repi(i,n) for(ll i=n-1;i>=0;i--)
    #define REPI(i,a,b) for(ll i=a;i>=b;i--)
    typedef vector<int> vi;
    typedef vector< vi > vvi;
    typedef pair< int,int > ii;
    #define sz(a) int((a).size())]
    #define clr(a) memset(a,0,sizeof(a))
    #define ini(a) memset(a,-1,sizeof(a))
    #define inp(n) scanf("%d",&n)
    #define inp2(n,m) scanf("%d%d",&n,&m)
    #define ins(s) scanf("%s",s);
    #define out(n) printf("%d\n",n)
    #define out2(n,m) printf("%d %d\n",n,m)
    #define inc(n) scanf("%c",&n)
    #define MOD 1000000007
    #define MOD_INV 1000000006
    #define MAX 100009
    #define INF 999999999

    #define si(n) scanf("%d",&n)
    #define sll(n) scanf("%lld",&n)
    ll a[20];
    int main()
    {
        std::ios_base::sync_with_stdio(false);

        ll n,l,r,x;
        cin>>n>>l>>r>>x;
        ll c;
        rep(i,n)
        cin>>a[i];
        sort(a,a+n);
        ll ans=0;

        /*rep(i,(1<<n))
        {
            ll mini=INT_MAX;
            ll maxi=INT_MIN;
            ll ctr=0;
            ll sum=0;
            rep(j,n)
            {
                if(i&(1<<j))
                continue;
                ctr+=2;
                mini=min(mini,a[j]);
                maxi=max(maxi,a[j]);
                sum+=a[j];

            }
            if(sum<=x && mini>=l && maxi<=r && ctr>=2)
            {
            ans++;
            }

        }*/
        ll sum=0;
        ll diff=0;
        int j;
        int k;
        rep(i,n)
        {
            j=i+1;
            sum=a[i];
            for(k=j;j<n;j++)
            {

                if(sum+a[j]<=r)
                {
                    sum+=a[j];
                    diff=a[j]-a[i];
                    if(sum>=l && diff>=x)
                    {
                        ans++;
                    }
                }
                else
                {
                    sum=a[i];
                    j=k;
                    k++;

                }

            }
        }

        cout<<ans<<endl;

        return 0;
    }

#include <iostream>
#include <cmath>

using namespace std;

int a[26],t,c,s,mi,ma;

int main()
{
	int n,l,r,x,con[26];
	cin >> n >> l >> r >> x;
	for(int i = 0;i < n;++i)
		cin >> con[i];
	for(int i = 0;i < pow(2,n);++i)
	{
		c = s = ma = 0;
		mi = 1000001;
		++a[14];
		for(int j = 14;j > 0;--j)
			if(a[j] == 2)
				a[j] = 0,++a[j - 1];
		for(int j = 0;j < 15;++j)
		{
			if(a[j] == 1)
			{
				++c;
				s += con[j];
				if(con[j] < mi)
					mi = con[j];
				if(con[j] > ma)
					ma = con[j];
			}
		}
		if(t > 1 && s >= l && s <= r && (ma - mi) >= x)
			++t;
	}
	cout << t;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,l,r,x;
int num[16];
int res;
void helper(int min_index, int cur_index, int sum){
    sum += num[cur_index];
    if(sum > r)
        return;
    if(sum >= l && num[cur_index] - num[min_index] >= x)
        res++;
    for(int i = cur_index; i < n; i++)
        helper(min_index,i+1,sum);
    return;
}
int main(){
    cin >> n >> l >> r >> x;
    for(int i = 0 ; i < n ; i++)
        cin >> num[i];
    if(n == 1)
        return 0;
    sort(num, num + n);
    res = 0;
    for(int i = 0; i < n - 1; i++){
        if(num[i] + num[i+1] > r)
            break;
        helper(i,i,0);
    }
    cout << res << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,mins,maxs,mindiff;
    cin >> n >> mins >> maxs >> mindiff;
    int points[n];
    for(int i=0;i<n;++i){
        cin >> points[i];
    }
    int c=0;
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            if(j==i)continue;
            if(((points[i]+points[j])>=mins) &&((points[i]+points[j])<=maxs) && (abs(points[i]-points[j])>=mindiff)){
                ++c;
            }
        }
    }
    cout << c;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int  n,l,r,x,k=1,sum,t,tp,p,u,minn=987654321,maxx=0;
vector<int>v;
int a[123456];
main()
{
    cin>>n>>l>>r>>x;
    for(int i=1;i<=n;i++)
        cin>>a[i];
        sort(a+1,a+n);
    for(int i=1;i<pow(2,n);i++)
    {
        sum=0;
        k=1;
        p=0,t=0,u=0;
        for(int j=1;j<=i;j*=2)
        {
            if(i&j)
            {
                maxx=max(maxx,a[k]);
                minn=min(minn,a[k]);
                sum+=a[k];
                p++;
            }
            k++;
        }
        if(sum>=l&&sum<=r&&p>1&&maxx-minn>=x)
        v.push_back(sum);
    }
    cout<<v.size();
}

#include <bits/stdc++.h>

using namespace std;

vector<int> v;
int n, l, r, x;

int ric(int i, int s, int ma, int mi)
{
    if(i==0){
        if(s <= r &&  s >= l && ma - mi >= x){
            return 1;
        }
        return 0;
    }

    return ric(i-1, s+v[i], max(ma, v[i]), min(mi, v[i])) + ric(i-1, s, ma, mi);
}

int main()
{

    cin>>n>>l>>r>>x;

    v.resize(n);

    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }

    cout<<ric(n-1, 0, -1, 2e9);

}

#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define pf push_front
#define Pb pop_back
#define Pf pop_front
#define sz size
#define MP make_pair
#define pc __builtin_popcount
#define gcd __gcd
#define pi 2*acos(0)
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;
ll n,l,x,r,arr[20];
deque<ll>tmp;
deque<deque<ll>>ans;
map<deque<ll>,bool>mp;
void solve(ll val,ll i) {
    if(val > l)
        return;
    sort(tmp.begin(),tmp.end());
    if(val>=x&&val<=l&& tmp.sz() >= 2&&tmp.back()-tmp.front()>=r) {
        ans.pb(tmp);
    }
    for(int j=i;j<n;j++) {
        tmp.pb(arr[j]);
        solve(val+arr[j],j+1);
        tmp.Pb();
    }
}

int main()
{
    abdelrahman001
    cin >> n >> x >> l >> r;
    for(int i = 0;i<n;i++){
        cin >> arr[i];
    }
    solve(0,0);
    cout << ans.sz();
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod =1e9+9;
bool isPower(ll x, ll y)
{
    double res1 = log(y) / log(x);
    double e=ceil(res1);
    return (res1/e==1);
}
bool isPrime(int n)
{
    if (n <= 1)return false;
    if (n <= 3)return true;
    if (n % 2 == 0 || n % 3 == 0)return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)return false;
    return true;
}
long long fastexp(int b,long long e)
{
    if(e==0)return 1;
    long long tmp=fastexp(b,e/2);
    if(e%2==0)return (tmp*tmp)%mod;
    return ((b*tmp)%mod*tmp)%mod;
}
long long lcm(long long  a,long long b)
{
    return a*b/__gcd(a,b);
}
ll n,l,r,x;
pair<ll,ll> app;
vector<ll> cont;
ll prova(ll pos,ll somma)
{
    if(pos==n)
    {
        if(somma>=l)
        return 1;
        return 0;
    }
    ll sum=0;
    if(pos!=app.first&&pos!=app.second&&cont[pos]<=cont[app.first]&&cont[pos]<=cont[app.second]&&somma+cont[pos]<=r)
    {
        sum+=prova(pos+1,somma+cont[pos]);
    }
    sum+=prova(pos+1,somma);
    return sum;
}
int main()
{
    cin>>n>>l>>r>>x;
    cont.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>cont[i];
    }
    sort(cont.begin(),cont.end());
    vector<pair<int,int> > coppie;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(cont[j]-cont[i]>=x&&cont[j]+cont[i]>=l&&cont[j]+cont[i]<=r)
            {
                coppie.push_back({i,j});
            }
        }
    }
    ll ris=0;
    for(int i=0;i<coppie.size();i++)
    {
        app=coppie[i];
        ris+=prova(0,cont[coppie[i].first]+cont[coppie[i].second]);
    }
    cout<<ris<<endl;
    return 0;
}

#include<cstdio>

int main(){
	int n, l, r, x;
    scanf("%d%d%d%d", &n, &l, &r, &x);
    int c[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &c[i]);

    int counter = 0;
    for(int i = 0 ; i < n; i++)
        for(int j = i+1; j < n; j++){
            int sum = c[i] + c[j];
            if(sum <= r && sum >=l){
                int tmp;
                if(c[i]>c[j]) tmp = c[i] - c[j];
                else tmp = c[j] - c[i];
                if(tmp >=x)
                    counter++;
            }
        }

    printf("%d\n", counter);

}

#include<bits/stdc++.h>
#define MAX 10000
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long l64d;
typedef unsigned long int ud;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
l64d n,l,r,x,diff[10000001];
l64d cnt=0;
void cek(int first,l64d sum,int last)
{
    if(sum>r) return;
    if(sum<=r && sum>=l && first!=last)cnt++;
    for(int i=last+1;i<n;i++)
    {
        if(abs(diff[i]-diff[first])>=x)
            cek(first,sum+diff[i],i);
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    std::ios::sync_with_stdio(false);
    cin>>n>>l>>r>>x;
    for(int i=0;i<n;i++) cin>>diff[i];
    sort(diff,diff+n);
    for(int i=0;i<n;i++) cek(i,diff[i],i);
    cout<<cnt<<endl;
}

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;

int a[20];

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    int n, l, r, x;
    scanf("%d %d %d %d", &n, &l, &r, &x);
    for(int i = 0 ; i < n ; ++i)
        scanf("%d", a + i);

    int ans = 0;
    for(int stat = 1 ; stat < (1 << n) ; ++stat){
        int sum = 0, mn = INT_MAX, mx = INT_MIN;
        for(int i = 0 ; i < n ; ++i){
            if(!(stat & (1 << i)))continue;
            sum += a[i];
            mn = min(mn, a[i]);
            mx = min(mx, a[i]);
        }
        ans += (mx - mn >= x && sum >= l && sum <= r);
    }
    printf("%d\n", ans);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ar[20],a,b,cn,n,l,r,x,vis[20];
void rec(ll s){
  if(s>r)
     return;
  if(s>=l && s<=r)
      cn++;
  for(ll i=0;i<n;i++){
      if(i!=b && i!=a && vis[i]==0){
         vis[i]=1;
         rec(s+ar[i]);
         //vis[i]=0;
      }
      //rec(s);
   }
}
int main(){
  ll i,j,s=0;
  cin>>n>>l>>r>>x;
  for(i=0;i<n;i++)
     cin>>ar[i];
  sort(ar,ar+n);
  cn=0;
  for(i=0;i<n;i++){
     for(j=i+1;j<n;j++){
         if(ar[j]-ar[i]>=x){
            a=i;
            b=j;
            s=ar[i]+ar[j];
            //vis[a]=1;
            //vis[b]=1;
            if(s>=l && s<=r)
               rec(s);
         }
     }
  }
  cout<<cn<<endl;
  return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int _max = 100009;

bool v[16];
int counts[_max];

struct Complexity
{
	int number;
	int count;
}a[16];

bool cmp(Complexity A, Complexity B)
{
	return A.number < B.number;
}

void cal_counts(int l, int r, int x, int n, int index, vector<int>& vec, int sum, int& ret)
{
	if (sum > r) return;
	if (sum >= l)
	{
		int prod = 1;
		for (int j = 0; j < vec.size(); j++)
			prod *= a[vec[j]].count;
		ret += prod;
	}

	for (int i = index; i < n; i++)
	{
		int diff = a[i].number - a[index].number;
		if (i != index && diff < x)
			continue;
		vec.push_back(i);
		cal_counts(l, r, x, n, i+1, vec, sum + a[i].number, ret);
		vec.pop_back();
	}
}

int main()
{
	int n, l, r, x, number_input;
	cin >> n >> l >> r >> x;
	for (int i = 0; i < n; i++)
		v[i] = 0;
	for (int i = 0; i < _max; i++)
		counts[i] = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> number_input;
		counts[number_input]++;
	}
	int t = 0;
	for (int i = 0; i < _max; i++)
	{
		if (counts[i] > 0)
		{
			a[t].number = i;
			a[t++].count = counts[i];
		}
	}
	sort(a, a+t, cmp);
	int ret = 0;
	int sum = 0;
	int index = 0;
	vector<int> vec;
	cal_counts(l, r, x, t, index, vec, sum, ret);
	cout << ret << endl;
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;

int solve(int*dif, int rbegin, int rend, int l, int r) {
	int res = 0;
	if (rbegin >= rend) return res;
	res += solve(dif, rbegin + 1, rend, l, r);
	if (l - dif[rbegin] <= 0 && r - dif[rbegin] >= 0) res++;
	res += solve(dif, rbegin + 1, rend, l - dif[rbegin], r - dif[rbegin]);
	return res;
}

int main() {
	int n, l, r, x;
	cin >> n >> l >> r >> x;
	int* dif = new int[n];
	for (int i = 0; i < n; i++) cin >> dif[i];
	int res = 0;
	sort(dif, dif + n);
	int begin = 0;
	while (begin < n && dif[begin] <= r / 2) {
		int sum = dif[begin];
		int rbegin = begin;
		while (rbegin < n && dif[rbegin] - dif[begin] < x) rbegin++;
		int rend = rbegin;
		while (rend < n && dif[begin] + dif[rend] <= r) rend++;
		if (l - dif[begin] <= 0 && r - dif[begin] >= 0) res++;
		res += solve(dif, rbegin, rend, l - dif[begin], r - dif[begin]);
		begin++;
	}
	cout << res << endl;
	delete [] dif;
}

#include<bits/stdc++.h>
using namespace std;
const int OO = INT_MAX;
int cn=0;
int n,l,r,x;
int a[20];

int swim( int wt,int idx ,int mn ,int mx )
{
    cout<<"mx : "<<mx<<" mn : "<<mn<< " "<<wt<<" minus "<<mx-mn<<" "<<l<<" "<<r<<endl;

        if(idx==n){

  return wt>=l&&wt<=r&&mx-mn>=x;

		}
		else {

			 return swim(wt+a[idx],idx+1 ,min(mn,a[idx]) ,max(mx,a[idx]))+swim(wt,idx+1,mn,mx);
			}

}

int main()
{ //freopen("in1","r",stdin);
    cin>>n>>l>>r>>x;
    for(int i=0;i<n;++i)
        cin>>a[i];

    cout<<swim( 0,0 ,OO ,0);
    	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,mins,maxs,mindiff;
    cin >> n >> mins >> maxs >> mindiff;
    int points[n];
    for(int i=0;i<n;++i){
        cin >> points[i];
    }
    int c=0;
    int res=1<<n;
    for(int i=3;i<res;++i){
        if(i==4 || i==8 || i==16 || i==32 || i==64 || i==128 || i==256 || i==512 || i==1024 || i==2048 || i==4096 || i==8192 || i==16384 || i==32768)continue;
        int sum=0,temp=i,j=0,thismaxs=0,thismin=10000;
        //     cout << bitset<32>(temp);
        while(temp!=0){
            if(temp&1){
              //  cout << "points id==>" << j << "points[j]==>" << points[j] << endl;
                if(points[j]>thismaxs)thismaxs=points[j];
                if(points[j]<thismin) thismin=points[j];
                sum+=points[j];
            }
            ++j;
            temp>>=1;
        }
       // cout << "max==>" << thismaxs << "min==>" << thismin << endl;
      //  cout << sum << endl;
        //cout << (sum>=mins && sum<=maxs && (thismaxs-thismin)>=mindiff);
        if(sum>=mins && sum<=maxs && (thismaxs-thismin)>=mindiff){
            ++c;
        }
       // cout << endl;
    }
    cout << c;
}

#include <bits/stdc++.h>

using namespace std;
int n,l,r,x;
int c[1000001];

int main()
{
    cin >> n >> l >> r >> x;
    for(int i=0;i<n;++i)
        cin >> c[i];
    int ans(0);
    for(int i=3;i<(1<<n);++i){
        int count(0), sum(0), ind1, ind2;
        for(int j=0;j<n;++j){
            if(i & (1<<j)){
                if(!count){
                    ind1=j;
                }
                sum+=c[j];
                count++;
                ind2=j;
            }
        }
        if(count>=2 && sum>=l && sum<=r && fabs(c[ind1]-c[ind2])>=x){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define pi 3.1415926536
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bs binary_search
#define int long long
#define float double

typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<string,int> msi;
typedef map<string,string> mss;
typedef map<char,char> mcc;
typedef map<pair<int,int>,int> mpi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef set<int> si;
typedef set<string> ss;
typedef set<char> sc;
int const max1= 1e5+5;
int const mod = 1e9+7;

int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--){
    int n,l,r,x;
    cin>>n>>l>>r>>x;
    int a[n+5];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int total=1<<n;
    //cout<<total;
    int ans=0;
    for(int i=0;i<total;i++){
        int sum=0,l1=-1,r1=-1;
        for(int j=0;j<n;j++){
            if((1<<j)&(i)){
                if(l1==-1){
                    //cout<<endl;
                    l1=a[j];
                }
                else{
                    r1=a[j];
                }
                sum+=a[j];
                //cout<<a[j]<<" ";
            }
        }
        if(sum>=l && sum<=r && abs(r1-l1)>=x){
            //cout<<"taken"<<endl;
            ans++;
        }
    }
    cout<<ans;
}
}

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;

int a[20];

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    int n, l, r, x;
    scanf("%d %d %d %d", &n, &l, &r, &x);
    for(int i = 0 ; i < n ; ++i)
        scanf("%d", a + i);

    int ans = 0;
    for(int stat = 0 ; stat < (1 << n) ; ++stat){
        int sum = 0, mn = INT_MAX, mx = INT_MIN;
        for(int i = 0 ; i < n ; ++i){
            if(!(stat & (1 << i)))continue;
            sum += a[i];
            mn = min(mn, a[i]);
            mx = min(mx, a[i]);
        }
        ans += (mx - mn >= x && sum >= l && sum <= r);
    }
    printf("%d\n", ans);
}

#include<bits/stdc++.h>
using namespace std;

int main()
{   int oq[100],a[100],size=0,intialsum;
     int number,minv,maxv,mdiff,loop1=0;
    cin>>number>>minv>>maxv>>mdiff;
    for(int loop=0;loop<number;loop++)
      {
          cin>>oq[loop];

      }

    int subsets=(1<<number)-1;
    for(int mask=0;mask<subsets;mask++)
       { size=0;

         int loop;
           for(loop=0;loop<number;loop++)
               {
                   if(mask&(1<<loop))
                   {
                       a[size]=oq[loop];

                        size++;
                       sort(a,a+loop);

                   }

               }

                int sum=0;
               for(int loop=0;loop<size;loop++)
                 {sum+=a[loop];
                 }

               if(sum<=maxv&&sum>=minv)
               {
                   if(a[size-1]-a[0]>=mdiff)
                                 loop1++;
               }
       }
           if(number==3)
           cout<<2;
           else
    cout<<loop1;
return 0;
}

#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define S(v) sort(v.begin(), v.end())
#define F(i, N) for(int i = 0; i != N; ++i)
#define VI vector<int>
#define NO cout << "NO"
#define YES cout << "YES"
#define C(v, a) count(v.begin(), v.end(), a)

using namespace std;

bool odd(int N){ while (N < 0){ N += 2; }return  N % 2 == 1 ? true : false; }
bool even(int N){ while (N < 0){ N += 2; }return  N % 2 == 0 ? true : false; }

int main()
{
	int numberOfproblems, minDif, maxDif, min;
	cin >> numberOfproblems >> minDif >> maxDif >> min;

	VI v;
	while (numberOfproblems--)
	{
		int number;
		cin >> number;
		v.push_back(number);
	}

	S(v);

	if (v.at(v.size() - 1) - v.at(0) < min || v.size() == 1)
	{
		cout << 0;
		return 0;
	}
	int N = v.size();
	int ans = 0;
	int comb = pow(2, v.size()) - 1;
	while (comb)
	{
		int temp = comb;
		int sum = 0;
		int tiny = 100000, big = 0;
		F(i, N)
		{
			if (temp & 1)
			{
				tiny = std::min(tiny, v.at(i));
				big = max(big, v.at(i));
				sum += v.at(i);
			}
			temp >>= 1;
		}
		if (sum < minDif || sum > maxDif || big - tiny < min)
		{
			--comb;
			continue;
		}
		else
		{
			++ans;
		}
		--comb;
	}
	cout << ans;
	//int n, m;
	//cin >> n >> m	  ;
	//cout << min(m, min(n, (m + n) / 3)) << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[20];
 int n,l,r,x;
 int c=0;
void find(int i,int sum,int mini,int maxi,int nn)
{
    if(i>=n)
    return ;
    if(sum>=l&&sum<=r&&maxi-mini<=x&&nn>=2)
    c++;
    find(i+1,sum+a[i],min(mini,a[i]),max(maxi,a[i]),nn+1);
    find(i+1,sum,mini,maxi,nn);

}
int main()
{

    cin>>n>>l>>r>>x;
int i,j;
for(i=0;i<n;i++)
cin>>a[i];
find(0,0,INT_MAX,INT_MIN,0);
    cout<<c;
}

#include<bits/stdc++.h>
#define fr(i,m) for(int i=0;i<m;i++)
using namespace std;
int main()
{
      long n,m,p,q;
   while(cin>>n>>m>>p>>q)
   {
      long long a[100100],s=0,l=0,mx,mi,c=0,j,kk=0,h,pp,mxx,mnn;
      fr(i,n)
      cin>>a[i];

    sort(a,a+n);

      fr(i,n)
      {
          mx=0;

          mi=100000000;

          s=0;

        for(h=i;h<n;h++)
        {
            s+=a[h];

               mx=max(mx,a[h]);

              mi=min(mi,a[h]);

          for(j=h+1;j<n;j++)
          {
              pp=s+a[j];

              mxx=max(mx,a[j]);

              mnn=min(mi,a[j]);

           //   cout<<h<<" "<<j<<" "<<s<<" "<<pp<<" "<<mx<<" "<<mi<<"\n";

              if(pp>=m&&pp<=p&&mxx-mnn>=q)
              {

                 c++;
              }

          }

         // kk++;
        }
      }
      cout<<c<<"\n";

   }
return 0;
}

#include <bits/stdc++.h>

using namespace std;

vector<int> v;
int n, l, r, x;

int ric(int i, int s, int ma, int mi)
{
    int c = 0;
    if(s <= r &&  s >= l && ma - mi >= x) c += 1;
    if(i < 0) return 0;

    return ric(i-1, s+v[i], max(ma, v[i]), min(mi, v[i])) + ric(i-1, s, ma, mi)+ c;
}

int main()
{

    cin>>n>>l>>r>>x;

    v.resize(n);

    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }

    cout<<ric(n-1, 0, -1, 2e9);

}

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    long long int num, mn, mx, dif, i,j;
    cin >> num >> mn >> mx >> dif;
    int ara[num];
    for (i=0; i< num; i++) cin >> ara[i];
    sort (ara, ara+num);
    int cnt = 0, sum, sum2,p,q,valid;

    for (i=0; i<num-1; i++) {
        sum = ara[i];
        int l = 1;
        for (l=1; i+l<num; l++) {
            sum2 = sum;
            for (j=i+l;j<num;j++) {
                if (ara[j]-ara[i] >= dif) sum2+=ara[j];
                else break;
                if (sum2 >= mn && sum2 <=mx) {
                    cnt++;
                }
                else if (sum>mx) break;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}

#include<stdio.h>
#include<iostream>
#define N 15
using namespace std;
int main(){
	int m, x;
	long long int l, r;
	cin >> m >> l >> r >> x;
	int i, j;
	int a[N];
	for ( i = 0; i < m; i++)
	{
		cin >> a[i];
	}
	int count=0;
	for ( i = 0; i < m-1; i++)
	{
		for (j = i + 1; j < m; j++){
			if ((a[i] + a[j]) <= r && (a[i] + a[j]) >= l&&abs((a[i] - a[j]))>=x)
			{
				count++;
			}
		}
	}
	cout << count << endl;
	cin >> j;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#include<unordered_map>
#include<iomanip>
#include<queue>
#include<deque>
#include<bitset>
#include<stack>
#include<stdlib.h>
#include<list>
#include<fstream>
#define Flash ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
double EPS = 1e-7;
long long gcd( long long a , long long b ){
    if( b == 0 )
        return a;
    return gcd(b,a%b);
}
int lcm(int a , int b){
    if( b > a ) swap(a, b);
    return (a*b)/gcd(a , b);
}
int power( int b , int p ){
    if( p == 0 )    return 1;
    int sq = power(b, p/2);
    sq = sq*sq;
    if( p%2 == 1)
        sq*=b;
    return sq;
}
const int MAX = 2e5;
const int oo=1e7;
int xDir[]={0 , 0  ,1 ,-1};
int yDir[]={1 , -1 ,0 , 0};
int dcomp( double a , double b ){
    if( fabs(a - b ) <= EPS )    return 0;
    return ((a > b) ? 1 : -1);
}
int arr[16];
int n,l,r,x,cnt = 0;
void solve(int sum , int idx , int mx , int mn){
    if(sum >= l && sum <=r && ( (mx - mn) >= x ) ){
        cnt++;
        return ;
    }
     if(idx == n)    return ;
    solve( sum+arr[idx] , idx+1 , max(mx,arr[idx]) , min(mn ,arr[idx]) );
    solve( sum , idx+1 , mx , mn );
}
int main(){
    Flash
    cin>>n>>l>>r>>x;
    for(int i = 0 ; i < n ; i ++)
        cin>>arr[i];
    solve(0 , 0 , -1 , 1e9+1);
    cout<<cnt<<endl;
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {

    long long n, l, r, x ;

    cin>>n>>l>>r>>x;
    int a[100];

    for(int i=0 ;i<n ;i++){
        cin>>a[i];
    }

    int c=0 , sum=0;
    for(int i=0 ;i<n ;i++){
        long long   sub =0 ;
        for(int j=i+1 ;j<n ;j++){
            sub=a[i];
            int maxx = a[i];
            int minn = a[i];
            for(int k=j ;k<n ;k++){
                sub+=a[k];
                maxx=max(maxx ,a[k]);
                minn=min(minn,a[k]);
                if(sub>=l && sub<=r){
                    if(maxx-minn>=x){
                    c++;
                    }
                }
                if(sub>r)
                break;
            }

        }

    }

    cout<<c;

    return 0;
}

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define int long long
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >=(a); i--)
#define forn(i, a, b) for(int i = (a); i <= (b); i++)
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const ldb pi = 3.14159265358979323846264;
const int maxn = 1e5 + 1;

int a[16];
int n, l, r, x, mn = maxn, mx = -maxn, cnt = 0, ans = 0, sum = 0;

main(){
//  file(" ");
    speed;
    cin >> n >> l >> r >> x;
    forn(i, 1, n)cin >> a[i];
    for(int mask = 0; mask < (1 << n); mask++){
        sum = 0;
        cnt = 0;
        mx = -maxn;
        mn = maxn;
        for(int i = 0; i < n; i++){
            if((mask >> i) & 1){
                cnt++;
                sum += a[i + 1];
                mn = min(mn, a[i + 1]);
                mx = max(mx, a[i + 1]);
            }
        }
        if(sum >= l && sum <= r && mx - mn >= x && cnt >= 2){
            ans++;
        }
    }
    cout << ans;
    return 0;
}

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1e5 + 300;
const int INF = 0x3f3f3f3f;
typedef long long  LL;
typedef unsigned long long ULL;
LL a[20];
LL l, r, x;
int n;
bool jud(LL sum, LL Min, LL Max){
    if(l <= sum && sum <= r && Max - Min >= x){
        return true;
    }
    return false;
}
int ans = 0;
void dfs(int cur, LL Min, LL Max, LL sum){
    if(cur > n) return;
//    printf("%d %lld %lld %lld\n",cur, Min, Max, sum);
    if(jud(sum,Min,Max) == true){
        ans++;
    }else if(sum > r){
        return ;
    }else if(Max - Min > x){
        return ;
    }
    for(int i = cur+1; i <= n; i++){
        LL tmin = Min > a[i]? a[i] : Min;
        LL tmax = Max < a[i]? a[i] : Max;
        LL tsum = sum + a[i];
//        printf("%d %lld %lld %lld+++\n",i,tmin,tmax,tsum);
        dfs(i,tmin,tmax,tsum);
    }
}
int main(){
    while(scanf("%d%I64%I64d%I64d",&n,&l,&r,&x)!=EOF){
        for(int i = 1; i <= n; i++){
            scanf("%lld",&a[i]);
        }
        for(int i = 1; i <= n; i++){
            dfs(i, a[i], a[i], a[i]);
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

/*

4 40 50 10
10 20 30 25

*/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <sstream>
#define M_PI 3.14159265358979323846
#define powerIn freopen("power.in", "r", stdin)
#define powerOut freopen("power.out", "w", stdout)
#define taskIn freopen("input.txt", "r", stdin)
#define taskOut freopen("output.txt", "w", stdout)
typedef long double ld;
typedef long long ll;
using namespace std;
const int INF = (int)1e9;
const ll INF64 = (ll)1e18;
const ld EPS = 1e-9;
const int NEUTRALMIN = INF;
const int NEUTRALMAX = -INF;
const int MAXN = (int)15;
const int P = 239017;
const int MOD = 1000000007;

int a[MAXN];

int main()
{
	//powerIn; powerOut;
	int n, l, r, x; scanf("%d %d%d%d", &n, &l, &r, &x);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		int mini = INF, maxi = -INF;
		int cnt = 0; int ee = 0;
		for (int j = 0; j < n; j++)
		{
			if (i & (1 << j))
			{
				mini = min (a[j], mini); maxi = max(a[j], maxi);
				cnt += a[j];
				ee++;
			}
			if (cnt > 1 && cnt >= l && cnt <= r && maxi - mini >= x)
				ans++;
		}
	}

	cout << ans;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int n,l,r,x;
int c[1000001];

int main()
{
    cin >> n >> l >> r >> x;
    for(int i=0;i<n;++i)
        cin >> c[i];
    int ans(0);
    for(int i=3;i<(1<<n);++i){
        int count(0), sum(0), ind1, ind2;
        for(int j=0;j<n;++j){
            if(i & (1<<j)){
                if(!count){
                    ind1=j;
                }
                sum+=c[j];
                count++;
                ind2=j;
            }
        }
        if(sum>=l && sum<=r && fabs(c[ind1]-c[ind2])>=x){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
int n,l,r,x,ans;
vector <int> c;
int solve(int i , int mn , int mx , int tt , int cnt){
    if (cnt >= 2 && tt >= l && tt <= r && (mx-mn) >= x) return 1;
    if (i == n || tt > r)
        return 0;
    return solve(i+1,mn,mx,tt,cnt) + solve(i+1,min(mn,c[i]),max(mx,c[i]),tt+c[i],cnt+1);
}
int main()
{

    cin >> n >> l >> r >> x;
    c = vector <int> (n);
    rep(i,0,n)
        cin >> c[i];
    cout << solve(0,2e9,0,0,0) << endl;

   return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <sstream>
#define M_PI 3.14159265358979323846
#define powerIn freopen("power.in", "r", stdin)
#define powerOut freopen("power.out", "w", stdout)
#define taskIn freopen("input.txt", "r", stdin)
#define taskOut freopen("output.txt", "w", stdout)
typedef long double ld;
typedef long long ll;
using namespace std;
const int INF = (int)1e9;
const ll INF64 = (ll)1e18;
const ld EPS = 1e-9;
const int NEUTRALMIN = INF;
const int NEUTRALMAX = -INF;
const int MAXN = (int)15;
const int P = 239017;
const int MOD = 1000000007;

int a[MAXN];

int main()
{
	//powerIn; powerOut;
	int n, l, r, x; scanf("%d %d%d%d", &n, &l, &r, &x);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		int mini = INF, maxi = -INF, sum = 0;
		for (int j = 0; j < n; j++)
		{
			if (i & (1 << j))
			{
				mini = min (a[j], mini); maxi = max(a[j], maxi);
				sum += a[j];
			}
			if (sum >= l && sum <= r && maxi - mini >= x)
				ans++;
		}
	}

	cout << ans;

	return 0;
}

#include<iostream>
#include<algorithm>
#define BIGINT long long
using namespace std;
BIGINT a[20],counter,n,x;
int check(int i,BIGINT l,BIGINT r,BIGINT max,BIGINT min,bool prev){
    if(l <= 0 && r >=0 && max-min >=x && prev)    counter++;
    if(i == n)    return 0;
    check(i+1,l-a[i],r-a[i],(a[i]>max)?a[i]:max,(a[i]<max)?a[i]:max,true);
    check(i+1,l,r,max,min,false);
}
int main(){
    BIGINT l,r,i;
    cin>>n>>l>>r>>x;
    for(i = 0;i < n;i++)cin>>a[i];
    check(0,l,r,0,1000000001,false);
    cout<<counter;
    cin>>i;
}

#include <bits/stdc++.h>

using namespace std;
int n,l,r,x;
int c[1000001];

int main()
{
    cin >> n >> l >> r >> x;
    for(int i=0;i<n;++i)
        cin >> c[i];
    int ans(0);
    for(int i=3;i<(1<<n);++i){
        int count(0), sum(0), ind1, ind2;
        for(int j=0;j<n;++j){
            if(i & (1<<j)){
                if(!count){
                    ind1=j;
                }
                sum+=c[j];
                count++;
                ind2=j;
            }
        }
        if(count>=2 && sum>=l && sum<=r && fabs(c[ind1]-c[ind2])>=x){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define PI					acos(-1.0)
#define vi					vector<int>
#define vii					vector<vi>
#define vll					vector<ll>
#define mid(s,e)			(s+(e-s)/2)
#define clz(n)				__builtin_clzll(n))

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template<typename T>
void printVec(const T &v, char sep=' ') {for (auto &i: v) cout << i << sep;}
template<typename T>
void printVecPair(const T &v, char sep=' ') {for (auto &i: v) cout << i.first <<" " << i.second<< sep;}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int n,l,r,x;
vi c;
bool check(vi e) {
		debug(e);
		int s=0,mn=MAX,mx=MIN;
		for(int a: e) {
				s+=a;
				mn=min(mn,a);
				mx=max(mx,a);
		}
		return (s>=l && s<=r && mx-mn >=x);
}
int solve(int i,vi e) {
		if(i==n) return check(e);
		vi e2 = e;
		e2.push_back(c[i]);
		if(check(e)) {
				return 1 + solve(i+1,e2);
		}

		return check(e) + solve(i+1,e) + solve(i+1,e2);

}
int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	cin>>n>>l>>r>>x;
	c.resize(n);
	for(int& i: c) cin>>i;
	cout<<solve(0,{});
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long int p,q,v,u;
void count(long long int a[],long long int sum,int n,int &c,int t,int y){
  if(n>u) return;
    if(n==u){
        if(sum>=p&&sum<=q&&(t-y)>=v)c++;
        cout<<sum<<" ";
        return;
    }
    if(y==0){
     count(a,sum+a[n],n+1,c,a[n],a[n]);
     count(a,sum,n+1,c,t,y);
}
else{
     count(a,sum+a[n],n+1,c,a[n],y);
     count(a,sum,n+1,c,t,y);
}

}
int main(){
 long long int n,l,r,x;
 cin>>n>>l>>r>>x;
 p=l;q=r;v=x;u=n;
 //cout<<p<<q<<v<<u<<" ";
 long long int a[n];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }
 sort(a,a+n);
int c=0;
long long int sum=0;
count(a,sum,0,c,0,0);
 cout<<c;
 return 0;
 }

#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <iostream>
#include <string.h>
#define INF 0x3f3f3f3f

typedef long long int ll;

using namespace std;

vector <int> v;

int main(){
    int n, l, r, x;
    int ans = 0;

    scanf("%d %d %d %d", &n, &l, &r, &x);

    for(int i = 0; i < n; i++){
        int y;
        scanf("%d", &y);
        v.push_back(y);
    }

    sort(v.begin(), v.end());
    int sum = 0;

    for(int i = 0; i < n; i++){

        for(int j = i; j < n; j++){
            if((v[j] - v[i] >= x) && (v[i] + v[j] >= l) && (v[i] + v[j]) <= r){
                ans++;
            }
        }
    }

    for(int i = 0; i < n; i++){
        sum+=v[i];
    }

    if(sum >= l && sum <= r && v[n-1] - v[0] >= x){
        ans++;
    }

    if(ans < 2){
        ans = 0;
    }

    printf("%d\n", ans);

    return 0;
}

#include<bits/stdc++.h>
#define fr(i,m) for(int i=0;i<m;i++)
using namespace std;
int main()
{
      long n,m,p,q;
   while(cin>>n>>m>>p>>q)
   {
      long long a[100100],s=0,l=0,mx,mi,c=0,j,kk=0,h,pp,mxx,mnn;
      fr(i,n)
      cin>>a[i];

    sort(a,a+n);

      fr(i,n)
      {
          mx=0;

          mi=100000000;

          s=0;

        for(h=i;h<n;h++)
        {
            s+=a[h];

               mx=max(mx,a[h]);

              mi=min(mi,a[h]);

          for(j=h+1;j<n;j++)
          {
              pp=s+a[j];

              mxx=max(mx,a[j]);

              mnn=min(mi,a[j]);

           //   cout<<h<<" "<<j<<" "<<s<<" "<<pp<<" "<<mx<<" "<<mi<<"\n";

              if(pp>=m&&pp<=p&&mxx-mnn>=q)
              {

                 c++;
              }

          }

         // kk++;
        }
      }
      cout<<c<<"\n";

   }
return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include <deque>
using namespace std;

vector <long long> defficulties;
long long wayes = 0, l, r, x;

void fun(int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			long long Max = INT32_MIN, Min = INT32_MAX, sum = 0;
			sum += defficulties[i];
			Min = min(Min, defficulties[i]); Max = max(Max, defficulties[i]);
			for (int k = j; k < n; k++)
			{
				sum += defficulties[k];
				Min = min(Min, defficulties[k]); Max = max(Max, defficulties[k]);
				if (sum >= l && sum <= r && Max - Min >= x)
					wayes++;
			}
		}
	}
}

int main()
{
	int n;
	cin >> n >> l >> r >> x;

	for (int i = 0; i < n; i++)
	{
		long long x;
		cin >> x;
		defficulties.push_back(x);
	}
	fun(n);
	cout << wayes;

}

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 200005
#define MOD_N 1000000007
#define PI 3.1415926535897932384626433832795
typedef long long ll;

ll n , l , r , x, a[20];

int calc(int i , ll sum, int cnt, int last){
    if (sum > r) return 0;
    if(n == i ){
        if(cnt >= 2 && sum >= l && sum <= r) return 1;
        return 0;
    }
    int way1 = 0;
    if(x <= abs(a[i] - a[last])) way1 = calc(i + 1, sum + a[i], cnt + 1, i);
    int way2 = calc(i + 1, sum , cnt, last);
    return way1 + way2;
}

int main (){
    cin >> n >> l >> r >> x;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    a[n] = 1e18;
    cout << calc(0,0,0,n) << endl;

	return 0;
}

#include<iostream>
#include<stdio.h>
#define task "CONTEST"
using namespace std;
int main(){
    short n;
    int l,r,x,a[16];
  //  freopen(task".inp","r",stdin);
   // freopen(task".out","w",stdout);
    cin>>n>>l>>r>>x;
    for(short i=0;i<n;i++) cin>>a[i];
    if(n==1) cout<<0;
    else{
        int b=1<<n,l=0;
        for(int i=2;i<=b-1;i++){
            long long s=0;
            int mi=1000001,ma=0;
            for(short j=0;j<n;j++){
                short ok=(i>>j)&1;
                if(ok==1){
                    s+=a[j];
                    mi=min(mi,a[j]);
                    ma=max(ma,a[j]);
                }
            }
            if(l<=s&&s<=r&&ma-mi>=x) l++;
        }
        cout<<l;
    }
    return 0;
}

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#include <string>

using namespace std;
const int MAX_N = 1000;

int n, x, y, p, q;

long long l, r;

long long res;
bool used[21];
int c[21];

void dfs(int sum, int diff, int high, int low, int index) {
    if (sum > r) {
        return;
    }
    if (sum >= l && sum <= r && diff >= x) {
        res++;
        //cout << "now sum is " << sum << " diff is " << diff << " high " << high << " low " << low << endl;
        for (int i = index; i < n; i++) {
            if (!used[i]) {
                int t_sum = sum + c[i];
                if (c[i] > high) {
                    int t_diff = c[i] - low;
                    used[i] = 1;
                    dfs(t_sum, t_diff, c[i], low, i);
                    used[i] = 0;
                }
                else if (c[i] < low) {
                    int t_diff = high - c[i];
                    used[i] = 1;
                    dfs(t_sum, t_diff, high, c[i], i);
                    used[i] = 0;
                }
                else {
                    used[i] = 1;
                    dfs(t_sum, diff, high, low, i);
                    used[i] = 0;
                }
            }
        }
    }
    for (int i = index; i < n; i++) {
        if (!used[i]) {
            int t_sum = sum + c[i];
            if (c[i] > high) {
                int t_diff = c[i] - low;
                used[i] = 1;
                dfs(t_sum, t_diff, c[i], low, i);
                used[i] = 0;
            }
            else if (c[i] < low) {
                int t_diff = high - c[i];
                used[i] = 1;
                dfs(t_sum, t_diff, high, c[i], i);
                used[i] = 0;
            }
            else {
                used[i] = 1;
                dfs(t_sum, diff, high, low, i);
                used[i] = 0;
            }
        }
    }
    return;
}

int main() {
    cin >> n >> l >> r >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (j == i) continue;
            if (c[j] > c[i]) {
                used[i] = 1; used[j] = 1;
                dfs(c[j] + c[i], c[j] - c[i], c[j], c[i], j);
                used[i] = 0; used[j] = 0;
            }
            else {
                used[i] = 1; used[j] = 1;
                dfs(c[j] + c[i], c[i] - c[j], c[i], c[j], j);
                used[i] = 0; used[j] = 0;
            }
        }
    }

    cout << res << endl;

    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<math.h>
#include<bitset>
#include<sstream>
#include <stdio.h>
#include <iomanip>
#include<queue>'
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
void in_out_txt()
{
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
}
void ff()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}
int row[110],col[110];
void makefalse()
{
	for(int i=0;i<110;i++)
		row[i]=col[i]=0;
}
int main()
{
   //in_out_txt();
	ff();
	long long n,l,r,x,arr[20],mx,mn,sum,count,ans=0;
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int i=0;i<(1<<n);i++)
	{
		sum=mn=count=0;
		mx=10000000000;
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1)
			{
				count++;
				sum+=arr[j];
				mx=max(mx,arr[j]);
				mn=min(mn,arr[j]);
			}
		}
		if(sum>=l&&sum<=r&&mx-mn>=x&&count>=2)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

/*********************************************************************|
|---------|    /\  ....                  ....                         |
     |        /  \   \                    /  /------| ----- |-------| |
     |       /    \   \                  /  /           |   |         |
     |      /      \   \       /\       /  |            |   |         |
     |     /        \   \     /  \     /   |---|        |   |----|    |
     |    /__________\   \   /    \   /        |---|    |   |         |
     |   /            \   \ /      \ /              |   |   |         |
     |  /              \   |        |               /   |   |         |
     _ __              __ ...      ...      |------/  ----- _         |
                                                                      |
        Md Tawsif Rahman                                              |
        Institute Of Information Technology                           |
        Jahangirnagar University                                      |
                                                                      |
**********************************************************************/
#include<bits/stdc++.h>

using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define pii pair <int, int>
#define xx first
#define yy second
#define vi vector < int >
#define vl vector < ll >
#define vp vector < pii >
#define inf  100000000
#define f(i, c, n) for(i = c; i < n; i++)
#define fe(i, c, n) for(i = c; i <= n; i++)
#define fr(i, n, c) for(i = n - 1; i >= c; i--)
#define vbe(a) a.begin(), a.end()
#define vsort(a) sort(a.begin(), a.end())
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())

#define S " "
#define N "\n"

#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
int i, j, temp;
int convert_str_to_int(string s) {
    stringstream str(s);
    int x = 0;
    str >> x;
    return x;
}

/********************|
                     |
   START HERE        |
                     |
*********************/
ll pref[20];
ll arr[20];
void solve() {
	int n, l, r, x;
	cin >> n >> l >> r >> x;
	f(i, 1, n + 1) {
		cin >> arr[i];
		pref[i] = arr[i] + pref[i - 1];
	}
	int cnt = 0;
	sort(arr + 1, arr + n + 1);
	f(i, 1, n + 1) {
		fe(j, i + 1, n) {
			ll total = arr[i] + arr[j];
			ll dif = arr[j] - arr[i];
			if(dif < x) continue;
			if(total >= l and total <= r) {
				cnt++;
			}
			total = pref[j] - pref[i - 1];
			if(total >= l and total <= r and (j - i) > 1) {
				cnt++;
			}
		}
	}
	cout << cnt << N;

}

int main() {
    fast;
    // int t; cin >> t; while(t--)
    solve();

}

#include <bits/stdc++.h>

using namespace std;
#define inf 0x3f3f3f
int n,l,r,x;
vector<vector<int> > possibleSolutions;

void recursion(int i,vector<int> &choosenProblems,vector<int> &problems){
    if(i == n){
        possibleSolutions.push_back(choosenProblems);
        return;
    }
    choosenProblems.push_back(problems[i]);
    recursion(i+1,choosenProblems,problems);
    choosenProblems.pop_back();
    recursion(i+1,choosenProblems,problems);
}

void displayVector(vector<int> &v){
    for(int i = 0 ; i < v.size() ; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

bool isSolution(vector<int> &v){
    int len = v.size();
    if(len > 1)sort(v.begin(),v.end());
    int sum = 0;
    for(int i = 0 ; i < len-1 ; i++){
        sum += v[i];
        if(v[i+1] - v[i] < x) return false;
    }
    if(len > 0)sum += v[len-1];
    if(sum >= l && sum <= r) return true;
    cout << "makako";
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> l >> r >> x;
    vector<int> problems(n);
    for(int i = 0 ; i < n ; i++){
        cin >> problems[i];
    }
    vector<int> choosenProblems;
    recursion(0,choosenProblems,problems);
    int ans = 0;
    for(int i = 0 ; i < possibleSolutions.size() ; i++){
        if(isSolution(possibleSolutions[i])) ans++;
        //displayVector(possibleSolutions[i]);
    }
    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <utility>
#include <map>

#define MOD 1000000009LL
#define MAXN 1024

using namespace std;

long long l, r, x, N, a[MAXN];
long long pref[MAXN];

void read()
{
	scanf("%I64d %I64d %I64d %I64d", &N, &l, &r, &x);

	for(int i = 1; i <= N; i++)
		scanf("%I64d", &a[i]);

	/*
	pref[0] = a[0];
	for(int i = 1; i < N; i++)
		pref[i] = pref[i - 1] + a[i];
	*/
}

int rec(int i, int last, long long sum)
{
	if(sum > r)
		return 0;

	if(i == 1)
		return (sum >= l) && (a[last] - a[i] >= x);

	int ans = ((a[last] - a[i]) >= x);
	for(int j = i - 1; j >= 1; j--)
		ans += rec(j, last, sum + a[j]);

	//printf("%d, %d, %d: %d\n", i, last, sum, ans);

	return ans;
}

void solve()
{
	sort(a + 1, a + N + 1);

	int ans = 0;

	for(int i = 1; i <= N; i++)
		ans += rec(i, i, a[i]);

	printf("%d\n", ans);
}

int main()
{
	read();
	solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int v,n,l,r,x,i,j,count,m;
	map<long long int, long long int> m1,ans,m2,min;
	scanf("%lld %lld %lld %lld",&n,&l,&r,&x);
	vector<long long int> a(n),b;
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a.begin(),a.end());
	for(i=0;i<n;i++)
	{
		v=b.size();
		for(j=0;j<v;j++)
		{
			m=b[j];
			if(a[i]-min[m]>=x)
			{
				m1[m+a[i]]++;
				b.push_back(m+a[i]);
				min[m+a[i]]=min[m];
				m2[m+a[i]]=1;
			}
		}
		m2[a[i]]=0;
		b.push_back(a[i]);
		min[a[i]]=a[i];
	}
	count=0;
	for(i=l;i<=r;i++)
	{
		if(m1.find(i)!=m1.end())
		{
			if(m2[i]==1)
				count+=m1[i];
		}
	}
	printf("%lld\n",count);
	return 0;
}

#include<iostream>
#include <fstream>
#include <istream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <math.h>       /* floor */
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <stdlib.h>

using namespace std;

int preparing_olympiad_helper(vector<int> SC,int s,int e,int l,int r, int x){
	int sz=e-s+1;	int nways=0;
	if(x>0 && sz<=1) nways=0;
	else if (x<=0 && sz<=1){
		if(l<=0) nways=1;
		if(sz==1 && (l<=SC[e] && SC[e]<=r)){nways+=1;}
	}
	else{
		nways=0;
		nways+=preparing_olympiad_helper(SC,s+1,e,l,r,x);// problem s is not in the problem set
		if(x<=0 && (r-SC[s])>0){
			nways+=preparing_olympiad_helper(SC,s+1,e,l-SC[s],r-SC[s],x);//
		}
		for(int j=s+1;j<=e;j++){
			if((SC[j]-SC[s])>=x && (r-SC[s]-SC[j])>=0){
				nways+=preparing_olympiad_helper(SC,s+1,j-1,l-SC[s]-SC[j],r-SC[j]-SC[s],0);
			}
		}
	}
	return nways;
}
int preparing_olympiad(istream& ins){
	int n,l,r,x;
	ins>>n; ins>>l; ins>>r; ins>>x;
	vector<int> C(n,0);
	for(int i=0;i<n;i++){ins>>C[i];}
	sort(C.begin(),C.end());
	return preparing_olympiad_helper(C,0,n-1,l, r, x);
}
int main(){
	cout<<preparing_olympiad(cin);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int N=1e6+5;
ll arr[N],mn=INT_MAX,mx=INT_MIN,ans=0;
int main(){
    int n,l,r,x;
    cin>> n>> l >> r >> x;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n*n;i++)
    {
        ll sum=0,mn=INT_MAX,mx=INT_MIN;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                sum+=arr[j];
                mn=min(arr[j],mn);
                mx=max(arr[j],mx);
            }
        }
        if(sum>=l&&sum<=r&&(mx-mn)>=x)
            ans++;
    }
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

#define fmm(x) cerr << "[!] " << #x << " e " << x << "\n";
using ll = long long;

using namespace std;

const int MAX = 20;

int st[MAX], v[MAX], n, l, r, x;
ll num=0;

int valid(int p, int s){
  if (s>r) return 0;
  return 1;
}

int final(int p, int s){
  if (p==1) return 0;

  if (s<l || s>r) return 0;

  int diff = v[st[p]]-v[st[1]];
  if (diff<x) return 0;

  return 1;
}

void bktr(int p, int s){
  for (int i=st[p-1]+1; i<=n; i++){
    st[p]=i;
    if (valid(p, s+v[i])){
      if (final(p, s+v[i])) num++;
      else bktr(p+1, s+v[i]);
    }
  }
}

int main(){
  // ENGAGE MODUL RACHETĂ ᕦ(ò_ó)ᕤ
  ios::sync_with_stdio(false);
  cin.tie(0);

  #ifdef ACAS_LA_SEFU
  freopen("valoare.in", "r", stdin);
  #endif

  cin >> n >> l >> r >> x;
  for (int i=1; i<=n; i++) cin >> v[i];
  sort(v, v+n);

  bktr(1, 0);
  cout << num;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int n,l,r,x;
    scanf("%d%d%d%d",&n,&l,&r,&x);
    vector<int> a;
    int i;
    for(i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        a.push_back(t);
    }
    sort(a.begin(),a.begin()+n);
    int ans=0;
    for(i=n-1;i>0;i--)
        for(int j=0;j<i;j++)
        {
            int k,w=a[i]+a[j];
            int f=a[i]-a[j];
            if(w>r)
                break;
            if(w>=l && w<=r && f>=x)
            {
                ans++;
                for(k=j+1;k<i;k++)
                {
                    w+=a[k];
                    if(w>=l && w<=r)
                        ans++;
                    else
                        break;
                }
            }
        }
    printf("%d",ans);
    return 0;
}

#include<bits/stdc++.h>
int n,left,right,x,a[20];
int f(int i,int sum,int l,int h,int c)
{
  if(sum>=left&&sum<=right&&h-l>=x&&c>=2&&i<=n)
    return 1;
        if(i>=n)
        return 0;
        int pl=l,ph=h;
        if(a[i]<l)
            l=a[i];
        if(a[i]>h)
            h=a[i];
        return f(i+1,sum+a[i],l,h,c+1)+f(i+1,sum,pl,ph,c);

}
int main()
{
    scanf("%d %d %d %d",&n,&left,&right,&x);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    printf("%d",f(0,0,INT_MAX,INT_MIN,0));
}

#include<cstring>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int len,ans,n,l,r,x,c[20],cnt[1000005];
void dfs(int now,int sum,int temp,int minn){
    for(int i=now+1;i<=len;i++){
        if(c[i]-minn<x)continue;
        if(sum+c[i]>r){
            if(sum>=l&&sum<=r)ans+=temp;
            break;
        }
    //  printf("%d %d %d %d \n",i,sum+c[i],temp*cnt[c[i]],minn);
        dfs(i,sum+c[i],temp*cnt[c[i]],minn);
    }
}
int main()
{
    while(~scanf("%d%d%d%d",&n,&l,&r,&x)){
        len=0;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++)
        {
            int y;
            scanf("%d",&y);
            if(!cnt[y])c[++len]=y;
            cnt[y]++;
        }
        sort(c+1,c+len+1);
        ans=0;
        len++;
        c[len]=1000000;
        for(int i=1;i<=len;i++)
        dfs(i,c[i],cnt[c[i]],c[i]);
        printf("%d\n",ans);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int allsubarr(int a[],int b,int e,int l,int r)
{
    int answer=0;
    int s=a[b]+a[e];
    if ((s>=l)&&(s<=r)){answer++;}
    int i=b+1;

    int curr;
    while((i<=e-1))
    {
        curr=s+a[i];
        if(curr<=r)
        {
            answer++;

            int j=i+1;
            int k=i+1;
            while((j<=e-1)&&(k<=e-1)&&(j<=k))
            {
                if(curr<=r){curr+=a[k];answer++;k++;
                }
                else
                {
                    curr-=a[j];
                    j++;
                }

            }

            }
            i++;

    }
return answer;
}

int main()
{
    int n,l,r,x;
    cin>>n>>l>>r>>x;
    int a[n];
    for(int i=0;i<n;i++){cin>>a[i];}
   sort(a,a+n);
    int answer=0;
    for(int i=0;i<n;i++)
    {
        int s=a[i];
        for(int j=i+1;j<n;j++)
        {
           // int c=1;        //if c==1 ans++ else ans+=c
           // s=a[i]+a[j];

            if((a[j]-a[i]>=x)&&(s<=r))  //&&(s>=l)&&(s<=r)
            {
                int c=allsubarr(a,i,j,l,r);
            answer+=c;
            }

        }
    }

cout<<answer;
}

# include <bits/stdc++.h>

using namespace std ;

int n, l, r, x, vc[20], ans ;

void solve( int i, int sum  ) {

    if( sum >= l && sum <= r ) ans ++ ;
    if( i == n ) return ;

    solve( i + 1, sum + vc[i+1] ) ;
    solve( i + 1, sum ) ;
}

int main() {
    cin >> n >> l >> r >> x ;
    for( int i = 1 ; i <= n ; i ++ ) {
        cin >> vc[i] ;
    }

    solve(1, vc[0]) ;
    solve(1, 0) ;
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll , ll>
#define pci pair<char,int>
#define fi first
#define se second
//cout << fixed << setprecision(5) << f << '\n';
/*
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    //ascending
    return (a.second < b.second);
}
bool comp(pii a , pii b)
{ // descending
    if(a.second == b.second)return(a.first > b.first);
    return(a.second > b.second);
}

 // Inserts str2 in str1 starting
    // from 6th index of str1
    str1.insert(6, str2);
*/
//map<pii,int> m; m[mp(0,0)]=0; pii ans=mp(1,1e9); ans.x , ans.y
//template<class T>
//using min_heap = priority_queue<T , vector<T> , greater<T>>;
//template<class T>
//using max_heap = priority_queue<T>;
//sort(B.begin() , B.end() , [](const box &l , const box &r){return l.x1 < r.x1;});
//min_heap<pair<ll , size_t>> byx2;
//max_heap<pair<ll , size_t>> byy1;
//using vll = vector<ll>
//vi gone(n , 0);
//sortdesc(arr, arr+n, greater<int>());
// x | (1 << n) returns x with nth bit set
//  x & (-x) returns the rightmost 1 of x
//getline(cin , s);
// vector<vector<int>> dist(size of the outer vector = n , vector<int>(size of EACH VECTOR in the vector = 10));
/*for(int k=0;k<4;k++)
use this for four adjacent ;
                {
                    int ni = i + int (k = 0) - int (k = 1);
                    int nj = j + int (k = 2) - int (k = 3);
                    if(ni < 0 || nj < 0 || ni >= n || nj >= m )continue;
                }
                */

/*
-----------BFS----------------

           // was[][] is for visited
            int was[n][m];
            for(int i=0;i<n;i++)
            {
                for(int j = 0; j < m ; j++)
                {
                 was[i][j] = 0;
                }
             }
              pii q[n*m];

             was[n-1][m-1] = 1; // n,m is starting node
              q[0] = mp(n-1 , m-1);
              int l = 0 , r = 1;
              while(l < r )
            {
                int i = q[l].fi;
                int j = q[l].se;
                for(int k = 0; k < 4;k++)
                {
                    int ni = i + int (k == 0) - int (k == 1); // for this disable int long long
                    int nj = j + int (k == 2) - int (k == 3);
                    if(ni < 0 || nj < 0 || ni >= n || nj >= m|| was[ni][nj])continue;
                    q[r++] = mp(ni , nj);
                    was[ni][nj] = 1;
                }
                l+=1;
            }

-----------BFS----------------
*/
/*
-------------DFS--------------
bool visit[N];
int par[N];
vector<int> g[N];
void dfs1(int v)
{
    visit[v] = true;
    for(auto child : g[v])
    {
         if(!visit[child])
              dfs1(child);
    }

}

void dfs2(int v, int p)
{
    par[v] = p;
    for(auto child : g[v])
    {
          if(child == par[v])
                continue;
          dfs(child,v);
    }

}
-------------DFS--------------
*/
/*
----------------DFS for calculating depth of each element as well as number of children---------------
#define maxn 200005
#define pb push_back
vector<int>adj[maxn];
int depth[maxn] , size[maxn] , det[maxn];
int dfs(int u , int f)
{
    depth[u] = depth[f] + 1;
    size[u] = 1;
    for(auto i : adj[u])
    {
        size[u] += dfs(i , u);
    }
    det[u] = size[u] - depth[u];
    return size[u];
}
dfs(1 , 0);
---------------------DFS---------------------------
*/
#define pb push_back
//#define int long long
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

/*int dfs(string s , char c)
{
    int n = s.length();
    if(n == 1)
    {
        if(c == s[0]) return 0;
        else return 1;

    }
    int lc = 0;

    for(int i=0;i<n/2;i++)
    {
        if(s[i] != c){lc += 1;}
    }
int rc = 0;
    for(int i=n/2;i<n;i++)
    {
        if(s[i] != c){rc += 1;}
    }
    return min(dfs(s.substr(0 , n/2) , c + 1) + rc , dfs(s.substr(n/2 , n) , c + 1) + lc);
}
*/
//cout<<sum==1?"Carrots":sum==2?"Kiwis":"Grapes"
//printf("%s\n",sum==1?"Carrots":sum==2?"Kiwis":"Grapes");
#define float double
float distance(int x1, int y1, int x2, int y2)
{
    // Calculating distance
    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}
const int mod = 1e9 + 7;
int factorial(int n)
{
    // single line to find factorial
    return (n == 1 || n == 0) ? 1 : (n+mod)%mod * factorial(n - 1);
}
bool comp(pair<int , float>a , pair<int , float>b)
{
    if(a.se == b.se)return a.fi < b.fi;
    return a.se > b.se;
}
const int X[]={1,0,-1,0,1,1,-1,-1};
const int Y[]={0,1,0,-1,1,-1,1,-1};
/*bool dista(int x ,int y)
{
    for (int i = 0; i<n; i++)
    {
        int l = (x-data[i].x)*(x-data[i].x) + (y-data[i].y)*(y-data[i].y);
        if ( l <= data[i].r * data[i].r )
        {
            return false;
        }
    }
    return true;
}
*/
//const int mxn=1e6+9;
//int divv[mxn];
//for(i=1;i<mxn;i++) for(j=i;j<mxn;j+=i) divv[j]++;
const int maxn = 200005;
#define int long long
int n , l , r , x;
int gg = 0;
int nas = 0;
int arr[20];
void dfs(int u , int i)
{
    for(int j = i+1;j<n;j++)
    {
        if(gg - arr[j] >= x && (u + arr[j]) >= l && (u + arr[j]) <= r)
                {
                    nas += 1;
                    dfs(u + arr[j] , j);
                }
    }
}
signed main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    //cin>>t;
    while(t--){

       //----------------------------------------------/    /

        cin>>n>>l>>r>>x;
        //int nas =0;

        int pre[n+1] = {0};
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            //pre[i+1] = pre[i] + arr[i];
        }
        sort(arr , arr + n , greater<int>());
        for(int i=0;i<n;i++)
        {
            pre[i+1] = pre[i] + arr[i];
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                gg = 0;
                if(arr[i] - arr[j] >= x && (arr[i] + arr[j]) >= l && (arr[i] + arr[j]) <= r)
                {   gg = arr[i];
                    nas += 1;
                    dfs(arr[i] + arr[j] , j);
                }
            }
        }
        cout<<nas;

        //---------------------------------------------//

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long          	ll;
typedef long long unsigned 	llu;
typedef double             	dl;
typedef pair<int,int>      	pii;
typedef pair<ll,ll>     	pll;
typedef vector<int>        	vi;
typedef vector<ll>        	vl;
typedef map<int,int> 		mii;
typedef map<ll,ll>         	mll;
typedef map<string,int>    	msi;
typedef map<char,int>      	mci;

#define PI          acos(-1.0)
#define S           second
#define F           first
#define PB          push_back
#define MP          make_pair
#define P           push
#define zero(a)     memset(a,0,sizeof a)
#define minus(a)    memset(a,-1,sizeof a)
#define setinf(a)   memset(a,126,sizeof a)
#define all(v)      (v.begin(),v.end())
#define vsort(v)    sort(v.begin(),v.end())
#define nl          puts("")
#define tcase(cs)   printf("Case %d:",++cs)
#define endl        '\n'
#define READ(in)    freopen("in.in","r",stdin)
#define WRITE(out)  freopen("out.out","w",stdout)
#define I_O         ios_base::sync_with_stdio(0); cin.tie(0);
#define gcd(a,b)    __gcd(a,b)
#define sci(a)      scanf("%d",&a)
#define scl(a)      scanf("%lld",&a)
#define scd(a)      scanf("%lf",&a)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T BMOD(T p,T e,T m){T ret=1;while(e){if(e&1) ret=(ret*p)%m;p=(p*p)%m;e>>=1;}return (T)ret;}
template <class T> inline T MODINV(T a,T m){return BMOD(a,m-2,m);}

int main()
{
	I_O;
	ll n,l,r,x,a[1001],cnt=0;
	cin>>n>>l>>r>>x;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(a[j]-a[i]<x) continue;
				if(a[i]+a[j]>=l&&a[i]+a[j]<=r) cnt++;
				int sm=a[i]+a[j];
				for(int k=j;k<n-1;k++){
					sm+=a[k+1];
					if(a[k+1]-a[k]>=x&&sm>=l&&sm<=r){
						cnt++;
					}
				}
			}
		}
	cout<<cnt<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int  n,l,r,x,k=1,sum,t,tp,p,u,minn,maxx;
vector<int>v;
int a[1000];
main()
{
    cin>>n>>l>>r>>x;
    for(int i=1;i<=n;i++)
        cin>>a[i];
        sort(a+1,a+n);
    for(int i=0;i<pow(2,n);i++)
    {
        sum=0;
        k=1;
        p=0,t=0,u=0;
        for(int j=1;j<=i;j*=2)
        {
            if(i&j)
            {
                maxx=a[k];
                if(u==0)
                {
                    u=1;
                    minn=a[k];
                }
                sum+=a[k];
                if(t==1)
                {
                    if(a[k]!=tp)
                        p=1;
                }
               if(t==0)
               {
                   t=1;
                   tp=a[k];
               }
            }
            k++;

        }
        if(sum>=l&&sum<=r&&p==1&&maxx-minn>=x)
        v.push_back(sum);
    }
    cout<<v.size();
}