You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.

The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

Print the number of ways to choose a suitable problemset for the contest.

NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

#include<stdio.h>

int a[20];

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

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

		int i;
		int ans=0;
		for( i=0 ; i<n ; i++ )
				scanf("%d",&a[i]);

		for( i=2 ; i < (1<<n) ; i++ )
		{
				int min=1000006;
				int max=0;
				int sum=0;
				int j=i;
				int count=1;
				while( j!=0 )
				{
						if( j%2==1 )
						{
								sum+=a[n-count];
								if( min > a[n-count])
										min=a[n-count];
								if( max < a[n-count])
										max=a[n-count];

						}
						count++;
						j=j/2;
				}
				if( max-min >= x && sum<=r && sum>=l )
						ans++;
		}
		printf("%d\n",ans);
		return 0;
}

#include<stdio.h>
void print(int *a,int n){
	int i;
	for(i=0;i<n;i++)
		printf("%d ",a[i]);
	printf("\n");
}
int a[20];
int x,l,r;
int check(int i)
{
	int max=0,min=10000006,sum=0,j=0;
	while(i>0)
	{
		if((i&1)==1){
			sum+=a[j];
			if(max<a[j])
				max=a[j];
			if(min>a[j])
				min=a[j];
		}
		i=(i>>1);
		j++;
	}
	if(max-min<x)
		return 0;
	if(sum<l||sum>r)
		return 0;
return 1;
}
int main()
{
	int n,ans=0,i;
	scanf("%d %d %d %d",&n,&l,&r,&x);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=3;i<(1<<n);i++)
	{
		if(check(i))
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

#include<stdio.h>
int n,l,r,x,a[20],ans=0,state=0;
void func(int k,int d,int e,int h,int t)
{
	if(k==n)
	{
		if(h-e>=x && d>=l && d<=r && t>1)
		{
			ans++;
			//	printf("%d %d %d %d\n",t,d,e,h);
		}
		return;
	}
	if(state==0)
	{
		state=1;
		func(k+1,d+a[k],a[k],a[k],t+1);
		state=0;
		func(k+1,d,e,h,t);
	}
	else
	{
		if(a[k]<e)
		{
			func(k+1,d+a[k],a[k],h,t+1);
			func(k+1,d,e,h,t);
		}
		else if(a[k]>h)
		{
			func(k+1,d+a[k],e,a[k],t+1);
			func(k+1,d,e,h,t);
		}
		else
		{
			func(k+1,d+a[k],e,h,t+1);
			func(k+1,d,e,h,t);
		}
	}
	return;
}
int main()
{
	int i;
	scanf("%d %d %d %d",&n,&l,&r,&x);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	func(0,0,0,0,0);
	printf("%d\n",ans);
	return 0;
}

#include<stdio.h>
#include<math.h>
long ans,l,r,x;

void powerset(long a[],int n)
{
	long powersize=pow(2,n),c,bit,sum;
	ans=0;
	long int counter,j,min,max;
	for(counter=1;counter<powersize;counter++)
	{
		c=counter;
		sum=0,min=100000009,max=0;
		for(j=0;j<n;j++)
		{
			bit=c%2;
			c=c/2;
			if(bit==1)
			{
				//printf("%ld ",a[j]);
				sum+=a[j];
				if(a[j]>max)
				max=a[j];
				if(a[j]<min)
				min=a[j];
			}
		}
		if(sum>=l&&sum<=r&&max-min>=x)
		ans++;
		//printf("\n");
	}
}

int main()
{
	 int n,i;
	 long a[15];
	 scanf("%d%ld%ld%ld",&n,&l,&r,&x);
	 for(i=0;i<n;i++)
	 scanf("%ld",&a[i]);
	 powerset(a,n);
	 printf("%ld",ans);
	 return 0;
}

#include<stdio.h>
typedef unsigned u;
u R,N[22],n,l,r,d;
void F(u min,u max,u sum,u sel,u deep,u new)
{
	if(new&&sel>1&&max-min>=d&&sum>=l&&sum<=r)++R;
	if(deep==n||sum>r)return;
	F(min,max,sum,sel,deep+1,0);
	F(min>N[deep]?N[deep]:min,max<N[deep]?
	N[deep]:max,sum+N[deep],sel+1,deep+1,1);
	return;
}
int main()
{
	u i=-1;
	for(scanf("%u%u%u%u",&n,&l,&r,&d);++i<n;scanf("%u",N+i));
	F(-1,0,0,0,0,0);printf("%u\n",R);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int count=0;
int cmpfunc (const void * a, const void * b){
   return ( *(int*)a - *(int*)b );
}
void combinationUtil(int arr[],int n,int r,int index,int data[],int i,int m,int l,int x);
void printCombination(int arr[],int n,int r,int m,int l,int x){
    int data[r];
    combinationUtil(arr,n,r,0,data,0,m,l,x);
}
void combinationUtil(int arr[],int n,int r,int index,int data[],int i,int m,int l,int x){
    int j;
    if(index==r){
        int max=data[0],min=data[0],sum=0;
        for(j=0;j<r;j++){
            sum+=data[j];
            if(data[j]>max) max=data[j];
            else if(data[j]<min) min=data[j];
        }
        if(sum<=m && sum>=l && (max-min)>=x) count++;
        return;
    }
    if(i>=n) return;
    data[index]=arr[i];
    combinationUtil(arr,n,r,index+1,data,i+1,m,l,x);
    combinationUtil(arr,n,r,index,data,i+1,m,l,x);
}
int main(){
    int n,l,r,x;
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int c[n],i;
    for(i=0;i<n;i++) scanf("%d",&c[i]);
    qsort(c, n, sizeof(int), cmpfunc);
    for(i=2;i<=n;i++) printCombination(c,n,i,r,l,x);
    printf("%d",count);
    return 0;
}

#include <stdio.h>
#include <math.h>
int comp (const void * elem1, const void * elem2)
{
    int f = *((int*)elem1);
    int s = *((int*)elem2);
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}
int main(void)
{
int n,l,r,x,i,j,c=0,f=0;
scanf("%d %d %d %d",&n,&l,&r,&x);
int a[15];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
qsort (a,n, sizeof(int), comp);
int s=pow(2,n)-1;
int s1=0,d=0,max=0,min=0,count=0;
for(i=3;i<=s;i++)
{
j=i;c=0;f=0;s1=0;
			while(j>0)
			{
				d=j%2;
				if(d==1)
				{
				f++;
				s1=s1+a[c];
				if(f==1)
				min=a[c];
				if(j/2==0)
				max=a[c];
				}
				c++;
				j=j/2;
			}
			if(((max-min)>=x)&&(s1>=l)&&(s1<=r))
			count++;
}
printf("%d",count);
	return 0;
}

#include <stdio.h>
#include <math.h>
int n,l,r,x;
void PowerSet(int *set, int set_size)
{
    unsigned int pow_set_size = pow(2, set_size);
    int counter, j,ar[set_size],cnt=0,ind,sum,i,max,min;
    for(counter = 0; counter < pow_set_size; counter++)
    { ind=0;
      for(j = 0; j < set_size; j++)
       {
          if(counter & (1<<j))
            ar[ind++]=set[j];
       }
       sum=0;
       min=1000000002;
       max=-1;
       for(i=0;i<ind;i++)
        {

              if(min>ar[i])
              min=ar[i];
              if(max<ar[i])
              max=ar[i];
                         sum+=ar[i];
        }
        if(max-min>=x && sum>=l && sum<=r)
        cnt++;

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

int main()
{

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

//scanf("%d",&i);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int is_good(int *flags, int *c, int n, int l, int r, int x)
{
    int i=0;
    int count_tasks=0;
    while(!flags[i])
    {
        i++;
    }
    int min=c[i], max=min;
    int summary=0;
    for( i=0; i<n; i++)
    {
        if (flags[i])
        {
            count_tasks++;
            if (c[i]>max) max=c[i];
            if (c[i]<min) min=c[i];
            summary+=c[i];
        }
    }
    if (  (count_tasks>1)&&(max-min>=x)&&(summary>=l)&&(summary<=r)  )
        return 1;
    else
        return 0;
}

int exp_x(int x, int pow)
{
    int k=1;
    while(pow)
    {
        k*=x;
        pow--;
    }
        return k;
}

void ten_to2arr(int n, int *arr)
{
    int i=0;
    while (n>0)
    {
        arr[i]=n%2;
        n/=2;
        i++;
    }
}

int answer(FILE *f)
{
    int i,j;
    int n, l, r, x;
    fscanf(f,"%d %d %d %d",&n, &l, &r, &x);
    if (n<2) return 0;
    int *c=(int *)calloc(n, sizeof(int));

    for ( i=0; i<n; i++)
        fscanf(f,"%d",&c[i]);

    // get input
    int max=exp_x(2,n);
    int *flags=(int *)calloc(n, sizeof(int));
    int COUNT=0;
    for (i=0; i<max; i++)
    {
        ten_to2arr(i, flags);
        if (is_good(flags, c, n, l, r, x))
            COUNT++;
    }
    free(flags);
    free(c);
        return COUNT;
}

int main(int argc, char* argv[])
{
    int count;
    FILE *f=fopen("test2.txt","r");
    //count=answer(f);
    count=answer(stdin);
    FILE *o=fopen("Output.txt","w");
    fprintf(o,"%d",count);
    printf("%d",count);
    fclose(o);
    fclose(f);
        return 0;
}

#include <stdio.h>

void fn(int a[],int index,int n,int min,int max,int sum,int sum_min,int sum_max,int min_diff,int *ans)
{
	if(index<n)
	{
		fn(a,index+1,n,min,max,sum,sum_min,sum_max,min_diff,ans);

		sum = sum + a[index];
		max = a[index];
		if(sum>=sum_min && sum<=sum_max && (max-min)>=min_diff)
			*ans = *ans + 1;
		fn(a,index+1,n,min,max,sum,sum_min,sum_max,min_diff,ans);
	}
}

int main()
{
	int n,l,r,x;
	scanf("%d%d%d%d",&n,&l,&r,&x);
	int a[n];
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	int j;
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(a[i]>a[j])
			{
				int temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}

	int ans = 0;
	for(i=0;i<n;i++)
	{
		fn(a,i+1,n,a[i],0,a[i],l,r,x,&ans);
	}
	printf("%d",ans);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	int i=0,mark=1,counter=0,bla=2,j=0,tmp=0,min,max,score,ones;
	int n;
	long l,r,x;
	char *string,*ptr;
	char del = ' ';
	int *ptr1,*ptr2;

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

	while((getchar()) != '\n');

	int problems[n];

	string = malloc(n*sizeof(char)*1000000+2);
	fgets(string,n*sizeof(char)*1000000+2,stdin);

	ptr = strtok(string,&del);
        while(ptr != NULL){
                problems[i++]=atoi(ptr);
                ptr = strtok(NULL,&del);
        }

	while(mark){
		mark = 0;
		for(ptr1 = &problems[0],ptr2 = &problems[1];ptr2 < &problems[0]+n;ptr1++,ptr2++){
			if(*ptr1 > *ptr2){
				*ptr1 = *ptr1 + *ptr2;
				*ptr2 = *ptr1 - *ptr2;
				*ptr1 = *ptr1 - *ptr2;
				mark = 1;
			}
		}
	}

	for(i=n-1;i>0;i--){
		bla = bla * 2;
	}

	for(i=0;i<=bla;i++){
		score = 0;
		mark = 0;
		tmp = i;
		ones = 0;
		for(j=0;j<n;j++){
			if(tmp%2){
				ones++;
				if(mark == 0){
					min=problems[j];
					mark = 1;
				}
				score = score + problems[j];
			}
			tmp = tmp / 2;
			if(tmp == 0){
				max=problems[j];
				break;
			}
		}
		if(ones > 1){
			if(score >= l && score <= r && max-min >= x)counter++;
		}
	}

	printf("%d",counter);
	free(string);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<math.h>
#include<string.h>

int cmp ( const void *p, const void *q)
{
	int l = *(const int *)p;
	int r = *(const int *)q;
	return l-r;
}

int po(int n)
{
	int ans=1;
	int base=2;
	while(n>0)
	{
		if(n%2==1)
			ans=ans*base;
		n = n>>1;
		base = base*base;
	}
	return ans;
}

int main()
{
	int n,l,r,x,a[16],p,i,min,max,sum,count,bit[16]={0};
	scanf("%d%d%d%d",&n,&l,&r,&x);
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),cmp);
	p=0;
	i=2;
	sum=0;
	count=0;
	int ran = po(n);
	int num=0;
	int z,k;
	for(i=3;i<=ran;i++)
	{
		z=i;
		p=0;
		max=0;
		num=0;
		sum=0;
		min=9999999;
		while(z>0)
		{
			bit[p++]=z%2;
			z=z/2;
		}
		for(k=0;k<p && k <=n;k++)
		{
//			printf("%d",bit[k]);
			if(bit[k]==1)
			{
				sum+=a[k];
				num++;
				if(a[k]>max)
					max=a[k];
				if(a[k]<min)
					min=a[k];

			}
		}
//		printf("\nsum: %d max: %d min : %d\n",sum,max,min);

		if(num>=2 && sum >= l && sum <= r && max - min>=x)
			count++;

	}

printf("%d\n",count);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int comp(const void *elem1,const void *elem2)
{
    int f=*((int*)elem1);
    int s=*((int*)elem2);
    if(f>s)return 1;
    if(f<s)return -1;
    return 0;
}

int main(void)
{  int i,n,l,r,x,c[15];
   scanf("%d %d %d %d",&n,&l,&r,&x);
    for(i=0;i<n;i++)
    scanf("%d ",&c[i]);
    qsort(c,n,sizeof(int),comp);
    int s=pow(2,n),a=0,j,max=0,min=0,z=0,c1[15],sum=0;
    for(i=0;i<15;i++)
    c1[i]=0;
    for(i=2;i<s;i++)
    {   a=i,sum=0,max=0,min=0;
        for(j=n-1;j>=0;j--)
        {
            c1[j]=a%2;
            a=a/2;
            if((max==0)&&(c1[j]==1))
            max=j;
            if(c1[j]==1)
            min=j;
        }
        if(c[max]-c[min]>=x)
        {
            for(j=0;j<n;j++)
             if(c1[j]==1)
             sum=sum+c[j];
             if((sum<=r)&&(sum>=l))
              z++;
    }
    }

    printf("%d",z);

    return 0;
}

/*
 *    Assignment - NCTU DCS CP
 *    ========================
 *    Student ID :  CS 0316218
 *    GCC Option : -ansi -Wall -Wextra -pedantic
 *    GCC Linker : -lc
 */

#include<stdio.h>
#include<stdlib.h>

int n, l, r, x;
int count = 0;
int problem_str[16], dedicated_str[16];

void permutation(int, int, int);
int  summation(int);
int  difference(int);

int main(void)
{
    scanf("%d %d %d %d", &n, &l, &r, &x);

    {
        int i;

        for (i = 0; i < n; i++)
            scanf("%d", &problem_str[i]);
    }

    {
        int i;

        for (i = 2; i <= n; i++)
            permutation(-1, 1, i);
    }

    printf("%d", count);

    return 0;
}

void permutation(int pos, int depth, int max_depth)
{
    if (pos >= n)
        return;

    if (depth == max_depth + 1)
    {
        int sum = summation(max_depth);
        int dif = difference(max_depth);

        if (l <= sum && sum <= r && dif >= x)
            count++;
    }
    else if (depth <= max_depth)
    {
        int i;

        for (i = pos + 1; i < n; i++)
        {
            dedicated_str[depth - 1] = problem_str[i];
            permutation(i, depth + 1, max_depth);
        }
    }
}

int summation(int length)
{
    int i, sum = 0;

    for (i = 0; i < length; i++)
        sum += dedicated_str[i];

    return sum;
}

int difference(int length)
{
    int i, min = dedicated_str[0], max = dedicated_str[0];

    for (i = 0; i < length; i++)
    {
        if (min > dedicated_str[i])
            min = dedicated_str[i];
        if (max < dedicated_str[i])
            max = dedicated_str[i];
    }

    return (max - min);
}

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

void check(int a[],int b[],int n,int l,int r,int x,int* count)
{
    int i,c[20],m=0,count2=0;
    for(i=0;i<n;i++)
        if(b[i]==1)
        {
            c[m++]=a[i];
            count2+=a[i];
        }
    if(count2>=l && count2<=r && c[m-1]-c[0]>=x)
        (*count)++;
    return;
}

void superset(int a[],int b[],int n,int idx,int l,int r,int x,int* count)
{
    if(idx==n)
    {
        check(a,b,n,l,r,x,count);
        return;
    }
    b[idx]=1;
    superset(a,b,n,idx+1,l,r,x,count);
    b[idx]=0;
    superset(a,b,n,idx+1,l,r,x,count);
    return;
}

int main()
{
    int n,l,r,x,a[20],b[20]={0},i,j,temp,count=0;
    scanf("%d%d%d%d",&n,&l,&r,&x);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
            if(a[i]>a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
    superset(a,b,n,0,l,r,x,&count);
    printf("%d\n",count);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#define fr(i,n) for(i=0;i<n;i++)
#define frw(i,a,b) for(i=a;i<b;i++)
int power(int a,int b)
{
if(b==0)
return 1;
int k=power(a,b/2);
k=k*k;
if(b&1) k*=a;
return k;
}
int arr[100]={0};
main()
{
int n,l,r,x,i,j,k,min,max;long long int sum;
scanf("%d %d %d %d",&n,&l,&r,&x);
fr(i,n)
scanf("%d",&arr[i]);
int g=power(2,n);
//printf("%d",g);
int count=0;
    fr(i,g)
    {
    min=-1;
    max=-1;
    sum=0;

        k=1;
        fr(j,n)
        {
        if(i & k)
            {
            sum+=arr[j];
            if(min==-1 || arr[min]>arr[j])
                min=j;
            if(max==-1 || arr[max]<=arr[j])
                max=j;
            }
        k<<=1;
        }
        if(min!=-1 && max!=-1 && min!=max && arr[max]-arr[min]>=x && sum>=l && sum<=r){count++;}
    }
printf("%d\n",count);
return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
int n,l,r,x,i,j,maxx,minn;
int a[16];
long int sum=0,cnt=0;
scanf("%d%d%d%d",&n,&l,&r,&x);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
}
for(i=0;i<pow(2,n);i++)
    {
        maxx=0,minn=1000001;
        sum=0;

        for(j=0;j<n;j++)
        {
            if((i&1<<j))
            {
                sum+=a[j];
                if(maxx<a[j]){
                    maxx=a[j];
                }
                if(minn>a[j]){
                    minn=a[j];
                }
            }

        }
        if(sum>=l && sum<=r){
            if((maxx-minn)>=x)
            {
                cnt++;
            }
        }

    }

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

return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 1000010
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

int n, l, r, x, ar[15];

int main(){
    int i, j, k, bitmask, y, z, sum, min, max, lim, counter, res;

    while (scanf("%d %d %d %d", &n, &l, &r, &x) != EOF){
        lim = (1 << n) - 1;
        for (i = 0; i < n; i++) scanf("%d", &ar[i]);

        counter = 0;
        for (bitmask = 1; bitmask <= lim; bitmask++){
            if (__builtin_popcount(bitmask) < 2) continue;

            sum = 0, min = 1 << 20, max = 0;
            for (i = 0; i < n; i++){
                if (bitmask & (1 << i)){
                    sum += ar[i];
                    if (ar[i] < min) min = ar[i];
                    if (ar[i] > max) max = ar[i];
                }
            }

            if ((sum >= l) && (sum <= r) && (max - min) >= x){
                counter++;
            }
        }

        printf("%d\n", counter);
    }
    return 0;
}

/* Problem: 550B - Preparing Olympiad */
/* Solver: Gusztav Szmolik */

#include <stdio.h>

int main ()
    {
    unsigned short n;
    unsigned int l;
    unsigned int r;
    unsigned int x;
    unsigned short i;
    unsigned int c[15];
    unsigned short slx;
    unsigned short an;
    unsigned short m;
    unsigned short oc;
    unsigned int sc;
    unsigned int cmx;
    unsigned int cmn;
    unsigned short j;

    if (scanf("%hu %u %u %u",&n,&l,&r,&x) != 4)
        return -1;
    if (n < 1 || n > 15)
        return -1;
    if (l < 1 || l > 1000000000 || r < 1 || r > 1000000000 || x < 1 || x > 1000000)
        return -1;
    for (i = 0; i < n; i++)
        {
        if (scanf("%u",&c[i]) != 1)
            return -1;
        if (c[i] < 1 || c[i] > 1000000)
            return -1;
        }
    slx = 1;
    for (i = 0; i < n; i++)
        slx *= 2;
    an = 0;
    for (i = 3; i < slx; i++)
        {
        m = 1;
        oc = 0;
        sc = cmx = 0;
        cmn = 1000001;
        for (j = 0; j < n; j++)
            {
            if (i & m)
                {
                oc++;
                sc += c[j];
                if (c[j] < cmn)
                    cmn = c[j];
                if (c[j] > cmx)
                    cmx = c[j];
                }
            m <<= 1;
            }
        if (oc > 1 && sc >= l && sc <= r && cmx-cmn >= x)
            an++;
        }
    printf ("%hu\n",an);
    return 0;
    }

#include<stdio.h>
int comp(const void*a,const void *b);
void dfs(int min,int max,int sum,int k);
int n,l,r,x;
int ans=0;
int pro[100000];
int main(){
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i,j;
    for(i=0;i<n;i++)
        scanf("%d",&pro[i]);
    qsort((void*)pro,i,sizeof(int),comp);
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            dfs(pro[i],pro[j],pro[i]+pro[j],j+1);
        }
    }
    printf("%d\n",ans);
    return 0;
}
int comp(const void*a,const void *b){
    return *(int*)a>*(int*)b?1:-1;
}
void dfs(int min,int max,int sum,int k){
    if(sum>r)
        return;
    int i;
    if(sum>=l&&sum<=r&&max-min>=x)
        ans++;
    for(i=k;i<n;i++)
        dfs(min,pro[i],sum+pro[i],i+1);
}

#include <stdio.h>
#include <stdlib.h>

int n, l, r, x, c[16];
int ans;

int compare(const void* a, const void* b) {
	return (*(int*)a - *(int*)b);
}
void solve(int idx, int sum, int min, int max, int cnt);

int main()
{
	int i;

	scanf("%d%d%d%d", &n, &l, &r, &x);
	for(i = 0; i < n; i++) {
		scanf("%d", &c[i]);
	}
	qsort(c, n, sizeof(int), compare);
	ans = 0;
	solve(0, 0, 0, 0, 0);
	printf("%d\n", ans);

	return 0;
}

void solve(int idx, int sum, int min, int max, int cnt) {
	if(idx == n) {
		if(cnt >= 2 && sum >= l && sum <= r && (max - min) >= x)	ans++;
		return;
	}
	if(!min)	solve(idx + 1, sum + c[idx], c[idx], c[idx], cnt + 1);
	else	solve(idx + 1, sum + c[idx], min, c[idx], cnt + 1);
	solve(idx + 1, sum, min, max, cnt);
}

#include<stdio.h>
#include<stdlib.h>
long long int n,l,r,x,a[20],ans=0,i;
long long int cmpfunc (const void * a, const void * b)
{
   return ( *(long long int*)a - *(long long int*)b );
}
void f(long long int min, long long int max, long long int s, long long int n1, long long int i)
{
    if(i>=n)
    {
                   // printf("%I64d %I64d %I64d %I64d %I64d\n",min,max,s,n1,i);

        if(n1>=2&&s>=l&&s<=r&&(max-min)>=x)
            {ans++;

            }
    }
    else if(!n1)
    {
        f(a[i],a[i],s+a[i],n1+1,i+1);
        f(min,max,s,n1,i+1);
    }
    else
    {
        f(min,a[i],s+a[i],n1+1,i+1);
        f(min,max,s,n1,i+1);
    }

}
int main()
{
scanf("%I64d %I64d %I64d %I64d",&n,&l,&r,&x);
for(i=0;i<n;i++)
    scanf("%I64d",&a[i]);
qsort(a,n,sizeof(long long),cmpfunc);
f(0,0,0,0,0);
printf("%I64d",ans);
return 0;
}

#include<stdio.h>
#include<malloc.h>

int ways = 0;
int *a, *b;
int n, l, r, x;

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

cal(int i)
{
	if(i==n)
	{
		int j, k, no, sum;

		sum = 0;
		no = 0;
		for(j=0; j<n; j++)
		{
			if(b[j] == 1)
			{
				sum += a[j];
				no++;
			}
		}

		if(sum>=l && sum<=r && no>=2)
		{
			for(j=0; b[j]==0; j++);
			for(k=n-1; b[k]==0; k--);

			if(a[k]-a[j] >= x)
				ways++;
		}
	}

	else
	{
		b[i] = 0;
		cal(i+1);
		b[i] = 1;
		cal(i+1);
	}
}

int main()
{
	int i;

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

	a = (int *)malloc(sizeof(int)*n);
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);

	qsort(a, n, sizeof(int), cmp);

	b = (int *)malloc(sizeof(int)*n);
	for(i=0; i<n; i++)
		b[i] = 0;

	b[0] = 0;
	cal(1);
	b[0] = 1;
	cal(1);

	printf("%d", ways);

	free(a);
	free(b);

	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	long long int n,l,r,x,i,j,k,row,count;
	scanf("%I64d %I64d %I64d %I64d",&n,&l,&r,&x);
	long long int arr[n];
	for(i=0;i<n;i++)
	{
		scanf("%I64d",&arr[i]);
	}
	j=(long long int)pow(2,n);
	k=j/2;
	int bit[j][n],flag=0;
	for(i=0;i<n;i++)
	{
		count=0;
		row=0;
		while(row<j)
		{
			if(flag==0)
			{
				bit[row][i]=0;
				count++;
				if(count==k)
				{
					count=0;
					flag=1;
				}
			}
			else if(flag==1)
			{
				bit[row][i]=1;
				count++;
				if(count==k)
				{
					count=0;
					flag=0;
				}
			}
			row++;
		}
		k/=2;
	}
	count=0;
	long long int sum,c1,min,max;

	for(row=0;row<j;row++)
	{
		sum=0;
		c1=0;
		max=0;
		flag=0;
		for(i=0;i<n;i++)
		{
			if(bit[row][i]==1)
			{
				sum+=arr[i];
				if(flag==0)
				{
					min=arr[i];
					flag=1;
				}
				if(arr[i]<min)
				{
					min=arr[i];
				}
				if(arr[i]>max)
				{
					max=arr[i];
				}
				if(sum>r)
				{
					break;
				}
				c1++;
			}
		}
		if(sum>=l && sum<=r && c1>=2 && ((max-min)>=x))
		{
			count++;
		}
	}
	printf("%I64d",count);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>

int	darr[32];

static int
do_ways(int N, long lo, long hi, int dif)
{
	int 	ans = 0;
	int	i,j;

	for (i = 0; i < (1 << N); i++) {
		int	h = 0;
		int	l = INT_MAX;
		long	sum = 0L;

		for (j = 0; j < N; j++) {
			if (i & (1 << j)) {
				sum = sum + darr[j];

				if (darr[j] > h) {
					h = darr[j];
				}

				if (darr[j] < l ) {
					l = darr[j];
				}
			}
		}
		if (sum >= lo && sum <= hi) {
			if (h-l >= dif) {
				++ans;
			}
		}
	}
	return ans;
}

int main ()
{
	int i, n, low, high, diff;

	scanf ("%d%d%d%d", &n, &low, &high, &diff);
	for (i = 0; i < n; i++) {
		scanf("%d", &darr[i]);
	}

	printf("%d\n", do_ways(n, low, high, diff));
	return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int cmpfunc(const void* a,const void* b)
{
	return *(int*)a-*(int*)b;
}
int n,l,r,x,arr[100],count=0;
void func(int i)
{
	int a[100],ans=0,j,f=0;
	for(j=0;j<n;j++)
	{
	   a[j]=i%2;
	   i=i/2;
	}
	int first=0,last=n-1;
	for(j=0;j<n;j++)
	{
//		printf("%d ",a[j]);
		if(a[j]==1)
		{
		f++;
		ans=ans+arr[j];
		last=j;
		}
	}
//	printf("\n");
//	printf("ans is %d\n",ans);
	if(f>1)
	{
	for(i=n-1;i>=0;i--)
	{
		if(a[i]==1)
		first=i;
	}
	if(ans>=l && ans<=r && arr[last]-arr[first]>=x)
	count++;
	}

}
int main()
{
	int i,j;
	scanf("%d %d %d %d",&n,&l,&r,&x);
	for(i=0;i<n;i++)
	{
	scanf("%d",&arr[i]);
	}
	qsort(arr,n,sizeof(int),cmpfunc);
	for(i=0;i<=pow(2,n)-1;i++)
	{
		func(i);
	}
	printf("%d\n",count);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
long long int max(long long int a, long long int b)
{
    if(a>b) return a;
    else return b;
}
long long int min(long long int a, long long int b)
{
    if(a<b) return a;
    else return b;
}

int main()
{
    long long int n, l, r, x, i, j, mx, mn,ans=0, sum=0;
    scanf("%lld %lld %lld %lld", &n, &l, &r, &x);
    long long int aray[n];
    for(i=0;i<n;i++){
        scanf("%lld", &aray[i]);
    }
    for(i=1;i<(1<<n);i++){
        sum=0;
        mx = 0;
        mn = 1000006;
        for(j=0;j<n;j++){
            if(i&(1<<j)){
                sum+=aray[j];
                mx=max(mx,aray[j]);
                mn=min(mn,aray[j]);
            }
           // printf("j:%lld i:%lld sum:%lld\n", j,i, sum);
        }
        //printf("%lld %lld\n", mx, mn);
        if(mx-mn>=x && sum>=l && sum<=r){
            ans++;
        }
    }
    printf("%lld ", ans);

    return 0;
}

#include<stdio.h>
#define MAXN 20
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b

int n,l,r,x,num;
int c[MAXN],d[MAXN];
char vis[1<<20];

void dfs(int state,int max,int min,int len,int sum)
{
    int i,tmax,tmin,tsum;

    vis[state]=1;
    if(len>1&&sum>=l&&sum<=r&&max-min>=x)num++;
    if(len==n)return ;
    tmax=max;
    tmin=min;
    tsum=sum;
    for(i=0;i<n;i++)
    {
        if((state&d[i])==0)
        {
            if(len==0)
            {
                tmax=tmin=c[i];
                tsum=c[i];
            }
            else
            {
                tmax=Max(max,c[i]);
                tmin=Min(min,c[i]);
                tsum=sum+c[i];
            }
            if(tsum<=r&&!vis[state|d[i]])dfs(state+d[i],tmax,tmin,len+1,tsum);
        }
    }
}

int main()
{
    int i;

    scanf("%d%d%d%d",&n,&l,&r,&x);
    for(i=0;i<n;i++)scanf("%d",&c[i]);
    d[0]=1;
    for(i=1;i<n;i++)d[i]=d[i-1]*2;
    num=0;
    dfs(0,0,0,0,0);
    printf("%d\n",num);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef long long ll;
int n,l,r,x,a[15],ans;
int main(void) {
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i,j,k;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int sub=(1<<n)-1;
    int tmp,min,max;
    //printf("%d",sub);
    for(i=1;i<=sub;i++)
    {   tmp=0;min=1000000000;max=0;
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
            {   //printf("%d includes %d\n",i,j);
                tmp+=a[j];
                if(a[j]<min)min=a[j];
                if(a[j]>max)max=a[j];
            }
        }
        ///puts("end");
        if(tmp<=r && tmp>=l && (max-min)>=x)
        {
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

#include <stdio.h>

int n,l,r,c[15],x;

int check(int Mask)
{
	int NoOfProblem=0,Max=0,Min=1000001,Sum=0,j=Mask,i;
	for (i=0;i<n;i++)
	{
		if (j%2==1)
		{
			NoOfProblem++;
			Max=Max>c[i]?Max:c[i];
			Min=Min<c[i]?Min:c[i];
			Sum+=c[i];
		}
		j/=2;
	}
	if ((NoOfProblem>=2)&&(Sum>=l)&&(Sum<=r)&&(Max-Min>=x))
		return 1;
	else
		return 0;
}

int main()
{
	int i,count=0;
	scanf(" %d%d%d%d",&n,&l,&r,&x);
	for (i=0;i<n;i++)
		scanf(" %d",&c[i]);
	for (i=0;i<1<<n;i++)
		count+=check(i);
	printf("%d\n",count);
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    long l,r,x,pows,counter,max,min,ans,i,s,ct,j;
    long arr[20];
    scanf("%d %ld %ld %ld",&n,&l,&r,&x);
    for(i=0; i<n; i++)
    {
        scanf("%ld",&arr[i]);
    }
    pows=pow(2,n);
    ans=0;
    for(counter = 0; counter < pows; counter++)
    {
        s=0; ct=0; min=1000000001; max=-1;
        for(j = 0; j < n; j++)
        {
          if(counter & (1<<j))
          {
            if(arr[j]>max)
            max=arr[j];
            if(arr[j]<min)
            min=arr[j];
            ct++;
            s=s+arr[j];
          }
        }
        if(ct>1)
        {
            if(s>=l && s<=r)
            {
                if((max-min)>=x)
                {
                    ans++;
                }
            }
        }

    }
    printf("%ld",ans);
    return 0;
}

#include<stdio.h>
#include<limits.h>
int main()
{
    long long int n,l,r,x,i,a[20],sum,high,low,choosen,ans,t,j;
    scanf("%lld %lld %lld %lld",&n,&l,&r,&x);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    t=1;
    for(i=0;i<n;i++)
    {
        t=t*2;
    }
    ans=0;
    //printf("%lld ",t);
    for(i=0;i<t;i++)
    {
        choosen=0;
        sum=0;
        high=INT_MIN;
        low=INT_MAX;
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                sum=sum+a[j];
                if(a[j]>high)
                high=a[j];
                if(a[j]<low)
                low=a[j];
                choosen++;
            }
        }
        //printf("%lld %lld %lld\n",i,sum,choosen);
        if(choosen>1&&(high-low>=x)&&sum>=l&&sum<=r)
        ans++;
    }
    printf("%lld",ans);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long long int count1=0;

void powerset_bits(long long int a[],long long int n,long long int l,long long int r, long long int x)
{
    long long int size = pow(2,n);

    long long int i,j;

    for (i=0;i<size;i++)
    {
        long long int sum=0;
        long long int min1=1000000002;
        long long int max1=-1;
        for (j=0;j<n;j++)
        {
            if (i& 1<<j)
            {
                if (a[j]<=min1)
                {
                    min1 = a[j];
                }
                if (a[j]>=max1)
                {
                    max1 = a[j];
                }
                sum = sum+a[j];
            }
        }
       if ((sum>=l && sum<=r ) && (max1 - min1 >=x) && max1!=-1)
           count1++;

    }
    //count_bits = i;

}

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

int main()
{
    long long int n,l,r,x,i,j;

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

    long long int c[n];

    for (i=0;i<n;i++)
    {
        scanf("%lld",&c[i]);
    }
    /*
    qsort(c,n,sizeof(long long int),cmpfnc);

    for (i=0;i<n;i++)
    {
        if (c[i]>r)
            break;

    }
    */

    powerset_bits(c,n,l,r,x);
    printf("%lld\n",count1);
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
int n,l,r,x,i,j,maxx,minn;
int a[16];
long int sum=0,cnt=0;
scanf("%d%d%d%d",&n,&l,&r,&x);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
}
for(i=0;i<pow(2,n);i++)
    {
        maxx=0,minn=1000001;
        sum=0;

        for(j=0;j<n;j++)
        {
            if((i&1<<j))
            {
                sum+=a[j];
                if(maxx<a[j]){
                    maxx=a[j];
                }
                if(minn>a[j]){
                    minn=a[j];
                }
                //printf("%d ",a[j]);
            }

        }
        if(sum>=l && sum<=r){
            if((maxx-minn)>=x)
            {
                cnt++;
            }
        }

    }

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

return 0;
}

#include <stdio.h>
#define MAXN 15
#define INF 0x7fffffff

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

    int min, max, sum, ct, ans = 0;
    // Brute force.
    for (i = 0; i < (1 << n); ++i) {
        min = INF, max = sum = ct = 0;
        for (j = 0; j < n; ++j) if ((i >> j) & 1) {
            ++ct;
            sum += c[j];
            if (min > c[j]) min = c[j];
            if (max < c[j]) max = c[j];
        }
        if (ct >= 2 && sum >= l && sum <= r && max - min >= x) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    int n,sd,i,j,k;
    long long int ways,c,l,r,x,s,diff,maxd,mind;
    int a[1005];
    int b[100];
    scanf("%d %lld %lld %lld",&n,&l,&r,&x);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    long long int f=1;
    for(i=1;i<=n;i++)
    {
        f=f*2;
    }
    c=0;
    for(i=0;i<f;i++)
    {
        j=i;
        k=0;
        s=0;
        maxd=0;
        mind=10000000;
        diff=0;
        sd=0;
        while(k<n)
        {
            int r1=j%2;
            s=s+a[k]*r1;
            b[k]=r1;
            if(r1==1)
            {
                if(mind>a[k])
                    mind=a[k];
                if(maxd<a[k])
                    maxd=a[k];
                diff=maxd-mind;
            }
            j=j/2;
            k++;
        }
        for(j=0;j<k;j++)
        {
            if(b[j]==1)
                sd++;
        }
        if(s>=l && s<=r && sd>=2 && diff>=x)
            c++;
    }
    printf("%lld\n",c);
    return 0;
}

#include<stdio.h>
long int c=0, l, ma, mi, rr, s, x;
void printCombination(long int arr[], long int n, long int r);
void combinationUtil(long int arr[], long int data[], long int start, long int end, long int index, long int r);
main()
{
 long int a[100], i, j, n, p, t;
 scanf("%ld %ld %ld %ld", &n, &l, &rr, &x);
 for(i=0;i<n;i++)
 {
  scanf("%ld", &a[i]);
 }
 n--;
 for(i=0;i<n;i++)
  for(j=0;j<n-i;j++)
   if(a[j]>a[j+1])
   {
    t=a[j];
    a[j]=a[j+1];
    a[j+1]=t;
   }
 n++;
 for(p=2;p<=n;p++)
 {
  printCombination(a, n, p);
 }
 printf("%ld", c);
 return 0;
}
void printCombination(long int arr[], long int n, long int r)
{
    long int data[r];
    combinationUtil(arr, data, 0, n-1, 0, r);
}
void combinationUtil(long int arr[], long int data[], long int start, long int end, long int index, long int r)
{
    long int i, j;
    if (index == r)
    {
     ma=s=0;
     mi=1000000;
        for (j=0; j<r; j++)
        {
          if(ma<data[j])
           ma=data[j];
          if(mi>data[j])
           mi=data[j];
          s+=data[j];
        }
       if(s>=l&&s<=rr&&ma-mi>=x)
        c++;
        return;
    }
    for (i=start; i<=end && end-i+1 >= r-index; i++)
    {
        data[index] = arr[i];
        combinationUtil(arr, data, i+1, end, index+1, r);
    }
}

/*
Spirits coming from the mind,
waking up my deepest horrors,
capture my thoughts, make me blind.

Weird, ‘cause I don't want to see
the abyss of my possibilities.

Scared I can't look away.

It has come to my side.
Sister demon - my bride.

I want you, I need you
and I have set you free.
You're always right behind me,
I know the devil's sent you to me.
You want me, you need me,
now that I've set you free.
Look always right behind you,
You know the devil's sent me to you.

What has started as a longing
almost is possession now,
it drives me again and again.
Put a light into your window,
maybe I can find a hold.
I run against myself ‘till I find the end.

Sent by the devil
*/

/* .................... compiled by alankar....................
*/

//......................SHORTCUTS..............................

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//...........................................................

#define pi 3.14159265358979323846  //float type
#define MAX 100000  //for rmq
#define SQRTMAX 317   //for rmq
//#define gc getchar_unlocked

#define FOR(i,a,b) for(i=(a);i<(b);i++)

//only for +ve and single terms
#define s(x) scanf("%d",&x);
#define sl(x) scanf("%lld",&x);
#define p(x) printf("%d\n",x);
#define pl(x) printf("%lld\n",x);
//..........................................................

typedef long long int ll;
const ll MOD=1000000007;

//returns int and +ve numbers

/*inline int inp(){
    int n=0;
    char c;
    c=gc();
    while(c<'0' || c>'9'){
        c=gc();
    }
    while(c>='0' && c<='9'){
        n=(n<<3)+(n<<1)+c-'0';
        c=gc();
    }
    return n;
}
*/
//...................................

//power with mod........long long int
 ll power(ll a,ll b,ll mod){
      if(b==0)
            return 1;
      ll temp=power(a,b/2,mod);
      temp=(temp*temp)%mod;
      if(b&1)
            temp=(temp*a)%mod;
      return temp;
}

 //power without mod........ int
ll pwr(ll a,ll b){
      if(b==0)
            return 1;
      ll temp=pwr(a,b/2);
      temp=(temp*temp);
      if(b&1)
            temp=(temp*a);
      return temp;
}
 // .....long long int
ll gcd(ll a,ll b){
      return b==0?a:gcd(b,a%b);
}
 //......long long int
ll lcm(ll a,ll b){
      return (a/gcd(a,b))*b;
}
 //......long long int with mod
ll modularInverse(ll a,ll m){
      return power(a,m-2,m);
}

 //only for int
 int min(int a,int b) { return a<b? a : b; }
 int max(int a,int b) { return a>b? a : b; }

//normal compare func on integers //for qsort(name,size,sizeof(type),compare)
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int BinarySearch(int *array, int number_of_elements, int key)
{
        int low = 0, high = number_of_elements-1, mid;
        while(low <= high)
        {
                mid = (low + high)/2;
                if(array[mid] < key)
                {
                        low = mid + 1;
                }
                else if(array[mid] == key)
                {
                        return mid;
                }
                else if(array[mid] > key)
                {
                        high = mid-1;
                }

        }
        return -1;
}
//.......................................................

//segment tree
//not template but how to use ST
//for minimum element
/*
long long s[400000];
long long a[1000000];
int create(long long b,long long e,long long n)
{
    if(b==e)
    {
        s[n]=a[b];
    }
    else
        {
            create(b,(b+e)/2,2*n+1);
            create((b+e)/2+1,e,2*n+2);
            s[n]=s[2*n+1]<s[2*n+2]?s[2*n+1]:s[2*n+2];
        }
    return 0;
}

//for finding minimum element b/w l and r
long long messi(long long b,long long e,long long l,long long r,long long n)
{
    long long i,j;
    if(e<l||b>r)
    {
        return 100000001;
    }
    if(b>=l&&e<=r)
    {
        return s[n];
    }
    i=messi(b,(b+e)/2,l,r,2*n+1);
    j=messi((b+e)/2+1,e,l,r,2*n+2);
    return i<j?i:j;
}
*/
//............................................................................
//range minimam query
//for mim and max number
/*

//preprocess create the min array

long min[SQRTMAX], max[SQRTMAX], b[MAX];
int size, n;

void preProcess(int n){
    int i=0, j=0, k=0;
    long minimum, maximum;

    size = sqrt(n);
    //printf("size = %d\n",size);
    while(j<size){
        minimum = maximum = b[i];
        for(k=0 ; k<size ; k++){
            if(minimum>b[i])
                minimum = b[i];
            if(maximum<b[i])
                maximum = b[i];
            i++;
        }
        min[j] = minimum;
        max[j] = maximum;
        j++;
    }
}

long findMin(int l, int r){
    int j, j2;
    long minimum = b[l];

    j = l/size + 1;
    j2 = r/size - 1;

    //printf("j= %d and j2 = %d\n", j,j2);
    while(l<j*size && l<=r){
        if(minimum > b[l]){
            minimum = b[l];

        }
        //printf("Checked for %d\n", l);
        l++;
    }
    while(j<=j2 && l<=r && j<size){
        if(minimum > min[j])
            minimum = min[j];
        l = (j+1)*size;
        //printf("Checked for %d  <-->  %d\n", j*size, l-1);
        j++;
    }
    while(l<=r){
        if(minimum > b[l]){
            minimum = b[l];
        }
        //printf("Checked for %d\n", l);
        l++;
    }
    return minimum;
}

//finding max value
long findMax(int l, int r){
    int j, j2;
    long maximum = b[l];

    j = l/size + 1;
    j2 = r/size - 1;

    //printf("j= %d and j2 = %d\n", j,j2);
    while(l<j*size && l<=r){
        if(maximum < b[l]){
            maximum = b[l];

        }
        //printf("Checked for %d\n", l);
        l++;
    }
    while(j<=j2 && l<=r && j<size){
        if(maximum < max[j])
            maximum = max[j];
        l = (j+1)*size;
        //printf("Checked for %d  <-->  %d\n", j*size, l-1);
        j++;
    }
    while(l<=r){
        if(maximum < b[l]){
            maximum = b[l];
        }
        //printf("Checked for %d\n", l);
        l++;
    }
    return maximum;
}
*/

//...........................................END OF TEMPLATE.................................................................

ll a[20];
int main()
{ ll i,j=20,k=20,t,n,l,r,x,ans=0,xe,tot,sum=0,ju=0,ma,mi;
    sl(n)
    sl(l)
    sl(r)
    sl(x)

    FOR(i,0,n)
    sl(a[i])

    qsort(a,n,sizeof(ll),compare);

    FOR(i,0,n)
    {
        if(a[i]>=l)
        {
            j=i;
            break;
        }
    }

    for(i=n-1;i>=0;i--)
    {
        if(a[i]<=l)
        {
            k=i;
            break;
        }
    }

    if(n<2)
        printf("0\n");

      else
      {

          FOR(i,3,1<<n)
          {
              xe=i;
              tot=0;
              while(xe)
              {
                  xe=(xe&(xe-1));
                  tot++;
              }
             // pl(tot)
              if(tot<2)
                continue;

               sum=0;
                ju=0;
                ma=0,mi=1000000000000;
               FOR(j,0,n)
               {
                   if((i>>j)&1)
                   {

                       {
                           if(a[j]>=ma)
                            ma=a[j];
                           if(a[j]<=mi)
                            mi=a[j];
                           sum=sum+a[j];
                       }

                   }
               }
               if(sum>=l&&sum<=r&&ju==0&&(ma-mi>=x))
                ans++;

          }

          pl(ans)
      }

    return 0;
}

#include<stdio.h>
#include<conio.h>
long long int max(long long int a, long long int b)
{
    if(a>b) return a;
    else return b;
}
long long int min(long long int a, long long int b)
{
    if(a<b) return a;
    else return b;
}

int main()
{
    long long int n, l, r, x, i, j, mx, mn,ans=0, sum=0;
    scanf("%I64d %I64d %I64d %I64d", &n, &l, &r, &x);
    long long int aray[n];
    for(i=0;i<n;i++){
        scanf("%I64d", &aray[i]);
    }
    for(i=1;i<(1<<n);i++){
        sum=0;
        mx = 0;
        mn = 1000006;
for(j=0;j<n;j++){
            if(i&(1<<j)){
                sum+=aray[j];
                mx=max(mx,aray[j]);
                mn=min(mn,aray[j]);
            }
           // printf("j:%lld i:%lld sum:%lld\n", j,i, sum);
        }
        //printf("%I64d %I64d\n", mx, mn);
        if(mx-mn>=x && sum>=l && sum<=r){
            ans++;
        }
    }
    printf("%I64d ", ans);

    return 0;
}

#include<stdio.h>
long long int i,j,c[15]={0},z,a[30],l,r,n,x,ans = 0;
void bit(long long int now){
	long long int p,sum;
	if(now == z) {
		sum = a[i] + a[j];
		for(p=0;p<z;p++)
			if(c[p] == 1)
				sum += a[i+p+1];
		if(sum >= l && sum<=r)
			ans++;
	}
	else {
		c[now] = 0;
		bit(now+1);
		c[now] = 1;
		bit(now+1);
	}
	return ;
}
int main(){
	long long int k,m,p,q;
	scanf("%lld%lld%lld%lld",&n,&l,&r,&x);
	for(p=0;p<n;p++)
		scanf("%lld",&a[p]);
	for(p=n-1;p>0;p--)
		for(q=0;q<p;q++)
			if(a[q] > a[q+1]) {
				k = a[q];
				a[q] = a[q+1];
				a[q+1] = k;
			}
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(a[j]-a[i] >= x && a[j]+a[i]<=r) {
				for(p=0;p<15;p++)
					c[p] = 0;
				z = j-i-1;
				bit(0);
			}
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#define ABS(x) ((x) < 0 ? -1*(x) : (x))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MOD 1000000007
#define INF 2000000000

int diffs[20];

int main()
{
	int l,r,x,i,tot,n,count,t,td,j,k,max,min;
	scanf("%d",&n);
	scanf("%d",&l);
	scanf("%d",&r);
	scanf("%d",&x);

	for(i = 0; i < n; ++i)
		scanf("%d", &diffs[i]);

	tot = (1<<n);
	count = 0;
	for(i = 0; i < tot; ++i)
	{
		j = i;
		t = 0;
		k = 0;
		td = 0;
		max = -1;
		min = 100000000;
		while(j)
		{
			if(j & 1)
			{
				td += diffs[k];
				if(diffs[k] < min)
					min = diffs[k];
				if(diffs[k] > max)
					max = diffs[k];
				++t;
			}
			++k;
			j >>= 1;
		}
		if(t > 1 && td >= l && td <= r && ((max-min) >= x))
			++count;
	}

	printf("%d\n", count);
	return 0;
}

#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#include<limits.h>
//using namespace std;
long long int a[1000500];
long long int count,l,r,x,n;
long long int func(long long int sum,long long int ind,long long int mii,long long int maa);
int main()
{
    scanf("%I64d %I64d %I64d %I64d",&n,&l,&r,&x);;
    long long int j=0,i;
    count=0;
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&a[i]);
    }
    func(0,0,INT_MAX,INT_MIN);
    printf("%I64d\n",count);
    return 0;
}
long long int func(long long int sum,long long int ind,long long int mii,long long int maa)
{
    if(sum>r)
        return 0;
    if(ind==n)
    {
        if(sum>=l&&sum<=r&&(maa-mii)>=x)
            count++;
        return 0;
    }
    long long int mi=a[ind],ma=a[ind];
    func(a[ind]+sum,ind+1,min(mi,mii),max(ma,maa));
    func(sum,ind+1,mii,maa);
    return 0;
}

#include <stdio.h>
#include <math.h>
long long int n,l,r,x;
long long int po(long long int y)
{
	int res;
	if(y==1)
		return 2;
	res=2*po(y-1);
	return res;
}
void printPowerSet(long long int *set,long long int set_size)
{
	long long int ans=0,sum=0,small=1000000000,large=-1;
	/*set_size of power set of a set with set_size
	  n is (2**n -1)*/
	long long int pow_set_size = po(set_size);
	long long int counter, j;

	/*Run from counter 000..0 to 111..1*/
	for(counter = 0; counter < pow_set_size; counter++)
	{
		for(j = 0; j < set_size; j++)
		{
			/* Check if jth bit in the counter is set
			   If set then pront jth element from set */
			if(counter & (1<<j))
			{
				sum+=set[j];
				if(set[j]<small)
					small=set[j];
				if(set[j]>large)
					large=set[j];
			//	printf("%d", set[j]);
			}
		}
	//	printf("\n");
		if(sum>=l&&sum<=r)
		{
			if(large-small>=x)
				ans++;
		}
		small=1000000000,large=-1,sum=0;

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

/*Driver program to test printPowerSet*/
int main()
{
	long long int i,j,set[100];
	scanf("%lld%lld%lld%lld",&n,&l,&r,&x);
	for(i=0;i<n;i++)
		scanf("%lld",&set[i]);
	printPowerSet(set,n);
//	getchar();
	return 0;
}

#include<limits.h>
#include<stdio.h>
int main()
{
	long long int j,n,ans=1,i,l,r,x;
	scanf("%lld %lld %lld %lld",&n,&l,&r,&x);
	long long int add,small,big,count =0,p,s[n],k,arr[n];
	for(i=0;i<n;i++)
	{
		scanf("%lld",&arr[i]);
		ans*=2;
	}
	for(i=0;i<ans;i++)
	{
		p=i;
		add=0;
		small=INT_MAX;
		big=0;
		for(j=0;j<n;j++)
		{
			k=p%2;
			p=p/2;
			s[n-1-j]=k;
			if(k==1)
			{
				add+=arr[n-1-j];
				if(arr[n-1-j]<small)
					small=arr[n-1-j];
				if(arr[n-1-j]>big)
					big=arr[n-1-j];

			}
		}
		int flag=1;
		if((add<=r)&&(add>=l))
			flag=0;
		else
			flag=1;
		if(flag==0)
		{
			if(big-small>=x)
				flag=0;
			else
				flag=1;
		}
		if(flag==0)
			count++;

	}
	printf("%lld\n",count);
	return 0;
}

#include <stdio.h>
void sort(int d[],int n);
void merge(int d[],int x[],int y[],int l,int r);
int main()
{
	int n,l,r,x;
	scanf("%d %d %d %d",&n,&l,&r,&x);
	int i,f,temp,a[n+1],j,num,countway=0,countprb,sum,min,max;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,n);
	for(i=1;i < (1<<n) ;i++)
	{
		countprb=0;
		sum=0;
		max=0;
		min=1000005;
		f=1;
		for(j=0;j<n;j++)
		{
			temp = (( i & ( 1<<j ))?1:0);
			//printf("%d  %d %d \n ",temp,j,i);
			if(temp)
			{
				if(a[j]<min)
					min=a[j];
				if(a[j]>max)
					max=a[j];
				countprb++;
				sum+=a[j];
				if(sum>r)
				{
					f=0;
					break;
				}
			}
		}
		if(!f)
			continue;
		if(sum>=l  && (max-min)>=x && countprb>1)
			{countway++;/*printf("%d fgdfvdfv \n",i);*/}
	}
	printf("%d",countway);
	return 0;
}
void sort(int d[],int n)
{
	if(n==1)
		return;
	int i,j;
	int x[(n+1)/2],y[n-(n+1)/2];
	for(i=0;i<(n+1)/2;i++)
		x[i]=d[i];
	for(i=(n+1)/2,j=0;i<n;i++,j++)
		y[j]=d[i];
	sort(x,(n+1)/2);
	sort(y,j);
	merge(d,x,y,((n+1)/2),j);
}
void merge(int d[],int x[],int y[],int l,int r)
{

	//printf("%d %d \n",l,r);
	int i=0,j=0,k=0;
	for(;i<l && j<r;k++)
	{
		if(x[i]<=y[j])
		{
			d[k]=x[i];
			i++;
		}
		else
		{
			d[k]=y[j];
			j++;
		}
	}
	while(i<l)
	{
		d[k]=x[i];
		i++;
		k++;
	}
	while(j<r)
	{
		d[k]=y[j];
		j++;
		k++;
	}
}

#include <stdio.h>
#include <limits.h>
#include <math.h>
#define INF 999999999999
typedef long long int ll;
ll a[15];
int main(void) {
	// your code goes here
	ll n,l,r,x,sum,i,j,ans=0,count=0;
	scanf("%I64d %I64d %I64d %I64d",&n,&l,&r,&x);
	for(i=0;i<n;i++)
		scanf("%I64d",&a[i]);
	for(i=0;i<(1LL<<n);i++)
	{
		sum=0;
		count=0;
		ll greatest = -INF,smallest = INF;
		//printf("\n");
		for(j=0;j<n;j++)
		{

			if((i&(1LL<<j))!=0)
			{
				count++;
				//printf("%lld-",a[j]);
				sum+=a[j];
				if(a[j]>greatest)greatest = a[j];
				if(a[j]<smallest)smallest = a[j];
			}
		}
		if(sum>=l&&sum<=r&&abs(greatest-smallest)>=x)ans++;
	}
	printf("%I64d\n",ans);
	return 0;
}

#include <stdio.h>
#define lli long long int
lli a[20];
lli n,l,r,x;
int main(void)
{
long long int n,mask=0,sum=0,i,s,ans=0,min,max,j;
scanf("%lld %lld %lld %lld",&n,&l,&r,&x);
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
mask=(1<<n);
for(i=0;i<mask;i++)
{
sum=0;min=1000005,max=-1,s=1;
for(j=0;j<n;j++)
{
if((i&s)!=0)
{
if(a[j]<min)
min=a[j];
if(a[j]>max)
max=a[j];
sum+=a[j];
//printf("i=%lld s=%lld\n i&s=%lld j=%lld max=%lld min=%lld\n",i,s,i&s,j,max,min);
}
s=(s<<1);
}
if((max-min)>=x && sum>=l && sum<=r){
ans++;
//printf("i=%lld %lld %lld %lld %lld %lld\n",i,max,min,max-min,x,sum);
}
}
printf("%lld\n",ans);
return 0;
}

#include<stdio.h>
#define SIZE 100004
typedef long long int ll;
ll n,l,r,x,count;
ll arr[20];
void func(ll sum,int i,ll min, ll max,int num)
{
    if(i==n)
    {
        if(sum>=l && sum<=r && (max-min)>=x && num>=2){
            count++;
            //printf("sum : %lld\n",sum);
        }
    }
    else{
        func(sum,i+1,min,max,num);
        func(sum+arr[i], i+1,min = arr[i]<min?arr[i]:min,max = arr[i]>max?arr[i]:max,num+1);
    }
}
int main(void)
{
    int i;
    scanf("%lld%lld%lld%lld",&n,&l,&r,&x);
    for(i=0;i<n;i++)
        scanf("%lld",&arr[i]);
    func(0,0,1000004,0,0);
    printf("%lld",count);
    return 0;
}

#include<stdio.h>
typedef long long ll;
ll arr[25];
ll inde[25];
void merge (ll *a,ll start,ll mid,ll end)
{
     ll k,n1,n2,i,j;
     ll l[mid-start+1],r[end-mid];
     n1=mid-start+1;
     n2=end-mid;
     for(k=0;k<n1;k++)
     {
             l[k] = a[start+k];
     }
     for(k=0;k<n2;k++)
     {
             r[k] = a[mid+k+1];
     }
     i=0;
     j=0;
     for(k=start;k<=end;k++)
     {
            if(n1!=0&&n2!=0)
            {
                   if(l[i]<=r[j])
                   {
                         a[k] = l[i];
                         i++;
                         n1--;
                   }
                   else if(l[i]>r[j])
                   {
                        a[k] = r[j];
                         j++;
                         n2--;
                   }
            }
            else if(n1==0)
            {
                 while(n2>0)
                 {
                         a[k] = r[j];
                         j++;
                         n2--;
                         k++;
                 }
            }
            else if(n2==0)
            {
                 while(n1>0)
                 {
                         a[k] = l[i];
                         i++;
                         n1--;
                         k++;
                 }
            }
     }
     return ;
};
void merge_sort(ll * a,ll start,ll end)
{
     if(end<=start)
     return ;
     ll mid;
     mid=(start+end)/2;
     merge_sort(a,start,mid);
     merge_sort(a,(mid+1),end);
     merge(a,start,mid,end);
     return ;
};
int main()
{
      ll n,l,r,x,i,j,k;
      ll count = 0;
      ll pow[25];
      ll ans = 0,tmp,t1,tot,set,max,min;
      pow[0] = 1;
      for(i=1;i<=16;i++)
      pow[i] = pow[i-1]*2;
      scanf("%lld%lld%lld%lld",&n,&l,&r,&x);
      for(i=0;i<n;i++)
      scanf("%lld",&arr[i]);
      merge_sort(arr,0,n-1);
      ll num = pow[n];
      for(i=0;i<=num;i++)
      {
            t1 = i;
            tot = 0;
            set = 0;
            max = -1;
            min = 25;
            for(k=0;k<n;k++)
            {
                   if(t1%2==1)
                   {
                         inde[k] = 1;
                         tot+=arr[k];
                         set++;
                         if(k>max)
                         max=k;
                         if(k<min)
                         min = k;
                   }
                   else
                   {
                        inde[k] = 0;
                   }
                   t1 = t1/2;
            }
             if(set>=2)
             {
                          if(tot>=l&&tot<=r)
                          {
                                tmp = arr[max]-arr[min];
                                if(tmp>=x)
                                ans++;

                          }
             }
      }
      printf("%lld\n",ans);
      return 0;
}

#include <limits.h>
#include <stdio.h>

int main() {
	int v, i, n, l, r, x, sum, min, max, cnt;
	static int a[15];

	scanf("%d%d%d%d", &n, &l, &r, &x);
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	cnt = 0;
	for (v = 1; v < 1 << n; v++) {
		min = INT_MAX;
		max = 0;
		sum = 0;
		for (i = 0; i < n; i++)
			if ((v & 1 << i) > 0) {
				sum += a[i];
				if (max < a[i])
					max = a[i];
				if (min > a[i])
					min = a[i];
			}
		if (max - min >= x && sum >= l && sum <= r)
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

#include <stdio.h>

int main()
{
    char n,i;
    long l,r,x,j;
    long min,max,sum,count=0;
    char s;
    scanf("%d%ld%ld%ld",&n,&l,&r,&x);
    long c[n];
    for(i=0;i<n;i++)
        scanf("%ld",c+i);
    long a=1L<<n;
    for(j=1;j<a;j++){
        min=1000000;
        max=1;
        sum=0;
        s=0;
        for(i=0;i<n;i++)
            if(j&(1L<<i)){
                if(c[i]<min)min=c[i];
                if(c[i]>max)max=c[i];
                sum+=c[i];
                s++;
            }
        if(s>1 && sum>=l && sum<=r && (max-min)>=x)
            count++;
    }
    printf("%ld\n",count);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
void read(long *, int);
long min(long, long);
long max(long, long);
long count_no_of_problem_sets(long *, int,long, long,long);

int main()
{
    int no_of_problems;
    long min_difficulty, max_difficulty,least_difficulty_range, no_of_problem_sets;
    scanf("%d %ld %ld %ld",&no_of_problems, &min_difficulty, &max_difficulty, &least_difficulty_range);

    long *problem_difficulty = malloc(no_of_problems*sizeof(long));
    read(problem_difficulty, no_of_problems);

    no_of_problem_sets = count_no_of_problem_sets(problem_difficulty, no_of_problems, min_difficulty, max_difficulty, least_difficulty_range);
    printf("%ld\n",no_of_problem_sets);

    free(problem_difficulty);
    return 0;
}

long count_no_of_problem_sets(long *problem_difficulty, int no_of_problems,long min_difficulty, long max_difficulty,long least_difficulty_range)
{
    /*We construct a binary string in bijection to the problems chosen. If the i-th bit is 1, then it means that the i-th problem is chosen
    If i-th bit is 0, then it isn't chosen. This bitmask is n digits long. We know n is always less than 15
    The binary string is helpful in visiting every set that can be chosen from these n elements.*/
    int current_problem_no, bitmask, total_no_of_problem_sets = 1 << no_of_problems; //No of binary strings of length n is 2^n. 1 right shifted n times is 2^n
    long total_legitimate_arrangements = 0, current_min_difficulty, current_max_difficulty, problems_in_set;
    long total_difficulty;

    //Now, we iterate through all the bitmasks
    for(bitmask = 1; bitmask < total_no_of_problem_sets; bitmask++)
    {
        total_difficulty = 0;
        problems_in_set = 0;
        /*The values of minimum and maximum are so set that the first problem selected becomes both min and max and from there it's just the
        standard way of finding min and max in an array.
        The min and max can't be set to the first element like usual because the first element may not be part of the chosen set.*/
        current_min_difficulty = 1e6 + 1;
        current_max_difficulty = -1;

        for(current_problem_no = 0; current_problem_no < no_of_problems; current_problem_no++)
        {
            //The number 2^j corresponds with only the j-th problem chosen. We AND this with the current bitmask. If it's non-zero, then j-problem
            //is chosen in this arrangement
            if(bitmask & (1 << current_problem_no))
            {
                current_min_difficulty = min(current_min_difficulty, *(problem_difficulty + current_problem_no));
                current_max_difficulty = max(current_max_difficulty, *(problem_difficulty + current_problem_no));
                total_difficulty = total_difficulty + *(problem_difficulty + current_problem_no);
                problems_in_set++;
            }
        }

        if( (problems_in_set >= 2) && (total_difficulty >= min_difficulty) && (total_difficulty <= max_difficulty) &&
           (current_max_difficulty-current_min_difficulty >=least_difficulty_range) )
        {
            total_legitimate_arrangements++;
        }
    }

    return total_legitimate_arrangements;
}

void read(long *problem_difficulty, int no_of_problems)
{
    int i;
    for(i = 0; i < no_of_problems; i++)
    {
        scanf("%ld",(problem_difficulty + i));
    }
}

long min(long a, long b)
{
    if(a < b)
        return a;
    else
        return b;
}
long max(long a, long b)
{
    if(a > b)
        return a;
    else
        return b;
}

#include <stdio.h>
#include <stdlib.h>
void read(long *, int);
long min(long, long);
long max(long, long);
long count_no_of_problem_sets(long *, int,long, long,long);

int main()
{
    int no_of_problems;
    long min_difficulty, max_difficulty,least_difficulty_range, no_of_problem_sets;
    scanf("%d %ld %ld %ld",&no_of_problems, &min_difficulty, &max_difficulty, &least_difficulty_range);

    long *problem_difficulty = malloc(no_of_problems*sizeof(long));
    read(problem_difficulty, no_of_problems);

    no_of_problem_sets = count_no_of_problem_sets(problem_difficulty, no_of_problems, min_difficulty, max_difficulty, least_difficulty_range);
    printf("%ld\n",no_of_problem_sets);

    free(problem_difficulty);
    return 0;
}

long count_no_of_problem_sets(long *problem_difficulty, int no_of_problems,long min_difficulty, long max_difficulty,long least_difficulty_range)
{
    //We construct a binary string in bijection to the problems chosen. If the i-th bit is 1, then it means that the i-th problem is chosen
    //If i-th bit is 0, then it isn't chosen. This bitmask is n digits long. We know n is always less than 15
    int current_problem_no, bitmask, total_no_of_problem_sets = 1 << no_of_problems; //No of binary strings of length n is 2^n. 1 right shifted n times is 2^n
    long total_legitimate_arrangements = 0, current_min_difficulty, current_max_difficulty, problems_in_set;
    long total_difficulty;

    //Now, we iterate through all the bitmasks
    for(bitmask = 1; bitmask < total_no_of_problem_sets; bitmask++)
    {
        total_difficulty = 0;
        problems_in_set = 0;
        current_min_difficulty = 1e6 + 1;
        current_max_difficulty = -1;

        for(current_problem_no = 0; current_problem_no < no_of_problems; current_problem_no++)
        {
            //The number 2^j corresponds with only the j-th problem chosen. We AND this with the current bitmask. If it's non-zero, then j-problem
            //is chosen in this arrangement
            if(bitmask & (1 << current_problem_no))
            {
                current_min_difficulty = min(current_min_difficulty, *(problem_difficulty + current_problem_no));
                current_max_difficulty = max(current_max_difficulty, *(problem_difficulty + current_problem_no));
                total_difficulty = total_difficulty + *(problem_difficulty + current_problem_no);
                problems_in_set++;
            }
        }

        if( (problems_in_set >= 2) && (total_difficulty >= min_difficulty) && (total_difficulty <= max_difficulty) &&
           (current_max_difficulty-current_min_difficulty >=least_difficulty_range) )
        {
            total_legitimate_arrangements++;
        }
    }

    return total_legitimate_arrangements;
}

void read(long *problem_difficulty, int no_of_problems)
{
    int i;
    for(i = 0; i < no_of_problems; i++)
    {
        scanf("%ld",(problem_difficulty + i));
    }
}

long min(long a, long b)
{
    if(a < b)
        return a;
    else
        return b;
}
long max(long a, long b)
{
    if(a > b)
        return a;
    else
        return b;
}

#include<stdio.h>

int n,l,r,x;
int input[15];
int solution[15];
int count=0;

void backtrack(int);

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

	backtrack(0);
	printf("%d\n",count);

	return 0;
}

void backtrack(int num)
{
	if(num==n)
	{
		int i;
		int min=1000000,max=0;
		int sum=0;
		for(i=0;i<n;i++)
		{
			if(solution[i])
			{
				sum+=input[i];
				if(input[i]>max)
					max=input[i];
				if(input[i]<min)
					min=input[i];
			}
		}

		if(sum<l || sum>r)
			return;
		if((max-min)<x)
			return;
		count++;
		return;
	}

	int i;
	for(i=0;i<=1;i++)
	{
		solution[num]=i;
		backtrack(num+1);
	}
}

#include<stdio.h>

int solution[15];
int n,l,s,x;
int hard[15];
int count=0;

void backtrack(int k)
{
	if(k==n)
	{
		int i;
		int c=0;
		for(i=0;i<n;i++)
		{
			if(solution[i]!=0)
				c++;
		}
		if(c<2)
			return;

		int sum=0;
		int max=0,min=1000000;
		for(i=0;i<n;i++)
		{
			if(solution[i]!=0)
			{
				sum=sum+hard[i];
				if(min>hard[i])
					min=hard[i];
				if(max<hard[i])
					max=hard[i];
			}
		}

		if(!(sum<=s && sum>=l))
			return;

		if(max-min<x)
			return;

		count++;
		return;
	}

	solution[k]=1;
	backtrack(k+1);
	solution[k]=0;
	backtrack(k+1);
	return;
}

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

	backtrack(0);
	printf("%d\n",count);

	return 0;
}

#include <stdio.h>
#include <stdio.h>
#include <math.h>
long long sum=0,max=0,min=0;
int n,l,r,x,i,count=0;
void printPowerSet(int *set, int set_size)
{
    /*set_size of power set of a set with set_size
      n is (2**n -1)*/
    unsigned int pow_set_size = pow(2, set_size);
    int counter, j;
    /*Run from counter 000..0 to 111..1*/
    for(counter = 0; counter < pow_set_size; counter++)
    {
    	sum=0;
    	min=1000000000,max=0;
      for(j = 0; j < set_size; j++)
       {
          /* Check if jth bit in the counter is set
             If set then pront jth element from set */
          if(counter & (1<<j))
          {

          	 if(set[j]>max)
          	   max=set[j];
          	 if(set[j]<min)
          	   min=set[j];
          	 sum+=set[j];

          }
       }

       if(counter!=0)
       {
       	if(sum>=l&&sum<=r&&(max-min)>=x)
       	  count++;

        }

       }

}
int main(void) {
	scanf("%d%d%d%d",&n,&l,&r,&x);
	int a[n+1];
	for(i=0;i<n;i++)
	  scanf("%d",&a[i]);
	  printPowerSet(a,n);
	  printf("%d\n",count);

	return 0;
}

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

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

int main( void ) {
    int n, l, r, x;
    scanf("%i %i %i %i", &n, &l, &r, &x);

    int A[n], B[n];

    int i;
    for( i = 0; i < n; i++ )
	scanf("%i", &A[i]);

    qsort(A, n, sizeof(int), cmp);

    long long nways = 0;
    for( i = 1; i < (1 << n); i++ ) {
	int m = __builtin_popcount(i);

	if( m < 2 ) continue;

	int mask = i, k = 0, top = 0;

	long long tot = 0;
	while( mask ) {
	    if( mask & 01 ) {
		B[top++] = A[k];
		tot += A[k];
	    }
	    mask >>= 1;
	    k++;
	}

	bool ok = true;

	if( tot < l || tot > r ) ok = false;
	if( (B[m - 1] - B[0]) < x  ) ok = false;

	if( ok ) nways++;
    }

    printf("%lld\n", nways);

    return 0;
}

#include<stdio.h>
#define N 15
int counter=0;
int n,r,l,x;
int c[N];
int b[N];
int nb=0;
void print(int *a, int size) {
    int i;
    for(i=0; i<size; i++) {
        printf(" %d",a[i]);
    }
    printf("\n");
}
void sort(int *a, int size) {
    int i,j;
    for(i=0; i<size-1; i++) {
        int k=i;
        for(j=i+1; j<size; j++) {
            if(a[j]<a[k]) {
                k=j;
            }
        }
        //there we only swap min with a[i];
        int tmp=a[k];
        a[k]=a[i];
        a[i]=tmp;
    }
}
void dfs2(int start,int deep) {
    if(nb>=2) {
        /*printf("dfs(%d,%d)\n",start,deep);
        print(b,nb);
	*/
        int sum=0;
        int j;
        for(j=0; j<nb; j++) {
            sum+=b[j];
        }
	/*
	printf("sum = %d\n",sum);
        printf("r=%d, sum=%d, l=%d\n",r,sum,l);
        printf("max=%d, x=%d, min=%d\n",b[nb-1],x,b[0]);
	*/
        if((sum<=r) && (b[nb-1]-b[0]>=x) && (sum>=l)) {
            counter++;
	    /*printf("counter = %d\n",counter);
            print(b,nb);
	    */
        }
    }
    if(deep==n) return;
    else {
        int i;
        for(i=start+1; i<n; i++) {
            b[nb]=c[i];
            nb++;
            dfs2(i,deep+1);
            nb--;
        }
    }
}

int main() {
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d",&c[i]);
    }
    //print(c,n);
    sort(c,n);
    //print(c,n);
    //dfs(0,0);
    dfs2(-1,0);
    printf("%d\n",counter);

    return 0;
}

#include<stdio.h>
#define N 15
int counter=0;
int n,r,l,x;
int c[N];
int b[N];
int nb=0;
void print(int *a, int size) {
    int i;
    for(i=0; i<size; i++) {
        printf(" %d",a[i]);
    }
    printf("\n");
}
void sort(int *a, int size) {
    int i,j;
    for(i=0; i<size-1; i++) {
        int k=i;
        for(j=i+1; j<size; j++) {
            if(a[j]<a[k]) {
                k=j;
            }
        }
        //there we only swap min with a[i];
        int tmp=a[k];
        a[k]=a[i];
        a[i]=tmp;
    }
}
void comb(int set,int select,int cn,int cm) {
        int i;
    if(select==cm) {
        int sum=0;
        int max=0;
        int min=1000001;
        for(i=0; i<cm; i++) {
            sum+=b[i];
            if(b[i]>max)max=b[i];
            if(b[i]<min)min=b[i];
        }
        if((sum<=r) && (max-min>=x) && (sum>=l)) {
            //print(b,cm);
            counter++;
        }
    } else {
        for(i=set; i<cn; i++) {
            b[select]=c[i];
            comb(i+1,select+1,cn,cm);
        }
    }
}
int main() {
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d",&c[i]);
    }
    sort(c,n);
    //print(c,n);
    for(i=2; i<=n; i++) {
        comb(0,0,n,i);
    }
    printf("%d\n",counter);

    return 0;
}

#include<stdio.h>
#define N 15
int counter=0;
int n,r,l,x;
int c[N];
int b[N];
int nb=0;
void print(int *a, int size) {
    int i;
    for(i=0; i<size; i++) {
        printf(" %d",a[i]);
    }
    printf("\n");
}
void sort(int *a, int size) {
    int i,j;
    for(i=0; i<size-1; i++) {
        int k=i;
        for(j=i+1; j<size; j++) {
            if(a[j]<a[k]) {
                k=j;
            }
        }
        //there we only swap min with a[i];
        int tmp=a[k];
        a[k]=a[i];
        a[i]=tmp;
    }
}
void comb(int set,int select,int cn,int cm) {
        int i;
    if(select==cm) {
        int sum=0;
        for(i=0; i<cm; i++) {
            sum+=b[i];
        }
        if((sum<=r) && (b[cm-1]-b[0]>=x) && (sum>=l)) {
            //print(b,cm);
            counter++;
        }
    } else {
        for(i=set; i<cn; i++) {
            b[select]=c[i];
            comb(i+1,select+1,cn,cm);
        }
    }
}
int main() {
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d",&c[i]);
    }
    sort(c,n);
    //print(c,n);
    for(i=2; i<=n; i++) {
        comb(0,0,n,i);
    }
    printf("%d\n",counter);

    return 0;
}

#include<stdio.h>
#define N 15
int counter=0;
int n,r,l,x;
int c[N];
int b[N];
int nb=0;
void print(int *a, int size) {
    int i;
    for(i=0; i<size; i++) {
        printf(" %d",a[i]);
    }
    printf("\n");
}
void comb(int set,int select,int cn,int cm) {
    int i;
    if(select==cm) {
        int sum=0;
        int max=0;
        int min=1000001;
        for(i=0; i<cm; i++) {
            sum+=b[i];
            if(b[i]>max)max=b[i];
            if(b[i]<min)min=b[i];
        }
        if((sum<=r) && (max-min>=x) && (sum>=l)) {
            //print(b,cm);
            counter++;
        }
    } else {
        for(i=set; i<cn; i++) {
            b[select]=c[i];
            comb(i+1,select+1,cn,cm);
        }
    }
}
int main() {
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d",&c[i]);
    }
    for(i=2; i<=n; i++) {
        comb(0,0,n,i);
    }
    printf("%d\n",counter);

    return 0;
}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
	return (*(int *)a - *(int*)b );
}
int main()
{
	long int n,l,r,x;
	scanf("%ld %ld %ld %ld",&n,&l,&r,&x);
	long int i;
	long int a[n];
	for(i=0;i<n;i++)
		scanf("%ld",&a[i]);
	qsort(a,n,sizeof(long int),cmpfunc);
	/*set_size of power set of a set with set_size
    n is (2**n -1)*/
    long int pow_set_size = pow(2,n);
    long int counter, j;
    long int flag = 0;
    long int min;
    long int max;
    long int count = 0;
    long int sum = 0;
    long int num = 0;
    for(counter = 0; counter < pow_set_size; counter++)
    {
   	   for(j = 0; j < n; j++)
       {
        	if(counter & (1<<j)){
        		num++;
        		if(flag == 0)
        		{
        			flag = 1;
        			min = a[j];
        		}
        		max = a[j];
            	sum = sum + a[j];
            	//printf("%ld", a[j]);
        	}
       }
       if(num >=2)
       {
       		if(max - min >= x){
       			if(sum >=l && sum <=r)
       				count++;
       		}
       }
       //printf("\n%ld\n", num);
       num = 0;
       //printf("\n");
       flag = 0;
       max = 0;
       sum = 0;
    }
	printf("%ld\n",count);
	return 0;
}

#include <stdio.h>

int hardest(int ar[], int size);

int easiest(int ar[], int size);

int total(int ar[], int size);

int main()
{
    int i[100], j, k, n, l, r, x, c[100], p[100], a, b, d, size, count = 0;

    for (a = 1; a <= 99; a++)
    {
        p[a] = 0;
    }

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

    for (a = 1; a <= n; a++)
    {
        scanf("%d", &c[a]);
    }

    for (i[1] = 1; i[1] <= n; i[1]++)
    {

        for (i[2] = i[1] + 1; i[2] <= n; i[2]++)
        {
            size = 2;
            for (a = 1; a <= size; a++)
            {
                p[a] = c[i[a]];
            }
            if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
            {
                count++;
            }
            //p[2]++;
            for (i[3] = i[2] + 1; i[3] <= n; i[3]++)
            {
                size = 3;
                for (a = 1; a <= size; a++)
                {
                    p[a] = c[i[a]];
                }
                if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                {
                    count++;
                }
                //p[3]++;
                for (i[4] = i[3] + 1; i[4] <= n; i[4]++)
                {
                    size = 4;
                    for (a = 1; a <= size; a++)
                    {
                        p[a] = c[i[a]];
                    }
                    if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                    {
                        count++;
                    }
                    //p[4]++;
                    for (i[5] = i[4] + 1; i[5] <= n; i[5]++)
                    {
                        size = 5;
                        for (a = 1; a <= size; a++)
                        {
                            p[a] = c[i[a]];
                        }
                        if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                        {
                            count++;
                        }
                        //p[5]++;
                        for (i[6] = i[5] + 1; i[6] <= n; i[6]++)
                        {
                            size = 6;
                            for (a = 1; a <= size; a++)
                            {
                                p[a] = c[i[a]];
                            }
                            if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                            {
                                count++;
                            }
                            //p[6]++;
                            for (i[7] = i[6] + 1; i[7] <= n; i[7]++)
                            {
                                size = 7;
                                for (a = 1; a <= size; a++)
                                {
                                    p[a] = c[i[a]];
                                }
                                if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                {
                                    count++;
                                }
                                //p[7]++;
                                for (i[8] = i[7] + 1; i[8] <= n; i[8]++)
                                {
                                    size = 8;
                                    for (a = 1; a <= size; a++)
                                    {
                                        p[a] = c[i[a]];
                                    }
                                    if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                    {
                                        count++;
                                    }
                                    //p[8]++;
                                    for (i[9] = i[8] + 1; i[9] <= n; i[9]++)
                                    {
                                        size = 9;
                                        for (a = 1; a <= size; a++)
                                        {
                                            p[a] = c[i[a]];
                                        }
                                        if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                        {
                                            count++;
                                        }
                                        //p[9]++;
                                        for(i[10] = i[9] + 1; i[10] <= n; i[10]++)
                                        {
                                            size = 10;
                                            for (a = 1; a <= size; a++)
                                            {
                                                p[a] = c[i[a]];
                                            }
                                            if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                            {
                                                count++;
                                            }
                                            //p[10]++;
                                            for(i[11] = i[10] + 1; i[11] <= n; i[11]++)
                                            {
                                                size = 11;
                                                for (a = 1; a <= size; a++)
                                                {
                                                    p[a] = c[i[a]];
                                                }
                                                if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                                {
                                                    count++;
                                                }
                                                //p[11]++;
                                                for (i[12] = i[11] + 1; i[12] <= n; i[12]++)
                                                {
                                                    size = 12;
                                                    for (a = 1; a <= size; a++)
                                                    {
                                                        p[a] = c[i[a]];
                                                    }
                                                    if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                                    {
                                                        count++;
                                                    }
                                                    //p[12]++;
                                                    for (i[13] = i[12] + 1; i[13] <= n; i[13]++)
                                                    {
                                                        size = 13;
                                                        for (a = 1; a <= size; a++)
                                                        {
                                                            p[a] = c[i[a]];
                                                        }
                                                        if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                                        {
                                                            count++;
                                                        }
                                                        //p[13]++;
                                                        for(i[14] = i[13] + 1; i[14] <= n; i[14]++)
                                                        {
                                                            size = 14;
                                                            for (a = 1; a <= size; a++)
                                                            {
                                                                p[a] = c[i[a]];
                                                            }
                                                            if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                                            {
                                                                count++;
                                                            }
                                                            //p[14]++;
                                                            for (i[15] = i[14] + 1; i[15] <= n; i[15]++)
                                                            {
                                                                size = 15;
                                                                for (a = 1; a <= size; a++)
                                                                {
                                                                    p[a] = c[i[a]];
                                                                }
                                                                if (total(p, size) >= l && total(p, size) <= r && hardest(p, size) - easiest(p, size) >= x)
                                                                {
                                                                    count++;
                                                                }
                                                                //p[15]++;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

   printf("%d", count);
}

int hardest(int ar[], int size)
{
    int i, j, k, l;

    int ret = ar[1];

    for (i = 1; i <= size; i++)
    {
        if (ar[i] > ret)
        {
            ret = ar[i];
        }
    }

    return ret;
}

int easiest(int ar[], int size)
{
    int i, j, k, m, ret = ar[1];

    for (i = 1; i <= size; i++)
    {
        if (ar[i] < ret)
        {
            ret = ar[i];
        }
    }

    return ret;
}

int total(int ar[], int size)
{
    int i, ret = 0;

    for (i = 1; i <= size; i++)
    {
        ret += ar[i];
    }

    return ret;
}

#include <stdio.h>

int n, l, r, x, c[15], v;

int valid(int b)
{
    int size = 0, sum = 0, min = 1000000, max = 1;
    for (int i = 0; i < n; i++)
        if (b & 1 << i) {
            size++, sum += c[i];
            if (c[i] < min)
                min = c[i];
            if (c[i] > max)
                max = c[i];
        }
    return size >= 2 && sum >= l && sum <= r && max - min >= x;
}

int main(void)
{
    scanf("%d %d %d %d", &n, &l, &r, &x);
    for (int i = 0; i < n; i++)
        scanf("%d", &c[i]);
    for (int b = 0; b < 1 << n; b++)
        v += valid(b);
    printf("%d", v);
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

#define MAX_N 15

int nbComb = 0;

int n;
int x;
int l;
int r;
int dif[MAX_N];
int mas[MAX_N];

int changeCombinaison()
{
	int carry = 1;
	int nb = 0;
	int i;
	for (i = 0; i < n; i++)
	{
		if (carry == 1)
		{
			if (mas[i] == 1)
			{
				mas[i] = 0;
				carry = 1;
			}
			else
			{
				mas[i] = 1;
				carry = 0;
			}
		}
		if (mas[i] == 1)
		{
			nb++;
		}
	}

	if (nb == 0)
	{
		return -1;
	}

	if (nb <= 1)
	{
		return changeCombinaison();
	}

	return 1;
}

void VerifCombinaison()
{
	/*for (int i = 0; i < n; i++)
	{
		printf("%d - ", mas[i]);
	}
	printf("\r\n");*/

	int i, j;
	int verif = 1;
	int verifX = 0;
	int somme = 0;

	for (i = 0; i < n; i++)
	{
		if (mas[i] == 1)
		{
			for (j = 0; j < i; j++)
			{
				if (mas[j] == 1)
				{
					if (dif[i] - dif[j] >= x || dif[j] - dif[i] >= x)
					{
						/* printf("|%d / %d| ", dif[i], dif[j]); */
						verifX = 1;
						break;
					}
				}
			}
			somme += dif[i];
		}
		if (somme > r)
		{
			verif = 0;
			break;
		}
	}

	/* printf("%d\r\n", somme); */

	if (somme < l)
	{
		verif = 0;
	}

	if (verif == 1 && verifX == 1)
	{
		nbComb++;
	}

	if (changeCombinaison() != -1)
	{
		VerifCombinaison();
	}
}

int main()
{
	int i;
	scanf("%d %d %d %d", &n, &l, &r, &x);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &dif[i]);
		mas[i] = 0;
	}

	changeCombinaison();
	VerifCombinaison();

	printf("%d\r\n", nbComb);
	return 0;
}

#include <stdio.h>

#define N 15
#define C 1000000

int main() {
	static int cc[N];
	int n, l, r, x, i, b, cnt, sum, cmax, cmin, ans;

	scanf("%d%d%d%d", &n, &l, &r, &x);
	for (i = 0; i < n; i++)
		scanf("%d", &cc[i]);
	ans = 0;
	for (b = 0; b < 1 << n; b++) {
		sum = cnt = cmax = 0;
		cmin = C + 1;
		for (i = 0; i < n; i++)
			if (b & 1 << i) {
				cnt++;
				sum += cc[i];
				if (cmax < cc[i])
					cmax = cc[i];
				if (cmin > cc[i])
					cmin = cc[i];
			}
		if (cnt >= 2 && sum >= l && sum <= r && cmax - cmin >= x)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int min(int a,int b)
{
   return a>=b?b:a;
}
int max(int a,int b)
{
    return a>=b?a:b;
}
int main()
{
   int l,r,x,n,res=0,a[16],i,j,low,high,sum=0,count=0;
   scanf("%d%d%d%d",&n,&l,&r,&x);
   for(i=0;i<n;i++)
    scanf("%d",&a[i]);
   for(i=0;i<1<<n;i++)
   {
       low=1000000000;
       high=count=sum=0;
       for(j=0;j<n;j++)
       {
           if(i&1<<j)
           {
               low=min(low,a[j]);
               high=max(high,a[j]);
               sum+=a[j];
               count++;
           }
       }
      if(count>=2 && sum>=l && sum<=r && high-low>=x)
            res++;
   }
    printf("%d",res);
   return 0;
}

#include <stdio.h>

int main()
{
    int mask, n, l, r, x, i, Ans = 0;
    int C[15];
    scanf("%d %d %d %d", &n, &l, &r, &x);
    for(i = 0; i < n; ++i) {
        scanf("%d", &C[i]);
    }
    for(mask = 1; mask < (1 << n); ++mask) {
        int Min = 0x7f7f7f7f;
        int Max = 0;
        int CurSum = 0;
        for(i = 0; i < n; ++i) {
            if((1 << i)&mask) {
                CurSum += C[i];
                if(Min > C[i]) {
                    Min = C[i];
                }
                if(Max < C[i]) {
                    Max = C[i];
                }
            }
        }
        if(CurSum >= l && CurSum <= r && Max - Min >= x) {
            ++Ans;
        }
    }
    printf("%d\n", Ans);
    return 0;
}

#include<stdio.h>
int main()
{
	long long n,l,r,x,i,mask,cnt,cnt1,max,min,diff,sum,cnt2;
	scanf("%I64d",&n);
	scanf("%I64d",&l);
	scanf("%I64d",&r);
	scanf("%I64d",&x);
	long long int A[n];
	for(i=1;i<=n;i++)
	{
	scanf("%I64d",&A[i]);
    }
	cnt1 = 0;
	for(i=1;i<=1<<n;i++)
	{
		min = 10000000;
     	max = 1;
     	cnt = 0;
     	sum = 0;
     	mask = 1;
     	cnt2 = 1;
		while(mask<=i)
		{
			if(i&mask)
			{
				cnt = cnt +1;
				if(A[cnt2]>max)
				max= A[cnt2];
				if(A[cnt2]<min)
				min = A[cnt2];
				sum = sum + A[cnt2];
			}
			mask = mask<<1;
			cnt2 = cnt2 +1;
		}

		diff = max - min;
		if(cnt>=2)
		{
			if(sum>=l && sum <= r && diff >=x)
			{
				cnt1 = cnt1 +1;
			}
		}
	}
	printf("%I64d",cnt1);
	return 0;
}

#include <stdio.h>
#include <limits.h>

int main(void) {
  int i, n, l, r, x, pattern, count, sum, min, max, c[15];
  scanf("%d%d%d%d", &n, &l, &r, &x);
  for (i = 0; i < n; ++i) {
    scanf("%d", &c[i]);
  }
  count = 0;
  for (pattern = 0; pattern < (1 << n); ++pattern) {
    if (__builtin_popcount(pattern) >= 2) {
      sum = 0;
      max = INT_MIN;
      min = INT_MAX;
      for (i = 0; i < n; ++i) {
        if (pattern & (1 << i)) {
          sum += c[i];
          min = c[i] < min ? c[i] : min;
          max = c[i] > max ? c[i] : max;
        }
      }
      if (l <= sum && sum <= r && max - min >= x) {
        ++count;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}

/* DHUOJ solution #368727 @ 2018-11-11 20:53:55.897 */

#include<stdio.h>
#include<string.h>
int c[20];
int n,l,r,x,cnt=0;
void search(int dep,int sum,int min,int max,int nn)
{
	if(dep==n+1)
	{
		if(sum>=l&&sum<=r&&max-min>=x&&nn>=2) cnt++;
		return ;
	}
	search(dep+1,sum,min,max,nn);
	int num=c[dep];
	int mi=min>num?num:min;
	int ma=max>num?max:num;
	search(dep+1,sum+num,mi,ma,nn+1);
}
int main()
{
	int i;
	scanf("%d%d%d%d",&n,&l,&r,&x);
	for(i=1;i<=n;i++) scanf("%d",&c[i]);
	search(1,0,1000000000,-1,0);
	printf("%d",cnt);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int cal(int dif[],int jd,int l,int r,int x)
{
    int sum=0,max,min;
    int i;
    if (jd==0) return 0;
    for (i=0;jd%2==0 && jd!=0;jd=jd>>1,i=i+1);
    min=dif[i];
    sum=sum+dif[i];
    for (i++,jd=jd>>1;jd!=0;jd=jd>>1,i++)
        if (jd%2!=0) sum=sum+dif[i];
    max=dif[i-1];
    if (max-min >=x && sum>=l && sum<=r) return 1;
    else return 0;
}

void kuaipai (int *left,int *right)
{
    int key=*left;
    int *stl=left;
    int *str=right;
    if (left >= right) return;
    while (left < right)
    {
        while (left < right && key <= *right)
        {
            right--;
        }
        *left = *right;
        while (left < right && key >= *left)
        {
            left++;
        }
        *right = *left;
    }
    *left=key;
    kuaipai(stl,left-1);
    kuaipai(right+1,str);
}

int main()
{
    int n,l,r,x;
    int i;
    int sum;
    int dif[15]={0};
    while (scanf("%d %d %d %d",&n,&l,&r,&x)!=EOF)
    {
        sum=0;
        for (i=0;i<n;i++)
            scanf("%d",&dif[i]);
        kuaipai(&dif[0],&dif[n-1]);
        for (i=0;i<pow(2,n);i++)
        {
            if (cal(dif,i,l,r,x)) sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

#include<stdio.h>
typedef int ll;
ll nw,left,right,xw;
ll count=0;
void qcksrt(int a[],int first,int last){
	if(first<=last){
        int wall=first,pivot=first,i,temp;
        for(i=first;i<=last;i++){
            if(a[i]<a[pivot]){
            	wall++;
            	temp=a[wall];
            	a[wall]=a[i];
            	a[i]=temp;
            }
        }
        temp=a[wall];
        a[wall]=a[pivot];
        a[pivot]=temp;
        qcksrt(a,first,wall-1);
        qcksrt(a,wall+1,last);
    }
}
void combinationUtil(int arr[], int data[], int start, int end, int index, int r);
 void printCombination(int arr[], int n, int r)
{
   int data[r];
    combinationUtil(arr, data, 0, n-1, 0, r);
}
void combinationUtil(int arr[], int data[], int start, int end, int index, int r)
{   if (index == r)
    {
    	int j;
    	ll sum=0;
        for (j=0; j<r; j++)
            {
            	sum+=data[j];
            }
           // printf("%d\n",sum );
        if((sum >=left) && (sum <=right) && ((data[r-1]-data[0])>=xw))
        {
        	count++;
        }
        return;
    }
    int i;
    for (i=start; i<=end && end-i+1 >= r-index; i++)
    {
        data[index] = arr[i];
        combinationUtil(arr, data, i+1, end, index+1, r);
    }
}
int main()
{
	ll i,j,k,g,test;
	scanf("%d %d %d %d",&nw,&left,&right,&xw);
	int a[nw+1];
	for(i=0;i<nw;i++)
	{
		scanf("%d",&a[i]);
	}
	qcksrt(a,0,nw-1);
	ll r;
	for(k=2;k<=nw;k++)
	{
		printCombination(a,nw,k);
	}
	printf("%d\n",count );
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
	return (*(int *)a - *(int*)b );
}
int main()
{
	long int n,l,r,x;
	scanf("%ld %ld %ld %ld",&n,&l,&r,&x);
	long int i,j;
	long int a[n];
	for(i=0;i<n;i++)
		scanf("%ld",&a[i]);
	qsort(a,n,sizeof(long int),cmpfunc);
	long int min;
	long int max;
	long int count = 0;
	long int sum = 0;
	long int val = 0;
	long int k;
	for(i=0;i<n;i++){
		min = a[i];
		max = a[i];
		sum = a[i];
		for(j=i+1;j<n;j++){
			for(k=j;k<n;k++)
			{
				max = a[k];
				if(max - min >= x){
					if(sum + a[k] >= l && sum + a[k] <= r)
					{
						count++;
					}
				}
			}
			sum = sum + a[j];
		}
	}
	printf("%ld\n",count);
	return 0;
}

#include<stdio.h>
int n,l,r,x,a[20],ans=0,state=0;
void func(int k,int d,int e,int h,int t)
{
	int q=0;
	if(h-e>=x && d>=l && d<=r && t>1)
	{
		ans++;
	//	printf("%d %d %d %d\n",k,d,e,h);
		q=1;
	}
	if(k==n)
		return;
	if(state==0)
	{
		state=1;
		func(k+1,d+a[k],a[k],a[k],t+1);
		state=0;
		if(q==0)
			func(k+1,d,e,h,t);
	}
	else
	{
		if(a[k]<e)
		{
			func(k+1,d+a[k],a[k],h,t+1);
			if(q==0)
				func(k+1,d,e,h,t);
		}
		else if(a[k]>h)
		{
			func(k+1,d+a[k],e,a[k],t+1);
			if(q==0)
				func(k+1,d,e,h,t);
		}
		else
		{
			func(k+1,d+a[k],e,h,t+1);
			if(q==0)
				func(k+1,d,e,h,t);
		}
	}
	return;
}
int main()
{
	int i;
	scanf("%d %d %d %d",&n,&l,&r,&x);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	func(0,0,0,0,0);
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>
#include <math.h>
int n,l,r,x;
void PowerSet(int *set, int set_size)
{
    unsigned int pow_set_size = pow(2, set_size);
    int counter, j,ar[set_size],cnt=0,ind,sum,i;
    for(counter = 0; counter < pow_set_size; counter++)
    {ind=0;
      for(j = 0; j < set_size; j++)
       {
          if(counter & (1<<j))
            ar[ind++]=set[j];

       }
       sum=0;
       for(i=0;i<ind;i++)
        {
                         if(i+1<ind && abs(ar[i]-ar[i+1])<x)
                         break;
                         sum+=ar[i];
        }
        if(i==ind && sum>=l && sum<=r)
        cnt++;

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

/*Driver program to test printPowerSet*/
int main()
{

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

//scanf("%d",&i);
    return 0;
}

#include<stdio.h>
int comp(const void*a,const void *b);
void dfs(int min,int max,int sum,int k);
int n,l,r,x;
int ans=0;
int pro[100000];
int main(){
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i,j;
    for(i=0;i<n;i++)
        scanf("%d",&pro[i]);
    qsort((void*)pro,i,sizeof(int),comp);
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            dfs(pro[i],pro[j],pro[i]+pro[j],j+1);
        }
    }
    printf("%d\n",ans);
    return 0;
}
int comp(const void*a,const void *b){
    return *(int*)a>*(int*)b?1:-1;
}
void dfs(int min,int max,int sum,int k){
    if(sum>r)
        return;
    int i;
    if(sum>=l&&sum<=r&&max-min>=x)
        ans++;
    for(i=k;i<n;i++)
        dfs(min,pro[i],sum+pro[i],k+1);
}

/*
Spirits coming from the mind,
waking up my deepest horrors,
capture my thoughts, make me blind.

Weird, ‘cause I don't want to see
the abyss of my possibilities.

Scared I can't look away.

It has come to my side.
Sister demon - my bride.

I want you, I need you
and I have set you free.
You're always right behind me,
I know the devil's sent you to me.
You want me, you need me,
now that I've set you free.
Look always right behind you,
You know the devil's sent me to you.

What has started as a longing
almost is possession now,
it drives me again and again.
Put a light into your window,
maybe I can find a hold.
I run against myself ‘till I find the end.

Sent by the devil
*/

/* .................... compiled by alankar....................
*/

//......................SHORTCUTS..............................

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//...........................................................

#define pi 3.14159265358979323846  //float type
#define MAX 100000  //for rmq
#define SQRTMAX 317   //for rmq
//#define gc getchar_unlocked

#define FOR(i,a,b) for(i=(a);i<(b);i++)

//only for +ve and single terms
#define s(x) scanf("%d",&x);
#define sl(x) scanf("%lld",&x);
#define p(x) printf("%d\n",x);
#define pl(x) printf("%lld\n",x);
//..........................................................

typedef long long int ll;
const ll MOD=1000000007;

//returns int and +ve numbers

/*inline int inp(){
    int n=0;
    char c;
    c=gc();
    while(c<'0' || c>'9'){
        c=gc();
    }
    while(c>='0' && c<='9'){
        n=(n<<3)+(n<<1)+c-'0';
        c=gc();
    }
    return n;
}
*/
//...................................

//power with mod........long long int
 ll power(ll a,ll b,ll mod){
      if(b==0)
            return 1;
      ll temp=power(a,b/2,mod);
      temp=(temp*temp)%mod;
      if(b&1)
            temp=(temp*a)%mod;
      return temp;
}

 //power without mod........ int
ll pwr(ll a,ll b){
      if(b==0)
            return 1;
      ll temp=pwr(a,b/2);
      temp=(temp*temp);
      if(b&1)
            temp=(temp*a);
      return temp;
}
 // .....long long int
ll gcd(ll a,ll b){
      return b==0?a:gcd(b,a%b);
}
 //......long long int
ll lcm(ll a,ll b){
      return (a/gcd(a,b))*b;
}
 //......long long int with mod
ll modularInverse(ll a,ll m){
      return power(a,m-2,m);
}

 //only for int
 int min(int a,int b) { return a<b? a : b; }
 int max(int a,int b) { return a>b? a : b; }

//normal compare func on integers //for qsort(name,size,sizeof(type),compare)
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int BinarySearch(int *array, int number_of_elements, int key)
{
        int low = 0, high = number_of_elements-1, mid;
        while(low <= high)
        {
                mid = (low + high)/2;
                if(array[mid] < key)
                {
                        low = mid + 1;
                }
                else if(array[mid] == key)
                {
                        return mid;
                }
                else if(array[mid] > key)
                {
                        high = mid-1;
                }

        }
        return -1;
}
//.......................................................

//segment tree
//not template but how to use ST
//for minimum element
/*
long long s[400000];
long long a[1000000];
int create(long long b,long long e,long long n)
{
    if(b==e)
    {
        s[n]=a[b];
    }
    else
        {
            create(b,(b+e)/2,2*n+1);
            create((b+e)/2+1,e,2*n+2);
            s[n]=s[2*n+1]<s[2*n+2]?s[2*n+1]:s[2*n+2];
        }
    return 0;
}

//for finding minimum element b/w l and r
long long messi(long long b,long long e,long long l,long long r,long long n)
{
    long long i,j;
    if(e<l||b>r)
    {
        return 100000001;
    }
    if(b>=l&&e<=r)
    {
        return s[n];
    }
    i=messi(b,(b+e)/2,l,r,2*n+1);
    j=messi((b+e)/2+1,e,l,r,2*n+2);
    return i<j?i:j;
}
*/
//............................................................................
//range minimam query
//for mim and max number
/*

//preprocess create the min array

long min[SQRTMAX], max[SQRTMAX], b[MAX];
int size, n;

void preProcess(int n){
    int i=0, j=0, k=0;
    long minimum, maximum;

    size = sqrt(n);
    //printf("size = %d\n",size);
    while(j<size){
        minimum = maximum = b[i];
        for(k=0 ; k<size ; k++){
            if(minimum>b[i])
                minimum = b[i];
            if(maximum<b[i])
                maximum = b[i];
            i++;
        }
        min[j] = minimum;
        max[j] = maximum;
        j++;
    }
}

long findMin(int l, int r){
    int j, j2;
    long minimum = b[l];

    j = l/size + 1;
    j2 = r/size - 1;

    //printf("j= %d and j2 = %d\n", j,j2);
    while(l<j*size && l<=r){
        if(minimum > b[l]){
            minimum = b[l];

        }
        //printf("Checked for %d\n", l);
        l++;
    }
    while(j<=j2 && l<=r && j<size){
        if(minimum > min[j])
            minimum = min[j];
        l = (j+1)*size;
        //printf("Checked for %d  <-->  %d\n", j*size, l-1);
        j++;
    }
    while(l<=r){
        if(minimum > b[l]){
            minimum = b[l];
        }
        //printf("Checked for %d\n", l);
        l++;
    }
    return minimum;
}

//finding max value
long findMax(int l, int r){
    int j, j2;
    long maximum = b[l];

    j = l/size + 1;
    j2 = r/size - 1;

    //printf("j= %d and j2 = %d\n", j,j2);
    while(l<j*size && l<=r){
        if(maximum < b[l]){
            maximum = b[l];

        }
        //printf("Checked for %d\n", l);
        l++;
    }
    while(j<=j2 && l<=r && j<size){
        if(maximum < max[j])
            maximum = max[j];
        l = (j+1)*size;
        //printf("Checked for %d  <-->  %d\n", j*size, l-1);
        j++;
    }
    while(l<=r){
        if(maximum < b[l]){
            maximum = b[l];
        }
        //printf("Checked for %d\n", l);
        l++;
    }
    return maximum;
}
*/

//...........................................END OF TEMPLATE.................................................................

ll a[20];
int main()
{ ll i,j=20,k=20,t,n,l,r,x,ans=0,xe,tot,sum=0,ju=0,ma,mi;
    sl(n)
    sl(l)
    sl(r)
    sl(x)

    FOR(i,0,n)
    sl(a[i])

    qsort(a,n,sizeof(ll),compare);

    FOR(i,0,n)
    {
        if(a[i]>=l)
        {
            j=i;
            break;
        }
    }

    for(i=n-1;i>=0;i--)
    {
        if(a[i]<=l)
        {
            k=i;
            break;
        }
    }

    if(n<2)
        printf("0\n");

      else
      {

          FOR(i,3,1<<n)
          {
              xe=i;
              tot=0;
              while(xe)
              {
                  xe=(xe&(xe-1));
                  tot++;
              }
             // pl(tot)
              if(tot<2)
                continue;

               sum=0;
                ju=0;
               FOR(j,0,n)
               {   ma=0,mi=1000000000000;
                   if((i>>j)&1)
                   {

                       {
                           if(a[j]>=ma)
                            ma=a[j];
                           if(a[j]<=mi)
                            mi=a[j];
                           sum=sum+a[j];
                       }

                   }
               }
               if(sum>=l&&sum<=r&&ju==0&&(ma-mi>=x))
                ans++;

          }

          pl(ans)
      }

    return 0;
}

#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
//using namespace std;
long long int a[1000500];
long long int count,l,r,x,n;
long long int func(long long int sum,long long int ind,long long int mii,long long int maa);
int main()
{
    scanf("%lld %lld %lld %lld",&n,&l,&r,&x);;
    long long int j=0,i;
    count=0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    func(0,0,100000,-100000);
    printf("%lld\n",count);
    return 0;
}
long long int func(long long int sum,long long int ind,long long int mii,long long int maa)
{
    if(ind==n)
    {
        if(sum>=l&&sum<=r&&(maa-mii)>=x)
            count++;
        return 0;
    }
    long long int mi=a[ind],ma=a[ind];
    func(a[ind]+sum,ind+1,min(mi,mii),max(ma,maa));
    func(sum,ind+1,mii,maa);
    return 0;
}

#include<stdio.h>

int solution[15];
int n,l,s,x;
int hard[15];
int count=0;

void backtrack(int k)
{
	if(k==n)
	{
		int i;
		int c=0;
		for(i=0;i<n;i++)
		{
			if(solution[i]!=0)
				c++;
		}
		if(c<2)
			return;

		int sum=0;
		int max=0,min=100000;
		for(i=0;i<n;i++)
		{
			if(solution[i]!=0)
			{
				sum=sum+hard[i];
				if(min>hard[i])
					min=hard[i];
				if(max<hard[i])
					max=hard[i];
			}
		}

		if(!(sum<=s && sum>=l))
			return;

		if(max-min<x)
			return;

		count++;
		return;
	}

	solution[k]=1;
	backtrack(k+1);
	solution[k]=0;
	backtrack(k+1);
	return;
}

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

	backtrack(0);
	printf("%d\n",count);

	return 0;
}

#include<stdio.h>
#define N 15
int counter=0;
int n,r,l,x;
int c[N];
int b[N];
int nb=0;
void sort(int *a, int size) {
    int i,j;
    for(i=0; i<size-1; i++) {
        int k=i;
        for(j=i+1; j<size; j++) {
            if(a[j]<a[k]) {
                k=j;
            }
        }
        //there we only swap min with a[i];
        int tmp=a[k];
        a[k]=a[i];
        a[i]=tmp;
    }
}
void comb(int set,int select,int total,int choose) {
  if(select==choose) {
        int sum=0;
        int j;
        for(j=0; j<choose; j++) {
            sum+=b[j];
        }
        if((sum<=r) && (b[choose-1]-b[0]>=x) && (sum>=l)) {
            counter++;
        }
    } else {
        int i;
        for(i=set; i<total; i++) {
            b[select]=c[i];
            comb(set+1,select+1,total,choose);
        }
    }
}

int main() {
    scanf("%d%d%d%d",&n,&l,&r,&x);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d",&c[i]);
    }
    sort(c,n);
    for(i=2;i<=n;i++) {
      comb(0,0,n,i);
    }
    printf("%d\n",counter);

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
	return (*(int *)a - *(int*)b );
}
int main()
{
	long int n,l,r,x;
	scanf("%ld %ld %ld %ld",&n,&l,&r,&x);
	long int i,j;
	long int a[n];
	for(i=0;i<n;i++)
		scanf("%ld",&a[i]);
	qsort(a,n,sizeof(long int),cmpfunc);
	long int min = 0;
	long int max = 0;
	long int count = 0;
	long int sum = 0;
	long int val = 0;
	long int k;
	for(i=0;i<n-1;i++){
		min = a[i];
		sum = a[i];
		for(j=i+1;j<n;j++){
			for(k=j;k<n;k++)
			{
				max = a[k];
				if(max - min >= x){
					if(sum + a[k] >= l && sum + a[k] <= r)
					{
						count++;
					}
				}
			}
			sum = sum + a[j];
		}
	}
	printf("%ld\n",count);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
	return (*(int *)a - *(int*)b );
}
int main()
{
	long int n,l,r,x;
	scanf("%ld %ld %ld %ld",&n,&l,&r,&x);
	long int i,j;
	long int a[n];
	for(i=0;i<n;i++)
		scanf("%ld",&a[i]);
	qsort(a,n,sizeof(long int),cmpfunc);
	int temp;
	long int min = 0;
	long int max = 0;
	long int count = 0;
	long int sum = 0;
	long int k;
	for(i=0;i<n-1;i++){
		min = a[i];
		sum = a[i];
		for(j=i+1;j<n;j++){
			for(k=j;k<n;k++)
			{
				max = a[k];
				if(sum + a[k] >= l && sum + a[k] <= r)
				{
					if(max - min >=x)
						count++;
				}
			}
			sum = sum + a[j];
		}
	}
	printf("%ld\n",count);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char nm[101]={'\0'};
    int len,key,res,i,aaaa;
    while (scanf("%s",nm)!=EOF)
    {
        len=strlen(nm);
        aaaa=0;
        for (key=0;key<len;key++)
        {
            i=0;
            if (i!=key)
                res=nm[i]-48;
            else res=0;
            for (i++;i<len;i++)
            {
                if (i==key)  continue;
                res=(res*10+(nm[i]-48))%8;

            }
            if (res%8==0 && len!=1)
            {
                aaaa++;
                if (aaaa==1) printf("YES\n");
                for (i=0;i<len;i++)
                {
                    if (i==key) continue;
                    else printf("%d",nm[i]-48);
                }
                printf("\n");
            }
        }
        if (aaaa==0) printf("NO\n");
    }

    return 0;
}