Getting TLE in last testcase
Adding all the possible combinations to heap and then checking for duplicates is not desired because this is quite similar to using maps and thus it is showing TLE.
Here is my solution for your reference:
https://ide.codingblocks.com/s/46640