malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, k, s, a[5][205];   struct node {     int id, x, y;   };   vector<node> ans;   inline void park() {     for (int i = 0; i <= 2 * n - 1; ++i)       if (a[1][i] && a[1][i] == a[0][i]) {         ans.push_back(node{a[1][i], i / n ? 4 : 1, i % n + 1});         a[1][i] = 0;         k--;       }   }   inline bool judge() {     park();     for (int i = 0; i <= 2 * n - 1; ++i)       if (!a[1][i]) return 1;     return 0;   }   inline void turn() {     vector<node> t1, t2;     int t = a[1][2 * n - 1];     for (int i = 2 * n - 1; i >= 1; --i) {       a[1][i] = a[1][i - 1];       if (a[1][i]) {         if (i > s)           t1.push_back(node{a[1][i], i / n ? 3 : 2, i % n + 1});         else           t2.push_back(node{a[1][i], i / n ? 3 : 2, i % n + 1});       }     }     a[1][0] = t;     if (t) t2.push_back(node{t, 2, 1});     int sz1 = t1.size(), sz2 = t2.size();     for (int i = 0; i <= sz2 - 1; ++i) ans.push_back(t2[i]);     for (int i = 0; i <= sz1 - 1; ++i) ans.push_back(t1[i]);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i <= n - 1; ++i) scanf( %d , &a[0][i]);     for (int i = 0; i <= n - 1; ++i) scanf( %d , &a[1][i]);     for (int i = 2 * n - 1; i >= n; --i) scanf( %d , &a[1][i]);     for (int i = 2 * n - 1; i >= n; --i) scanf( %d , &a[0][i]);     if (!judge()) return puts( -1 ), 0;     for (int i = 0; i <= 2 * n - 1; ++i)       if (!a[1][i]) {         s = i;         break;       }     while (k) {       turn();       park();       s = (s + 1) % (2 * n);     }     int sz = ans.size();     printf( %d n , sz);     for (int i = 0; i < sz; ++i) {       if (ans[i].x == 3 || ans[i].x == 4) ans[i].y = n - ans[i].y + 1;       printf( %d %d %d n , ans[i].id, ans[i].x, ans[i].y);     }     return 0;   }
#include <bits/stdc++.h>   #define int long long   using namespace std;   signed main(){       int t;       cin >> t;       while(t--){           int k, n, m;           cin >> k >> n >> m;           int a[n + 1], b[m + 1];           for(int i = 0;i < n;i++){               cin >> a[i];           }           for(int i = 0;i < m;i++){               cin >> b[i];           }           a[n] = 0x3f3f3f3f, b[m] = 0x3f3f3f3f;           vector<int> ans; //答案序列           int l = k, ai = 0, bi = 0; //ai，bi分别表示两个数组分别删到了哪里，l为行数           bool flag = false;           while(ans.size() < n + m){               if(a[ai] == 0){                   ai++, ans.push_back(0);                   l++;                   continue;               }               else if(b[bi] == 0){                   bi++, ans.push_back(0);                   l++;                   continue;               }               int p = min(a[ai], b[bi]);               if(p == a[ai]){                   ai++;               }               else{                   bi++;               }               if(p > l){                   flag = true;                   break;               }               ans.push_back(p);           }           if(flag){               cout << -1 << endl;           }           else{               for(int i = 0;i < ans.size();i++){                   cout << ans[i] <<    ; //输出答案序列               }               cout << endl;           }       }       return 0;   }
#include <bits/stdc++.h>   const int M = 2000;   int T, n, x, ans, f0[M + 10], f1[M + 10];   inline int min(int x, int y) { return x < y ? x : y; }   inline int max(int x, int y) { return x > y ? x : y; }   void work() {     for (int i = 0; i <= M; ++i) f0[i] = i;     scanf( %d , &n), ans = 114514;     while (n--) {       scanf( %d , &x), memset(f1, 0x3f, sizeof f1);       for (int i = 0; i <= M; ++i)         i - x >= 0 && (f1[i] = min(f1[i], max(f0[i - x], i))),             i + x <= M && (f1[i] = min(f1[i], f0[i + x]));       memcpy(f0, f1, sizeof f0);     }     for (int i = 0; i <= M; ++i) ans = min(ans, f0[i]);     printf( %d n , ans);   }   int main() {     scanf( %d , &T);     while (T--) work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int L = 332748118, M = 998244353, N = 1e6 + 5;   int l[N];   int ksm(int a, long long b) {     int an = 1;     while (b) {       if (b & 1) an = 1ll * an * a % M;       a = 1ll * a * a % M;       b >>= 1;     }     return an;   }   int main() {     int n, c = 1, a = 0, b = 0, f = 1, s, d = 1, e, g, h;     scanf( %d , &n);     e = s = ksm(L, n);     h = g = ksm(3, 1ll * n * n);     l[1] = 1;     for (int i = 1; i <= n; i++) {       if (i != 1) l[i] = (M - 1ll * M / i * l[M % i]) % M;       c = 1ll * (n - i + 1) * l[i] % M * c % M;       d = 1ll * d * s % M;       e = 3ll * e % M;       h = 3ll * h * s % M;       a = (a + 1ll * f * c % M * h % M) % M;       b = (b + 1ll * f * c * d % M * (ksm(1 - e, n) - 1) % M) % M;       f = -f;     }     printf( %lld , (((a << 1) + 3ll * g * b) % M + M) % M);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, d;     cin >> n >> k >> d;     vector<int> U(k, 0);     for (int i = 0; i < k; i++) U[i] = i + 1;     vector<int> V(d - 1, 0);     for (int i = 0; i < d - 1; i++) V[i] = i + 1;     vector<long long> dp2(n + 1, 0);     vector<long long> dp1(n + 1, 0);     dp2[0] = 1;     dp1[0] = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < U.size(); j++) {         if (i + U[j] <= n)           dp2[i + U[j]] = (dp2[i + U[j]] % (long long)1000000007 +                            dp2[i] % (long long)1000000007) %                           (long long)1000000007;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < V.size(); j++) {         if (i + V[j] <= n)           dp1[i + V[j]] = (dp1[i + V[j]] % (long long)1000000007 +                            dp1[i] % (long long)1000000007) %                           (long long)1000000007;       }     }     cout << (dp2[n] - dp1[n] + (long long)1000000007) % (long long)1000000007          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct triple {     int x, y, z;   };   int n, x1, y11, x2, y22;   string s[9];   int main() {     cin >> n;     while (n--) {       for (__typeof(8) i = 1; i <= 8; i++) cin >> s[i], s[i] =  #  + s[i];       bool tmp = false;       for (__typeof(8) i = 1; i <= 8; i++) {         for (__typeof(8) j = 1; j <= 8; j++)           if (s[i][j] ==  K ) {             if (tmp == false) {               tmp = true;               x1 = i;               y11 = j;             } else {               x2 = i;               y22 = j;             }           }       }       tmp = false;       for (__typeof(8) i = 1; i <= 8; i++)         for (__typeof(8) j = 1; j <= 8; j++)           if (tmp == false && s[i][j] !=  # ) {             int tx1 = abs(i - x1), ty1 = abs(j - y11), tx2 = abs(i - x2),                 ty2 = abs(j - y22);             if (tx1 % 2 == 0 && ty1 % 2 == 0 && tx2 % 2 == 0 && ty2 % 2 == 0 &&                 (tx1 / 2 + ty1 / 2) % 2 == 0 && (tx2 / 2 + ty2 / 2) % 2 == 0 &&                 (max(tx1 / 2, ty1 / 2) + max(tx2 / 2, ty2 / 2)) % 2 == 0) {               cout <<  YES n ;               tmp = true;             }           }       if (tmp == false) cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, b;   int t[200005], d[200005];   queue<pair<int, pair<int, int> > > Q;   long long ans[200005];   int main() {     int i, j;     scanf( %d , &n);     scanf( %d , &b);     for (i = 1; i <= n; i++) {       scanf( %d , &t[i]);       scanf( %d , &d[i]);     }     memset(ans, -1, sizeof(ans));     long long curr = 0;     i = 1;     while (1) {       if (i <= n && Q.size() == 0) {         Q.push({i, {t[i], d[i]}});         i++;       }       if (Q.size() == 0) break;       pair<int, pair<int, int> > now = Q.front();       Q.pop();       curr = max(curr, (long long)now.second.first);       long long en = curr + now.second.second;       ans[now.first] = en;       while (i <= n && Q.size() < b) {         Q.push({i, {t[i], d[i]}});         i++;       }       while (i <= n && t[i] < en) {         i++;       }       curr = en;     }     for (i = 1; i <= n; i++) printf( %lld  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int SIZE = (int)1e6;   int n, k, from, to;   vector<int> g[SIZE], h[SIZE];   vector<int> ord;   vector<bool> check;   string ans;   int component[SIZE];   int comp;   void dfs1(int v) {     check[v] = true;     for (int i : g[v]) {       if (!check[i]) {         dfs1(i);       }     }     ord.push_back(v);   }   void dfs2(int v) {     check[v] = true;     component[v] = comp;     for (int i : h[v]) {       if (!check[i]) {         dfs2(i);       }     }   }   int main() {     cin >> n >> k;     for (int j = 0; j < 2; j++) {       cin >> from;       from--;       for (int i = 1; i < n; i++) {         cin >> to;         to--;         g[from].push_back(to);         h[to].push_back(from);         from = to;       }     }     check.resize(n, false);     for (int i = 0; i < n; i++) {       if (!check[i]) {         dfs1(i);       }     }     for (int i = 0; i < n; i++) {       check[i] = false;     }     for (int i = ord.size() - 1; i >= 0; i--) {       if (!check[ord[i]]) {         dfs2(ord[i]);         comp++;       }     }     if (comp < k) {       cout <<  NO ;       return 0;     }     ans.resize(n);     cout <<  YES  << endl;     for (int i = 0; i < ans.size(); i++) {       if (k - 1 < component[i]) {         ans[i] = char( a  + k - 1);       } else {         ans[i] = char( a  + component[i]);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p, k, ans, cnt, num[1000005], check[1000005], a, now, fac[100005];   int main() {     fac[0] = fac[1] = 1;     ans = 1;     scanf( %lld%lld , &p, &k);     if (k == 0) {       for (int i = 1; i < p; i++) {         ans *= p;         ans %= 1000000007;       }       printf( %lld , ans);       return 0;     }     if (k == 1) {       for (int i = 0; i < p; i++) {         ans *= p;         ans %= 1000000007;       }       printf( %lld , ans);       return 0;     }     check[0] = 1;     for (int i = 1; i < p; i++) {       a = (k * i) % p;       num[i] = a;     }     for (int i = 1; i < p; i++) {       if (!check[i]) {         now = i;         while (!check[now]) {           check[now] = 1;           now = num[now];           cnt++;         }       }       if (cnt > 1) ans *= p;       cnt = 0;       ans %= 1000000007;     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long tmp = sqrt(n);       vector<long long> ans;       ans.push_back(0);       for (long long i = 1; i <= tmp; i++) {         ans.push_back(i);         if (n / i != i) {           ans.push_back(n / i);         }       }       sort(ans.begin(), ans.end());       cout << ans.size() << endl;       for (long long v : ans) cout << v <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int is_prime(long long int n) {     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a, b, c, d, k;       cin >> a >> b >> c >> d >> k;       a = (a + c - 1) / c;       b = (b + d - 1) / d;       if (a + b <= k)         cout << a <<     << b << endl;       else         cout << -1 << endl;     }     return 0;   }
#include<iostream>   #include<cmath>   using namespace std;      long long l,r,d;      int main()   {    int t;    cin >> t;    while(t--)    {     scanf( %lld %lld %lld ,&l,&r,&d);     if(min(l,r) * d >= max(l,r) - min(l,r)) cout <<  YES  << endl;     else cout <<  NO  << endl;    }    return 0;    }
#include <bits/stdc++.h>   using namespace std;   char st[100000 + 123];   bool inm[256];   int main() {     scanf( %s , st);     memset(inm, 0, sizeof(inm));     inm[ A ] = true;     inm[ H ] = true;     inm[ I ] = true;     inm[ M ] = true;     inm[ O ] = true;     inm[ T ] = true;     inm[ U ] = true;     inm[ V ] = true;     inm[ W ] = true;     inm[ X ] = true;     inm[ Y ] = true;     int r = strlen(st) - 1;     int l = 0;     bool flag = true;     while (l <= r) {       if (st[l] != st[r] || !inm[st[l]]) {         flag = false;         break;       }       l++;       r--;     }     if (flag)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   long long niz[300005];   long long ima[605][605];   long long res[300005];   long long dp[300005];   struct strukt {     int a, b, ind;   } query[300005];   bool cmp(strukt a, strukt b) { return a.b < b.b; }   const int k = 600;   int main() {     ios_base::sync_with_stdio(false);     cout.precision(10);     cout << fixed;     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> niz[i];     int q;     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> query[i].a >> query[i].b;       query[i].ind = i;     }     sort(query + 1, query + 1 + q, cmp);     for (int i = 1; i <= q; i++) {       if (query[i].b > k) {         long long sum = 0;         int a = query[i].a;         int b = query[i].b;         for (int j = a; j <= n; j += b) {           sum += niz[j];         }         res[query[i].ind] = sum;       } else if (query[i].b == query[i - 1].b) {         res[query[i].ind] = dp[query[i].a];       } else {         int b = query[i].b;         for (int j = n; j >= 1; j--) {           if (j + b > n)             dp[j] = niz[j];           else             dp[j] = niz[j] + dp[j + b];         }         res[query[i].ind] = dp[query[i].a];       }     }     for (int i = 1; i <= q; i++) cout << res[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     int m;     cin >> n >> m;     int l;     int r;     int arr[n];     int pos = 0;     int neg = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == -1) {         neg++;       } else {         pos++;       }     }     int mn = min(neg, pos);     for (int i = 0; i < m; i++) {       cin >> l >> r;       int c = 0;       if (l == r) {         cout <<  0  << endl;         c++;       }       if (c == 0) {         if ((abs(l - r) + 1) / 2 <= mn && (abs(l - r) + 1) % 2 == 0) {           cout <<  1  << endl;         } else {           cout <<  0  << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1147483646;   const long long MX2 = 9223372036854775800;   const int MOD = 1000000007;   int p[30];   int find(int n) {     if (p[n] < 0) return n;     return p[n] = find(p[n]);   }   void uni(int e1, int e2) {     e1 = find(e1);     e2 = find(e2);     if (e1 == e2) return;     p[e1] = e2;     return;   }   int main() {     int n;     scanf( %d , &n);     char s1[100011], s2[100011];     vector<pair<int, int> > ans;     fill(p, p + 30, -1);     scanf( %s %s , s1, s2);     int a1, a2;     for (int i = 0; i < n; i++) {       a1 = find(int(s1[i] -  a ));       a2 = find(int(s2[i] -  a ));       if (a1 != a2) {         ans.push_back({a1, a2});         uni(a1, a2);       }     }     printf( %d n , ans.size());     for (pair<int, int> x : ans) {       printf( %c %c n , x.first +  a , x.second +  a );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> res;     res.push_back(a[0]);     int last = a[0], flag = 1;     for (int i = 1; i < n - 1;) {       if (abs(a[i] - last) + abs(a[i] - a[i + 1]) > abs(last - a[i + 1])) {         res.push_back(a[i]);         last = a[i];         i++;       } else         i++;     }     if (flag) res.push_back(a[n - 1]);     cout << res.size() <<   n ;     for (auto x : res) cout << x <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool valid(int i, int j, int n, int m) {     return i >= 0 && i < n && j >= 0 && j < m;   }   void solve() {     int n, m;     int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> a[i][j];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           for (int p = 0; p < 4; p++) {             if (valid(i + dir[p][0], j + dir[p][1], n, m) &&                 a[i + dir[p][0]][j + dir[p][1]] ==  . )               a[i + dir[p][0]][j + dir[p][1]] =  # ;           }         }       }     }     bool visited[n][m];     memset(visited, false, sizeof(visited));     queue<pair<int, int> > q;     if (a[n - 1][m - 1] ==  . ) {       q.push(make_pair(n - 1, m - 1));       visited[n - 1][m - 1] = true;     }     while (!q.empty()) {       pair<int, int> temp = q.front();       q.pop();       for (int p = 0; p < 4; p++) {         int x = temp.first + dir[p][0];         int y = temp.second + dir[p][1];         if (valid(x, y, n, m)) {           if (!visited[x][y] && a[x][y] !=  # ) {             q.push(make_pair(x, y));             visited[x][y] = true;           }         }       }     }     bool ans = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  G  && visited[i][j] != true) {           ans = false;           break;         } else if (a[i][j] ==  B  && visited[i][j] != false) {           ans = false;           break;         }       }     }     cout << (ans ?  Yes  :  No );   }   int main() {     int t, c = 0;     cin >> t;     while (t--) {       solve();       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;   int main() {     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       int mn = INF, mx = -1;       for (int i = 1; i <= n; ++i) {         int x;         scanf( %d , &x);         mn = min(mn, x);         mx = max(mx, x);       }       int m = (mx + mn) >> 1;       printf( %d n , max(m - mn, mx - m) <= k ? mn + k : -1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {   #ifdef DEBUG     freopen( a.in ,  r , stdin);   #endif     ios_base::sync_with_stdio(false), cin.tie(0);     int T;     cin >> T;     while (T--) {       int a[2];       cin >> a[0] >> a[1];       string s;       cin >> s;       int n = a[0] + a[1];       vector<pair<int, int>> x;       for (int i = 0; i < n / 2; ++i) {         if (s[i] ==  ?  && s[n - 1 - i] ==  ? ) {           x.emplace_back(i, n - 1 - i);         } else if (s[i] ==  ? ) {           a[s[n - 1 - i] -  0 ] -= 2;           s[i] = s[n - 1 - i];         } else if (s[n - 1 - i] ==  ? ) {           a[s[i] -  0 ] -= 2;           s[n - 1 - i] = s[i];         } else {           if (s[i] != s[n - 1 - i]) {             a[0] = -1;           } else {             a[s[i] -  0 ] -= 2;           }         }       }       if (a[0] < 0 || a[1] < 0) {         cout << -1 <<   n ;         continue;       }       for (int i = 0; i < x.size(); ++i) {         if (a[0] >= 2) {           s[x[i].first] = s[x[i].second] =  0 ;           a[0] -= 2;         } else if (a[1] >= 2) {           s[x[i].first] = s[x[i].second] =  1 ;           a[1] -= 2;         } else {           a[0] = -1;         }       }       if (a[0] < 0 || a[1] < 0) {         cout << -1 <<   n ;         continue;       }       if ((n & 1) && s[n / 2] !=  ? ) a[s[n / 2] -  0 ]--;       if ((n & 1) && s[n / 2] ==  ? ) s[n / 2] = a[0] ?  0  :  1 ;       if (a[0] < 0 || a[1] < 0)         cout << -1 <<   n ;       else         cout << s <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, k, i, j, swap;     scanf( %d %d , &n, &k);     int ara[n + 1][3];     for (i = 1; i <= n; i++) {       scanf( %d , &ara[i][1]);       ara[i][2] = i;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= (n - i); j++) {         if (ara[j][1] > ara[j + 1][1]) {           swap = ara[j][1];           ara[j][1] = ara[j + 1][1];           ara[j + 1][1] = swap;           swap = ara[j][2];           ara[j][2] = ara[j + 1][2];           ara[j + 1][2] = swap;         }       }     }     int sum = 0, p = 0;     for (i = 1; i <= n; i++) {       sum = sum + ara[i][1];       if (sum <= k)         p++;       else         break;     }     if (p == 0)       printf( 0 n );     else {       printf( %d n , p);       for (i = 1; i <= p; i++) printf( %d  , ara[i][2]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int p[n + 1];     for (int i = 1; i <= n; i++) cin >> p[i];     bool done[n + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) done[j] = false;       int start = i;       while (1) {         if (done[start] == true) {           cout << start <<    ;           break;         }         done[start] = true;         start = p[start];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};   const double EPS = 1e-8;   const double PI = acos(-1.0);   int popcount(int n) { return __builtin_popcount(n); }   int popcount(long long n) { return __builtin_popcountll(n); }   template <class T>   int SIZE(T a) {     return a.size();   }   template <class T>   string IntToString(T num) {     string res;     stringstream ss;     ss << num;     return ss.str();   }   template <class T>   T StringToInt(string str) {     T res = 0;     for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] -  0 );     return res;   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   void PrintSeq(T &a, int sz) {     for (int i = 0; i < sz; i++) {       cout << a[i];       if (sz == i + 1)         cout << endl;       else         cout <<    ;     }   }   bool EQ(double a, double b) { return abs(a - b) < EPS; }   void fastStream() {     cin.tie(0);     std::ios_base::sync_with_stdio(0);   }   vector<string> split(string str, char del) {     vector<string> res;     for (int i = 0, s = 0; i < SIZE(str); i++) {       if (str[i] == del) {         if (i - s != 0) res.push_back(str.substr(s, i - s));         s = i + 1;       } else if (i == SIZE(str) - 1) {         res.push_back(str.substr(s));       }     }     return res;   }   int froms[1000001];   int tos[1000001];   vector<pair<int, int> > G[1000001];   bool used[1000001];   void dfs(int pprv, int prv, int now) {     used[now] = true;     for (int i = 0; i < (int)G[now].size(); i++) {       int to = G[now][i].first;       int en = G[now][i].second;       if (!used[to]) {         dfs(prv, en, to);       }     }     if (prv != -1 && pprv != -1) cout << pprv <<     << prv << endl;   }   int main() {     fastStream();     int N;     cin >> N;     for (int i = 0; i < N - 1; i++) {       cin >> froms[i] >> tos[i];       G[froms[i]].push_back(make_pair(tos[i], i + 1));       G[tos[i]].push_back(make_pair(froms[i], i + 1));     }     cout << N - 1 << endl;     for (int i = 0; i < N - 1; i++)       cout << 2 <<     << froms[i] <<     << tos[i] << endl;     for (int i = 0; i < N; i++) {       if (G[i + 1].size() == 1) {         dfs(-1, -1, i + 1);         break;       }     }     return 0;   }