• + 3 comments
    • Since there are n astronauts ,there are N choose 2 pairs. Initialise the answer to this number.
    • But we aren't allowed astronaut pairs from the same country.
    • So subtract the astronaut pairs from same country from the total answer.
    • Do this for every country which has more than 1 astronaut.

    long int ans= (n*(n-1))/2;

    for(auto it = m.begin(); it!= m.end(); it++){
        long int astros = it->second;
         if(astros > 1)
            ans-= (astros*(astros-1))/2; 
    }
    return ans;