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
#include<bits/stdc++.h>
#define N 1000000
using namespace std;

int ilosc, act, maxnp, np;
long long suma;
priority_queue <int> kol;


int main() {
	scanf("%d", &ilosc);
	if (ilosc == 1) { 
		cin >> np;
		if (np % 2 == 1) {
			printf("NIESTETY");
			return 0;
		}
		if (np % 2 == 0) {
			printf("%d", np);
			return 0;
		}
	}
	for (int i = 0; i < ilosc; i++) {
		cin >> act;
		if (act % 2 == 0) suma = suma + act;
		if (act % 2 == 1) kol.push(act);
	}
	
	
	int dl=kol.size();
	for (int i = 0; i < dl; i++) {
		maxnp = maxnp + kol.top();
		kol.pop();
		np++;
		if (np % 2 == 0) {
			suma = suma + maxnp; maxnp = 0;
		}
	}
	printf("%lld", suma);
	return 0;
}