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

int n, val, last, cnt, x;
vector<int> v;

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> x;
		if(!(x&1))val+=x;
		else
		{
			cnt++;
			
			if(cnt == 1)last = x;
			if(!(cnt&1))
			{
				val += last + x;
//				cout << "Wrzucam parę: " << last << ' ' << x << "\n";
				if(last > x)last = x;		
			}	
			else
			{
				if(x > last) 
				{
					val = val - last + x;
//					cout << "Wywalam: " << last << " wrzucam " << x << "\n"; 
				}
				else if(x < last)
				{
//					cout << "New last: " << x << " old " << last << '\n';
					last = x;
				}
			}	
		}
	}
	if(val == 0)cout << "NIESTETY\n";
	else cout << val << endl;
}