To store modulos values
@ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] val = new Vector [ m ] ; for ( int i = 0 ; i < val . length ; i ++ ) val [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { val [ a [ i ] % m ] . add ( i ) ; } long ans = 0 ; Vector < pair > extra = new Vector < > ( ) ; for ( int i = 0 ; i < 2 * m ; ++ i ) { int cur = i % m ;