The input data is broken. Either there are blank lines in between or there are blanks instead of line ends.
That doesn't effect reading in C/C++, but in Python.
Solution: Read the whole input in one piece (as string), split that string and process afterwards.