Skip to main content

Fast I/O

Some CCC problems have large amounts of input (tens of thousands of lines), which can cause an otherwise correct and efficient solution to time out while reading the input.

To mitigate this issue, fast I/O methods can be used.

Instead of using input(), read directly from sys.stdin. A hacky way to do this is to simply redefine input as sys.stdin.readline at the beginning of your program:

input = sys.stdin.readline
# Use input() as normal

Note, however, that the result of sys.stdin.readline will contain trailing newlines, which may need to be stripped out manually.