/* The Great Computer Language Shootout http://shootout.alioth.debian.org/ contributed by Jeffrey Stedfast */ using System; using System.IO; class SumCol2 { static int SumStream (Stream stream) { byte[] buf = new byte [4097]; int nread, n, v = 0; bool negate = false; bool first = true; int sum = 0; char c; do { if ((nread = stream.Read (buf, 0, 4096)) <= 0) break; buf[nread] = (byte) '\n'; n = 0; do { if (first) { if (buf[n] == (byte) '-') { negate = true; first = false; n++; } else if (buf[n] != (byte) '\n') first = false; } while (buf[n] != (byte) '\n') { c = (char) buf[n]; if (c < '0' || c > '9') { Console.WriteLine ("{0} not a digit, v is {1}", c, v); throw new Exception (); } v = v * 10 + (c - '0'); n++; } if (n == nread) break; if (negate) sum -= v; else sum += v; negate = false; first = true; v = 0; n++; } while (true); } while (true); if (negate) sum -= v; else sum += v; return sum; } static void Main () { Stream stdin = Console.OpenStandardInput (); int sum; try { sum = SumStream (stdin); Console.WriteLine (sum); } catch { Console.WriteLine ("Invalid input"); } } }