Traverse from left to right
for ( vector < int > :: iterator i = v . begin ( ) ; i != v . end ( ) ; i ++ ) { vector < int > :: iterator j = upper_bound ( v . begin ( ) , v . end ( ) , ( 2 * ( * i ) ) ) ;