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
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

const int mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int sum = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	if (a[0] != 1) {
		cout << "0\n";
		return 0;
	}
	long long ans = 0;
	int cur = 0, num = 0, count = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] <= cur + 1) {
			ans++;
			ans %= mod;
			cur += a[i];
			if (num == a[i]) {
				count++;
			}
			else {		
				ans += pow(2, count) - 1;
				ans %= mod;
				if (count > 1) ans -= count;
				ans %= mod;
				count = 1;
				num = a[i];
			}
		}
		else {
			break;
		}
	}
	cout << ans << "\n";
	

	return 0;
}