SUBSUMS - Subset Sums

Given a sequence of N (1 ≤ N ≤ 34) numbers S1, ..., SN (-20,000,000 ≤ Si ≤ 20,000,000), determine how many subsets of S (including the empty one) have a sum between A and B (-500,000,000 ≤ A ≤ B ≤ 500,000,000), inclusive.

Input

The first line of standard input contains the three integers N, A, and B. The following N lines contain S1 through SN, in order.

Output

Print a single integer to standard output representing the number of subsets satisfying the above property. Note that the answer may overflow a 32-bit integer.

Example

Input:
3 -1 2
1
-2
3

Output:
5

The following 5 subsets have a sum between -1 and 2:

  • 0 = 0 (the empty subset)
  • 1 = 1
  • 1 + (-2) = -1
  • -2 + 3 = 1
  • 1 + (-2) + 3 = 2

Added by:Neal Wu
Date:2009-01-19
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO

hide comments
2016-01-25 11:09:41 minhthai
very nice question :D
2015-12-29 19:25:26 GAURAV CHANDEL
Cool ... very cool....
2015-10-20 20:22:33
A great question....indeed bitmask + binary search :D
2015-06-19 16:04:53 karan
nice problem :)
2015-05-24 16:58:18 i_am_looser
Finally AC.............. ; )
2015-05-24 15:17:35 prateek goyal
\m| 100th on spoj feeling relaxed :)
2015-02-13 03:30:19 Rocker3011
finally did this problem, it took me 2 years of training to be able to solve it with ease, :)
2014-12-29 15:45:54 ashish kumar
wrong ans on 15th testcase
2014-08-14 13:27:08 Archit Jain
nice concept
2014-08-12 05:37:30 selfcompiler
:D it gives TLE ,use Fast Fourier Transformation :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.