All elements of array are equal Send tickets from each counter 1 time until K > 0.
while ( k > 0 and arr [ i ] != 0 ) : NEW_LINE INDENT ans = ans + min ( n , k ) * arr [ i ] NEW_LINE k -= n NEW_LINE arr [ i ] -= 1 NEW_LINE DEDENT ans = ans % mod NEW_LINE