Storing elements and indexes
ArrayList < int [ ] > Ap = new ArrayList < > ( ) ; ArrayList < int [ ] > Bp = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) Ap . add ( new int [ ] { A [ i ] , i } ) ; for ( int i = 0 ; i < n ; i ++ ) Bp . add ( new int [ ] { B [ i ] , i } ) ;