count elements which occur more than once
for ( Map . Entry < Integer , Integer > i : m . entrySet ( ) ) { if ( i . getValue ( ) > 1 ) { if ( i . getValue ( ) >= 4 && i . getValue ( ) % 2 == 0 ) check ++ ; count ++ ; } } boolean flag ; if ( check % 2 != 0 ) flag = false ; if ( check % 2 != 0 ) System . out . println ( " Yes " ) ; else if ( n % 2 == 0 && count % 2 == 0 ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; }