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
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class kie {

    public static void main(String[] args) {
        //long startTime = System.currentTimeMillis();

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long sum = 0;

        List<Integer> data = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            int number = scanner.nextInt();
            if (number % 2 == 0) {
                sum += number;
            } else {
                data.add(number);
                if (data.size() != 3)
                    continue;

                int a = data.get(0);
                int b = data.get(1);
                int c = data.get(2);
                data.clear();
                if (a <= b && a <= c) {
                    sum += b + c;
                    data.add(a);
                } else if (b <= a && b <= c) {
                    sum += a + c;
                    data.add(b);
                } else {
                    sum += a + b;
                    data.add(c);
                }
            }
        }

        if (data.size() == 2)
            sum += data.get(0) + data.get(1);

        if (sum == 0)
            System.out.println("NIESTETY");
        else
            System.out.println(sum);

        //long endTime = System.currentTimeMillis();
        //System.err.println(endTime - startTime);
    }
}