Not able to pass all the test cases

Help me out to find the error in my code. Not able to validate all the test cases.

link to my code - https://ide.codingblocks.com/s/218550

what is error in my code. link to the code - https://ide.codingblocks.com/s/218550

you can not sort the input as order of input is of importance here.

updated code: https://ide.codingblocks.com/s/222068

thank