func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr <<     << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void inp_out() {}   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     inp_out();     long long int n, m;     cin >> n >> m;     vector<pair<long long int, long long int>> a(n);     long long int cnt = 0;     multiset<pair<long long int, long long int>> st;     vector<multiset<long long int>> adj(m + 1);     for (long long int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;       adj[a[i].first].insert(a[i].second);       if (a[i].first == 1)         ++cnt;       else         st.insert({a[i].second, a[i].first});     }     vector<long long int> ans(n + 1, 3e18);     for (long long int i = max(1ll, cnt); i <= n; ++i) {       vector<multiset<long long int>> temp_adj = adj;       multiset<pair<long long int, long long int>> temp_st = st;       long long int val = cnt, cost = 0;       for (long long int j = 2; j <= m; ++j) {         while (temp_adj[j].size() >= i) {           cost += *temp_adj[j].begin();           temp_st.erase(temp_st.find({*temp_adj[j].begin(), j}));           temp_adj[j].erase(temp_adj[j].begin());           ++val;         }       }       if (val > i) continue;       while (val < i) {         cost += (*temp_st.begin()).first;         temp_st.erase(temp_st.begin());         ++val;       }       ans[i] = cost;     }     long long int fa = *min_element(ans.begin(), ans.end());     cout << fa;     return 0;   }   