Sequence Land - https://www.codechef.com/INOIPRAC/problems/INOI1302/

My Code - https://pastebin.com/Lba17fTe

I’m creating a set for each person in the sequence land. I’m comparing elements between each person. If two people have more than K elements in common and also given that one of the them (Exactly one of them, it could be the first one or the second one but not both of them) have more than K elements in common with president, then I increment the total extended family value.

It fails in two test cases, can someone help me with this?