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
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#define _CRT_SECURE_NO_WARNINGS
#define ONLINE_JUDGE
#include <iostream>
#include <cstdio>
#include <vector>
#include <cassert>
#include <algorithm>
#include <map>
using namespace std;

#define REP(i,n) for(int _n=(n), i=0;i<_n;++i)

typedef vector<int> VI;
typedef long long LL;

const LL Modulo = 1e9 + 7;

int power2modulo(int exponent, LL modulo)
{
    LL result = 1;
    LL power = 2;

    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * power) % modulo;

        power = (power * power) % modulo;
        exponent /= 2;
    }

    return result;
}

class Solver
{
public:
    static int solve(VI& numbers)
    {
        map<int, int> allPossibleSum;
        allPossibleSum[0] = 1;
        sort(numbers.begin(), numbers.end());

        for (auto n : numbers)
        {
            map<int, int> newSum = allPossibleSum;
            for (map<int, int>::reverse_iterator it = allPossibleSum.rbegin(); it != allPossibleSum.rend(); ++it)
            {
                const int i = it->first;
                if (i < n - 1)
                    break;
                const int  xxxx = it->second;
                newSum[i + n] = (newSum[i + n] + it->second) % Modulo;
            }

            allPossibleSum = newSum;
        }

        int result = 0;
        for (map<int, int>::iterator it = allPossibleSum.begin(); it != allPossibleSum.end(); ++it)
            result = (result + it->second) % Modulo;

        return (result + (Modulo - 1)) % Modulo;
    }
};

VI readNumbers()
{
    int n;
    scanf("%d", &n);
    VI result(n);

    for (int i = 0; i < result.size(); ++i)
    {
        scanf("%d", &n);
        result[i] = n;
    }

    return result;
}

int main()
{
    VI numbers;
    Solver solver;
#ifndef ONLINE_JUDGE
    numbers = VI{ 2, 7, 4, 4, 1 };
    assert(solver.solve(numbers) == 8);

    numbers = VI{ 1 };
    assert(solver.solve(numbers) == 1);

    for (int i = 2; i <= 100; ++i)
    {
        numbers = VI{ i };
        assert(solver.solve(numbers) == 0);
    }

    numbers = VI{ 1, 1 };
    assert(solver.solve(numbers) == 3);

    numbers = VI{ 1, 2 };
    assert(solver.solve(numbers) == 2);

    for (int i = 3; i <= 100; ++i)
    {
        numbers = VI{ 1, i };
        assert(solver.solve(numbers) == 1);
    }

    numbers = VI{ 2, 3 };
    assert(solver.solve(numbers) == 0);

    for (int size = 3; size <= 50; ++size)
    {
        numbers = VI(size, 1);
        const int expectedAnswer = (power2modulo(size, Modulo) + (Modulo - 1)) % Modulo;
        assert(solver.solve(numbers) == expectedAnswer);
    }

    numbers = VI{ 1, 2, 3 };
    assert(solver.solve(numbers) == 3);

    numbers = VI{ 1, 1, 2, 3 };
    assert(solver.solve(numbers) == 10);

    numbers = VI{ 1,2,2,4,5,6 };
    assert(solver.solve(numbers) == 19);

    numbers = VI{ 1,2,2,4,5 };
    assert(solver.solve(numbers) == 11);

    numbers = VI{ 1,2,2,4 };
    assert(solver.solve(numbers) == 7);

    printf("Tests finished.\n");
#endif
    numbers = readNumbers();
    printf("%d\n", solver.solve(numbers));
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}