Help needed to find error in logic

@O17LPOLA020023 sir can u please check my code:https://ide.codingblocks.com/s/210944

@spagire4
I checked your code
It is working fine
Where was the error ?

@Aarnav-Jindal-1059677350830863 but code is not passing any testcase giving wrong anwer

@spagire4
The issue was with printing output in lexicographic order
Your output values are correct
But output sequence is not correct


I’ve modified your code accordingly
You can see the difference