0Pricing
Competitive Programming Academy · Lesson

Batch Output the Right Way

Buffer with a list and join to print fast.

Output Can Be Slow Too

Just like reading, writing matters. Calling print() thousands of times flushes repeatedly and can quietly cost you the time limit.

Collect, Then Print

The fix is to gather your answers in a list first, then send them out in a single write at the end.

out = []

All lessons in this course

  1. input() vs sys.stdin Showdown
  2. Parse Many Numbers on One Line
  3. Batch Output the Right Way
  4. Read N Lines and Edge Cases
← Back to Competitive Programming Academy