To store modulos values
vector < vector < int > > val ( m ) ; for ( int i = 0 ; i < n ; ++ i ) { val [ a [ i ] % m ] . push_back ( i ) ; } long long ans = 0 ; vector < pair < int , int > > extra ; for ( int i = 0 ; i < 2 * m ; ++ i ) { int cur = i % m ;