Read the input all at once
transcript
Your algorithm is linear. It passes every small test. On the big test, it still times out. Why?
A million numbers come in on standard input. Reading them one call at a time is slow. The reading alone can use the whole time limit.
Read everything in one call. Split it, then convert. Print once at the end.
In Python, read the whole buffer in one call. In Java, use a buffered reader and a print writer. In C plus plus, untie the streams first.
Fast input is not the only habit. Keep your slow solution too. Run both on small random inputs. Stop at the first difference between them.
Then shrink the failing input. Try sizes one, two, three, and so on. A tiny input is easy to trace by hand. Fix the bug, and run the test again.
Read once. Print once. Stress test before you submit. Full breakdown in the lecture.