using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            int productsCount;
            int minWeight;
            int maxWeight;
            int minDifference;
            List<int> weights = new List<int>();

       //     Console.WriteLine("Введите первую строку:");
            string[] inputString = Console.ReadLine().Split(' ');

            productsCount = Convert.ToInt32(inputString[0]);
            minWeight = Convert.ToInt32(inputString[1]);
            maxWeight = Convert.ToInt32(inputString[2]);
            minDifference = Convert.ToInt32(inputString[3]);

     //       Console.WriteLine("Введите вторую строку:");
            string[] inputWeights = Console.ReadLine().Split(' ');

            if (inputWeights.Length != productsCount)
            {
                Console.WriteLine("count weights error!!!");
                return;
            }

            for (int i = 0; i < productsCount; i++)
            {
                weights.Add(Convert.ToInt32(inputWeights[i]));
            }

            List<List<int>> productSets = CreateProductSets(weights);

            int countVar = 0;

            foreach (List<int> subset in productSets)
            {
                int totalWeight = subset.Sum();
                int heaviestItem = subset.Max();
                int easiestItem = subset.Min();
                int difference = heaviestItem - easiestItem;

                if (totalWeight >= minWeight && totalWeight <= maxWeight)
                    if (difference >= minDifference)
                        countVar++;
            }

     //       Console.WriteLine();
            Console.WriteLine(countVar);
            Console.ReadLine();
        }

        static List<List<int>> CreateProductSets(List<int> weights)
        {
            List<List<int>> productSets = new List<List<int>>();

            for (int i = 0; i < weights.Count; i++)
            {
                int subsetCount = productSets.Count;
                productSets.Add(new List<int> { weights[i] });

                for (int j = 0; j < subsetCount; j++)
                {
                    int[] newSubset = new int[productSets[j].Count + 1];
                    productSets[j].CopyTo(newSubset, 0);
                    newSubset[newSubset.Length - 1] = weights[i];
                    productSets.Add(newSubset.ToList());
                }
            }

            return productSets;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Xml.Schema;

namespace CodeforcesTasks
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = arr[0];
            var l = arr[1];
            var r = arr[2];
            var x = arr[3];
            var result = 0;
            var tasks = Console.ReadLine().Split().Select(int.Parse).ToArray();

            CalculatePossiblePermutations(tasks, 0, int.MaxValue, int.MinValue, r , l, x, ref result);
            Console.WriteLine(result);
        }

        public static void CalculatePossiblePermutations(IEnumerable<int> tasks, int currentComplexitySum,
            int minComplexity, int maxComplexity, int maxSum, int minSum, int x, ref int result)
        {
            if (!tasks.Any())
            {
                if (maxComplexity - minComplexity >= x && currentComplexitySum >= minSum)
                {
                    result += 1;
                }
                return;
            }

            CalculatePossiblePermutations(tasks.Skip(1), currentComplexitySum, minComplexity, maxComplexity, maxSum, minSum, x, ref result);

            var nextTask = tasks.First();
            var newSum = currentComplexitySum + nextTask;
            if (newSum <= maxSum)
            {
                if (nextTask < minComplexity)
                {
                    minComplexity = nextTask;
                }

                if (nextTask > maxComplexity)
                {
                    maxComplexity = nextTask;
                }

                CalculatePossiblePermutations(tasks.Skip(1), newSum, minComplexity, maxComplexity, maxSum, minSum, x, ref result);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Round306
{
    class Program
    {
        #region Common Helper

        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }

        #endregion

        #region Problem A

        private static bool ProblemAHelper(string s, string input, string reverse)
        {
            var indexAB = s.IndexOf(input, StringComparison.InvariantCulture);
            if (indexAB == -1)
                return false;
            if (indexAB == 0)
            {
                if (s.Length < 4)
                {
                    return false;
                }
                if (s.Substring(2, s.Length - 2).Contains(reverse))
                {
                    return true;
                }
            }
            else if (s.Substring(0, indexAB - 1).Contains(reverse) || s.Substring(indexAB + 2, s.Length - indexAB - 2).Contains(reverse))
            {
                return true;
            }
            return false;
        }

        private static void ProblemA()
        {
            var s = Console.ReadLine();
            if (ProblemAHelper(s, "AB", "BA") || ProblemAHelper(s, "BA", "AB"))
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
        }

        private static void TwoSubstring()
        {
            var s = Console.ReadLine();
            var subA = "AB";

            var indexA = s.IndexOf(subA, StringComparison.InvariantCulture);
            if (indexA == -1)
            {
                Console.WriteLine("NO");
                return;
            }

            var subB = "BA";
            var indexB = s.LastIndexOf(subB, StringComparison.InvariantCulture);
            if (indexB == -1)
            {
                Console.WriteLine("NO");
                return;
            }
            if (indexA + 1  < indexB)
            {
                Console.WriteLine("YES");
                return;
            }

            indexA = s.LastIndexOf(subA);
            indexB = s.IndexOf(subB);
            if (indexB + 1 < indexA)
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
        }

        private static void TwoSubstring2()
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Contains("AB") && s.Contains("BA") &&
            (s.LastIndexOf("BA", StringComparison.OrdinalIgnoreCase) - 1 > s.IndexOf("AB", StringComparison.OrdinalIgnoreCase) ||
             s.LastIndexOf("AB", StringComparison.OrdinalIgnoreCase) - 1 > s.IndexOf("BA", StringComparison.OrdinalIgnoreCase))
                ? "YES": "NO");
        }

        #endregion

        #region Problem B

        private static IEnumerable<List<int>> powerSet(IList<int> input, int n = 1)
        {
            var data = input.ToArray();
            for (var i = 0; i < ((n + 1) << data.Length); i++)
            {
                var tempList = new List<int>(n + 1);
                tempList.AddRange(data.Where((t, j) => (i >> j)%2 == 1));
                yield return tempList;
            }

        }

        private static void ProblemB()
        {
            var n = Next();
            var l = Next();
            var r = Next();
            var x = Next();
            var c = new int[n];
            for (var i = 0; i < n; i++)
                c[i] = Next();

            reader.Close();
            var ans = 0;
            var total = 2 << (n - 1);
            for (var i = 0; i < total; i++)
            {
                int i1 = i;
                var tempList = c.Where((t, j) => (i1 >> j)%2 == 1).ToArray();
                if (tempList.Length > 1 && tempList.Sum() >= l && tempList.Sum() <= r && tempList.Max() - tempList.Min() >= x)
                    ans++;
            }

            Console.WriteLine(ans);
        }

        #endregion
        static void Main(string[] args)
        {
            //ProblemA();
            //TwoSubstring();
            //TwoSubstring2();

            ProblemB();
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace _306
{
    class Program
    {
        private static int ans = 0;
        private static int max, min,l,r,x,sum;
        private static int[] mas;
        static void rec(int k, string s)
        {
            if (k > 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    rec(k - 1, s + i);
                }
            }
            else
            {
                min = int.MaxValue;
                max = int.MinValue;
                sum = 0;
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == '1')
                    {
                        sum += mas[i];
                        if (mas[i] > max) max = mas[i];
                        if (mas[i] < min) min = mas[i];
                    }
                }
                if (sum >= l && sum <= r && max - min >= x) ans++;
            }
        }

        private static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(s[0]);
             l = Convert.ToInt32(s[1]);
             r = Convert.ToInt32(s[2]);
             x = Convert.ToInt32(s[3]);
            s = Console.ReadLine().Split(' ');
            mas= new int[n];
            for (int i = 0; i < n; i++)
            {
                mas[i] = int.Parse(s[i]);
            }
            rec(n,"");
            Console.WriteLine(  ans);
        }
    }
}


using System;
using System.IO;
using System.Text;

using System.Timers;

namespace x
{

    class Program
    {
        static bool readingFail;
        static StreamReader In = new StreamReader(Console.OpenStandardInput());
        static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput());

        static public char getchar()
        { return (char)In.Read(); }

        static public int getint()
        {
            try
            {
                int res = 0;
                bool mi = false;
                int c = In.Read();
                while (c < '0' || '9' < c) { mi = (c == '-'); c = In.Read(); }
                while ('0' <= c && c <= '9') { res = res * 10 + c - '0'; c = In.Read(); }
                return mi ? -res : res;
            }
            catch (IOException)
            {
                readingFail = true;
                return -1;
            }
        }

        static char[] c_pool = new char[105000];
        static public string getstring()
        {
            int len = 0;
            char c = getchar();
            while (c != ' ' && c != '\t' && c != '\n' && c != '\r')
            { c_pool[len++] = c; c = getchar(); }
            c_pool[len] = (char)0x0;
            string s = new string(c_pool);
            return s;
        }

        const int INF = (1 << 30) - 1;

        static int n;
        static int L, R, X;
        static int[] dif = new int[20];
        static bool[] use = new bool[20];
        static int res=0;

        static int Check()
        {
            int mx = -INF;
            int mi = INF;
            int sum = 0;
            int tot = 0;
            for (int i = 0; i < n; i++)
                if (use[i])
                {
                    if (mx < dif[i]) mx = dif[i];
                    if (mi > dif[i]) mi = dif[i];
                    sum += dif[i];
                    tot++;
                }

            //Out.WriteLine(mx.ToString() + " " + mi.ToString() + " " + sum.ToString() + " " + tot.ToString() + " " + (L <= sum && sum <= R && mx - mi >= X && tot >= 2).ToString());

            if (L <= sum && sum <= R && mx - mi >= X && tot >= 2)
                return 1;
            else
                return 0;
        }

        static void DFS(int dep)
        {
            if (dep == n)
            {
                res+=Check();
                return;
            }
            use[dep] = true;
            DFS(dep + 1);
            use[dep] = false;
            DFS(dep + 1);
        }

        static void Main()
        {
            n = getint();
            L = getint();
            R = getint();
            X = getint();
            for (int i = 0; i < n; i++)
                dif[i] = getint();

            DFS(0);

            Out.Write(res);
            Out.WriteLine("");
            Out.Flush();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static object Solve()
    {
        var n = ReadInt();
        var l = ReadInt();
        var r = ReadInt();
        var x = ReadInt();
        var a = 0;
        var c = ReadIntArray();
        for (int i = 0; i <= 1 << n; i++)
        {
            var b = new List<int>();
            for (int j = 0; j < n; j++)
            {
                if (((i >> j) & 1) != 0)
                {
                    b.Add(c[j]);
                }
            }
            if (b.Count >= 2 && l <= b.Sum() && b.Sum() <= r && b.Max() - b.Min() >= x)
            {
                a++;
            }
        }
        writer.WriteLine(a);
        return null;
    }
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        try
        {
            object result = Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            throw;
        }
        reader.Close();
        writer.Close();
    }
    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }
    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }
    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    static int Next()
    {
        int c;
        int res = 0;
        do
        {
            c = reader.Read();
            if (c == -1)
                return res;
        } while (c != '-' && (c < '0' || c > '9'));
        int sign = 1;
        if (c == '-')
        {
            sign = -1;
            c = reader.Read();
        }
        res = c - '0';
        while (true)
        {
            c = reader.Read();
            if (c < '0' || c > '9')
                return res * sign;
            res *= 10;
            res += c - '0';
        }
    }
    #endregion
}


using System;

namespace ConsoleApplication1
{
    class Program
    {

        public static long Rec(long ss, long i, long s, long l, long r, long x, long n, long[] mas, long k)
        {
            s += mas[i];
            if ((s <= r) && (s >= l) && ((mas[i] - mas[k]) >= x))
            {
                ss++;
            }
            if (s < r)
            {
                for (long j = i + 1; j < n; j++)
                {
                    ss = Rec(ss, j, s, l, r, x, n, mas, k);
                }
            }
            return ss;
        }
        static void Main(string[] args)
        {
            long n, l, r, x;

            string[] lines = Console.ReadLine().Split(' ');
            n = long.Parse(lines[0]);
            l = long.Parse(lines[1]);
            r = long.Parse(lines[2]);
            x = long.Parse(lines[3]);
            long[] mas;
            mas = new long[n];
            string[] lines1 = Console.ReadLine().Split(' ');
            for (long i = 0; i < n; i++)
                mas[i] = long.Parse(lines1[i]);

            for (long i = 0; i < mas.Length; i++)
            {
                for (long j = 0; j < mas.Length - 1; j++)
                {
                    if (mas[j] > mas[j + 1])
                    {
                        long z = mas[j];
                        mas[j] = mas[j + 1];
                        mas[j + 1] = z;
                    }
                }
            }
            long s = 0, ss = 0, sl = 0;
            for (long jj = 0; jj < (n - 1); jj++)
            {
                sl = Rec(0, jj, s, l, r, x, n, mas, jj);
                ss += sl;
            }
            Console.WriteLine(ss);
        }
    }
}


// Submitted by Silithus @ Macau
using System;
using System.IO;
using System.Collections.Generic;
using CCF_XOI;

namespace CodeForces
{
	class CF550B
	{
		public void Solve(XOI xoi)
		{
			int N, L, R, X, i, j, k, c, s, e, ans = 0;
			int[] C;

			N = xoi.ReadInt();
			L = xoi.ReadInt();
			R = xoi.ReadInt();
			X = xoi.ReadInt();
			C = new int[N];
			for (i = 0; i < N; i++)
				C[i] = xoi.ReadInt();

			for (i = 0; i < (1 << N); i++)
			{
				c = 0; s = Int32.MaxValue; e = Int32.MinValue;
				for (j = i, k = 0; j != 0; j >>= 1, k++)
				{
					if ((j & 0x1) != 0)
					{
						c += C[k];
						s = Math.Min(s, C[k]);
						e = Math.Max(e, C[k]);
					}
				}

				if (c >= L && c <= R && (e - s) >= X) ans++;
			}

			xoi.o.WriteLine(ans);
		}
	}

	class CodeForcesMain
	{
		static void Main(string[] args)
		{
			(new CF550B()).Solve(new XOI());
		}
	}
}

namespace CCF_XOI
{	// version 2014.06.20
	class XOI
	{
		protected StreamReader sr;
		public StreamWriter o;
		protected Queue<string> buf = new Queue<string>();
		public bool EOF = false;

		public XOI()
		{
			this.sr = new StreamReader(Console.OpenStandardInput());
			this.o = new StreamWriter(Console.OpenStandardOutput());
			this.o.AutoFlush = true;
		}

		public XOI(string in_path, string out_path)
		{
			this.sr = new StreamReader(in_path);
			this.o = new StreamWriter(out_path);
			this.o.AutoFlush = true;
		}

		public int ReadInt()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int32.Parse(s);
		}

		public long ReadLong()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int64.Parse(s);
		}

		public double ReadDouble()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Double.Parse(s, System.Globalization.CultureInfo.InvariantCulture);
		}

		public string ReadString()
		{
			string s = this.GetNext();
			return (s == null ? null : s);
		}

		public string ReadLine()
		{	// I will ignore current buffer and read a new line
			string s = "";
			while (s == "" && !this.EOF)
			{
				s = sr.ReadLine();
				this.EOF = (s == null);
			}
			return (this.EOF ? null : s);
		}

		protected string GetNext()
		{
			if (buf.Count == 0)
			{
				while (buf.Count == 0 && !this.EOF)
				{
					string s = sr.ReadLine();
					if (s == null)
						this.EOF = true;
					else
						foreach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
							buf.Enqueue(ss);
				}
			}

			return (this.EOF ? null : buf.Dequeue());
		}
	}
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N3
{
    class Program
    {
        static int[] weights;
        static int n, m, k, p, variants;
        static int[] fullComb;

        static void Main(string[] args)
        {
            //Console.Write("Введите числа n, m, k, p (через пробел): ");

            string[] conditions = Console.ReadLine().Split(' ');

            n = int.Parse(conditions[0]);
            m = int.Parse(conditions[1]);
            k = int.Parse(conditions[2]);
            p = int.Parse(conditions[3]);

            weights = new int[n];
            fullComb = new int[n];

            //Console.Write("Введите вес каждого предмета (через пробел): ");
            string[] strweights = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
                weights[i] = int.Parse(strweights[i]);

            for (int i = 1; i < n; i++)
                GetCombinations(i, n);

            for (int i = 0; i < n; i++)
                fullComb[i] = i + 1;

            variants += CheckCombination(fullComb);

           // Console.WriteLine("Количество вариантов: " + variants);
            Console.WriteLine(variants);
           // Console.ReadLine();
        }

        static void GetCombinations(int k, int n)
        {
            int[] Comb = new int[k];
            int q;

            for (int i = 0; i < k; i++)
                Comb[i] = i+1;

            q = k;

            while (q >= 1)
            {
                variants += CheckCombination(Comb);

                if (Comb[k - 1] == n)
                    q -= 1;
                else
                    q = k;

                if (q >= 1)
                    for (int j = k; j >= q; j--)
                        Comb[j - 1] = Comb[q - 1] + j - q + 1;
            }
        }

        static byte CheckCombination(int[] Comb)
        {
            int sum = 0;
            int[] temparray = new int[Comb.Length];

            for (int i = 0; i < Comb.Length; i++)
            {

                temparray[i] = weights[Comb[i]-1];
                sum += temparray[i];
            }

            Array.Sort(temparray);

            if (sum < m || sum > k)
                return 0;
            if ((temparray[temparray.Length - 1] - temparray[0]) < p)
                return 0;
            return 1;
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Preparing_Olympiad
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int l = Next();
            int r = Next();
            int x = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }
            int mask = 1 << n;

            int count = 0;
            for (int i = 1; i < mask; i++)
            {
                int sum = 0;
                int cnt = 0;
                int min = int.MaxValue;
                int max = 0;
                for (int j = 0; j < n; j++)
                {
                    if ((i & (1 << j)) != 0)
                    {
                        cnt++;
                        sum += nn[j];
                        if (min > nn[j])
                            min = nn[j];
                        if (max < nn[j])
                            max = nn[j];
                    }
                }
                if (cnt > 1 && sum >= l && sum <= r && max - min >= x)
                {
                    count++;
                }
            }

            writer.WriteLine("{0}", count);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Round306
{
    class Program
    {
        #region Common Helper

        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }

        #endregion

        #region Problem A

        private static bool ProblemAHelper(string s, string input, string reverse)
        {
            var indexAB = s.IndexOf(input, StringComparison.InvariantCulture);
            if (indexAB == -1)
                return false;
            if (indexAB == 0)
            {
                if (s.Length < 4)
                {
                    return false;
                }
                if (s.Substring(2, s.Length - 2).Contains(reverse))
                {
                    return true;
                }
            }
            else if (s.Substring(0, indexAB - 1).Contains(reverse) || s.Substring(indexAB + 2, s.Length - indexAB - 2).Contains(reverse))
            {
                return true;
            }
            return false;
        }

        private static void ProblemA()
        {
            var s = Console.ReadLine();
            if (ProblemAHelper(s, "AB", "BA") || ProblemAHelper(s, "BA", "AB"))
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
        }

        private static void TwoSubstring()
        {
            var s = Console.ReadLine();
            var subA = "AB";

            var indexA = s.IndexOf(subA, StringComparison.InvariantCulture);
            if (indexA == -1)
            {
                Console.WriteLine("NO");
                return;
            }

            var subB = "BA";
            var indexB = s.LastIndexOf(subB, StringComparison.InvariantCulture);
            if (indexB == -1)
            {
                Console.WriteLine("NO");
                return;
            }
            if (indexA + 1  < indexB)
            {
                Console.WriteLine("YES");
                return;
            }

            indexA = s.LastIndexOf(subA);
            indexB = s.IndexOf(subB);
            if (indexB + 1 < indexA)
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
        }

        private static void TwoSubstring2()
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Contains("AB") && s.Contains("BA") &&
            (s.LastIndexOf("BA", StringComparison.OrdinalIgnoreCase) - 1 > s.IndexOf("AB", StringComparison.OrdinalIgnoreCase) ||
             s.LastIndexOf("AB", StringComparison.OrdinalIgnoreCase) - 1 > s.IndexOf("BA", StringComparison.OrdinalIgnoreCase))
                ? "YES": "NO");
        }

        #endregion

        #region Problem B

        private static IEnumerable<List<int>> powerSet(IList<int> input, int n = 1)
        {
            var data = input.ToArray();
            for (var i = 0; i < ((n + 1) << data.Length); i++)
            {
                var tempList = new List<int>(n + 1);
                tempList.AddRange(data.Where((t, j) => (i >> j)%2 == 1));
                yield return tempList;
            }

        }

        private static void ProblemB()
        {
            var n = Next();
            var l = Next();
            var r = Next();
            var x = Next();
            var c = new int[n];
            for (var i = 0; i < n; i++)
                c[i] = Next();

            //reader.Close();
            var ans = 0;
            var total = 2 << (n - 1);
            for (var i = 0; i < total; i++)
            {
                var min = int.MaxValue;
                var max = 0;
                var sum = 0;
                var count = 0;
                for (var j = 0; j < n; j++)
                {
                    if ((i >> j)%2 == 1)
                    {
                        sum += c[j];
                        max = Math.Max(max, c[j]);
                        if (sum > r)
                            break;
                        min = Math.Min(min, c[j]);
                        count++;
                    }
                }
                if (count > 1 && sum <= r && sum >= l && max - min >= x)
                  ans++;
            }

            Console.WriteLine(ans);
        }

        #endregion
        static void Main(string[] args)
        {
            //ProblemA();
            //TwoSubstring();
            //TwoSubstring2();

            ProblemB();
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Round306
{
    class Program
    {
        #region Common Helper

        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }

        #endregion

        #region Problem A

        private static bool ProblemAHelper(string s, string input, string reverse)
        {
            var indexAB = s.IndexOf(input, StringComparison.InvariantCulture);
            if (indexAB == -1)
                return false;
            if (indexAB == 0)
            {
                if (s.Length < 4)
                {
                    return false;
                }
                if (s.Substring(2, s.Length - 2).Contains(reverse))
                {
                    return true;
                }
            }
            else if (s.Substring(0, indexAB - 1).Contains(reverse) || s.Substring(indexAB + 2, s.Length - indexAB - 2).Contains(reverse))
            {
                return true;
            }
            return false;
        }

        private static void ProblemA()
        {
            var s = Console.ReadLine();
            if (ProblemAHelper(s, "AB", "BA") || ProblemAHelper(s, "BA", "AB"))
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
        }

        private static void TwoSubstring()
        {
            var s = Console.ReadLine();
            var subA = "AB";

            var indexA = s.IndexOf(subA, StringComparison.InvariantCulture);
            if (indexA == -1)
            {
                Console.WriteLine("NO");
                return;
            }

            var subB = "BA";
            var indexB = s.LastIndexOf(subB, StringComparison.InvariantCulture);
            if (indexB == -1)
            {
                Console.WriteLine("NO");
                return;
            }
            if (indexA + 1  < indexB)
            {
                Console.WriteLine("YES");
                return;
            }

            indexA = s.LastIndexOf(subA);
            indexB = s.IndexOf(subB);
            if (indexB + 1 < indexA)
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
        }

        private static void TwoSubstring2()
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Contains("AB") && s.Contains("BA") &&
            (s.LastIndexOf("BA", StringComparison.OrdinalIgnoreCase) - 1 > s.IndexOf("AB", StringComparison.OrdinalIgnoreCase) ||
             s.LastIndexOf("AB", StringComparison.OrdinalIgnoreCase) - 1 > s.IndexOf("BA", StringComparison.OrdinalIgnoreCase))
                ? "YES": "NO");
        }

        #endregion

        #region Problem B

        private static IEnumerable<List<int>> powerSet(IList<int> input, int n = 1)
        {
            var data = input.ToArray();
            for (var i = 0; i < ((n + 1) << data.Length); i++)
            {
                var tempList = new List<int>(n + 1);
                tempList.AddRange(data.Where((t, j) => (i >> j)%2 == 1));
                yield return tempList;
            }

        }

        private static void ProblemB()
        {
            var n = Next();
            var l = Next();
            var r = Next();
            var x = Next();
            var c = new int[n];
            for (var i = 0; i < n; i++)
                c[i] = Next();

            //reader.Close();
            var ans = 0;
            var total = 2 << (n - 1);
            for (var i = 0; i < total; i++)
            {
                var min = int.MaxValue;
                var max = 0;
                var sum = 0;
                //var count = 0;
                for (var j = 0; j < n; j++)
                {
                    if ((i >> j)%2 == 1)
                    {
                        sum += c[j];
                        if (sum > r)
                            break;
                        max = Math.Max(max, c[j]);

                        min = Math.Min(min, c[j]);
                        //count++;
                    }
                }
                if (sum <= r && sum >= l && max - min >= x)
                  ans++;
            }

            Console.WriteLine(ans);
        }

        #endregion
        static void Main(string[] args)
        {
            //ProblemA();
            //TwoSubstring();
            //TwoSubstring2();

            ProblemB();
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;

class Program {
	static void Main(string[ ] args)
	{
		string[ ] First = Console.ReadLine( ).Trim(' ').Split(' ');
		byte	nTasks = byte.Parse(First[0]);		//	Задач для формирования билетов
		UInt64	SetMin = UInt64.Parse(First[1]),	//	Минимальная суммарная сложность задач в наборе
				SetMax = UInt64.Parse(First[2]);	//	Максимальная суммарная сложность задач в наборе
		UInt32 MinDiff = UInt32.Parse(First[3]);	//	Минимальная разница сложности между самой тяжёлой и самой лёгкой задачами в наборе

		if (nTasks < 1 || SetMin > SetMax)
		{
			Console.WriteLine(0);
			return;
		}

		string[ ] Second = Console.ReadLine( ).Trim(' ').Split(' ');
		List<UInt32> Tasks = new List<UInt32>(nTasks);
		foreach (var Cur in Second)
			Tasks.Add(UInt32.Parse(Cur));

		List<bool> Set = new List<bool>(nTasks + 1);
		Set.Add(true);
		for (byte i = 0; i < nTasks; ++i)
			Set.Add(false);

		UInt64 Answer = 0;	//	Ответ: кол-во наборов
		do
		{
			UInt64 SetSum = 0;
			byte Min = (byte)Set.IndexOf(true),
				 Max = Min,
				 nTrue = 0;		//	Кол-во задействованных в текущем наборе задач

			for (byte i = Min; i < nTasks; ++i)
				if (Set[i])
				{
					++nTrue;
					if ((SetSum += Tasks[i]) > SetMax) break;

					if (Tasks[Max] < Tasks[i]) Max = i;
					else if (Tasks[Min] > Tasks[i]) Min = i;
				}

			if (Tasks[Max] - Tasks[Min] >= MinDiff &&
				SetSum >= SetMin &&
				SetSum <= SetMax)
				++Answer;

			for (byte i = 0; i <= nTasks; ++i)
				if (Set[i] = !Set[i])
					break;
		} while (Set[nTasks] == false);

		Console.WriteLine(Answer);
	}
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace CodeforcesCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ts = Console.ReadLine().Split(' ');

            var problems = int.Parse(ts[0]);
            var min = int.Parse(ts[1]);
            var max = int.Parse(ts[2]);
            var minDelta = int.Parse(ts[3]);

            var diffs = new int[problems];
            var masks = new int[problems];

            ts = Console.ReadLine().Split(' ');

            for (var i = 0; i < problems; ++i)
            {
                diffs[i] = int.Parse(ts[i]);
                masks[i] = i == 0
                    ? BitVector32.CreateMask()
                    : BitVector32.CreateMask(masks[i - 1]);
            }

            var all = 1 << problems;
            var ways = 0;
            for (var i = 1; i < all; ++i)
            {
                var bs = new BitVector32(i);
                var totDiff = 0;
                var minDiff = int.MaxValue;
                var maxDiff = int.MinValue;
                var ok = false;
                for (var j = 0; j < problems; ++j)
                {
                    if (bs[masks[j]])
                    {
                        totDiff += diffs[j];
                        minDiff = Math.Min(minDiff, diffs[j]);
                        maxDiff = Math.Min(maxDiff, diffs[j]);
                        ok = true;
                    }
                }
                if (ok && (min <= totDiff) && (totDiff <= max) && (maxDiff - minDiff >= minDelta))
                    ++ways;
            }

            Console.WriteLine(ways);
        }
    }
}


using System;
using System.Collections.Generic;

class Program {
	static void Main(string[ ] args)
	{
		string[ ] First = Console.ReadLine( ).Split(' ');
		byte	nTasks = byte.Parse(First[0]);		//	Задач для формирования билетов
		UInt64	SetMin = UInt64.Parse(First[1]),	//	Минимальная суммарная сложность задач в наборе
				SetMax = UInt64.Parse(First[2]);	//	Максимальная суммарная сложность задач в наборе
		UInt32 MinDiff = UInt32.Parse(First[3]);	//	Минимальная разница сложности между самой тяжёлой и самой лёгкой задачами в наборе

		if (nTasks < 1 || SetMin > SetMax)
		{
			Console.WriteLine(0);
			return;
		}

		string[ ] Second = Console.ReadLine( ).Split(' ');
		List<UInt32> Tasks = new List<UInt32>( );
		foreach (var Cur in Second)
			Tasks.Add(UInt32.Parse(Cur));

		List<bool> Set = new List<bool>(nTasks + 1);
		Set.Add(true);
		for (byte i = 0; i < nTasks; ++i)
			Set.Add(false);

		UInt16 Answer = 0;	//	Ответ: кол-во наборов
		if (SetMin == 0) ++Answer;	//	Если можно взять 0 задач, то +1 способ к ответу

		do
		{
			UInt64 SetSum = 0;
			byte Min = (byte)Set.IndexOf(true),
				 Max = Min,
				 nTrue = 0;		//	Кол-во задействованных в текущем наборе задач

			for (byte i = Min; i < nTasks; ++i)
				if (Set[i])
				{
					++nTrue;
					SetSum += Tasks[i];
					if (Tasks[Max] < Tasks[i]) Max = i;
					else if (Tasks[Min] > Tasks[i]) Min = i;
				}

			if ((nTrue < 2 || Tasks[Max] - Tasks[Min] >= MinDiff) &&
				SetSum >= SetMin &&
				SetSum <= SetMax)
				++Answer;

			for (byte i = 0; i <= nTasks; ++i)
				if (Set[i] = !Set[i])
					break;
		} while (Set[nTasks] == false);

		Console.WriteLine(Answer);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            const int pow6 = 1000000;
            const int pow9 = 1000000000;
            int n, m, k, p;
            string inputStr;
            string[] input;

            do
            {
                inputStr = Console.ReadLine();
                if (string.IsNullOrEmpty(inputStr))
                    continue;
                input = inputStr.Split(' ');
                if (input.Length != 4)
                    continue;

                if (!int.TryParse(input[0], out n) || n < 1 || n > 15)
                    continue;
                if (!int.TryParse(input[1], out m) || m < 1 || m > pow9)
                    continue;
                if (!int.TryParse(input[2], out k) || k < m || k > pow9)
                    continue;
                if (!int.TryParse(input[3], out p) || p < 1 || p > pow6)
                    continue;
                break;

            } while (true);

            int[] c = new int[n];
            do
            {
                inputStr = Console.ReadLine();
                if (string.IsNullOrEmpty(inputStr))
                    continue;
                input = inputStr.Split(' ');
                if (input.Length != n)
                    continue;

                int i;
                for (i = 0; i < n; i++)
                {
                    if (!int.TryParse(input[i], out c[i]) || c[i] < 1 || c[i] > pow6)
                        break;
                }

                if (i != n)
                    continue;
                break;
            } while (true);

            int answer = 0;
            R(ref answer, c, ref m, ref k, ref p, 0, 1);

            Console.WriteLine( answer);
        }

        private static void R(ref int @out, int[] c, ref int m, ref int k, ref int p, int sIndex, int range)
        {
            if (sIndex + range == c.Length)
            {
                R(ref @out, c, ref m, ref k, ref p, 0, range + 1);
                return;
            }

            if (range > c.Length)
                return;

            int sum = 0;
            int min = c[sIndex];
            int max = c[sIndex];

            for (int i = sIndex; i < sIndex + range; i++)
            {
                sum += c[i];
                if (c[i] < min)
                    min = c[i];
                if (c[i] > max)
                    max = c[i];
            }

            if (sum <= k)
            {
                for (int i = sIndex + range; i < c.Length; i++)
                {
                    int tmpMin = min;
                    int tmpMax = max;
                    int s = sum + c[i];

                    if (c[i] < min)
                        tmpMin = c[i];
                    if (c[i] > max)
                        tmpMax = c[i];

                    if (tmpMax - tmpMin >= p)
                        if (s >= m && s <= k)
                            @out++;
                }
            }

            R(ref @out, c, ref m, ref k, ref p, sIndex + 1, range);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace CodeforcesCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ts = Console.ReadLine().Split(' ');

            var problems = int.Parse(ts[0]);
            var min = int.Parse(ts[1]);
            var max = int.Parse(ts[2]);
            var minDelta = int.Parse(ts[3]);

            var diffs = new int[problems];
            var masks = new int[problems];

            ts = Console.ReadLine().Split(' ');

            for (var i = 0; i < problems; ++i)
            {
                diffs[i] = int.Parse(ts[i]);
                masks[i] = i == 0
                    ? BitVector32.CreateMask()
                    : BitVector32.CreateMask(masks[i - 1]);
            }

            var all = 1 << problems;
            var ways = 0;
            for (var i = 1; i < all; ++i)
            {
                var bs = new BitVector32(i);
                var minDiff = int.MaxValue;
                var maxDiff = int.MinValue;
                var ok = false;
                for (var j = 0; j < problems; ++j)
                {
                    if (bs[masks[j]])
                    {
                        if (diffs[j] < min)
                            break;
                        if (diffs[j] > max)
                            break;
                        minDiff = Math.Min(minDiff, diffs[j]);
                        maxDiff = Math.Min(maxDiff, diffs[j]);
                        ok = true;
                    }
                }
                if (ok && (maxDiff - minDiff >= minDelta))
                    ++ways;
            }

            Console.WriteLine(ways);
        }
    }
}


using System;
using System.Collections.Generic;

class Program {
	static void Main(string[ ] args)
	{
		string[ ] First = Console.ReadLine( ).Trim(' ').Split(' ');
		byte	nTasks = byte.Parse(First[0]);		//	Задач для формирования билетов
		UInt64	SetMin = UInt64.Parse(First[1]),	//	Минимальная суммарная сложность задач в наборе
				SetMax = UInt64.Parse(First[2]);	//	Максимальная суммарная сложность задач в наборе
		UInt32 MinDiff = UInt32.Parse(First[3]);	//	Минимальная разница сложности между самой тяжёлой и самой лёгкой задачами в наборе

		if (nTasks < 1 || SetMin > SetMax)
		{
			Console.WriteLine(0);
			return;
		}

		string[ ] Second = Console.ReadLine( ).Trim(' ').Split(' ');
		List<UInt32> Tasks = new List<UInt32>(nTasks);
		foreach (var Cur in Second)
			Tasks.Add(UInt32.Parse(Cur));

		List<bool> Set = new List<bool>(nTasks + 1);
		Set.Add(true);
		for (byte i = 0; i < nTasks; ++i)
			Set.Add(false);

		UInt64 Answer = 0;			//	Ответ: кол-во наборов
		if (SetMin == 0) ++Answer;	//	Если можно взять 0 задач, то +1 способ к ответу

		do
		{
			UInt64 SetSum = 0;
			byte Min = (byte)Set.IndexOf(true),
				 Max = Min,
				 nTrue = 0;		//	Кол-во задействованных в текущем наборе задач

			for (byte i = Min; i < nTasks; ++i)
				if (Set[i])
				{
					++nTrue;
					SetSum += Tasks[i];
					if (Tasks[Max] < Tasks[i]) Max = i;
					else if (Tasks[Min] > Tasks[i]) Min = i;
				}

			if ((nTrue < 2 || Tasks[Max] - Tasks[Min] >= MinDiff) &&
				SetSum >= SetMin &&
				SetSum <= SetMax)
				++Answer;

			for (byte i = 0; i <= nTasks; ++i)
				if (Set[i] = !Set[i])
					break;
		} while (Set[nTasks] == false);

		Console.WriteLine(Answer);
	}
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N3
{
    class Program
    {
        static int[] weights;
        static int n, m, k, p, variants;
        static int[] fullComb;

        static void Main(string[] args)
        {
            //Console.Write("Введите числа n, m, k, p (через пробел): ");

            string[] conditions = Console.ReadLine().Split(' ');

            n = int.Parse(conditions[0]);
            m = int.Parse(conditions[1]);
            k = int.Parse(conditions[2]);
            p = int.Parse(conditions[3]);

            weights = new int[n];
            fullComb = new int[n];

            //Console.Write("Введите вес каждого предмета (через пробел): ");
            string[] strweights = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
                weights[i] = int.Parse(strweights[i]);

            for (int i = 1; i < n; i++)
                GetCombinations(i, n);

            /*for (int i = 0; i < n; i++)
                fullComb[i] = i + 1;

            variants += CheckCombination(fullComb);
            */
           // Console.WriteLine("Количество вариантов: " + variants);
            Console.WriteLine(variants);
           // Console.ReadLine();
        }

        static void GetCombinations(int k, int n)
        {
            int[] Comb = new int[k];
            int q;

            for (int i = 0; i < k; i++)
                Comb[i] = i+1;

            q = k;

            while (q >= 1)
            {
                variants += CheckCombination(Comb);

                if (Comb[k - 1] == n)
                    q -= 1;
                else
                    q = k;

                if (q >= 1)
                    for (int j = k; j >= q; j--)
                        Comb[j - 1] = Comb[q - 1] + j - q + 1;
            }
        }

        static byte CheckCombination(int[] Comb)
        {
            int sum = 0;
            int[] temparray = new int[Comb.Length];

            for (int i = 0; i < Comb.Length; i++)
            {
                temparray[i] = weights[Comb[i]-1];
                sum += temparray[i];
            }

            Array.Sort(temparray);

            if (sum < m || sum > k)
                return 0;
            if ((temparray[temparray.Length - 1] - temparray[0]) < p)
                return 0;
            return 1;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace ConsoleApplication25
{
    class Program
    {
        static void Main(string[] args)
        {

            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var n = line[0];
            var l = line[1];
            var r = line[2];
            var x = line[3];

            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int ans = 0;

            for (int i = 0; i < (1 << n); i++)
            {
                int Min = int.MaxValue;
                int Max = int.MinValue;

                int sum = 0;
                int cnt = 0;

                for (int j = 0; j < n; j++)
                {
                    if ((i >> j & 1) == 1)
                    {
                        Min = Math.Min(Min, a[j]);
                        Max = Math.Max(Max, a[j]);

                        sum += a[j];
                        cnt++;
                    }

                    if (Max - Min >= x && sum >= l && sum <= r && cnt > 1)
                        ans++;
                }
            }
            Console.WriteLine(ans);
            Console.ReadLine();

        }

        static string IntToBinaryString(int bits, bool removeTrailingZero)
        {
            var sb = new StringBuilder(8);
            for (int i = 0; i < 8; i++)
            {
                if ((bits & 0x00000001) != 0)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                bits = bits << 1;
            }
            string s = sb.ToString();
            if (removeTrailingZero)
            {
                return s.TrimStart('0');
            }
            else
            {
                return s;
            }
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            int productsCount;
            int minWeight;
            int maxWeight;
            int minDifference;
            List<int> weights = new List<int>();

            string[] inputString = Console.ReadLine().Split(' ');

            productsCount = Convert.ToInt32(inputString[0]);
            minWeight = Convert.ToInt32(inputString[1]);
            maxWeight = Convert.ToInt32(inputString[2]);
            minDifference = Convert.ToInt32(inputString[3]);

            Console.WriteLine("Введите вторую строку:");
            string[] inputWeights = Console.ReadLine().Split(' ');

            if (inputWeights.Length != productsCount)
            {
                Console.WriteLine("count weights error!!!");
                return;
            }

            for (int i = 0; i < productsCount; i++)
            {
                weights.Add(Convert.ToInt32(inputWeights[i]));
            }

            List<List<int>> productSets = CreateProductSets(weights);

            int countVar = 0;

            foreach (List<int> subset in productSets)
            {
                int totalWeight = subset.Sum();
                int heaviestItem = subset.Max();
                int easiestItem = subset.Min();
                int difference = heaviestItem - easiestItem;

                if (totalWeight >= minWeight && totalWeight <= maxWeight)
                    if (difference >= minDifference)
                        countVar++;
            }

            Console.WriteLine();
            Console.WriteLine(countVar);
            Console.ReadLine();
        }

        static List<List<int>> CreateProductSets(List<int> weights)
        {
            List<List<int>> productSets = new List<List<int>>();

            for (int i = 0; i < weights.Count; i++)
            {
                int subsetCount = productSets.Count;
                productSets.Add(new List<int> { weights[i] });

                for (int j = 0; j < subsetCount; j++)
                {
                    int[] newSubset = new int[productSets[j].Count + 1];
                    productSets[j].CopyTo(newSubset, 0);
                    newSubset[newSubset.Length - 1] = weights[i];
                    productSets.Add(newSubset.ToList());
                }
            }

            return productSets;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] info = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); //кол-во, мин.вес, макс.вес, мин.разница веса
            int[] items = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(items);

            List<int[]> combos = GetCombination(items);
            int NumOfWays = GetNumOfWays(combos, info[1], info[2], info[3]);
            Console.WriteLine(NumOfWays);
            Console.ReadLine();

        }
        static int GetNumOfWays(List<int[]> combos, int minP, int maxP, int minDifference)
        {
            int numOfWays = 0;
            foreach (int[] combo in combos.ToArray())
            {
                if(checkCombination(combo, minP, maxP, minDifference))
                    numOfWays++;
            }
            return numOfWays;
        }
        static bool checkCombination(int[] combo, int minP, int maxP, int minDifference)
        {
            if (combo.Length > 1)
            {
                //Array.Sort(combo);
                if ((combo[combo.Length - 1] - combo[0]) < minDifference)
                    return false;
            }

            int p = 0;
            foreach (int item in combo)
                p += item;

            if(p < minP ^ p > maxP)
                return false;
            return true;
        }
        static List<int[]> GetCombination(int[] items)
        {
            int countCombos = Convert.ToInt32(Math.Pow(2, items.Count())) - 1;
           // char[] mask;
            string mask;
            List<int[]> combos = new List<int[]>();
            List<int> temp = new List<int>();
            for (int i = 1; i <= countCombos; i++)
            {
                mask = Convert.ToString(i, 2);//.PadLeft(items.Count(), '0').ToArray();
                for (int j = 0; j < mask.Length; j++)
                {
                    if (mask[j] == '1')
                        temp.Add(items[mask.Length-j-1]);
                }
                if (temp.Count > 1)
                    combos.Add(temp.ToArray());
                temp.Clear();
            }
            return combos;
        }
    }
}


using System;
using System.Collections.Generic;

class Program {
	static void Main(string[ ] args)
	{
		string[ ] First = Console.ReadLine( ).Trim(' ').Split(' ');
		byte	nTasks = byte.Parse(First[0]);		//	Задач для формирования билетов
		UInt64	SetMin = UInt64.Parse(First[1]),	//	Минимальная суммарная сложность задач в наборе
				SetMax = UInt64.Parse(First[2]);	//	Максимальная суммарная сложность задач в наборе
		UInt32 MinDiff = UInt32.Parse(First[3]);	//	Минимальная разница сложности между самой тяжёлой и самой лёгкой задачами в наборе

		if (nTasks < 1 || SetMin > SetMax)
		{
			Console.WriteLine(0);
			return;
		}

		string[ ] Second = Console.ReadLine( ).Trim(' ').Split(' ');
		List<UInt32> Tasks = new List<UInt32>(nTasks);
		foreach (var Cur in Second)
			Tasks.Add(UInt32.Parse(Cur));

		List<bool> Set = new List<bool>(nTasks + 1);
		Set.Add(true);
		for (byte i = 0; i < nTasks; ++i)
			Set.Add(false);

		UInt64 Answer = 0;	//	Ответ: кол-во наборов
		do
		{
			UInt64 SetSum = 0;
			byte Min = (byte)Set.IndexOf(true),
				 Max = Min,
				 nTrue = 0;		//	Кол-во задействованных в текущем наборе задач

			for (byte i = Min; i < nTasks; ++i)
				if (Set[i])
				{
					++nTrue;
					if ((SetSum += Tasks[i]) > SetMax) break;

					if (Tasks[Max] < Tasks[i]) Max = i;
					else if (Tasks[Min] > Tasks[i]) Min = i;
				}

			if ((nTrue < 2 || Tasks[Max] - Tasks[Min] >= MinDiff) &&
				SetSum >= SetMin &&
				SetSum <= SetMax)
				++Answer;

			for (byte i = 0; i <= nTasks; ++i)
				if (Set[i] = !Set[i])
					break;
		} while (Set[nTasks] == false);

		Console.WriteLine(Answer);
	}
}


using System;
using System.Collections.Generic;

class Program {
	static void Main(string[ ] args)
	{
		string[ ] First = Console.ReadLine( ).Split(' ');
		byte	nTasks = byte.Parse(First[0]);		//	Задач для формирования билетов
		UInt64	SetMin = UInt64.Parse(First[1]),	//	Минимальная суммарная сложность задач в наборе
				SetMax = UInt64.Parse(First[2]);	//	Максимальная суммарная сложность задач в наборе
		UInt32 MinDiff = UInt32.Parse(First[3]);	//	Минимальная разница сложности между самой
													//	тяжёлой и самой лёгкой задачами в наборе

		string[ ] Second = Console.ReadLine( ).Split(' ');
		List<UInt32> Tasks = new List<UInt32>( );
		foreach (var Cur in Second)
			Tasks.Add(UInt32.Parse(Cur));

		List<bool> Set = new List<bool>(nTasks + 1);
		Set.Add(true);
		for (byte i = 0; i < nTasks; ++i)
			Set.Add(false);

		UInt16 Answer = 0;	//	Ответ: кол-во наборов
		if (SetMin == 0) ++Answer;	//	Если можно взять 0 задач, то +1 способ к ответу

		do
		{
			UInt64 SetSum = 0;
			byte Min = (byte)Set.IndexOf(true),
				 Max = Min,
				 nTrue = 0;		//	Кол-во задействованных в текущем наборе задач

			for (byte i = Min; i < nTasks; ++i)
				if (Set[i])
				{
					++nTrue;
					SetSum += Tasks[i];
					if (Tasks[Max] < Tasks[i]) Max = i;
					else if (Tasks[Min] > Tasks[i]) Min = i;
				}

			if ((nTrue < 2 || Tasks[Max] - Tasks[Min] >= MinDiff) &&
				SetSum >= SetMin &&
				SetSum <= SetMax)
				++Answer;

			for (byte i = 0; i <= nTasks; ++i)
				if (Set[i] = !Set[i])
					break;
		} while (Set[nTasks] == false);

		Console.WriteLine(Answer);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            int productsCount;
            int minWeight;
            int maxWeight;
            int minDifference;
            List<int> weights = new List<int>();

            Console.WriteLine("Введите первую строку:");
            string[] inputString = Console.ReadLine().Split(' ');

            productsCount = Convert.ToInt32(inputString[0]);
            minWeight = Convert.ToInt32(inputString[1]);
            maxWeight = Convert.ToInt32(inputString[2]);
            minDifference = Convert.ToInt32(inputString[3]);

            Console.WriteLine("Введите вторую строку:");
            string[] inputWeights = Console.ReadLine().Split(' ');

            if (inputWeights.Length != productsCount)
            {
                Console.WriteLine("count weights error!!!");
                return;
            }

            for (int i = 0; i < productsCount; i++)
            {
                weights.Add(Convert.ToInt32(inputWeights[i]));
            }

            List<List<int>> productSets = CreateProductSets(weights);

            int countVar = 0;

            foreach (List<int> subset in productSets)
            {
                int totalWeight = subset.Sum();
                int heaviestItem = subset.Max();
                int easiestItem = subset.Min();
                int difference = heaviestItem - easiestItem;

                if (totalWeight >= minWeight && totalWeight <= maxWeight)
                    if (difference >= minDifference)
                        countVar++;
            }

            Console.WriteLine();
            Console.WriteLine("Result:  " + countVar);
            Console.ReadLine();
        }

        static List<List<int>> CreateProductSets(List<int> weights)
        {
            List<List<int>> productSets = new List<List<int>>();

            for (int i = 0; i < weights.Count; i++)
            {
                int subsetCount = productSets.Count;
                productSets.Add(new List<int> { weights[i] });

                for (int j = 0; j < subsetCount; j++)
                {
                    int[] newSubset = new int[productSets[j].Count + 1];
                    productSets[j].CopyTo(newSubset, 0);
                    newSubset[newSubset.Length - 1] = weights[i];
                    productSets.Add(newSubset.ToList());
                }
            }

            return productSets;
        }
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _307b
{
    class Program
    {
        const string _inputFilename = "";
        const string _outputFilename = "";

        static void Main(string[] args)
        {

            var outputWriter = new StreamWriter(Console.OpenStandardOutput(), Encoding.Default, 1024 * 1024);

#if DEBUG
            Console.SetIn(getInput());
#else
            if (!string.IsNullOrEmpty(_inputFilename))
            {
                var inputStream = new FileStream(_inputFilename, FileMode.Open);
                outputWriter = new StreamWriter(_outputFilename, true, Encoding.Default, 1024 * 1024);

                Console.SetIn(File.OpenText(_inputFilename));
            }
#endif
            Console.SetOut(outputWriter);

            try
            {
                solution();
            }
            finally
            {
                outputWriter.Close();
            }
        }

        static void solution()
        {
            #region SOLUTION
            var a = Console.ReadLine();
            var b = Console.ReadLine();
            var c = Console.ReadLine();

            var ac = new int[26];
            var bn = new int[26];
            var cn = new int[26];

            for (int i = 0; i < a.Length; i++)
            {
                // 97
                var next = ((int)a[i]) - 97;
                ac[next]++;
            }

            for (int i = 0; i < b.Length; i++)
            {
                var next = ((int)b[i]) - 97;
                bn[next]++;
            }

            for (int i = 0; i < c.Length; i++)
            {
                var next = ((int)c[i]) - 97;
                cn[next]++;
            }

            var maxb = 0;
            var maxc = 0;
            var max = 0;
            var temp = new int[26];
            for (int i = 0; i < a.Length; i++)
            {
                var can = i * b.Length <= a.Length;
                if (!can)
                {
                    break;
                }

                for (int j = 0; j < 26; j++)
                {
                    temp[j] = ac[j] - i * bn[j];

                    if (temp[j] < 0)
                    {
                        can = false;
                        break;
                    }
                }

                if (!can)
                {
                    continue;
                }

                var cc = int.MaxValue;
                for (int j = 0; j < 26; j++)
                {
                    if (cn[j] != 0)
                    {
                        cc = Math.Min(cc, temp[j] / cn[j]);
                    }
                }

                if (cc + i > max)
                {
                    max = cc + i;
                    maxb = i;
                    maxc = cc;
                }
            }

            if (max == 0)
            {
                Console.WriteLine(a);
                return;
            }
            else
            {
                var gcan = false;
                var bcount = maxb;
                var ccount = maxc;

                for (int j = 0; j < 26; j++)
                {
                    ac[j] -= bn[j] * bcount + cn[j] * ccount;
                }

                var sb = new StringBuilder();
                for (int i = 0; i < bcount; i++)
                {
                    sb.Append(b);
                }

                for (int i = 0; i < ccount; i++)
                {
                    sb.Append(c);
                }

                for (int i = 0; i < 26; i++)
                {
                    for (int j = 0; j < ac[i]; j++)
                    {
                        sb.Append(((char)(i + 97)));
                    }
                }

                Console.WriteLine(sb.ToString());
            }

            //var l = 0;
            //var r = a.Length;
            //while (true)
            //{
            //    if (l == r)
            //    {
            //        break;
            //    }

            //    var mid = l + (r - l + 1) / 2;

            //    var gcan = false;
            //    for (int i = 0; i < mid + 1; i++)
            //    {
            //        var bcount = i;
            //        var ccount = mid - i;
            //        var can = true;
            //        for (int j = 0; j < 26; j++)
            //        {
            //            if (ac[j] - bn[j] * bcount - cn[j] * ccount < 0)
            //            {
            //                can = false;
            //                break;
            //            }
            //        }

            //        if (can)
            //        {
            //            gcan = true;
            //            break;
            //        }
            //    }

            //    if (gcan)
            //    {
            //        l = mid;
            //    }
            //    else
            //    {
            //        r = mid - 1;
            //    }
            //}

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


	using System;

	namespace Project_1
	{
		class MainClass
		{
			public static void Main(string[] args)
			{
				/*	string s;
					s = Console.ReadLine();
					string str = "hello";
					Console.WriteLine(str[0]+s);
					Console.WriteLine(Calc(3, 5));*/
				//Вводим начальные данные
				int el_count=0;//количество предметов
				int min_weight=0, max_weight=0;//минимальный и максимальный вес предметов
			int min_element=0,max_element = 0;//минимальный и максимальный вес предметов в наборе
				int diff = 0;//минимальная разница в весе между минимальным и максимальным предметами в наборе
				int count = 0;//количество возможных комбинаций
			String str,substr="1";
			//	Console.Write("Введите количество предметов: ");
				el_count = Int32.Parse(Console.ReadLine());
		//		Console.Write("Введите минимальный общий вес: ");
				min_weight = Int32.Parse(Console.ReadLine());
		//		Console.Write("Введите максимальный общий вес: ");
				max_weight = Int32.Parse(Console.ReadLine());
		//		Console.Write("Введите минимальную разницу в весе м/у самым легким и самым тяжелым предметами: ");
				diff = Int32.Parse(Console.ReadLine());
				int[] mas = new int[el_count];

                string[] lines1 = Console.ReadLine().Split(' ');

		//		Console.WriteLine("Заполните веса предметов");
				for (int i = 0; i < mas.Length; i++)
				{
			//		Console.Write("вес предмета № {0}: ",i+1);
					mas[i] = Int32.Parse(lines1[i]/*Console.ReadLine()*/);
				}
				// сортировка
				int temp=0;
				for (int i = 0; i < mas.Length - 1; i++)
				{
					for (int j = i + 1; j < mas.Length; j++)
					{
						if (mas[i] > mas[j])
						{
							temp = mas[i];
							mas[i] = mas[j];
							mas[j] = temp;
						}
					}
				}
				// вывод
				/*Console.WriteLine("Вывод отсортированного массива");
				for (int i = 0; i < mas.Length; i++)
				{
					Console.WriteLine(mas[i]);
				}*/
				//Console.ReadLine();
			temp = 0;
			for (int i = 0; i < Math.Pow(2,mas.Length); i++)
				{
					str = Convert.ToString(i, 2);
					while (str.Length < mas.Length)
						{
							str = "0" + str;
						}
				//в переменной str хранятся все возможные комбинации предметов в формате 0/1
				min_element = 0;
				max_element = 0;
				temp = 0;
				for (int j = 0; j < mas.Length; j++)
				{

					if (Convert.ToString(str[j]) == "1")
					{
						if (min_element == 0)
						{
							min_element = mas[j];
						}
						if (max_element == 0)
						{
							max_element = mas[j];
						}
						if (min_element > mas[j])
						{
							min_element = mas[j];
						}
						if (max_element < mas[j])
						{
							max_element = mas[j];
						}
						temp += mas[j];
					}
				}
				if ((max_element - min_element) >= diff && temp >= min_weight && temp <= max_weight)
				{
					count++;
				}
				//Console.WriteLine(str);
				}

			Console.WriteLine(/*"Количество возможных комбинаций: "+*/Convert.ToString(count));
			}
			static int Calc(int a, int b)
			{
				return a + b;
			}
		}
	}


program Project3;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

var
  inStr: string;
  n, i, ii, MaxCombinations, dv,j: Integer;
  m, k, p, TotalWeigth, MinWeigth, MaxWeigth, PacksCount: Integer;
  Goods: array of Integer;
  TempGoods:array of Integer;

function ExtractNextNum(s: string):string;
begin
  Result := Copy(inStr,1,Pos(' ', inStr)-1);
  Delete(inStr,1,Pos(' ', inStr));
end;

begin
  Readln(inStr);
  inStr := inStr + ' ';
  n := StrToInt(ExtractNextNum(inStr));
  m := StrToInt(ExtractNextNum(inStr));
  k := StrToInt(ExtractNextNum(inStr));
  p := StrToInt(ExtractNextNum(inStr));

  Readln(inStr);
  inStr := inStr + ' ';
  SetLength(Goods, n);
  for i:=0 to n-1 do
    begin
      Goods[i]:= StrToInt(ExtractNextNum(inStr));
    end;

  PacksCount:=0;

  MaxCombinations := Trunc(Power(2, n));// - 1; //всего вариантов получить различные наборы товаров

  for i:=1 to MaxCombinations do //
    begin
      SetLength(TempGoods,0);
      //заполняем массив следующей комбинацией товаров
      //используем i как двоичную маску отбора элементов в массиве товаров
 //  for ii:=0 to n-1 do
    dv:=i;
	ii:=0 ;
	while (dv>0) do
	begin
	      if((dv mod 2)=1) then

      //   if ( (i and Trunc(Power(2,ii))) = (Trunc(Power(2,ii))) ) then
		  begin
		     SetLength(TempGoods,Length(TempGoods)+1);
             TempGoods[Length(TempGoods)-1]:=Goods[ii];
            end;
		     dv := dv div 2;
			 ii:=ii+1;
        end;

      if Length(TempGoods)<2 then Continue;//набор из 1 товара сразу нет

      TotalWeigth := 0;
      MinWeigth:=TempGoods[0];
      MaxWeigth:=TempGoods[0];

      for ii:=0 to Length(TempGoods)-1 do
       begin
         TotalWeigth:=TotalWeigth + TempGoods[ii];
         if MinWeigth > TempGoods[ii] then MinWeigth:= TempGoods[ii];
         if MaxWeigth < TempGoods[ii] then MaxWeigth:= TempGoods[ii];
       end;

      if ((TotalWeigth < m) or (TotalWeigth > k)) then Continue; //условие суммарного веса
      if ((MaxWeigth - MinWeigth) < p) then Continue;  //условие разницы крайних весов

      Inc(PacksCount);//условия подошли - берем как вариант пачки товаров

     end;

  Writeln(inttostr(PacksCount));
 // readln;

end.


using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
using System.Numerics;

class Solution
{
     public class GCD
    {
		public static int Euclidean(int n1, int n2)
		{
			if (n1 == n2) return n1;
			else if (n1 < n2)
			{
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}

			while (n1 % n2 > 0)
			{
				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;
			}
			return n2;
		}
        public static ulong Euclidean(ulong n1, ulong n2)
		{
			if (n1 == n2) return n1;
			else if (n1 < n2)
			{
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}

			while (n1 % n2 > 0)
			{
				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;
			}
			return n2;
		}

          public static long Inverse(long a, long n)
		{
            long x, y =0;
            EuclideanExt(a, n, out x, out y);
            return x<0?n+x:x;
        }

        public static long EuclideanExt(long n1, long n2, out long x, out long y)
		{
            x = 0;
            y = 1;

            bool r = false;
			if (n1 == n2) return n1;

			else if (n1 < n2)
			{
                r = true;
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}
            long q = 0;
            long xl =1;
            long yl = 0;

			while (n2 > 0)
			{
                q = n1 / n2;

				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;

                tmp = x;
                x = xl - q *x;
                xl = tmp ;

                tmp = y;
                y = yl - q*y;
                yl = tmp;

			}
            x = xl;
            y = yl;
            if (r)
            {
                x =yl;
                y =xl;
            }
			return x*n1+y*n2;
		}
	}
    static Tuple<ulong, ulong> sum(Tuple<ulong, ulong> a, Tuple<ulong, ulong> b)
    {
        if (a.Item1 == 0)
            return b;
        if(b.Item1 == 0)
            return a;
        return Tuple.Create(
            ((a.Item1 * b.Item2) % mod + (b.Item1 * a.Item2) % mod) % mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<ulong, ulong> prod(Tuple<ulong, ulong> a, Tuple<uint, uint> b)
    {
        return Tuple.Create(
            (a.Item1 * b.Item1) %mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<uint, uint> PInOneSide(uint cnt, uint totalcnt)
    {
        return Tuple.Create(
            cnt * (cnt - 1) + (totalcnt - cnt) * (totalcnt - cnt - 1),
            totalcnt * (totalcnt - 1)
        );
    }

    static Tuple<uint, uint> PIncreaseLeftA(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
             (leftCnt - leftACnt) * (leftCnt - leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static Tuple<uint, uint> PDecreaseLeftA(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
            leftACnt * (totalcnt - 2 * leftCnt + leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static Tuple<uint, uint> PSameInBothSide(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
             (leftCnt - leftACnt) * (totalcnt + 2 * leftACnt - 2 * leftCnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    const ulong mod = 1000000007L;
    static void Main(string[] args)
    {

        // var n = int.Parse( Console.ReadLine());
        var tmp = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToUInt64);
        var n = (uint)tmp[0];
        var k = tmp[1];

        var arr = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToByte);

        var leftcnt = (uint)arr.Count(el=>el==0);
        var leftAcnt = (uint)arr.Where((el, i)=>el == 0 && i<leftcnt ).Count();
        if (k < (leftcnt - leftAcnt))
        {
            Console.WriteLine("0");
            return;
        }
        if (leftcnt == n || leftcnt ==0)
        {
            Console.WriteLine("1");
            return;
        }

        var lowerBnd = Math.Max((uint)0, 2*leftcnt - n);
        Tuple<ulong, ulong>[] F =Enumerable.Repeat(0, (int)(leftcnt - lowerBnd+1))
        .Select(el =>new Tuple<ulong,ulong>(0, 0)).ToArray();

        F[leftAcnt - lowerBnd] = Tuple.Create(1ul,1ul);
        for(ulong j = 0; j < k; j++)
        {
            Tuple<ulong, ulong>[] Ftmp = new Tuple<ulong, ulong>[leftcnt - lowerBnd+1];

            for(uint i =0; i <= leftcnt - lowerBnd; i++)
            {

                var res = prod(F[i], PInOneSide(leftcnt, n));
                res = sum(res,prod(F[i], PSameInBothSide(leftcnt, i+lowerBnd , n)));
                if (i > 0)
                    res = sum(res,prod(F[i - 1], PIncreaseLeftA(leftcnt, i+lowerBnd -1 , n)));
                if (i < leftcnt - lowerBnd)
                    res = sum(res,prod(F[i + 1], PDecreaseLeftA(leftcnt, i+lowerBnd + 1 , n)));
                Ftmp[i] = res;
            }
            F = Ftmp;
        }
        var gcd = GCD.Euclidean(F.Last().Item1, F.Last().Item2);
        var ret = Tuple.Create(F.Last().Item1 / gcd, F.Last().Item2 / gcd);

        var ret2 = ((long)ret.Item1 * GCD.Inverse((long)ret.Item2, (long)mod )) % (long)mod;

        Console.WriteLine($"{ret2}");

    }
}


using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
using System.Numerics;

class Solution
{
     public class GCD
    {
		public static int Euclidean(int n1, int n2)
		{
			if (n1 == n2) return n1;
			else if (n1 < n2)
			{
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}

			while (n1 % n2 > 0)
			{
				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;
			}
			return n2;
		}
        public static ulong Euclidean(ulong n1, ulong n2)
		{
			if (n1 == n2) return n1;
			else if (n1 < n2)
			{
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}

			while (n1 % n2 > 0)
			{
				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;
			}
			return n2;
		}

          public static long Inverse(long a, long n)
		{
            long x, y =0;
            EuclideanExt(a, n, out x, out y);
            return x<0?n+x:x;
        }

        public static long EuclideanExt(long n1, long n2, out long x, out long y)
		{
            x = 0;
            y = 1;

            bool r = false;
			if (n1 == n2) return n1;

			else if (n1 < n2)
			{
                r = true;
				var tmp = n1;
				n1 = n2;
				n2 = tmp;
			}
            long q = 0;
            long xl =1;
            long yl = 0;

			while (n2 > 0)
			{
                q = n1 / n2;

				var tmp = n2;
				n2 = n1 % n2;
				n1 = tmp;

                tmp = x;
                x = xl - q *x;
                xl = tmp ;

                tmp = y;
                y = yl - q*y;
                yl = tmp;

			}
            x = xl;
            y = yl;
            if (r)
            {
                x =yl;
                y =xl;
            }
			return x*n1+y*n2;
		}
	}
    static Tuple<ulong, ulong> sum(Tuple<ulong, ulong> a, Tuple<ulong, ulong> b)
    {
        if (a.Item1 == 0)
            return b;
        if(b.Item1 == 0)
            return a;
        return Tuple.Create(
            ((a.Item1 * b.Item2) % mod + (b.Item1 * a.Item2) % mod) % mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<ulong, ulong> prod(Tuple<ulong, ulong> a, Tuple<uint, uint> b)
    {
        return Tuple.Create(
            (a.Item1 * b.Item1) %mod,
            (a.Item2 * b.Item2) % mod
        );
    }

    static Tuple<uint, uint> PInOneSide(uint cnt, uint totalcnt)
    {
        return Tuple.Create(
            cnt * (cnt - 1) + (totalcnt - cnt) * (totalcnt - cnt - 1),
            totalcnt * (totalcnt - 1)
        );
    }

    static Tuple<uint, uint> PIncreaseLeftA(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
             (leftCnt - leftACnt) * (leftCnt - leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static Tuple<uint, uint> PDecreaseLeftA(uint leftCnt, uint leftACnt, uint totalcnt)
    {
        return Tuple.Create(
            leftACnt * (totalcnt - 2 * leftCnt + leftACnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    static void CalcCashe(uint lowerBnd, uint leftCnt, uint totalcnt)
    {
        PInOneSideCache = PInOneSide(leftCnt, totalcnt);

        PIncreaseLeftACache = new Tuple<uint, uint>[leftCnt - lowerBnd + 1];
        PDecreaseLeftACache = new Tuple<uint, uint>[leftCnt - lowerBnd + 1];
        PSameInBothSideCache = new Tuple<uint, uint>[leftCnt - lowerBnd + 1];

        for(uint i =lowerBnd; i <= leftCnt; i++)
        {
            PIncreaseLeftACache[(int)(i - lowerBnd)] = PIncreaseLeftA(leftCnt, i, totalcnt);
            PDecreaseLeftACache[(int)(i - lowerBnd)] = PDecreaseLeftA(leftCnt, i, totalcnt);
            PSameInBothSideCache[(int)(i - lowerBnd)] = PSameInBothSide(leftCnt, i, totalcnt);
        }
    }
    static Tuple<uint, uint> PInOneSideCache;
    static Tuple<uint, uint>[] PSameInBothSideCache;
    static Tuple<uint, uint>[] PIncreaseLeftACache;
    static Tuple<uint, uint>[] PDecreaseLeftACache;
    static Tuple<uint, uint> PSameInBothSide(uint leftCnt, uint leftACnt, uint totalcnt)
    {

        return Tuple.Create(
             (leftCnt - leftACnt) * (totalcnt + 2 * leftACnt - 2 * leftCnt),
            (totalcnt * (totalcnt - 1)) / 2
        );
    }

    const ulong mod = 1000000007L;
    static void Main(string[] args)
    {

        // var n = int.Parse( Console.ReadLine());
        var tmp = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToUInt64);
        var n = (uint)tmp[0];
        var k = tmp[1];

        var arr = Array.ConvertAll(Console.ReadLine().Trim().Split(), Convert.ToByte);

        var leftcnt = (uint)arr.Count(el=>el==0);
        var leftAcnt = (uint)arr.Where((el, i)=>el == 0 && i<leftcnt ).Count();
        if (k < (leftcnt - leftAcnt))
        {
            Console.WriteLine("0");
            return;
        }
        if (leftcnt == n || leftcnt ==0)
        {
            Console.WriteLine("1");
            return;
        }

        var lowerBnd = Math.Max((uint)0, 2*leftcnt - n);
        Tuple<ulong, ulong>[] F =Enumerable.Repeat(0, (int)(leftcnt - lowerBnd+1))
        .Select(el =>new Tuple<ulong,ulong>(0, 0)).ToArray();

        F[leftAcnt - lowerBnd] = Tuple.Create(1ul,1ul);

        CalcCashe(lowerBnd,leftcnt, n);

        for(ulong j = 0; j < k; j++)
        {
            Tuple<ulong, ulong>[] Ftmp = new Tuple<ulong, ulong>[leftcnt - lowerBnd+1];

            for(uint i =0; i <= leftcnt - lowerBnd; i++)
            {

                var res = prod(F[i], PInOneSideCache);
                res = sum(res,prod(F[i], PSameInBothSideCache[i]));
                if (i > 0)
                    res = sum(res,prod(F[i - 1], PIncreaseLeftACache[i-1]));
                if (i < leftcnt - lowerBnd)
                    res = sum(res,prod(F[i + 1], PDecreaseLeftACache[i+1]));
                Ftmp[i] = res;
            }
            F = Ftmp;
        }
        if (F.Last().Item1 ==0)
        {
            Console.WriteLine("0");
            return;
        }
        var gcd = GCD.Euclidean(F.Last().Item1, F.Last().Item2);
        var ret = Tuple.Create(F.Last().Item1 / gcd, F.Last().Item2 / gcd);

        var ret2 = ((long)ret.Item1 * GCD.Inverse((long)ret.Item2, (long)mod )) % (long)mod;

        Console.WriteLine($"{ret2}");

    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int64;
using N = Number;
namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			//
			//dp[i,a,b] = i 回操作したあと、0 が来るべき箇所にある 1 の個数、1 が来るべき箇所にある 0 の個数
			//dp[i+1,a-1,b-1]+=dp[i,a,b]*a*b/n^2;
			//dp[i+1,a,b]+=dp[i,a,b]*(A*A+B*B + a*(B-b) + b*(A-a))/n^2
			//dp[i+1,a+1,b+1]+=dp[i,a,b]*(A-a)*(B-b)/n^2

			var n = ri; var k = ri;
			var A = Enumerate(n, x => ri);
			var K = n - A.Sum();
			var M = n - K;
			var B = Enumerate(n, x => x < K ? 0 : 1);
			var p = Enumerate(n, x => x).Count(x => A[x] != B[x]) / 2;
			var coef = ModInt.Inverse(n * (n - 1) / 2);
			var mat = new Matrix(n + 1, n + 1);
			//mat[i,j] = j->i
			for (int j = 0; j <= n; j++) {
				if (j != 0) mat[j - 1, j] += j * j * coef.num;
				mat[j, j] += (K * (K - 1) / 2 + M * (M - 1) / 2 + j * (M - j) + j * (K - j)) * coef.num;
				if (j != n) mat[j + 1, j] += (K - j) * (M - j) * coef.num;
			}
			for (int i = 0; i <= n; i++)
				for (int j = 0; j <= n; j++)
					mat[i, j] %= ModInt.Mod;
			var res = Matrix.Pow(mat, k);
			var vec = new Matrix(n + 1, 1); vec[p, 0] = 1;
			var ans = (res * vec)[0, 0];
			Console.WriteLine(ans);
		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < a.Length; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		//Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion

#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
	/// <summary>
	/// 剰余を取る値．
	/// </summary>
	public const long Mod = (int)1e9 + 7;

	/// <summary>
	/// 実際の数値．
	/// </summary>
	public long num;
	/// <summary>
	/// 値が <paramref name="n"/> であるようなインスタンスを構築します．
	/// </summary>
	/// <param name="n">インスタンスが持つ値</param>
	/// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
	public ModInt(long n) { num = n; }
	/// <summary>
	/// このインスタンスの数値を文字列に変換します．
	/// </summary>
	/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
	public override string ToString() { return num.ToString(); }
	public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
	public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
	public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
	public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

	/// <summary>
	/// 与えられた 2 つの数値からべき剰余を計算します．
	/// </summary>
	/// <param name="v">べき乗の底</param>
	/// <param name="k">べき指数</param>
	/// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
	public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

	/// <summary>
	/// 与えられた 2 つの数値からべき剰余を計算します．
	/// </summary>
	/// <param name="v">べき乗の底</param>
	/// <param name="k">べき指数</param>
	/// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
	public static ModInt Pow(long v, long k) {
		long ret = 1;
		for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
			if ((k & 1) == 1) ret = ret * v % Mod;
		return new ModInt(ret);
	}
	/// <summary>
	/// 与えられた数の逆元を計算します．
	/// </summary>
	/// <param name="v">逆元を取る対象となる数</param>
	/// <returns>逆元となるような値</returns>
	/// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
	public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion

#region Matrix
public class Matrix {
	int row, col;
	public N[] mat;
	/// <summary>
	/// <paramref name="r"/> 行 <paramref name="c"/> 列目の要素へのアクセスを提供します。
	/// </summary>
	/// <param name="r">行の番号</param>
	/// <param name="c">列の番号</param>
	public N this[int r, int c] {
		get { return mat[r * col + c]; }
		set { mat[r * col + c] = value; }
	}
	public Matrix(int r, int c) {
		row = r; col = c;
		mat = new N[row * col];
	}
	public static Matrix operator *(Matrix l, Matrix r) {
		System.Diagnostics.Debug.Assert(l.col == r.row);
		var ret = new Matrix(l.row, r.col);
		for (int i = 0; i < l.row; i++)
			for (int k = 0; k < l.col; k++)
				for (int j = 0; j < r.col; j++)
					ret.mat[i * r.col + j] = (ret.mat[i * r.col + j] + l.mat[i * l.col + k] * r.mat[k * r.col + j]) % ModInt.Mod;
		return ret;
	}
	/// <summary>
	/// <paramref name="m"/>^<paramref name="n"/> を O(<paramref name="m"/>^3 log <paramref name="n"/>) で計算します。
	/// </summary>
	public static Matrix Pow(Matrix m, long n) {
		var ret = new Matrix(m.row, m.col);
		for (int i = 0; i < m.row; i++)
			ret.mat[i * m.col + i] = 1;
		for (; n > 0; m *= m, n >>= 1)
			if ((n & 1) == 1)
				ret = ret * m;
		return ret;

	}
	public N[][] Items {
		get {
			var a = new N[row][];
			for (int i = 0; i < row; i++) {
				a[i] = new N[col];
				for (int j = 0; j < col; j++)
					a[i][j] = mat[i * col + j];
			}
			return a;
		}
	}
}
#endregion