func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   struct ky {     int u, val;     bool operator<(const ky &p) const { return val < p.val; }   } a[N], b[N];   int n, ca, cb, ci, vali;   bool tg[N];   inline void fr(int &num) {     num = 0;     char c = getchar();     int p = 1;     while (c <  0  || c >  9 ) c ==  -  ? p = -1, c = getchar() : c = getchar();     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     num *= p;   }   int main() {     fr(n);     for (register int i = 1; i <= n; ++i)       fr(ci), fr(vali), ci ? a[++ca] = (ky){i, vali} : b[++cb] = (ky){i, vali};     sort(a + 1, a + 1 + ca), sort(b + 1, b + 1 + cb);     register int i = 1, j = 1, minn;     while (i <= ca && j <= cb)       minn = (a[i].val < b[j].val ? a[i].val : b[j].val),       printf( %d %d %d n , a[i].u, b[j].u, minn), a[i].val -= minn,       b[j].val -= minn, tg[a[i].u] = tg[b[j].u] = true, !a[i].val ? ++i : ++j;     while (i <= ca) {       if (!tg[a[i].u]) printf( %d %d 0 n , a[i].u, b[1].u), tg[a[i].u] = 1;       ++i;     }     while (j <= cb) {       if (!tg[b[j].u]) printf( %d %d 0 n , a[1].u, b[j].u), tg[b[j].u] = 1;       ++j;     }     return 0;   }   