Problem - 652C - Codeforces

Can someone help me understand the idea to solve this problem…also c++ code if possible

Question : Codeforces 652-C - Foe pairs