#P9102. [PA 2020] Cukierki

[PA 2020] Cukierki

Problem Description

This problem is translated from PA 2020 Round 5 Cukierki.

Bytie is going to Bitek’s birthday party. He knows that Bitek likes sweets, so he wants to give him some candies as a gift. He bought nn bags of candies, and the ii-th bag contains aia_i candies.

However, these candies are quite heavy, and Bytie wants to know whether he needs to give all of them to Bitek. He decides that he will choose a non-empty subset of the bags, take them to Bitek, and say: “I have a total of xx candies here, how many do you want?”, where xx is the total number of candies in the bags brought to the party. After hearing this, Bitek may choose any integer yy in the range [1,x][1, x]. No matter what Bitek answers, Bytie wants to be able to select some of the bags he brought (and keep the rest for himself) so that the total number of candies in the selected bags is exactly yy. Of course, he cannot tear the wrappers—giving loose candies is impolite.

Therefore, Bytie is thinking: how many different non-empty subsets of bags can he bring so that, regardless of Bitek’s choice, he can give him the desired number of candies? Please help him compute this. Since the number of such subsets may be very large, output it modulo 109+710^9+7.

Input Format

The first line contains an integer nn, the number of candy bags Bytie has.

The second line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n, where aia_i is the number of candies in the ii-th bag.

Output Format

Output the number of possible subsets of candy bags modulo 109+710^9+7.

5
2 7 4 4 1
8

Hint

Explanation for Sample 1

Bytie can bring 88 non-empty subsets: $\{5\}, \{1, 5\}, \{1, 3, 5\}, \{1, 4, 5\}, \{1, 3, 4, 5\}, \{1, 2, 3, 5\}, \{1, 2, 4, 5\}$, and {1,2,3,4,5}\{1, 2, 3, 4, 5\}. For example, if Bytie brings the subset {1,2,4,5}\{1,2,4,5\} and Bitek wants 99 candies, then Bytie can only give him bags 11 and 22. Bytie cannot bring the subset {1,2,5}\{1,2,5\}, because if Bitek wants 66 candies then Bytie would not be able to satisfy him.


Constraints

This problem uses bundled testdata.

For 100%100\% of the testdata, it is guaranteed that 1n5×1031\le n\le 5\times 10^3 and 1ai5×1031\le a_i\le 5\times 10^3.

Translated by ChatGPT 5