Making sure that all elements are distinct array elements and an element is not considered more than once .
pair < int , int > p = mp [ X - sum ] ; if ( p . first != i && p . first != j && p . second != i && p . second != j ) { cout << arr [ i ] << " , ▁ " << arr [ j ] << " , ▁ " << arr [ p . first ] << " , ▁ " << arr [ p . second ] ; return ; } } } } }