func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int64_t> v[3001];   int64_t calc(int64_t taken, int64_t n, int64_t m) {     int64_t req = taken - v[0].size();     int64_t t = v[0].size();     int64_t ans = 0;     vector<int64_t> rem;     for (int64_t i = 1; i < m; i++) {       if (v[i].size() == 0) continue;       for (int64_t j = 0; j < v[i].size(); j++) {         if (j + taken <= v[i].size()) {           ans += v[i][j];           req--;         } else           rem.push_back(v[i][j]);       }     }     if (req > 0) {       sort(rem.begin(), rem.end());       int64_t i = 0;       while (req > 0 and i < rem.size()) {         ans += rem[i];         i++;         req--;       }     }     return ans;   }   void solve() {     int64_t n, m, i, ans;     cin >> n >> m;     for (int64_t i = 0; i < n; i++) {       int64_t p, c;       cin >> p >> c;       p--;       v[p].push_back(c);     }     for (int64_t i = 0; i < m; i++) {       sort(v[i].begin(), v[i].end());     }     ans = LLONG_MAX;     for (int64_t i = 1; i <= n; i++) {       int64_t curr_cost = calc(i, n, m);       ans = min(ans, curr_cost);     }     cout << ans <<   n ;   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     cerr <<   Execution :   << (1.0 * clock()) / CLOCKS_PER_SEC <<  s  n ;     return 0;   }   