1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, i, sum = 0;
    map<int, int>::iterator k;
    cin >> n;

    int* entries = new int[n]();
    map<int, int> sets;

    for (i = 0; i < n; i++)
    {
        cin >> entries[i];
    }

    sort(entries, entries + n);
    vector<pair<int, int>> toAdd;

    int largest = 0, newLargest = 0;

    if (entries[0] == 1)
    {
        sets.insert(sets.begin(), { 1, 1 });
    }
    else
    {
        cout << 0 << '\n';
        return 0;
    }

    for (i = 1; i < n; i++)
    {
        for (k = sets.lower_bound(entries[i] - 1); k != sets.end(); k++)
        {
            toAdd.push_back({ k->first + entries[i], k->second });
        }

        for (auto it : toAdd)
        {
            sets[it.first] += it.second;
            if (sets[it.first] >= 1000000007) sets[it.first] -= 1000000007;
            if (sum + it.second >= 1000000007) sum -= 1000000007;
            sum += it.second;
        }

        toAdd.clear();
    }

    cout << sum + 1 << '\n';
}