frequency count of all the elements
for ele in arr : NEW_LINE INDENT count [ ele ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for eleX , countX in enumerate ( count ) : NEW_LINE INDENT for eleY , countY in enumerate ( count ) : NEW_LINE INDENT if eleX < eleY : NEW_LINE INDENT continue NEW_LINE DEDENT if ( abs ( eleX - eleY ) % 2 == 1 ) : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT DEDENT