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 <bits/stdc++.h>
using namespace std;
int ile[5002], ilezakres[100];
// 2 do n  => 1 << n;
int main() {
//ios_base::sync_with_stdio(0);
int i, j, a, n, pot = 1, s= 0,koniec;
long long wyn = 0, mnoznik = 1, pierwsza = 1000000000 + 7,temp,koniecilezakres;
cin >> n;
for(i = 0; i < n; i++){
	cin >> a;
	ile[a]++;
}
if(n == 1 && ile[1] == 1) {
	cout << 1;
	return 0;
}
i = 2; s= ile[1];
while(i < 5001 ){
	if(s >= i - 1) {
		koniec = i - 1 ;
		s = s + i*ile[i];
		i++;
		//cout << "suma " << s << endl;
	}
	else break;
}
j= 0;
//cout << "koniec "<< koniec << endl;
for(i = 1; i <= koniec; i++){
	if(i <= pot) {
		ilezakres[j] += ile[i];		
	}
	else {
		j++;
		ilezakres[j] += ile[i];	
		pot *= 2;
	}
}
koniecilezakres = j;
//for(i = 0;i < koniecilezakres;i++) cout << (1 << i) <<" " <<ilezakres[i] << endl;

for(i = 0; i < koniecilezakres; i++){
	if(ilezakres[i]> 0) {
		mnoznik *= (1 << ilezakres[i]) - 1;
		mnoznik = mnoznik % pierwsza;
		wyn += mnoznik;
		wyn = wyn % pierwsza;
	}
	
}
cout << wyn;
	return 0;
}