import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; public class kie { private static InputStream in; public static void main(String[] args) throws IOException { in = new BufferedInputStream(System.in); int n = nextInt(); if (n == 1) { int a = nextInt(); System.out.println(a % 2 == 0 ? a : "NIESTETY"); return; } long initialSum = 0; int minEven = Integer.MAX_VALUE; int a; for (int i = 0; i < n; i++) { a = nextInt(); initialSum += a; if (a % 2 == 1 && a < minEven) { minEven = a; } } if (initialSum % 2 == 0) { System.out.println(initialSum); } else { System.out.println(initialSum - minEven); } in.close(); } private static int nextInt() throws IOException { int ret = 0; boolean dig = false; for (int c = 0; (c = in.read()) != -1; ) { if (c >= 48 && c <= 57) { dig = true; ret = ret * 10 + c - 48; } else if (dig) break; } return ret; } }
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 | import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; public class kie { private static InputStream in; public static void main(String[] args) throws IOException { in = new BufferedInputStream(System.in); int n = nextInt(); if (n == 1) { int a = nextInt(); System.out.println(a % 2 == 0 ? a : "NIESTETY"); return; } long initialSum = 0; int minEven = Integer.MAX_VALUE; int a; for (int i = 0; i < n; i++) { a = nextInt(); initialSum += a; if (a % 2 == 1 && a < minEven) { minEven = a; } } if (initialSum % 2 == 0) { System.out.println(initialSum); } else { System.out.println(initialSum - minEven); } in.close(); } private static int nextInt() throws IOException { int ret = 0; boolean dig = false; for (int c = 0; (c = in.read()) != -1; ) { if (c >= 48 && c <= 57) { dig = true; ret = ret * 10 + c - 48; } else if (dig) break; } return ret; } } |