using System; using System.Collections.Generic; using System.Linq; using Solver.Ex; using Watch = System.Diagnostics.Stopwatch; using StringBuilder = System.Text.StringBuilder; namespace Solver { public class Solver { public void Solve() { IO.Printer.Out.PrintLine("Hello World!"); } internal IO.StreamScanner sc; } #region Main and Settings static class Program { static void Main(string[] arg) { #if DEBUG var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream")); System.Diagnostics.Debug.AutoFlush = false; var sw = new Watch(); sw.Start(); try { #endif var solver = new Solver(); solver.sc = new IO.StreamScanner(Console.OpenStandardInput()); IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); solver.Solve(); IO.Printer.Out.Flush(); #if DEBUG } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.StackTrace); } finally { sw.Stop(); Console.ForegroundColor = ConsoleColor.Green; Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds); System.Diagnostics.Debug.Close(); System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); } #endif } } #endregion } #region IO Helper namespace Solver.IO { public class Printer { static Printer() { Out = new Printer(Console.Out); } public static Printer Out { get; set; } private readonly System.IO.TextWriter writer; private readonly System.Globalization.CultureInfo info; public string Separator { get; set; } public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? "\n"; } } public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null) { writer = tw ?? System.IO.TextWriter.Null; info = ci ?? System.Globalization.CultureInfo.InvariantCulture; NewLine = newLine; Separator = separator ?? " "; } public void Print(int num) { writer.Write(num.ToString(info)); } public void Print(int num, string format) { writer.Write(num.ToString(format, info)); } public void Print(long num) { writer.Write(num.ToString(info)); } public void Print(long num, string format) { writer.Write(num.ToString(format, info)); } public void Print(double num) { writer.Write(num.ToString("F12", info)); } public void Print(double num, string format) { writer.Write(num.ToString(format, info)); } public void Print(string str) { writer.Write(str); } public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); } public void Print(string format, IEnumerable sources) { writer.Write(format, sources.OfType().ToArray()); } public void Print(IEnumerable sources) { writer.Write(sources.AsString()); } public void Print(IEnumerable sources) { var res = new System.Text.StringBuilder(); foreach (var x in sources) { res.AppendFormat(info, "{0}", x); if (string.IsNullOrEmpty(Separator)) res.Append(Separator); } writer.Write(res.ToString(0, res.Length - Separator.Length)); } public void PrintLine() { writer.WriteLine(); } public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); } public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); } public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); } public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); } public void PrintLine(double num) { writer.WriteLine(num.ToString("F12", info)); } public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); } public void PrintLine(string str) { writer.WriteLine(str); } public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); } public void PrintLine(string format, IEnumerable sources) { writer.WriteLine(format, sources.OfType().ToArray()); } public void PrintLine(IEnumerable sources) { var res = new StringBuilder(); foreach (var x in sources) { res.AppendFormat(info, "{0}", x); if (!string.IsNullOrEmpty(Separator)) res.Append(Separator); } writer.WriteLine(res.ToString(0, res.Length - Separator.Length)); } public void Flush() { writer.Flush(); } } public class StreamScanner { public StreamScanner(System.IO.Stream stream) { iStream = stream; } private readonly System.IO.Stream iStream; private readonly byte[] buf = new byte[1024]; private int len, ptr; private bool eof = false; public bool EndOfStream { get { return eof; } } private byte readByte() { if (eof) throw new System.IO.EndOfStreamException(); if (ptr >= len) { ptr = 0; len = iStream.Read(buf, 0, 1024); if (len <= 0) { eof = true; return 0; } } return buf[ptr++]; } private bool inSpan(byte c) { const byte lb = 33, ub = 126; return !(c >= lb && c <= ub); } private byte skip() { byte b = 0; do b = readByte(); while (!eof && inSpan(b)); return b; } public char Char() { return (char)skip(); } public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = (char)skip(); return a; } public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; } public string Scan() { const byte lb = 33, ub = 126; if (eof) throw new System.IO.EndOfStreamException(); do { while (ptr < len && (buf[ptr] < lb || ub < buf[ptr])) { ptr++; } if (ptr < len) break; ptr = 0; len = iStream.Read(buf, 0, 1024); if (len <= 0) { eof = true; return null; } continue; } while (true); StringBuilder sb = null; do { var i = ptr; while (i < len) { if (buf[i] < lb || ub < buf[i]) { string s; if (sb != null) { sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr)); s = sb.ToString(); } else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr)); ptr = i + 1; return s; } i++; } i = len - ptr; if (sb == null) sb = new StringBuilder(i + 32); sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i)); ptr = 0; } while ((len = iStream.Read(buf, 0, 1024)) > 0); eof = true; return sb.ToString(); } public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; } public string ScanLine() { const byte el = 10, cr = 13; if (eof) throw new System.IO.EndOfStreamException(); StringBuilder sb = null; do { var i = ptr; while (i < len) { if (buf[i] == cr || buf[i] == el) { string s; if (sb != null) { sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr)); s = sb.ToString(); } else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr)); if (buf[i] == cr) i++; if (buf[i] == el) i++; ptr = i; return s; } i++; } i = len - ptr; if (sb == null) sb = new StringBuilder(i + 32); sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i)); ptr = 0; } while ((len = iStream.Read(buf, 0, 1024)) > 0); eof = true; return sb.ToString(); } public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); } public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; } public int Integer() { var ret = 0; byte b = 0; bool isMynus = false; const byte zero = 48, nine = 57, mynus = 45; do b = readByte(); while (!eof && !((b >= zero && b <= nine) || b == mynus)); if (b == mynus) { isMynus = true; b = readByte(); } while (true) { if (b >= zero && b <= nine) { ret = ret * 10 + b - zero; } else return isMynus ? -ret : ret; b = readByte(); } } public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; } public long Long() { long ret = 0; byte b = 0; bool isMynus = false; const byte zero = 48, nine = 57, mynus = 45; do b = readByte(); while (!eof && !((b >= zero && b <= nine) || b == mynus)); if (b == '-') { isMynus = true; b = readByte(); } while (true) { if (b >= zero && b <= nine) ret = ret * 10 + (b - zero); else return isMynus ? -ret : ret; b = readByte(); } } public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++) a[i] = Long(); return a; } public void Flush() { iStream.Flush(); } } } #endregion #region Extension namespace Solver.Ex { static public partial class EnumerableEx { static public string AsString(this IEnumerable source) { return new string(source.ToArray()); } static public string AsJoinedString(this IEnumerable source, string separator = " ") { return string.Join(separator, source); } static public T[] Enumerate(this int n, Func selector) { var res = new T[n]; for (int i = 0; i < n; i++) res[i] = selector(i); return res; } } } #endregion