Storing elements and indexes
Ap , Bp = [ ] , [ ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT Ap . append ( [ A [ i ] , i ] ) NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT Bp . append ( [ B [ i ] , i ] ) NEW_LINE DEDENT Ap . sort ( ) NEW_LINE Bp . sort ( ) NEW_LINE i , j = 0 , 0 , NEW_LINE ans = [ 0 ] * n NEW_LINE