func_code_string: #include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   const double eps = 1e-7;   using namespace std;   long long ans, n, s, a[maxn], b[maxn], num1, num2;   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       to1, to2;   void init() {     ans = 0;     num1 = 0;     num2 = 0;     while (to1.size()) to1.pop();     while (to2.size()) to2.pop();     memset(a, 0, sizeof(a)), memset(b, 0, sizeof(b));   }   int main() {     while (~scanf( %lld%lld , &n, &s)) {       init();       for (int i = 0; i <= n - 1; ++i) {         long long s, a, b;         scanf( %lld%lld%lld , &s, &a, &b);         if (a > b) {           num1 += s;           ans += s * a;           to2.push(pair<long long, long long>(a - b, s));         } else {           num2 += s;           ans += s * b;           to1.push(pair<long long, long long>(b - a, s));         }       }       num1 %= s, num2 %= s;       if (num1 + num2 > s) {         printf( %lld n , ans);         continue;       } else {         long long tmp1 = num1, tmp2 = num2, cost1 = 0, cost2 = 0;         while (tmp1) {           pair<long long, long long> tmp = to2.top();           to2.pop();           long long num = min(tmp1, tmp.second);           tmp1 -= num;           cost1 += num * tmp.first;         }         while (tmp2) {           pair<long long, long long> tmp = to1.top();           to1.pop();           int num = min(tmp2, tmp.second);           tmp2 -= num;           cost2 += num * tmp.first;         }         printf( %lld n , max(ans - cost1, ans - cost2));       }     }     return 0;   }   