For some reason, the output is not buffered in PyPy (unlike CPython).
So, for problems where you use lots of
For example, compare these 2 submissions -- 21354004, 21354013.
Both solutions are exactly the same except in the latter,
stdout is replaced by a buffer and all the output stored in the buffer is written to original
stdout at the end.
For explicit buffered output, prefix your code with following code like in 21354013
import atexit import io import sys buff = io.BytesIO() sys.stdout = buff @atexit.register def write(): sys.__stdout__.write(buff.getvalue()) # code
import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() raw_input = iter(_INPUT_LINES).next _OUTPUT_BUFFER = io.BytesIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) # code