If you have tried competitive programming, you may have come across a similar problem. So, let's understand how stdin works in Python.
Read this post on beancoder.com