To store modulos values
val = [ [ ] for i in range ( m ) ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT val [ a [ i ] % m ] . append ( i ) NEW_LINE DEDENT ans = 0 NEW_LINE extra = [ ] NEW_LINE for i in range ( 0 , 2 * m ) : NEW_LINE INDENT cur = i % m NEW_LINE DEDENT