#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvvl vector #define vvl vector> #define VV(a, b, c, d) vector>(a, vector(b, c)) #define VVV(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c> n; ll s = 0; multiset st; for(int i=0;i> q; for(int i=0;i> t; auto itr = st.lower_bound(t); vll c; while(itr!=st.end()){ ll num = (*itr); ll aft = num%t; s += - num + aft; c.push_back(num); itr++; } for(auto e:c){ auto itr = st.find(e); st.erase(itr); st.insert(e%t); } std::cout << s << '\n'; } return 0; }