Count elements which occur more than once
foreach ( KeyValuePair < int , int > i in m ) { if ( i . Value > 1 ) { if ( i . Value >= 4 && i . Value % 2 == 0 ) check ++ ; count ++ ; } } bool flag ; if ( check % 2 != 0 ) flag = false ; if ( check % 2 != 0 ) Console . WriteLine ( " Yes " ) ; else if ( n % 2 == 0 && count % 2 == 0 ) Console . WriteLine ( " No " ) ; else Console . WriteLine ( " Yes " ) ; }