malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int t, n;   string s;   int main() {     cin >> t;     for (int tc = 0; tc < t; ++tc) {       cin >> n >> s;       int res = n - 1;       for (int i = 0; i < n; ++i)         if (s[i] ==  >  || s[n - 1 - i] ==  < ) res = min(res, i);       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int, char**) {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     ;     int k;     cin >> k;     ;     int out = 0;     long long d = 1;     for (int i = 0; i < k; i++) {       d *= 10;     }     while (atoi(s.c_str()) % d != 0) {       for (string::reverse_iterator i = s.rbegin(); i != s.rend(); i++) {         if (*i !=  0 ) {           s.erase((i.base()) - 1);           out++;           break;         }       }     }     if (atoi(s.c_str()) == 0) {       out += s.length() - 1;     }     cout << out <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int in[201000];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (n); i++) {       scanf( %d , &in[i]);       in[i] += i;     }     sort(in, in + n);     for (int i = 0; i < (n - 1); i++) {       if (in[i] == in[i + 1]) {         puts( :( );         return 0;       }     }     for (int i = 0; i < (n); i++)       printf( %d%c , in[i] - i, ((i == n - 1) ?   n  :    ));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     const int maxn = 1e6 + 5e5;     vector<int> pr(maxn);     iota(pr.begin(), pr.end(), 0);     for (long long i = 2; i < maxn; ++i)       if (pr[i] == i)         for (long long j = i * i; j < maxn; j += i) pr[j] = i;     vector<bool> good(maxn, true);     good[0] = good[1] = false;     auto fill = [&](int x) {       while (x > 1) {         int p = pr[x];         while (x % p == 0) x /= p;         if (good[p])           for (int x = p; x < maxn; x += p) good[x] = false;       }     };     bool ok = true;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (!ok) continue;       if (good[x]) {         cout << x <<    n [i + 1 == n];         fill(x);       } else {         ok = false;         while (!good[x]) ++x;         cout << x <<    n [i + 1 == n];         fill(x);         for (int j = i + 1, p = 2; j < n; ++j) {           while (!good[p]) ++p;           cout << p <<    n [j + 1 == n];           fill(p);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::string;   using std::vector;   static const int MOD = 1000000000 + 7;   static long long gcd(long long x, long long y) {     return (!y) ? x : gcd(y, x % y);   }   int read_int() {     int x = 0, c = 0;     c = getchar();     while (c <= 32) c = getchar();     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   static const int N = 300000 + 8;   static const int SH = 20;   int n, c1, c2;   int dep[N], fa[N][SH], p1[N], p2[N];   int lca(int a, int b) {     if (dep[a] < dep[b]) ::std::swap(a, b);     int dif = dep[a] - dep[b];     for (int i = 0; (1 << i) <= dif; i++) {       if (dif & (1 << i)) a = fa[a][i];     }     if (a == b) return a;     for (int i = SH - 1; i >= 0; i--) {       if (fa[a][i] ^ fa[b][i]) {         a = fa[a][i];         b = fa[b][i];       }     }     return fa[a][0];   }   int get(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }   int solve() {     int mx = 0;     n = read_int();     p1[++c1] = 1;     for (int i = 2; i <= n + 1; i++) {       int pos = read_int();       fa[i][0] = pos;       dep[i] = dep[pos] + 1;       for (int j = 1; (1 << j) <= dep[i]; j++) {         fa[i][j] = fa[fa[i][j - 1]][j - 1];       }       int d1 = (c1 == 0 ? 0 : get(p1[1], i));       int d2 = (c2 == 0 ? 0 : get(p2[1], i));       if (d1 > mx) {         for (int j = 1; j <= c2; j++) {           if (get(p2[j], i) == d1) {             p1[++c1] = p2[j];           }         }         c2 = 1;         p2[1] = i;       } else if (d2 > mx) {         for (int j = 1; j <= c1; j++) {           if (get(p1[j], i) == d2) {             p2[++c2] = p1[j];           }         }         c1 = 1;         p1[1] = i;       } else if (d1 == mx)         p2[++c2] = i;       else if (d2 == mx)         p1[++c1] = i;       mx = ::std::max(mx, ::std::max(d1, d2));       printf( %d n , c1 + c2);     }     return 0;   }   int main(int argc, char* argv[]) {     ::std::ios::sync_with_stdio(false);     ::std::cin.tie(0);     ::std::cout.tie(0);     int test_count = 1;     while (test_count--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int n = a + b + 1;     int A[100000] = {0};     int x = n - a;     for (int i = 0; i < a + 1; i++) {       A[i] = x;       x++;     }     x = n - a - 1;     for (int i = a + 1; i < n; i++) {       A[i] = x;       x--;     }     for (int i = 0; i < n; i++) cout << A[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int a, b, c, d, m, n, p, q, r, x, y, z, aa, bb, cc, dd;     double pp, qq, rr, xx, yy, zz;     char ch1, ch2, ch3, ch4, ch5;     long long int i, j, k, l;     long long int cnt = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0, sum = 0, sum2 = 0,                   mx = LLONG_MIN, mn = LLONG_MAX;     long long int flag = 0, flag2 = 0;     vector<long long int> vec1, vec2, vec3;     string s1, s2, s3;     cin >> n;     for (long long int i = (long long int)(0); i < (long long int)(n); ++i) {       cin >> x;       vec1.push_back(x);     }     for (long long int i = (long long int)(0); i < (long long int)(n); ++i) {       cin >> x;       vec2.push_back(x);     }     if (n == 1) {       cout <<  0 n ;       return;     }     for (long long int i = (long long int)(n - 1); i >= (long long int)(0); --i) {       sum += vec1[i];       vec1[i] = sum;     }     sum = 0;     for (long long int i = (long long int)(0); i < (long long int)(n); ++i) {       sum += vec2[i];       vec2[i] = sum;     }     for (long long int i = (long long int)(0); i < (long long int)(n - 2); ++i) {       mx = max(vec2[i], vec1[i + 2]);       mn = min(mn, mx);     }     mn = min(mn, vec1[1]);     mn = min(mn, vec2[n - 2]);     cout << mn << endl;   }   int main() {     ios::sync_with_stdio(false);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int main() {     char s1[3000][11], s2[3000][10], s3[3000][11];     int m, n, i, j, k;     int len1, len2;     scanf( %d %d , &m, &n);     for (i = 0; i < n; i++) {       scanf( %s  , &s1[i]);       gets(s2[i]);     }     for (i = 0; i < m - 1; i++) {       scanf( %s  , &s3[i]);     }     gets(s3[m - 1]);     for (i = 0; i < m; i++) {       for (j = 0; j < n; j++) {         if (strcmp(s3[i], s1[j]) == 0 || strcmp(s3[i], s2[j]) == 0) {           len1 = strlen(s1[j]);           len2 = strlen(s2[j]);           if (len1 < len2) {             k = 0;             while (s1[j][k]) {               printf( %c , s1[j][k]);               k++;             }             printf(   );           } else if (len1 == len2) {             k = 0;             while (s1[j][k]) {               printf( %c , s1[j][k]);               k++;             }             printf(   );           } else {             k = 0;             while (s2[j][k]) {               printf( %c , s2[j][k]);               k++;             }             printf(   );           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int i, j, k, m, n, mm[110][110];     mm[0][0] = mm[1][0] = 0;     mm[1][1] = 1;     mm[0][1] = 2;     for (i = 2; i <= 100; i++) {       if (i == 2) k = 5;       for (j = 0; j <= i; j++) mm[i][j] = k;       for (j = i - 1; j >= 0; j--) mm[j][i] = k + 1;       k = mm[i][0] + 4;     }     while (scanf( %d%d , &i, &j) != EOF) {       if (i >= 0 && j >= 0)         printf( %d n , mm[i][j]);       else if (i == -1 && j == 0)         printf( 3 n );       else if (i < 0) {         if (j > -i)           printf( %d n , mm[-i][j]);         else if (j == -i)           printf( %d n , mm[-i][j] + 1);         else if (j >= 0)           printf( %d n , mm[-i][j] + 2);         else           printf( %d n , mm[-i][-j] + 2);       } else {         if (i < -j)           printf( %d n , mm[i][-j] + 2);         else if (i == -j)           printf( %d n , mm[i][-j] + 3);         else if (i == -j + 1)           printf( %d n , mm[i][-j] - 1);         else           printf( %d n , mm[i][-j]);       }     }     return 0;   }
#include <bits/stdc++.h>   const long long int mx = 1e9 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<pair<int, int>> vp, vpAns;       map<int, int> mp, mpAns, mpCnt;       int A[n + 2], x = n / k;       for (int i = 0; i < n; i++) {         cin >> A[i];         vp.push_back(make_pair(A[i], i));       }       sort(vp.begin(), vp.end());       int cnt = 0, cn = 0;       for (int i = 0; i < n; i++) {         int a = vp[i].first, b = vp[i].second;         mp[a]++;         if (mp[a] > k) {           vpAns.push_back(make_pair(b, 0));           continue;         }         cnt++;         vpAns.push_back(make_pair(b, cnt));         mpCnt[cnt]++;         if (cnt == k) cnt = 0;       }       int mn = 10000000;       for (auto u : mpCnt) {         mn = min(mn, u.second);       }       sort(vpAns.begin(), vpAns.end());       for (int i = 0; i < vpAns.size(); i++) {         int b = vpAns[i].second;         mpAns[b]++;         if (mpAns[b] > mn)           cout << 0 <<    ;         else           cout << vpAns[i].second <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const int mod = 1e9 + 7;   int t;   int n;   int m;   long long p[maxn];   int size[maxn];   vector<int> g[maxn];   void dfs(int u, int pre) {     size[u] = 1;     for (int v : g[u]) {       if (v == pre) continue;       dfs(v, u);       size[u] += size[v];     }   }   struct node {     long long x, y;     bool operator<(const node &r) const {       return (long long)x * y > (long long)r.x * r.y;     }   } Node[maxn];   bool cmp(int x, int y) { return x > y; }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) g[i].clear();       for (int i = 1; i < n; i++) {         int x, y;         scanf( %d%d , &x, &y);         g[x].push_back(y);         g[y].push_back(x);       }       scanf( %d , &m);       for (int i = 1; i <= m; i++) scanf( %lld , p + i);       sort(p + 1, p + m + 1, cmp);       dfs(1, 0);       int tot = 0;       for (int i = 2; i <= n; i++)         Node[++tot] = {(long long)n - size[i], (long long)size[i]};       sort(Node + 1, Node + tot + 1);       long long ans = 0;       if (n - 1 >= m) {         for (int i = 1; i <= m; i++) {           ans += (long long)p[i] * Node[i].x * Node[i].y;           ans %= mod;         }         for (int i = m + 1; i <= tot; i++) {           ans += (long long)Node[i].x * Node[i].y;           ans %= mod;         }       } else {         long long tt = 1;         for (int i = 1; i <= (m - n + 2); i++) {           tt *= p[i];           tt %= mod;         }         ans += (long long)tt * Node[1].x % mod * Node[1].y;         ans %= mod;         for (int i = m - n + 3; i <= m; i++) {           ans +=               (long long)p[i] * Node[i - (m - n + 1)].x * Node[i - (m - n + 1)].y;           ans %= mod;         }       }       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int S[100009], cnt[1 << 7], num[1 << 7];   char s[100009];   int len, n, nu;   inline long long rd() {     long long x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f ? -x : x;   }   int main() {     scanf( %s , s + 1);     len = strlen(s + 1);     int x;     int maxn = (1 << 6) - 1;     for (int i = 1; i <= len; ++i) {       int x = s[i] -  a ;       for (int j = 1; j <= maxn; ++j)         if (j & (1 << x)) cnt[j]++;     }     n = rd();     for (int i = 1; i <= n; ++i) {       x = rd();       scanf( %s , s + 1);       int xx = strlen(s + 1);       for (int j = 1; j <= xx; ++j) S[x] |= (1 << (s[j] -  a ));       for (int j = 1; j <= maxn; ++j)         if ((j & S[x]) == S[x]) num[j]++;     }     for (int i = 1; i <= len; ++i)       if (!S[i]) {         S[i] = maxn;         num[S[i]]++;       }     for (int i = 1; i <= len; ++i) {       bool tag = 0;       for (int j = 0; j < 6; ++j)         if ((1 << j) & S[i]) {           bool tg = 0;           for (int k = 1; k <= maxn; ++k) {             int x = (k & (1 << j)) ? cnt[k] - 1 : cnt[k],                 y = ((k & S[i]) == S[i]) ? num[k] - 1 : num[k];             if (x < y) {               tg = 1;               break;             }           }           if (!tg) {             tag = 1;             s[++nu] = j +  a ;             for (int k = 1; k <= maxn; ++k) {               if ((1 << j) & k) cnt[k]--;               if ((S[i] & k) == S[i]) num[k]--;             }             break;           }         }       if (!tag) {         puts( Impossible );         return 0;       }     }     for (int i = 1; i <= nu; ++i) printf( %c , s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     vector<int> ans;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     ans.push_back(a[0]);     for (int i = 1; i < n; i++) {       if (a[i] != ans.back()) ans.push_back(a[i]);     }     bool got = false;     int len = ans.size();     for (int i = 0; i < len - 2; i++) {       if ((ans[i + 1] - ans[i] < 3 && ans[i + 2] - ans[i] < 3 &&            ans[i + 2] - ans[i + 1] < 3)) {         got = true;         break;       }     }     cout << (got ?  YES n  :  NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0, count = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  8 ) cnt++;     }     while (cnt) {       n = n - 1;       cnt = cnt - 1;       if (n / 10 > 0) {         count++;         n = n - 10;       }     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 50, mo = 998244353;   int head[N], nn[N << 1][2], cnt;   void link(int u, int v) {     nn[++cnt][1] = v, nn[cnt][0] = head[u], head[u] = cnt;     nn[++cnt][1] = u, nn[cnt][0] = head[v], head[v] = cnt;     return;   }   int f[N][3];   void dfs(int x, int fa) {     f[x][0] = 1;     for (int i = head[x], y; i; i = nn[i][0])       if ((y = nn[i][1]) != fa) {         dfs(y, x);         int s1 = f[x][1], s2 = f[x][2];         f[x][1] = (1ll * (f[x][0] + s2) * (f[y][0] + f[y][2]) % mo +                    2ll * s1 * f[y][1] % mo + 1ll * s1 * f[y][0]) %                   mo;         f[x][2] =             (2ll * s2 * f[y][1] + 1ll * f[x][0] * f[y][1] + 1ll * s2 * f[y][0]) %             mo;         f[x][0] = 1ll * f[x][0] * (f[y][0] + f[y][1]) % mo;       }     return;   }   int main() {     int n, u, v;     cin >> n;     for (int i = 1; i < n; ++i) scanf( %d%d , &u, &v), link(u, v);     dfs(1, 0);     cout << (f[1][0] + f[1][1]) % mo;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long m, x, p[22], a[22], b[22], len, res = 1;   map<long long, int> Map[22];   inline void init(long long n) {     for (register long long i = 2; i * i <= n; i++)       if (n % i == 0) {         len++;         p[len] = i;         while (n % i == 0) n /= i, a[len]++;       }     if (n > 1) len++, p[len] = n, a[len] = 1;   }   inline void init2(long long n, int tp) {     for (register long long i = 2; i * i <= n; i++) {       while (n % i == 0) Map[tp][i]++, n /= i;     }     if (n > 1) Map[tp][n]++;   }   inline long long mul(long long a, long long n, long long mo) {     long long res = 0;     n %= mo;     a %= mo;     if (mo <= 2000000000) return a * n % mo;     while (n) {       if (n & 1) res = res + a < mo ? res + a : res + a;       a = a + a < mo ? a + a : a + a - mo;       n >>= 1;     }     return res % mo;   }   inline long long power(long long a, long long n, long long mo) {     long long res = 1;     if (mo == 1) return 0;     n %= mo - 1;     while (n) {       if (n & 1) res = mul(res, a, mo);       a = mul(a, a, mo);       n >>= 1;     }     return res;   }   inline void dfs(int dep, long long d) {     if (dep > len) {       if (d == 1) return;       map<long long, int> fac;       for (register int i = 1; i <= (len); i++)         if (b[i]) {           if (b[i] - 1) fac[p[i]] += b[i] - 1;           for (map<long long, int>::iterator it = Map[i].begin();                it != Map[i].end(); it++)             fac[(*it).first] += (*it).second;         }       static long long c[22];       int tot = 0;       long long phi = 1;       for (map<long long, int>::iterator it = fac.begin(); it != fac.end();            it++) {         tot++, c[tot] = (*it).first;         for (register int i = 1; i <= ((*it).second); i++) phi *= c[tot];       }       long long k = phi;       for (register int i = 1; i <= (tot); i++) {         while (k % c[i] == 0 && power(x, k / c[i], d) == 1) k /= c[i];       }       res += phi / k;       return;     }     for (register int i = 0; i <= (a[dep]); i++)       b[dep] = i, dfs(dep + 1, d), d *= p[dep], b[dep] = 0;   }   int main() {     scanf( %lld%lld , &m, &x);     init(m);     for (register int i = 1; i <= (len); i++) init2(p[i] - 1, i);     dfs(1, 1);     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int M = 1000010;   const int MAX = M;   struct BIT {     int bit[MAX + 1], N;     BIT() {}     BIT(int N) : N(N) { memset(bit, 0, sizeof(bit)); }     int sum(int i) {       i++;       int ret = 0;       while (i) {         ret += bit[i];         i -= i & -i;       }       return ret;     }     int sum(int i, int j) { return sum(j - 1) - sum(i - 1); }     void add(int i, int x) {       i++;       while (i <= N) {         bit[i] += x;         i += i & -i;       }     }     int find(int i) {       int lb = -1, ub = N, mid;       while (ub - lb > 1) {         mid = (lb + ub) / 2;         if (sum(mid) >= i)           ub = mid;         else           lb = mid;       }       return ub;     }   };   int n, m, a[M], seq[M], k[M];   int len, ns, ms;   BIT b;   void solve() {     if (!len) {       puts( Poor stack! );       return;     }     b = BIT(ns);     for (int i = (int)(0); i < (int)(ns); i++) b.add(i, 1);     for (int i = (int)(0); i < (int)(ms); i++) {       for (int j = k[i] - 1; j >= 0; --j) {         int pos = b.find(a[j]);         b.add(pos, -1);       }     }     for (int i = (int)(0); i < (int)(ns); i++)       if (b.sum(i, i + 1)) printf( %d , seq[i]);     puts(  );   }   void input() {     scanf( %d%d , &n, &m);     for (int i = (int)(0); i < (int)(m); i++) scanf( %d , a + i);     for (int i = (int)(0); i < (int)(n); i++) {       scanf( %d , seq + ns);       if (seq[ns] < 0) {         if (a[0] > len) continue;         k[ms] = lower_bound(a, a + m, len + 1) - a;         len -= k[ms++];       } else         ++len, ++ns;     }   }   int main() {     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> newvec;     int n;     int x;     int ans;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       newvec.push_back(x);     }     sort(newvec.begin(), newvec.end());     if (newvec.size() % 2 == 1) {       ans = newvec[newvec.size() / 2];     } else {       ans = newvec[newvec.size() / 2 - 1];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = pow(10, 9) + 7;   long long fac[1001];   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   void SieveOfEratosthenes(long long n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long p = 2; p <= n; p++)       if (prime[p])         ;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long n, long long p) { return power(n, p - 2, p); }   long long nCrModPFermat(long long n, long long r, long long p) {     if (n < r) return 0;     if (r == 0) return 1;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   void dfs(long long v, vector<vector<long long>> &adj, vector<long long> &used,            vector<long long> &maxD) {     for (long long u : adj[v]) {       if (!used[u]) {         used[u] = 1;         if (adj[u].size() == 1 && u != 1) {           maxD[u] = 0;           amax(maxD[v], 1 + maxD[u]);         } else {           dfs(u, adj, used, maxD);           amax(maxD[v], 1 + maxD[u]);         }       }     }   }   void solve() {     long long n, x, i;     cin >> n >> x;     vector<vector<long long>> adj(n + 1);     long long u, v;     for (i = 2; i <= n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     vector<long long> d(n + 1);     d[1] = 0;     vector<long long> visited(n + 1);     vector<long long> parent(n + 1);     visited[1] = 1;     parent[1] = 0;     queue<long long> q;     q.push(1);     while (!q.empty()) {       long long p = q.front();       q.pop();       for (auto el : adj[p]) {         if (!visited[el]) {           visited[el] = 1;           q.push(el);           d[el] = d[p] + 1;           parent[el] = p;         }       }     }     vector<long long> maxD(n + 1), used(n + 1);     used[1] = 1;     dfs(1, adj, used, maxD);     long long f = 1, ans = max(maxD[x] * 2, (abs(d[1] - d[x]) + maxD[x]) * 2),               start = x;     while (f) {       long long el = parent[x];       if (abs(d[el] - d[1]) > abs(d[el] - d[start])) {         long long z = max(maxD[el] * 2, (abs(d[1] - d[el]) + maxD[el]) * 2);         amax(ans, z);         x = el;       } else {         f = 0;         break;       }     }     cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test = 1;     switch (test) {       case 1:         solve();         break;       case 2: {         long long t;         cin >> t;         while (t--) {           solve();         }       }; break;     }   }
#include <bits/stdc++.h>   using namespace std;   int T;   int n;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> T;     while (T--) {       cin >> n;       float FloatN = n;       int Num8 = ceil(FloatN / 4);       int Num9 = n - Num8;       for (int i = 0; i < Num9; ++i) {         cout << 9;       }       for (int i = 0; i < Num8; ++i) {         cout << 8;       }       cout << endl;     }   }