I tried this problem using simple if-else and iterative loops. It seems to work for the given test case and all the test case which I tried on other IDEs;
Can you please help me with this; Is there any error with the output format?
Code link: https://ide.codingblocks.com/s/100597