used to avoid duplicates in result
set < pair < int , int > > arr ; for ( int i = 0 ; i <= min ( x , y ) ; i ++ ) { pair < int , int > pq ; pq = make_pair ( i , min ( x , y ) - i ) ; arr . insert ( pq ) ; } for ( auto it = arr . begin ( ) ; it != arr . end ( ) ; it ++ ) cout << ( * it ) . first << " ▁ " << ( * it ) . second << endl ; }