import java.util.*; import java.lang.*; import java.io.*; class kie { public static long sum(long howMuch, List<Long> lst) { List<Long> oddList = new ArrayList<Long>(); long sum = 0; for (int i = 0; i < howMuch; i++) { long item = lst.get(i); if (item % 2 != 0) { oddList.add(item); } sum += item; } if (sum % 2 == 0) { return sum; } else { long minOdd = Collections.min(oddList); return sum - minOdd; } } public static void main (String[] args) throws java.lang.Exception { List<Long> list = new ArrayList<Long>(); Scanner in = new Scanner(System.in); long n = in.nextLong(); for (long i = 0; i < n; i++) { long a = in.nextLong(); list.add(a); } long result = sum(n, list); if (result > 0) { System.out.println(result); } else { System.out.println("NIESTETY"); } } }
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 | import java.util.*; import java.lang.*; import java.io.*; class kie { public static long sum(long howMuch, List<Long> lst) { List<Long> oddList = new ArrayList<Long>(); long sum = 0; for (int i = 0; i < howMuch; i++) { long item = lst.get(i); if (item % 2 != 0) { oddList.add(item); } sum += item; } if (sum % 2 == 0) { return sum; } else { long minOdd = Collections.min(oddList); return sum - minOdd; } } public static void main (String[] args) throws java.lang.Exception { List<Long> list = new ArrayList<Long>(); Scanner in = new Scanner(System.in); long n = in.nextLong(); for (long i = 0; i < n; i++) { long a = in.nextLong(); list.add(a); } long result = sum(n, list); if (result > 0) { System.out.println(result); } else { System.out.println("NIESTETY"); } } } |