Contest Setup: Fast I/O
bufio: fast input/output and the Go contest template.
fmt.Scan reads character by character and is hopelessly slow on large inputs. The Go contest standard is buffered input/output from the bufio package:
• bufio.Reader + fmt.Fscan — fast reading;
• bufio.Writer + fmt.Fprintln — fast output; at the end writer.Flush() is mandatory, otherwise the buffer never gets printed (and you get Wrong Answer with a correct solution).
Go
The contest template. Enter: 4, then 10 20 30 40
What matters in the template:
• reader and writer are declared at package level — accessible from any function;
• defer writer.Flush() guarantees the buffer is flushed when main exits — writing this line first has become a ritual for Go competitors;
• fmt.Fscan(reader, &x) — the same Scan, but from the fast buffer.
The Go competitor's checklist:
1. Did you forget writer.Flush()? (defer settles it once and for all)
2. Go's int is 64-bit — int32 overflow is not a worry, but still check products of three large numbers.
3. len(s) — bytes; for Cyrillic and Unicode work through []rune.
4. Unused variables and imports won't compile — delete them.
The course is finished — congratulations!
Open the "Learn" section and start the "Competitive Programming Path" from Level 1: algorithm complexity, implementation problems and basic math. Good luck at the contests!