I wrote another solution as this(2nd). Surprisingly, this passed with 100 pts. The only difference was on line 60 and 67, where I just changed:
i on line 60 and,
(1<<res[i].second) on line 67.
I would be thankful if anyone could provide a reason for this, so to avoid such silly mistakes in further submissions.