|
| 1 | +import java.io.BufferedOutputStream; |
| 2 | +import java.io.IOException; |
| 3 | +import java.io.InputStream; |
| 4 | +import java.io.PrintWriter; |
| 5 | +import java.util.InputMismatchException; |
| 6 | + |
| 7 | +public class InputReaderSolution implements Runnable { |
| 8 | + |
| 9 | + private static void solve() { |
| 10 | + long sum = 0; |
| 11 | + int n = in.readInt(); |
| 12 | + while (n-- > 0) { |
| 13 | + sum += in.readInt(); |
| 14 | + } |
| 15 | + out.println(sum); |
| 16 | + } |
| 17 | + |
| 18 | + /** Template starts: */ |
| 19 | + @Override |
| 20 | + public void run() { |
| 21 | + solve(); |
| 22 | + out.flush(); |
| 23 | + System.exit(0); |
| 24 | + } |
| 25 | + |
| 26 | + private final static InputReader in = new InputReader(System.in); |
| 27 | + private final static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); |
| 28 | + |
| 29 | + public static void main(String[] args) { |
| 30 | + new Thread(null, new InputReaderSolution(), "Main", 1 << 26).start(); |
| 31 | + } |
| 32 | + |
| 33 | + private static class InputReader { |
| 34 | + private final InputStream stream; |
| 35 | + private final byte[] buf = new byte[1024]; |
| 36 | + private int curChar; |
| 37 | + private int numChars; |
| 38 | + |
| 39 | + InputReader(InputStream stream) { |
| 40 | + this.stream = stream; |
| 41 | + } |
| 42 | + |
| 43 | + private byte read() { |
| 44 | + if (numChars == -1) { |
| 45 | + throw new InputMismatchException("EOF has been reached"); |
| 46 | + } |
| 47 | + if (curChar >= numChars) { |
| 48 | + curChar = 0; |
| 49 | + try { |
| 50 | + numChars = stream.read(buf); |
| 51 | + } catch (IOException e) { |
| 52 | + throw new InputMismatchException(); |
| 53 | + } |
| 54 | + if (numChars <= 0) |
| 55 | + return -1; |
| 56 | + } |
| 57 | + return buf[curChar++]; |
| 58 | + } |
| 59 | + |
| 60 | + int readInt() { |
| 61 | + byte c = read(); |
| 62 | + while (isWhitespace(c)) { |
| 63 | + c = read(); |
| 64 | + } |
| 65 | + if (isEOF(c)) { |
| 66 | + throw new InputMismatchException("EOF has been reached"); |
| 67 | + } |
| 68 | + |
| 69 | + int sgn = 1; |
| 70 | + if (c == '-') { |
| 71 | + sgn = -1; |
| 72 | + c = read(); |
| 73 | + } |
| 74 | + int res = 0; |
| 75 | + do { |
| 76 | + if (c < '0' || c > '9') { |
| 77 | + throw new InputMismatchException(); |
| 78 | + } |
| 79 | + if (res > Integer.MAX_VALUE / 10) { |
| 80 | + throw new InputMismatchException("Input is not an integer"); |
| 81 | + } |
| 82 | + res *= 10; |
| 83 | + int d = c - '0'; |
| 84 | + if (res > Integer.MAX_VALUE - d) { |
| 85 | + throw new InputMismatchException("Input is not an integer"); |
| 86 | + } |
| 87 | + res += d; |
| 88 | + c = read(); |
| 89 | + } while (!isWhitespaceOrEOF(c)); |
| 90 | + return res * sgn; |
| 91 | + } |
| 92 | + |
| 93 | + long readLong() { |
| 94 | + byte c = read(); |
| 95 | + while (isWhitespace(c)) { |
| 96 | + c = read(); |
| 97 | + } |
| 98 | + if (isEOF(c)) { |
| 99 | + throw new InputMismatchException("EOF has been reached"); |
| 100 | + } |
| 101 | + |
| 102 | + int sgn = 1; |
| 103 | + if (c == '-') { |
| 104 | + sgn = -1; |
| 105 | + c = read(); |
| 106 | + } |
| 107 | + long res = 0; |
| 108 | + do { |
| 109 | + if (c < '0' || c > '9') { |
| 110 | + throw new InputMismatchException(); |
| 111 | + } |
| 112 | + if (res > Long.MAX_VALUE / 10) { |
| 113 | + throw new InputMismatchException("Input is not a long integer"); |
| 114 | + } |
| 115 | + res *= 10; |
| 116 | + int d = c - '0'; |
| 117 | + if (res > Long.MAX_VALUE - d) { |
| 118 | + throw new InputMismatchException("Input is not a long integer"); |
| 119 | + } |
| 120 | + res += d; |
| 121 | + c = read(); |
| 122 | + } while (!isWhitespaceOrEOF(c)); |
| 123 | + return res * sgn; |
| 124 | + } |
| 125 | + |
| 126 | + String readString() { |
| 127 | + byte c = read(); |
| 128 | + while (isWhitespace(c)) { |
| 129 | + c = read(); |
| 130 | + } |
| 131 | + if (isEOF(c)) { |
| 132 | + return null; |
| 133 | + } |
| 134 | + |
| 135 | + StringBuilder res = new StringBuilder(); |
| 136 | + do { |
| 137 | + if (Character.isValidCodePoint(c)) { |
| 138 | + res.appendCodePoint(c); |
| 139 | + } |
| 140 | + c = read(); |
| 141 | + } while (!isWhitespaceOrEOF(c)); |
| 142 | + return res.toString(); |
| 143 | + } |
| 144 | + |
| 145 | + private boolean isWhitespace(byte c) { |
| 146 | + return c == ' ' || c == '\n' || c == '\r' || c == '\t'; |
| 147 | + } |
| 148 | + |
| 149 | + private boolean isEOF(byte c) { |
| 150 | + return c == -1; |
| 151 | + } |
| 152 | + |
| 153 | + private boolean isWhitespaceOrEOF(byte c) { |
| 154 | + return isWhitespace(c) || isEOF(c); |
| 155 | + } |
| 156 | + } |
| 157 | +} |
0 commit comments