func_code_string: #include <bits/stdc++.h>   const int inf = 0x3f3f3f;   const long long INF = 1ll << 61;   using namespace std;   int n, x;   typedef struct Node {     int t, h, m;   };   Node aa[2000 + 55], bb[2000 + 55];   void init() {     memset(aa, 0, sizeof(aa));     memset(bb, 0, sizeof(bb));   }   int cnt1, cnt2;   bool input() {     while (cin >> n >> x) {       cnt1 = cnt2 = 0;       for (int i = 0; i < n; i++) {         int t;         scanf( %d , &aa[i].t);         scanf( %d %d , &aa[i].h, &aa[i].m);         bb[i].t = aa[i].t, bb[i].h = aa[i].h, bb[i].m = aa[i].m;       }       return false;     }     return true;   }   bool cmp1(Node x, Node y) { return x.m > y.m; }   void cal() {     sort(aa, aa + n, cmp1);     sort(bb, bb + n, cmp1);     int ans1 = 0;     int now = 0;     int tx = x;     for (int i = 0; i < n; i++) {       if (aa[i].t == now && tx >= aa[i].h) {         now = 1 - now;         tx += aa[i].m;         ans1++;         aa[i].t = -1;         i = -1;       }     }     int ans2 = 0;     now = 1;     for (int i = 0; i < n; i++) {       if (bb[i].t == now && x >= bb[i].h) {         now = 1 - now;         x += bb[i].m;         ans2++;         bb[i].t = -1;         i = -1;       }     }     int ans = max(ans1, ans2);     cout << ans << endl;   }   void output() {}   int main() {     while (true) {       init();       if (input()) return 0;       cal();       output();     }     return 0;   }   