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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define MOD 1000000007;

int main(){

  int n;
  long long powers[5001] = {0};
  powers[0] = 1;
  for(int i = 1; i < 5001; i++){
    powers[i] = (powers[i - 1] * 2) % MOD;
  }


  cin >> n;
  vector<int> numbs;
  for(int i = 0; i < n ;i ++){
    int tmp;
    cin >> tmp;
    numbs.push_back(tmp);
  }

  sort(numbs.begin(), numbs.end());
  long long ret = 0;
  long long sum_counts[5001] = {0};
  for(int i = 0; i < numbs.size(); i ++){
     for(int j = 5000; j >= 0; j--) {
      if(j + 1 >= numbs[i] and j + numbs[i] < 5001){
        sum_counts[j + numbs[i]] += sum_counts[j];
      } else if (j + 1 >= numbs[i] and j + numbs[i] >= 5001){
        long long curAdd = sum_counts[j];
        curAdd *= powers[numbs.size() - i - 1];
        curAdd %= MOD;
        ret += curAdd;
        ret %= MOD;
      }
    }
    if(numbs[i] == 1){
      sum_counts[numbs[i]] ++;
    }
  }
  for(auto a: sum_counts){
    ret += a;
    ret %= MOD;
  }
  cout << ret << endl;
}