func_code_string: #include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   long long findBest(vector<pair<long long, long long> >& ps, long long x) {     long long res = 0;     for (long long i = 0; i < ps.size(); i++) {       long long num = ps[i].second;       long long diff = ps[i].first;       if (x - num >= 0) {         res += (num * diff);         x -= num;       } else {         res += (x * diff);         break;       }     }     return res;   }   int main() {     long long n, s;     cin >> n >> s;     vector<pair<long long, long long> > ps;     long long total = 0;     long long positives = 0;     long long pieces = 0;     for (long long i = 0; i < n; i++) {       long long num, a, b;       cin >> num >> a >> b;       ps.push_back(make_pair(a - b, num));       total += num * b;       pieces += num;       if (a - b > 0) {         positives += num;       }     }     sort(ps.begin(), ps.end(), comp);     long long pizzas = (pieces % s == 0) ? (pieces / s) : (pieces / s + 1);     long long extra = pizzas * s - pieces;     long long best = total;     if (positives > 0) {       best = max(best, findBest(ps, positives / s * s) + total);       if (positives % s != 0) {         long long x = max(positives, (positives / s + 1) * s - extra);         best = max(best, findBest(ps, x) + total);       }     }     cout << best << endl;     return 0;   }   