func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e6 + 7;   const long long mod = 1e9 + 7;   const long long INF = 3e18 + 315;   vector<pair<long long, long long> > va, vb;   long long n, s, ans, na, nb, ta, tb;   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> s;     for (long long i = 0; i < n; i++) {       long long num, a, b;       cin >> num >> a >> b;       if (a > b) {         ans += num * a;         na += num;         va.push_back({a - b, num});       } else {         ans += num * b;         nb += num;         vb.push_back({b - a, num});       }     }     na %= s;     nb %= s;     sort(va.begin(), va.end());     sort(vb.begin(), vb.end());     if (na + nb > s) return cout << ans << endl, 0;     for (long long i = 0; i < ((long long)(va).size()); i++) {       ta += min(na, va[i].second) * va[i].first;       na -= min(na, va[i].second);     }     for (long long i = 0; i < ((long long)(vb).size()); i++) {       tb += min(nb, vb[i].second) * vb[i].first;       nb -= min(nb, vb[i].second);     }     ans -= min(ta, tb);     cout << ans << endl;     return 0;   }   