Under construction

Still being built. Things may change

Lower Algorithmics

Time limit4sMemory limit512 MB

Summary
Count the distinct positive integers that can be written as a sum of between l and r elements of set A, with repetition allowed.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

You are given a set AA of integers from 11 to 10001000 inclusive. Your task is to find the number of positive integers that can be represented as a sum of several elements of AA, with number of summands being from ℓ\ell to rr inclusive. Equal summands are allowed. Note that each number is counted only once, even if it has several such representations.

Input

The first line of the input contains three space-separated integers: nn, the number of elements in AA (1≤n≤10001 \leq n \leq 1000), followed by ℓ\ell and rr, the bounds on number of summands (1≤ℓ≤r≤20001 \leq \ell \leq r \leq 2000). The second line contains nn space-separated integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_1<a_2<…<a_n≤10001 \leq a\_1 < a\_2 < \ldots < a\_n \leq 1000): the elements of the set AA in increasing order.

Output

Output the number of integers that are representable as a sum of elements of AA, with number of summands being between ℓ\ell and rr.

Examples3

  1. Example 1

    Input
    2 1 2
    1 2
    
    Expected output
    4
    
  2. Example 2

    Input
    3 1 3
    1 3 10
    
    Expected output
    18
    
  3. Example 3

    Input
    6 3 5
    1 2 3 4 5 6
    
    Expected output
    28