Contest Setup: Fast I/O

Fast input via sys.stdin, Python's contest pitfalls and a checklist.

Python is concise but dozens of times slower than C++. For it to survive in contests you need to know a few tricks. The first and main one is fast input. The regular input() is slow; with large inputs (hundreds of thousands of lines) a solution can miss the time limit purely because of reading. The replacement is sys.stdin.
Python

A template with fast input. Enter: 4, then 10 20 30 40

What matters here: • input = sys.stdin.readline — replaces the slow input with a fast one (careful: readline keeps the trailing newline character; for numbers it doesn't matter, for strings use .strip()); • answers are collected in a list and printed with one print via join — thousands of separate print calls are noticeably slower. Python pitfalls to know in advance: 1. Deep recursion crashes: the default limit is about 1000 calls. Raise it with sys.setrecursionlimit(300000) or rewrite as a loop. 2. If the algorithm is right but the time still doesn't pass — first look for an extra loop in your own code, and only then blame the language. 3. Integers never overflow — in Python you can simply not think about it.
Checklist before submitting: 1. Edge cases: n = 1, empty input, negative numbers. 2. Are // and % correct (not /)? 3. Does the output format exactly match the statement? The course is finished — congratulations! Open the "Learn" section and start the "Competitive Programming Path" from Level 1. Good luck!
Доска