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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.*;

public class kie {

    private List<Integer> banknotes;

    public static void main(String[] args) {

        kie kieszonkowe = new kie();

        kieszonkowe.readValuesFromCommandLine();

        System.out.print(kieszonkowe.calculateMaxPossibleSum());

        System.exit(0);

    }

    private String calculateMaxPossibleSum() {
        long maxSum = 0;
        long tempMaxSum = 0;

        for (int currentIndex = banknotes.size() - 1; currentIndex >= 0; currentIndex--) {
            tempMaxSum = 0;
            for (int i = banknotes.size() - 1; i >= 0; i--) {
                    tempMaxSum += banknotes.get(i);
            }

            if(tempMaxSum %2 != 0) {
                tempMaxSum = 0;
                for (int i = banknotes.size() - 1; i >= 0; i--) {
                    if(i != currentIndex) {
                        tempMaxSum += banknotes.get(i);
                    }

                }
            }


            if (tempMaxSum % 2 == 0) {
                if (tempMaxSum > maxSum) {
                    maxSum = tempMaxSum;
                    break;
                }
            }

        }

        if (maxSum > 0) {
            return Long.valueOf(maxSum).toString();
        }

        return "NIESTETY";
    }

    private void readValuesFromCommandLine() {
        Scanner sc = new Scanner(System.in);

        sc.nextLine();
        String[] parameters = sc.nextLine().split(" ");
        banknotes = new ArrayList<Integer>();
        for (String param : parameters) {
            banknotes.add(Integer.valueOf(param));
        }

        Collections.sort(banknotes);
        Collections.reverse(banknotes);
    }
}