malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long n, f1, f2, f3, c, ans, t1[3], t2[5], aa1[3][3], aa2[5][5],       a1[3][3] = {{0, 0, 1}, {1, 0, 1}, {0, 1, 1}},       a2[5][5] = {{0, 0, 1, 0, 0},                   {1, 0, 1, 0, 0},                   {0, 1, 1, 0, 0},                   {0, 0, 1, 1, 0},                   {0, 0, 0, 1, 1}},       ans1[3], ans2[3], ans3[3], ans4[5];   long long kp(long long a, long long b) {     if (b == 0) return 1;     long long c = kp(a, b >> 1);     c = (c * c) % mod;     if (b & 1) c = (c * a) % mod;     return c;   }   int main() {     scanf( %lld%lld%lld%lld%lld , &n, &f1, &f2, &f3, &c);     ans1[0] = ans2[1] = ans3[2] = 1;     ans4[4] = ans4[3] = 2;     for (long long x = n - 3; x; x >>= 1) {       if (x & 1) {         for (int i = 0; i < 3; i++) t1[i] = ans1[i], ans1[i] = 0;         for (int i = 0; i < 3; i++)           for (int j = 0; j < 3; j++)             ans1[i] = (ans1[i] + t1[j] * a1[j][i]) % (mod - 1);         for (int i = 0; i < 3; i++) t1[i] = ans2[i], ans2[i] = 0;         for (int i = 0; i < 3; i++)           for (int j = 0; j < 3; j++)             ans2[i] = (ans2[i] + t1[j] * a1[j][i]) % (mod - 1);         for (int i = 0; i < 3; i++) t1[i] = ans3[i], ans3[i] = 0;         for (int i = 0; i < 3; i++)           for (int j = 0; j < 3; j++)             ans3[i] = (ans3[i] + t1[j] * a1[j][i]) % (mod - 1);         for (int i = 0; i < 5; i++) t2[i] = ans4[i], ans4[i] = 0;         for (int i = 0; i < 5; i++)           for (int j = 0; j < 5; j++)             ans4[i] = (ans4[i] + t2[j] * a2[j][i]) % (mod - 1);       }       for (int i = 0; i < 3; i++)         for (int j = 0; j < 3; j++) aa1[i][j] = a1[i][j], a1[i][j] = 0;       for (int i = 0; i < 3; i++)         for (int j = 0; j < 3; j++)           for (int k = 0; k < 3; k++)             a1[i][j] = (a1[i][j] + aa1[i][k] * aa1[k][j]) % (mod - 1);       for (int i = 0; i < 5; i++)         for (int j = 0; j < 5; j++) aa2[i][j] = a2[i][j], a2[i][j] = 0;       for (int i = 0; i < 5; i++)         for (int j = 0; j < 5; j++)           for (int k = 0; k < 5; k++)             a2[i][j] = (a2[i][j] + aa2[i][k] * aa2[k][j]) % (mod - 1);     }     ans = kp(f1, ans1[2]) * kp(f2, ans2[2]) % mod * kp(f3, ans3[2]) % mod *           kp(c, ans4[2]) % mod;     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0,                              x, y, z, cnt = 0;     string s;     set<long long> zero, one;     set<long long>::iterator it, it1;     vector<long long> v[200005];     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) {         zero.insert(i);       } else {         one.insert(i);       }     }     while (one.size()) {       i = -1;       if (zero.size() == 0) {         cout << -1;         return 0;       }       it = zero.lower_bound(i);       i = *it;       zero.erase(i);       v[ans].push_back(i);       while (one.size()) {         it = one.lower_bound(i);         if (it == one.end()) {           break;         }         i = *it;         one.erase(i);         v[ans].push_back(i);         it = zero.lower_bound(i);         if (it == zero.end()) {           cout << -1;           return 0;         }         i = *it;         zero.erase(i);         v[ans].push_back(i);       }       ans++;     }     k = ans + zero.size();     cout << k << endl;     for (i = 0; i < ans; i++) {       for (j = 0; j < v[i].size(); j++) {         if (j == 0) {           cout << v[i].size() <<    ;         }         cout << v[i][j] + 1 <<    ;       }       cout << endl;     }     while (zero.size()) {       it = zero.begin();       cout << 1 <<     << *it + 1 << endl;       zero.erase(it);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long int a[101];   long long int dp[101][101][101];   long long int f(int start, int end, int l) {     if (start > end) {       return 0;     }     if (start == end) {       return a[l];     }     if (dp[start][end][l] != 0) {       return dp[start][end][l];     }     long long int ans = a[l] + f(start + 1, end, 1);     for (int i = start + 1; i <= end; i++) {       if (s[i] == s[start]) {         ans = max(ans, f(start + 1, i - 1, 1) + f(i, end, l + 1));       }     }     dp[start][end][l] = ans;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> s;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     a[0] = 0;     cout << f(0, n - 1, 1);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 103, maxm = 1003;   int m, n, ar[maxn];   double dp[maxn * maxm], pre[maxn * maxm];   int main() {     scanf( %d%d , &n, &m);     if (m == 1) {       printf( 1 );       return 0;     }     int sum = 0;     for (int i = 1; i <= n; i++) scanf( %d , &ar[i]), sum += ar[i];     dp[0] = 1;     for (int i = 1; i <= n; i++) {       pre[0] = dp[0];       for (int j = 1; j <= i * m; j++) pre[j] = pre[j - 1] + dp[j];       for (int j = i * m; j; j--) {         dp[j] = pre[j - 1];         if (j - m - 1 >= 0) dp[j] -= pre[j - m - 1];         if (j - ar[i] >= 0) dp[j] -= dp[j - ar[i]];         dp[j] /= m - 1;       }       dp[0] = 0;     }     double ans = 0;     for (int i = 0; i < sum; i++) ans += dp[i];     printf( %.10lf n , 1 + ans * (m - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n, 0);       vector<long long> pos(32, 0);       for (long long i = 0; i < n; i++) {         cin >> a[i];         long long ind = 0;         long long num = a[i];         while (num != 0) {           if (num % 2 == 1) pos[ind] += 1;           ind++;           num /= 2;         }       }       long long f = 0;       for (long long i = pos.size() - 1; i >= 0; i--) {         if (pos[i] % 2 == 1) {           f = 1;           if (pos[i] == 1)             cout <<  WIN n ;           else {             if ((pos[i] / 2) % 2 == 0)               cout <<  WIN n ;             else {               if (n % 2 == 0)                 cout <<  WIN n ;               else                 cout <<  LOSE n ;             }           }           break;         }       }       if (f == 0) cout <<  DRAW n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, t, piles = 1;     bool flag = true;     cin >> n;     vector<int> s1, s2;     vector<int>::iterator it;     for (i = 0; i < n; i++) {       cin >> t;       s1.push_back(t);     }     sort(s1.begin(), s1.end());     while (flag) {       flag = false;       for (it = s1.begin(), i = 0; it != s1.end();) {         if ((*it) < i) {           flag = true;           s2.push_back(*it);           s1.erase(it);         } else {           it++;           i++;         }       }       if (flag) {         piles += 1;         s1.clear();         s1 = s2;         s2.clear();       }     }     cout << piles;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int M = 1 << 16;   bitset<N> mp[M];   int a[N], sum, rk[N], k, n;   priority_queue<pair<int, int> > que;   void dfs(int s, int t) {     if (s == 0) return;     int r = 0;     for (; t * k < N && mp[s][t * k]; r++, t *= k) {     }     for (int i = 0; i < n; i++) {       if (s & (1 << i)) rk[i] += r;     }     for (int i = 0; i < n; i++) {       if (s & (1 << i) && t >= a[i] && mp[s - (1 << i)][t - a[i]]) {         dfs(s - (1 << i), t - a[i]);         return;       }     }   }   int main() {     sum = 0;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       sum += a[i];     }     mp[0][0] = 1;     for (int s = 1; s < (1 << n); s++) {       for (int i = 0; i < n; i++) {         if (s & (1 << i)) mp[s] |= mp[s - (1 << i)] << a[i];       }       for (int i = sum / k; i >= 1; i--) {         if (mp[s][i * k]) mp[s][i] = 1;       }     }     if (!mp[(1 << n) - 1][1]) {       puts( NO );       return 0;     }     puts( YES );     dfs((1 << n) - 1, 1);     for (int i = 0; i < n; i++) {       que.push({rk[i], a[i]});     }     while (que.size() != 1) {       pair<int, int> u = que.top();       que.pop();       pair<int, int> v = que.top();       que.pop();       printf( %d %d n , u.second, v.second);       u.second += v.second;       while (u.second % k == 0) {         u.second /= k;         u.first--;       }       que.push(u);     }   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int u;     int v;     int c;   };   bool compare(edge e, edge u) { return e.c < u.c; }   int findparent(int parent[], int u) {     int p = parent[u];     if (p == u) {       return p;     }     int fp = findparent(parent, p);     if (p == fp) {       return fp;     }     parent[u] = fp;     return parent[u];   }   int mc = -1;   void uni(int special[], int parent[], int u, int v, int c) {     int up = findparent(parent, u);     int vp = findparent(parent, v);     if (vp == up) {       return;     }     parent[up] = vp;     if (special[up] != 0 && special[vp] != 0) {       special[vp] = c;       special[up] = c;       mc = c;     } else {       int max = special[up] > special[vp] ? special[up] : special[vp];       special[up] = special[vp] = max;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     vector<edge> edges;     int special[n];     for (int i = 0; i < n; i++) {       special[i] = 0;     }     for (int i = 0; i < k; i++) {       int tmp;       cin >> tmp;       tmp--;       special[tmp] = 1;     }     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       u--;       v--;       edges.push_back({u, v, w});     }     sort(edges.begin(), edges.end(), compare);     int parent[n];     for (int i = 0; i < n; i++) {       parent[i] = i;     }     for (int i = 0; i < m; i++) {       int u = edges[i].u;       int v = edges[i].v;       int c = edges[i].c;       uni(special, parent, u, v, c);     }     for (int i = 0; i < k; i++) {       cout << mc <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double f[400][3100], p[400][3100], ans;   int n, m, up[400];   void dp(int i) {     int j;     long double pre, nw;     pre = f[i][0];     f[i][0] = 0;     for (j = 1; j <= n; j++) {       nw = f[i][j];       f[i][j] = pre * p[i][j] + f[i][j - 1] * (1 - p[i][j]);       pre = nw;     }     up[i]++;   }   int main() {     int i, j, k, x, to;     long double mx;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &x);         p[j][i] = (long double)x / (long double)1000;       }     for (i = 1; i <= m; i++)       for (j = 0; j <= n; j++) f[i][j] = 1;     for (i = 1; i <= m; i++) up[i] = 0;     for (i = 1; i <= m; i++) dp(i);     ans = 0;     for (i = 1; i <= n; i++) {       mx = -1;       for (j = 1; j <= m; j++)         if (f[j][n] > mx) mx = f[j][n], to = j;       ans += mx;       dp(to);     }     double out = ans;     printf( %.11f n , out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1010], seq[1010], id;   int qtes, u[1000010], v[1000010];   inline void add(int x, int y) {     a[y] -= a[x], a[x] *= 2, u[++qtes] = x, v[qtes] = y;   }   inline void Solve(int x, int y, int z) {     int q[3] = {x, y, z};     register int i, j;     for (i = 0; i < 3; ++i)       for (j = i + 1; j < 3; ++j)         if (a[q[i]] > a[q[j]]) swap(q[i], q[j]);     x = q[0], y = q[1], z = q[2];     if (x == y) {       add(x, y);       return;     }     if (y == z) {       add(y, z);       return;     }     int w = a[y] / a[x];     int tmp = w, up;     for (i = 0; tmp; ++i)       if ((tmp >> i) & 1) up = i, tmp ^= (1 << i);     for (i = 0; i <= up; ++i) {       if ((w >> i) & 1)         add(x, y);       else         add(x, z);     }     if (a[x] == 0 || a[y] == 0 || a[z] == 0)       return;     else       Solve(x, y, z);   }   int main() {     int n;     scanf( %d , &n);     register int i, j;     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     int last = 0;     for (i = 1; i <= n; ++i)       if (a[i]) ++last;     if (last < 2) {       puts( -1 );       return 0;     } else if (last == 2) {       puts( 0 );       return 0;     }     for (last -= 2; last--;) {       for (id = 0, i = 1; i <= n; ++i)         if (a[i]) seq[++id] = i;       Solve(seq[1], seq[2], seq[3]);     }     printf( %d n , qtes);     for (i = 1; i <= qtes; ++i) printf( %d %d n , u[i], v[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MAXN = 1e5 + 10;   const int MAXK = 5 + 1;   long long sumv[MAXK][MAXN << 2], setv[MAXN << 2];   long long prefix[MAXK][MAXN], C[MAXK][MAXK];   void Pushdown(int o, int lft, int rht) {     if (setv[o] != -1) {       setv[(o << 1)] = setv[(o << 1 | 1)] = setv[o];       int mid = lft + rht >> 1;       for (int k = 0; k < MAXK; ++k) {         sumv[k][(o << 1)] =             setv[(o << 1)] * (prefix[k][mid] - prefix[k][lft - 1] + mod) % mod;         sumv[k][(o << 1 | 1)] =             setv[(o << 1 | 1)] * (prefix[k][rht] - prefix[k][mid] + mod) % mod;       }       setv[o] = -1;     }   }   void Pushup(int o) {     for (int k = 0; k < MAXK; ++k)       sumv[k][o] = sumv[k][(o << 1)] + sumv[k][(o << 1 | 1)];   }   void Build(int o, int lft, int rht) {     if (lft == rht) {       scanf( %lld , setv + o);       sumv[0][o] = setv[o] % mod;       for (int k = 1; k < MAXK; ++k) sumv[k][o] = sumv[k - 1][o] * lft % mod;     } else {       int mid = lft + rht >> 1;       Build((o << 1), lft, mid);       Build((o << 1 | 1), mid + 1, rht);       Pushup(o);     }   }   int ul, ur, uv;   void Update(int o, int lft, int rht) {     if (ul <= lft and rht <= ur) {       setv[o] = uv;       for (int k = 0; k < MAXK; ++k)         sumv[k][o] = setv[o] * (prefix[k][rht] - prefix[k][lft - 1] + mod) % mod;     } else {       Pushdown(o, lft, rht);       int mid = lft + rht >> 1;       if (ul <= mid) Update((o << 1), lft, mid);       if (ur > mid) Update((o << 1 | 1), mid + 1, rht);       Pushup(o);     }   }   int ql, qr, qk;   long long Query(int o, int lft, int rht) {     if (ql <= lft and rht <= qr) return sumv[qk][o];     Pushdown(o, lft, rht);     int mid = lft + rht >> 1;     long long ans = 0;     if (ql <= mid) ans += Query((o << 1), lft, mid);     if (qr > mid) ans += Query((o << 1 | 1), mid + 1, rht);     return ans % mod;   }   void work() {     for (int i = 0; i < MAXK; ++i) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;     }     for (int i = 1; i < MAXN; ++i) {       long long u = 1;       for (int k = 0; k < MAXK; ++k) {         prefix[k][i] = (prefix[k][i - 1] + u) % mod;         u = u * i % mod;       }     }     int N, Q, K;     char cmd[20];     long long ans, ret;     scanf( %d%d , &N, &Q);     memset(setv, -1, sizeof setv);     Build(1, 1, N);     while (Q--) {       scanf( %s , cmd);       switch (cmd[0]) {         case  ? :           scanf( %d%d%d , &ql, &qr, &K);           ans = 0;           ret = 1;           for (qk = K; qk >= 0; --qk, ret = ret * (1 - ql) % mod)             ans += Query(1, 1, N) * (ret) % mod * C[K][qk] % mod;           printf( %lld n , (ans % mod + mod) % mod);           break;         case  = :           scanf( %d%d%d , &ul, &ur, &uv);           Update(1, 1, N);           break;       }     }   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   const int D = 510;   const int S = 5010;   bool dp[S][D];   pair<pii, int> prv[S][D];   queue<pii> q;   string reconstruct(int s, int r) {     if (prv[s][r].second == -1) return   ;     return reconstruct(prv[s][r].first.first, prv[s][r].first.second) +            char(prv[s][r].second +  0 );   }   int main() {     ios_base::sync_with_stdio(false);     int d, s;     cin >> d >> s;     memset(dp, 0, sizeof dp);     memset(prv, -1, sizeof prv);     q.push({0, 0});     dp[0][0] = true;     while (!q.empty()) {       int sd = q.front().first;       int r = q.front().second;       q.pop();       for (int dig = 0; dig < 10; ++dig) {         int newr = (r * 10 + dig) % d;         if (sd + dig > s) continue;         if (!dp[sd + dig][newr]) {           dp[sd + dig][newr] = true;           prv[sd + dig][newr] = {{sd, r}, dig};           q.push({sd + dig, newr});         }       }     }     if (!dp[s][0])       cout << -1 <<   n ;     else       cout << reconstruct(s, 0) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, dst, cur;   int main() {     cin >> m >> n >> k;     dst = n + m + 34;     for (int i = 0; i < k; i++) {       cin >> x >> y;       cur = min(min(x - 1, y - 1), min(m - x, n - y));       dst = min(dst, cur);     }     if (dst < 5)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ceil(long long a, long long b) {     if (a % b == 0) return a / b;     return a / b + 1;   }   int main() {     long long n;     int q;     scanf( %lld %d , &n, &q);     for (int j = 0; (j) < int(q); (j)++) {       int x, y;       scanf( %d %d , &y, &x);       long long ans = 0;       int l = y - 1;       int m = l / 2;       if ((x + y) % 2 == 0) {         ans += ceil(n, 2) * (l - m) + (n / 2) * m;         ans += (y % 2 == 0 ? x : x + 1) / 2;       } else {         ans += ceil(n, 2) * m + (n / 2) * (l - m);         ans += (y % 2 == 0 ? x + 1 : x) / 2;         ans += ceil(n * n, 2);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, xian = (long long)1500000 * 1500000;   long long q[N], ans[N], n;   pair<long long, long long> a[N];   inline long long cal(pair<long long, long long> x) {     return x.first * x.first + x.second * x.second;   }   pair<long long, long long> solve(long long l, long long r) {     if (l == r) return a[q[l]];     long long mid = (l + r) >> 1;     while (1) {       random_shuffle(&q[l], &q[r + 1]);       pair<long long, long long> t1 = solve(l, mid), t2 = solve(mid + 1, r);       pair<long long, long long> t3 = make_pair(t1.first + t2.first,                                                 t1.second + t2.second),                                  t4 = make_pair(t1.first - t2.first,                                                 t1.second - t2.second);       pair<long long, long long> t = cal(t3) < cal(t4) ? t3 : t4;       if (cal(t) <= xian) return t;     }   }   pair<long long, long long> sol(long long l, long long r) {     if (l == r) return a[q[l]];     long long mid = (l + r) >> 1;     while (1) {       pair<long long, long long> t1 = sol(l, mid), t2 = sol(mid + 1, r);       pair<long long, long long> t3 = make_pair(t1.first + t2.first,                                                 t1.second + t2.second),                                  t4 = make_pair(t1.first - t2.first,                                                 t1.second - t2.second),                                  t;       if (cal(t3) < cal(t4))         t = t3;       else {         t = t4;         ans[mid + 1] *= -1;         ans[r + 1] *= -1;       }       if (cal(t) <= xian) return t;     }   }   long long an[N];   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i].first, &a[i].second);       q[i] = i;       ans[i] = 1;     }     solve(1, n);     sol(1, n);     ans[0] = 1;     for (long long i = 1; i <= n; i++) ans[i] *= ans[i - 1];     for (long long i = 1; i <= n; i++) an[q[i]] = ans[i];     for (long long i = 1; i <= n; i++)       if (an[i] == 1) {         putchar( 1 );         putchar(   );       } else {         putchar( - );         putchar( 1 );         putchar(   );       }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void gg(T &res) {     res = 0;     T fh = 1;     char ch = getchar();     while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) fh = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     res *= fh;   }   inline int gi() {     int x;     gg(x);     return x;   }   inline long long gl() {     long long x;     gg(x);     return x;   }   const int MAXN = 610;   const int MAXM = 200010;   const int INF = 1e9;   const int BIG = 1e7;   int bt = 1, b[MAXN], NEXT[MAXM], to[MAXM], val[MAXM];   inline void add(int x, int y, int z) {     NEXT[++bt] = b[x];     b[x] = bt;     to[bt] = y;     val[bt] = z;     NEXT[++bt] = b[y];     b[y] = bt;     to[bt] = x;     val[bt] = 0;   }   int T, dis[MAXN], q[MAXN];   bool fc() {     for (int i = 1; i <= T; i++) dis[i] = 0;     dis[0] = 1;     int l = 1, r = 0;     q[++r] = 0;     while (l <= r) {       int x = q[l++];       for (int i = b[x]; i; i = NEXT[i]) {         if (!val[i] || dis[to[i]]) continue;         dis[to[i]] = dis[x] + 1;         if (to[i] == T) return 1;         q[++r] = to[i];       }     }     return 0;   }   int dfs(int x, int M) {     if (x == T) return M;     int ans = 0;     for (int i = b[x]; i; i = NEXT[i]) {       if (!val[i] || dis[x] + 1 != dis[to[i]]) continue;       int r = dfs(to[i], min(val[i], M - ans));       val[i] -= r;       val[i ^ 1] += r;       if ((ans += r) == M) return ans;     }     dis[x] = -1;     return ans;   }   int main() {     int n = gi();     T = n + n + 1;     for (int i = 1; i <= n; i++)       for (int t = gi(); t--;) add(i, n + gi(), INF);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int x = BIG - gi();       ans -= x;       add(0, i, x);       add(n + i, T, BIG);     }     while (fc()) ans += dfs(0, INF);     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long INF = 1e12;   vector<long long> ans[200010];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) ans[i].push_back(-1);     ans[0][0] = a[0];     long long sz = 1;     for (long long i = 1; i < n; i++) {       long long l = -1, r = sz;       while (r - l > 1) {         long long mid = (l + r) / 2;         long long tmp = ans[mid][ans[mid].size() - 1];         if (tmp > a[i]) {           l = mid;         } else {           r = mid;         }       }       if (r == sz) {         ans[r][0] = a[i];         sz++;       } else {         ans[r].push_back(a[i]);       }     }     for (long long i = 0; i < sz; i++) {       for (long long ii = 0; ii < ans[i].size(); ii++) {         if (ii) cout <<    ;         cout << ans[i][ii];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   const int INF = 0x7ffffff;   const int MOD = 1e9 + 7;   int a[MAXN + 17], b[MAXN + 17], id[MAXN + 17];   bool cmp(int c, int d) { return a[c - 1] > a[d - 1]; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) id[i] = i + 1;     sort(id, id + n, cmp);     cout << n / 2 + 1 << endl;     cout << id[0] << endl;     if (!(n & 1)) cout << id[1] << endl;     int t = (n & 1) ? n / 2 : n / 2 - 1, j;     for (j = n - 1; t > 0; t--, j -= 2)       cout << (b[id[j] - 1] > b[id[j - 1] - 1] ? id[j] : id[j - 1]) <<    ;     return 0;   }