import java.io.*; import java.util.StringTokenizer; public class kie { private static int sum = 0; private static void readInputAndDoMagic(BufferedReader br) { int current, n, minOdd = Integer.MAX_VALUE; try { StringTokenizer st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { current = Integer.parseInt(st.nextToken()); if (current % 2 == 0) { sum += current; } else { sum += current; if (current < minOdd) { minOdd = current; } } } if (sum % 2 != 0) { sum -= minOdd; } } catch (IOException e) { System.out.print("IOException: " + e.toString()); } } private static void writeOutput() { if (sum == 0) { System.out.println("NIESTETY"); } else { System.out.println(sum); } } public static void main(String[] args) { BufferedReader br; if (args.length == 0) { br = new BufferedReader(new InputStreamReader(System.in)); } else { try { br = new BufferedReader(new FileReader(args[0])); } catch (FileNotFoundException e) { br = new BufferedReader(new InputStreamReader(System.in)); } } readInputAndDoMagic(br); writeOutput(); } }
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 | import java.io.*; import java.util.StringTokenizer; public class kie { private static int sum = 0; private static void readInputAndDoMagic(BufferedReader br) { int current, n, minOdd = Integer.MAX_VALUE; try { StringTokenizer st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { current = Integer.parseInt(st.nextToken()); if (current % 2 == 0) { sum += current; } else { sum += current; if (current < minOdd) { minOdd = current; } } } if (sum % 2 != 0) { sum -= minOdd; } } catch (IOException e) { System.out.print("IOException: " + e.toString()); } } private static void writeOutput() { if (sum == 0) { System.out.println("NIESTETY"); } else { System.out.println(sum); } } public static void main(String[] args) { BufferedReader br; if (args.length == 0) { br = new BufferedReader(new InputStreamReader(System.in)); } else { try { br = new BufferedReader(new FileReader(args[0])); } catch (FileNotFoundException e) { br = new BufferedReader(new InputStreamReader(System.in)); } } readInputAndDoMagic(br); writeOutput(); } } |