malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& _p) {     return os <<  (  << _p.first <<  ,  << _p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& _V) {     bool f = true;     os <<  [ ;     for (auto v : _V) {       os << (f ?    :  , ) << v;       f = false;     }     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& _S) {     bool f = true;     os <<  ( ;     for (auto s : _S) {       os << (f ?    :  , ) << s;       f = false;     }     return os <<  ) ;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& _M) {     return os << set<pair<T, U>>(_M.begin(), _M.end());   }   const signed long long INF = 1000000100;   const long double EPS = 1e-9;   template <typename T, typename F>   T bin_search(T a, T b, F f) {     while (a < b) {       T c = a + (b - a) / 2;       if (f(c)) {         b = c;       } else {         a = c + 1;       }     }     return a;   }   const int MAXN = 1000100;   int A[MAXN];   int S1[MAXN];   int S2[MAXN];   int N;   void read_data() {     scanf( %d , &N);     for (int(i) = (1); (i) <= (N); (i)++) scanf( %d , A + i);   }   void solve() {     vector<pair<int, int>> results;     for (int(i) = (1); (i) <= (N); (i)++) S1[i] = S1[i - 1] + (A[i] == 1);     for (int(i) = (1); (i) <= (N); (i)++) S2[i] = S2[i - 1] + (A[i] == 2);     for (int(i) = (N); (i) >= (1); (i)--) {       int t = 0;       int z1 = 0;       int z2 = 0;       bool fail = false;       int last = -1;       while (t < N) {         int k1 = bin_search(t + 1, N + 1, [&](int x) {           return x == N + 1 or S1[x] - S1[t] >= i;         });         int k2 = bin_search(t + 1, N + 1, [&](int x) {           return x == N + 1 or S2[x] - S2[t] >= i;         });         if (k1 < k2) {           if (S1[k1] - S1[t] != i) {             fail = true;             break;           }           ++z1;           last = 1;         } else if (k1 > k2) {           if (S2[k2] - S2[t] != i) {             fail = true;             break;           }           ++z2;           last = 2;         } else           fail = true;         t = min(k1, k2);       }       if (z1 > z2 and last != 1) continue;       if (z1 < z2 and last != 2) continue;       if (fail) continue;       if (z1 == z2) continue;       results.emplace_back(max(z1, z2), i);     }     sort(results.begin(), results.end());     printf( %d n , int(results.size()));     for (auto r : results) printf( %d %d n , r.first, r.second);   }   int main() {     read_data();     solve();   }
#include <bits/stdc++.h>   using namespace std;   template <class Int>   Int MAX(Int a, Int b) {     return (a > b) ? a : b;   }   template <class Int>   Int MIN(Int a, Int b) {     return (a < b) ? a : b;   }   const double PI = 2 * acos(0.0);   const int INF = 1 << 30;   int main(void) {     int l, d, v, g, r;     double tl;     int i, j, k, s;     bool f;     while (scanf( %d %d %d %d %d , &l, &d, &v, &g, &r) != EOF) {       tl = (double)d / (double)v;       j = floor(tl);       k = 0;       for (i = 0;; i++) {         if (i % 2 == 0) {           if (k + g <= j)             k += g;           else {             s = g;             f = true;             break;           }         } else {           if (k + r < j)             k += r;           else {             s = r;             f = false;             break;           }         }       }       if (f) {         tl += (double)((double)l - (double)d) / (double)v;       } else {         tl += (double)r - (double)((double)tl - (double)k);         tl += (double)((double)l - (double)d) / (double)v;       }       printf( %.8lf n , tl);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   const long double PI = 3.1415926535897932384626;   const long long int MAX = 1000000000 + 7;   char s[105][105];   int main() {     long long int n, m;     scanf( %lld , &n);     scanf( %lld , &m);     for (long long int i = 0; i <= n; i++) s[i][0] =  - ;     for (long long int j = 0; j <= m; j++) s[0][j] =  - ;     char x;     scanf( %c , &x);     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) {         scanf( %c , &s[i][j]);       }       scanf( %c , &x);     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) {         if (s[i][j] ==  . ) {           if (i % 2 == 1 and j % 2 == 1)             s[i][j] =  B ;           else if (i % 2 == 1 and (j % 2 == 0))             s[i][j] =  W ;           else if ((i % 2 == 0) and j % 2 == 1)             s[i][j] =  W ;           else if ((i % 2 == 0) and (j % 2 == 0))             s[i][j] =  B ;         }       }     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) printf( %c , s[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   int kmp(string const& s) {     int n = s.size();     vector<int> lps(n, 0);     for (int i = 1; i < n; i++) {       int j = lps[i - 1];       while (j > 0 && s[i] != s[j]) j = lps[j - 1];       if (s[i] == s[j]) j++;       lps[i] = j;     }     return lps.back();   }   bool cmp(vector<int>& a, vector<int>& b) {     for (int i = 0; i < a.size(); i++)       if (a[i] > b[i]) return false;     return true;   }   void sub(vector<int>& a, vector<int>& b) {     for (int i = 0; i < a.size(); i++) a[i] -= b[i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s, t;     cin >> s >> t;     int k = kmp(t);     string t1 = t.substr(0, k);     string t2 = t.substr(k, t.size() - k);     vector<int> cnts(2, 0), cntt1(2, 0), cntt2(2, 0);     for (char c : s) cnts[c -  0 ]++;     for (char c : t1) cntt1[c -  0 ]++;     for (char c : t2) cntt2[c -  0 ]++;     string ans =   ;     if (cmp(cntt1, cnts)) ans = t1, sub(cnts, cntt1);     while (cmp(cntt2, cnts)) {       for (char c : t2) ans += c;       sub(cnts, cntt2);     }     while (cnts[0] > 0) ans +=  0 , cnts[0]--;     while (cnts[1] > 0) ans +=  1 , cnts[1]--;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else {       return gcd(b, a % b);     }   }   int main() {     multiset<long long> s;     multiset<long long>::iterator it;     long long n, arr[100000], i, ache = 0, Max = -1, z, churi1, churi2, chilo,                                  haraise, a, y;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       s.insert(a);       if (a > Max) Max = a;       ache += a;     }     chilo = n * Max;     it = s.begin();     churi1 = Max - *it;     for (it = s.begin(); it != s.end(); it++) {       churi1 = gcd(churi1, Max - (*it));     }     haraise = chilo - ache;     y = haraise / churi1;     cout << y <<     << churi1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     return b == 0 ? abs(a) : gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long div_count(long long n) {     long long cunt = 0;     while (n > 1) {       if (n % 2 == 0) {         n = n / 2;       } else if (n % 3 == 0) {         n = 2 * n / 3;       } else if (n % 5 == 0) {         n = n * 4 / 5;       } else {         n = -1;       }       cunt++;     }     if (n == 1) {       return cunt;     }     return -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     long long n;     std::cin >> q;     for (int i = 0; i < q; i++) {       std::cin >> n;       cout << div_count(n) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int size(const T& c) {     return c.size();   }   template <class T>   inline int length(const T& c) {     return c.length();   }   unsigned long long l, r, k, m;   vector<unsigned long long> can;   struct matrix {     unsigned long long val[2][2];     friend matrix operator*(const matrix a, const matrix b) {       matrix ret;       for (int i = (0), _b = ((2) - 1); i <= _b; i++)         for (int j = (0), _b = ((2) - 1); j <= _b; j++) {           ret.val[i][j] = 0;           for (int k = (0), _b = ((2) - 1); k <= _b; k++)             ret.val[i][j] = (ret.val[i][j] + a.val[i][k] * b.val[k][j]) % m;         }       return ret;     }     friend matrix operator^(const matrix a, const unsigned long long n) {       if (n == 1) return a;       matrix ret = a ^ (n / 2);       ret = ret * ret;       if (n % 2 == 1) ret = ret * a;       return ret;     }   };   unsigned long long fibo(unsigned long long n) {     if (n <= 2)       return 1 % m;     else if (n == 3)       return 2 % m;     else {       matrix a;       a.val[0][0] = 0;       a.val[0][1] = 1;       a.val[1][0] = 1;       a.val[1][1] = 1;       n -= 3;       a = a ^ n;       return (a.val[1][0] + 2 * a.val[1][1]) % m;     }   }   int main() {     while (cin >> m >> l >> r >> k) {       can.clear();       for (unsigned long long i = 1; i * i <= r; i++) {         (can).push_back((i));         (can).push_back((r / i));         if (i * i <= l)           if (l % i == 0)             (can).push_back((l / i));           else             (can).push_back((l / (i - 1)));       }       unsigned long long ret = 1;       for (int i = (0), _b = ((can.size()) - 1); i <= _b; i++) {         unsigned long long a = l / can[i];         if (l % can[i] != 0) a++;         unsigned long long b = r / can[i];         if (b - a + 1 >= k) ret = max(ret, can[i]);       }       cout << fibo(ret) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s[n];     for (int i = 0; i < n; i++) {       cin >> s[i];       bool b = false;       if (i == 0) {         cout <<  NO  << endl;         continue;       }       for (int j = 0; j < i; j++) {         if (s[j] == s[i]) {           cout <<  YES  << endl;           b = true;           break;         }       }       if (!b) {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long p;     cin >> n >> p;     vector<pair<long long, int> > ar;     vector<long long> ans(n);     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       ar.push_back(make_pair(x, i));     }     sort(ar.begin(), ar.end());     set<int> waiting;     int q_smallest = n + 1;     queue<int> q;     long long time = 0;     int turn;     for (int i = 0; i < n || waiting.size() != 0 || q.size() != 0;) {       if (q.size() == 0 && waiting.size() == 0) {         q.push(ar[i].second);         q_smallest = ar[i].second;         time = ar[i++].first;       }       if (q.size() != 0) {         turn = q.front();         if (q_smallest == q.front()) q_smallest = n + 1;         q.pop();       } else if (waiting.size() != 0) {         turn = *(waiting.begin());         waiting.erase(waiting.begin());       }       time += p;       ans[turn] = time;       while (i < n && ar[i].first <= time) {         if ((q.size() == 0 || (q.size() > 0 && q_smallest > ar[i].second)) &&             turn > ar[i].second) {           q.push(ar[i].second);           q_smallest = ar[i].second;         } else {           waiting.insert(ar[i].second);         }         i++;       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     while (t--) {       int n, m, aux1, aux2;       int q;       cin >> q;       string ans =   ;       vector<pair<int, int> > v;       for (int i = 0; i < q; i++) {         cin >> n >> m;         v.push_back(make_pair(n, m));       }       sort(v.begin(), v.end());       bool f1 = true;       bool f2 = true;       int contr = 0;       for (auto i = v.begin(); i != v.end(); i++) {         if (f1) {           aux1 = i->first;           aux2 = i->second;           contr = aux2;           f1 = false;           for (int k = 0; k < aux1; k++) ans +=  R ;         } else {           if (aux2 > (i->second)) {             cout <<  NO  << endl;             f2 = false;             break;           }           if (aux1 != i->first) {             for (int k = 0; k < contr; k++) ans +=  U ;             contr = 0;           }           contr += (i->second - aux2);           for (int k = aux1; k < i->first; k++) ans +=  R ;           aux1 = i->first;           aux2 = i->second;         }       }       if (f2) {         for (int k = 0; k < contr; k++) ans +=  U ;         cout <<  YES  << endl;         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int mod = 998244353;   unsigned long long p[55];   unsigned long long f[55];   int d[55], to[55], used[55];   void upd(unsigned long long &x, unsigned long long y, unsigned long long w) {     if ((double)y * w > 2e18)       x += 2e18;     else       x += y * w;     if (x > 2e18) x = 2e18;   }   int ff(int x) {     if (to[x] != x) to[x] = ff(to[x]);     return to[x];   }   void solve2(int l, int r, unsigned long long id) {     d[l] = r;     memset(to, 0, sizeof(to));     memset(used, 0, sizeof(used));     for (int i = l; i <= r; ++i) to[i] = i;     to[l] = r;     used[r] = 1;     for (int i = l + 1; i <= r; ++i) {       if (i == r) {         for (int j = l; j <= r; ++j) {           if (!used[j]) {             d[i] = j;             return;           }         }       }       unsigned long long w = p[max(r - i - 1, 0)];       for (int j = l; j <= r; ++j) {         if (!used[j] && ff(j) != i) {           if (w < id)             id -= w;           else {             to[i] = j;             d[i] = j;             used[j] = 1;             break;           }         }       }     }   }   void solve(int i, int n, unsigned long long k) {     if (i > n) return;     for (int j = 0; j <= n - i; ++j) {       unsigned long long w = 0;       upd(w, f[n - i - j], p[max(j - 1, 0)]);       if (k < w) {         unsigned long long id = k / f[n - i - j] + 1;         k %= f[n - i - j];         solve2(i, i + j, id);         solve(i + j + 1, n, k);         return;       } else         k -= w;     }   }   int main() {     p[0] = 1;     for (int i = 1; i <= 50; ++i) upd(p[i], p[i - 1], i);     f[0] = 1;     for (int i = 0; i < 50; ++i) {       for (int j = 1; i + j <= 50; ++j) {         upd(f[i + j], f[i], p[max(j - 2, 0)]);       }     }     int t, n;     long long k;     scanf( %d , &t);     while (t--) {       scanf( %d%lld , &n, &k);       if (f[n] < k) {         puts( -1 );         continue;       }       solve(1, n, k - 1);       for (int i = 1; i <= n; ++i) printf( %d  , d[i]);       puts(  );     };     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 22, maxm = (1 << 21) + 5;   int n, plc[maxm];   unsigned long long a[maxm], b[maxm], c[maxn];   char s[maxm];   void FMT(unsigned long long *a, int sgn) {     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << n); j++)         if (!(j & (1 << i))) a[j | (1 << i)] = a[j | (1 << i)] + sgn * a[j];   }   int main() {     scanf( %d , &n);     plc[0] = 0;     for (int i = 1; i < (1 << n); i++) plc[i] = plc[i >> 1] + ((i & 1) << 1);     scanf( %s , s);     for (int i = 0; i < (1 << n); i++)       a[i] = ((unsigned long long)(s[i] -  0 ) << plc[i]);     scanf( %s , s);     for (int i = 0; i < (1 << n); i++)       b[i] |= ((unsigned long long)(s[i] -  0 ) << plc[i]);     FMT(a, 1);     FMT(b, 1);     for (int i = 0; i < (1 << n); i++) c[i] = a[i] * b[i];     FMT(c, -1);     for (int i = 0; i < (1 << n); i++) printf( %lld , (c[i] >> plc[i]) % 4);     puts(  );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:60000000 )   using namespace std;   const int MAXN = 10 + 100000;   const int INF = int(1e9);   const int m = 4;   int k, t, d;   int a[5][5], i, j, n;   void nhap() {     scanf( %d , &n);     for (int i = (1), _b = (m); i <= m; ++i)       scanf( %d%d%d%d , &a[i][1], &a[i][2], &a[i][3], &a[i][4]);   }   void xuli() {}   int main() {     nhap();     xuli();     for (int i = (1), _b = (m); i <= m; ++i) {       t = min(a[i][1], a[i][2]);       d = min(a[i][3], a[i][4]);       if (n - t >= d) {         cout << i <<     << t <<     << n - t;         return 0;       }     }     printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   const int N = 100005;   struct mes {     char c;     int id;   };   int n, m;   bool no[N];   mes all[N];   int p[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       cin >> all[i].c >> all[i].id;     }     int on = 0;     for (int i = 0; i < m; i++) {       if (all[i].c ==  + ) {         p[all[i].id] = 1;       }       if (all[i].c ==  -  && !p[all[i].id]) {         p[all[i].id] = 0;         on++;       }     }     for (int i = 0; i < m; i++) {       if (all[i].c ==  +  && (on || (i > 0 && all[i - 1].id != all[i].id))) {         no[all[i].id] = 1;       }       if (all[i].c ==  + ) {         on++;       }       if (all[i].c ==  - ) {         on--;       }       if (all[i].c ==  -  &&           (on || (i + 1 < m && (all[i + 1].id != all[i].id)))) {         no[all[i].id] = 1;       }     }     int k = 0;     for (int i = 1; i <= n; i++) {       k += 1 - no[i];     }     cout << k << endl;     for (int i = 1; i <= n; i++) {       if (!no[i]) {         cout << i <<    ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   using ll = long long;   struct TNode {     int l, r;     ll v;   } t[N << 2];   inline int lc(int pos) { return pos << 1; }   inline int rc(int pos) { return pos << 1 | 1; }   int a[N], n, m;   ll sum[N], lazy[N << 2];   inline void pushup(int pos) { t[pos].v = max(t[lc(pos)].v, t[rc(pos)].v); }   void build(int pos, int l, int r) {     t[pos].l = l;     t[pos].r = r;     if (l == r) {       t[pos].v = a[l] - sum[l - 1];       return;     }     int mid = (l + r) >> 1;     build(lc(pos), l, mid);     build(rc(pos), mid + 1, r);     pushup(pos);   }   inline void pushdown(int pos) {     t[lc(pos)].v += lazy[pos];     t[rc(pos)].v += lazy[pos];     lazy[lc(pos)] += lazy[pos];     lazy[rc(pos)] += lazy[pos];     lazy[pos] = 0;   }   void modify(int pos, int l, int r, int v) {     if (t[pos].l == l && t[pos].r == r) {       t[pos].v += v;       lazy[pos] += v;       return;     }     int mid = (t[pos].l + t[pos].r) >> 1;     pushdown(pos);     if (r <= mid)       modify(lc(pos), l, r, v);     else if (l > mid)       modify(rc(pos), l, r, v);     else       modify(lc(pos), l, mid, v), modify(rc(pos), mid + 1, r, v);     pushup(pos);   }   int query(int pos) {     if (t[pos].v < 0) return -1;     if (t[pos].l == t[pos].r) return t[pos].v ? -1 : t[pos].l;     pushdown(pos);     int ret = query(lc(pos));     if (ret == -1) ret = query(rc(pos));     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i];     build(1, 1, n);     int t1, t2;     for (int i = 1; i <= m; i++) {       cin >> t1 >> t2;       t2 = t2 - a[t1];       a[t1] += t2;       modify(1, t1, t1, t2);       if (t1 < n) modify(1, t1 + 1, n, -t2);       cout << query(1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[5010], b[5010], d[110][110];   double mat[110][110], res[110], flow[110][110], c[5010], ans;   bool used[110];   void input() {     memset(flow, 0x7f, sizeof(flow));     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> a[i] >> b[i] >> c[i];       ++d[a[i]][b[i]], ++d[b[i]][a[i]];       flow[a[i]][b[i]] = flow[b[i]][a[i]] = min(flow[a[i]][b[i]], c[i]);     }   }   bool achievable(int x) {     bool flg = (x == n);     used[x] = 1;     for (int i = 1; i <= n; ++i)       if (!used[i] && d[x][i]) flg |= achievable(i);     return flg;   }   void check() {     if (!achievable(1)) {       for (int i = 0; i <= m; puts( 0.00000 ), ++i)         ;       exit(0);     }   }   void potential() {     res[1] = 1.0, mat[n][n] = 1.0;     for (int i = 1; i < n; ++i) {       if (!used[i]) {         mat[i][i] = 1.0;         continue;       }       for (int j = 1; j <= n; ++j)         if (j != i) mat[i][i] += 1.0 * d[i][j], mat[i][j] -= 1.0 * d[i][j];     }   }   void Gauss() {     for (int i = 1; i <= n; ++i) {       int ind = i;       for (int j = i + 1; j <= n; ++j)         if (((mat[j][i]) > 0 ? (mat[j][i]) : (-mat[j][i])) >             ((mat[ind][i]) > 0 ? (mat[ind][i]) : (-mat[ind][i])))           ind = j;       if (ind != i)         for (int j = i; j <= n; ++j) swap(mat[ind][j], mat[i][j]);       swap(res[ind], res[i]);       for (int j = 1; j <= n; ++j) {         if (i == j) continue;         double ratio = -mat[j][i] / mat[i][i];         for (int k = i; k <= n; ++k) mat[j][k] += ratio * mat[i][k];         res[j] += ratio * res[i];       }     }     for (int i = 1; i <= n; ++i)       if (((mat[i][i]) > 0 ? (mat[i][i]) : (-mat[i][i])) > 1e-8)         res[i] /= mat[i][i];   }   void output() {     ans = 1.0e9;     for (int i = 0; i < m; ++i)       if ((((res[a[i]] - res[b[i]])) > 0 ? ((res[a[i]] - res[b[i]]))                                          : (-(res[a[i]] - res[b[i]]))) > 1e-8)         ans = min(ans, flow[a[i]][b[i]] / (((res[a[i]] - res[b[i]])) > 0                                                ? ((res[a[i]] - res[b[i]]))                                                : (-(res[a[i]] - res[b[i]]))));     cout << fixed << setprecision(9) << ans << endl;     for (int i = 0; i < m; ++i)       cout << fixed << setprecision(9) << (res[a[i]] - res[b[i]]) * ans << endl;   }   int main() {     input();     check();     potential();     Gauss();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, d[40005], v[4005], p[4005], cur, val, use[4005], cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> v[i] >> d[i] >> p[i];     for (int i = 1; i <= n; ++i)       if (!use[i]) {         cur = v[i];         for (int j = i + 1; j <= n; ++j)           if (!use[j]) {             if (cur == 0) break;             p[j] -= cur;             cur--;           }         for (int j = i + 1; j <= n; ++j)           if (p[j] < 0 && !use[j]) {             use[j] = 1;             val = d[j];             for (int k = j + 1; k <= n; ++k)               if (!use[k]) {                 p[k] -= val;                 if (p[k] < 0) {                   use[k] = 1;                   val += d[k];                 }               }             break;           }       }     for (int i = 1; i <= n; ++i)       if (p[i] >= 0) cnt++;     cout << cnt << endl;     for (int i = 1; i <= n; ++i)       if (p[i] >= 0) cout << i <<    ;   }