malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mo(long long a) { return a % (long long)(1e9 + 7); }   long long po(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 >>= 1;       x = (x * x) % p;     }     return res % p;   }   vector<long long> a;   long long solve(long long last_bit, vector<long long> &cur) {     if (last_bit < 0) return 0;     long long n = cur.size();     vector<long long> ze, one;     for (long long i = 0; i < n; i++) {       if ((1LL << last_bit) & cur[i])         one.push_back(cur[i]);       else         ze.push_back(cur[i]);     }     if (ze.size() == 0 || one.size() == 0)       return solve(last_bit - 1, cur);     else       return 1 + max(solve(last_bit - 1, ze), solve(last_bit - 1, one));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     a.resize(n);     for (long long i = 0; i < a.size(); i++) cin >> a[i];     ;     long long ans = solve(30, a);     cout << n - ans - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int p;     string s[100];     string s1, s2, s3 =   , s4 =   , s5 =   , s6, s7, s8, s9;     for (int i = 0; i < a; i++) {       int p = 0;       cin >> s[i];       s6 = s[i];       reverse(s6.begin(), s6.end());       if (s[i] == s6) {         s7 = s[i];       }     }     for (int i = 0; i < a - 1; i++) {       s2 = s[i];       reverse(s[i].begin(), s[i].end());       for (int j = i + 1; j < a; j++) {         if (s[i] == s[j]) {           s3 = s3 + s2;           s8 = s[j];           s4 = s8 + s4;         }       }     }     s9 = s3 + s7 + s4;     cout << s9.size() << endl;     int l = s9.size();     if (l != 0) {       cout << s3 + s7 + s4 << endl;     }   }
#include <bits/stdc++.h>   const int MAXN = 100010;   int flag[MAXN << 2];   int a[MAXN << 2];   int add;   int N, Q;   void PushDown(int rt) {     int lc = rt << 1;     int rc = rt << 1 | 1;     if (flag[rt]) {       flag[lc] += flag[rt];       flag[rc] += flag[rt];       flag[rt] = 0;     }     return;   }   void build(int l, int r, int rt) {     flag[rt] = 0;     if (l == r) {       scanf( %d , &a[rt]);       return;     }     int m = (l + r) >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     return;   }   void Update(int x, int c, int l, int r, int rt) {     if (l == x && r == x) {       flag[rt] = 0;       a[rt] = c;       return;     }     PushDown(rt);     int m = (l + r) >> 1;     if (x <= m)       Update(x, c, l, m, rt << 1);     else       Update(x, c, m + 1, r, rt << 1 | 1);     return;   }   int Query(int x, int l, int r, int rt) {     if (l == x && r == x) {       return a[rt] + flag[rt];     }     PushDown(rt);     int m = (l + r) >> 1;     if (x <= m)       return Query(x, l, m, rt << 1);     else       return Query(x, m + 1, r, rt << 1 | 1);   }   int main() {     while (~scanf( %d%d , &N, &Q)) {       build(1, N, 1);       while (Q--) {         int op, v, x;         scanf( %d , &op);         switch (op) {           case 1:             scanf( %d%d , &v, &x);             Update(v, x, 1, N, 1);             break;           case 2:             scanf( %d , &v);             flag[1] += v;             break;           case 3:             scanf( %d , &v);             printf( %d n , Query(v, 1, N, 1));             break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   int a[100001], b[100000], map[100000], c[634][100001];   int main() {     int n, q;     std::cin >> n >> q;     for (int i = 1; i <= n; ++i) std::cin >> a[i];     memcpy(b, &a[1], sizeof(b));     std::stable_sort(b, b + n);     int N = 0, i = 0;     while (i < n) {       int r = std::upper_bound(b, b + n, b[i]) - b;       if (r - i >= b[i]) map[N++] = b[i];       i = r;     }     for (int i = 0; i < N; ++i)       for (int j = 1; j <= n; ++j) c[i][j] = c[i][j - 1] + (a[j] == map[i]);     while (q--) {       int l, r, count = 0;       std::cin >> l >> r;       for (int i = 0; i < N; ++i) count += map[i] == c[i][r] - c[i][l - 1];       std::cout << count <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10, Mod = 1e9 + 7;   long long fact[2 * MAXN], dp[MAXN], ps[MAXN], inv[MAXN * 2];   pair<long long, long long> a[MAXN];   long long power(long long x, long long y) {     if (!y) return 1;     long long ans = power(x, y / 2);     ans *= ans;     ans %= Mod;     if (y % 2) ans *= x;     ans %= Mod;     return ans;   }   long long c(int n, int r) {     long long ans = fact[n];     ans *= inv[r];     ans %= Mod;     ans *= inv[n - r];     ans %= Mod;     return ans;   }   int main() {     fact[0] = 1;     inv[0] = 1;     for (int i = 1; i < 2 * MAXN; i++) {       fact[i] = (fact[i - 1] * i) % Mod;       inv[i] = power(fact[i], Mod - 2);     }     int w, h, n;     cin >> w >> h >> n;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     n++;     a[n].first = w;     a[n].second = h;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       dp[i] = c(a[i].first + a[i].second - 2, a[i].first - 1);       dp[i] %= Mod;       for (int j = 1; j < i; j++)         if (a[j].first <= a[i].first and a[j].second <= a[i].second) {           dp[i] -= dp[j] * c(a[i].first - a[j].first + a[i].second - a[j].second,                              a[i].first - a[j].first);           dp[i] %= Mod;           dp[i] += Mod;           dp[i] %= Mod;         }     }     cout << dp[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double p[21], dp[(1 << 21)], ans[21];   int n, k;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %lf , p + i);     dp[0] = 1;     for (int bit = 1; bit < (1 << n); bit++)       if (__builtin_popcount(bit) <= k) {         double rp = 1;         for (int i = 0; i < n; i++)           if ((bit & (1 << i))) rp -= p[i];         for (int i = 0; i < n; i++)           if ((bit & (1 << i))) {             if (p[i] < 1e-9) continue;             dp[bit] += dp[bit ^ (1 << i)] * p[i] / (rp + p[i]);             ans[i] += dp[bit ^ (1 << i)] * p[i] / (rp + p[i]);           }       }     for (int i = 0; i < n; i++) printf( %.11lf  , ans[i]);   }
#include <bits/stdc++.h>   const int N = 100, M = 1000;   int n, m;   double dp[N + 2][N * M + 2];   int main() {     scanf( %d %d , &n, &m);     if (m == 1) {       printf( 1.0 );       return 0;     }     dp[0][0] = m - 1;     int sumr = 0;     for (int i = 1; i <= n; i++) {       int rank;       scanf( %d , &rank);       sumr += rank;       double sum = 0.0;       for (int j = 1; j <= n * m; j++) {         sum += dp[i - 1][j - 1];         if (j > m) sum -= dp[i - 1][j - m - 1];         if (j >= rank)           dp[i][j] = (sum - dp[i - 1][j - rank]) / (m - 1);         else           dp[i][j] = sum / (m - 1);       }     }     double ans = 1.0;     for (int i = 1; i < sumr; i++) ans += dp[n][i];     printf( %.10lf , ans);     return 0;   }
#include <bits/stdc++.h>   int Set(int N, int pos) { return N = N | (1 << pos); }   int reSet(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   using namespace std;   string s;   int n;   bool dp[10010][4], taken[10010][4];   bool isSafe(int pos, int l1) {     if (pos - l1 < 0) return true;     for (int i = 0; i < l1; i++) {       if (s[pos + i] != s[pos - l1 + i]) return true;     }     return false;   }   bool go(int pos, int pre) {     if (pos > n) return false;     if (pos == n) return dp[pos][pre] = true;     if (taken[pos][pre]) return dp[pos][pre];     taken[pos][pre] = true;     bool ret = false;     if (pre == 3) {       ret |= go(pos + 2, 2);       if (isSafe(pos, 3)) ret |= go(pos + 3, 3);     }     if (pre == 2) {       ret |= go(pos + 3, 3);       if (isSafe(pos, 2)) ret |= go(pos + 2, 2);     }     if (pre == 1) {       ret |= go(pos + 1, 1);       ret |= go(pos + 2, 2);       ret |= go(pos + 3, 3);     }     return dp[pos][pre] = ret;   }   set<string> S;   void get_solution(int pos, int pre) {     if (pos > n || taken[pos][pre]) return;     taken[pos][pre] = true;     string res;     if (pre == 1) {       if (dp[pos + 1][1]) get_solution(pos + 1, 1);       if (dp[pos + 2][2]) {         res = s.substr(pos, 2);         S.insert(res);         get_solution(pos + 2, 2);       }       if (dp[pos + 3][3]) {         res = s.substr(pos, 3);         S.insert(res);         get_solution(pos + 3, 3);       }     }     if (pre == 2) {       if (dp[pos + 2][2]) {         res = s.substr(pos, 2);         S.insert(res);         get_solution(pos + 2, 2);       }       if (dp[pos + 3][3]) {         res = s.substr(pos, 3);         S.insert(res);         get_solution(pos + 3, 3);       }     }     if (pre == 3) {       if (dp[pos + 2][2]) {         res = s.substr(pos, 2);         S.insert(res);         get_solution(pos + 2, 2);       }       if (dp[pos + 3][3]) {         res = s.substr(pos, 3);         S.insert(res);         get_solution(pos + 3, 3);       }     }   }   int main() {     int tc, t = 1;     while (cin >> s) {       n = s.size();       memset(taken, false, sizeof taken);       if (go(5, 1)) {         memset(taken, false, sizeof taken);         get_solution(5, 1);       }       for (int i = 0; i < n + 1; i++) {         for (int j = 1; j < 4; j++) {         }       }       set<string>::iterator it;       cout << S.size() << endl;       for (it = S.begin(); it != S.end(); it++) {         cout << *it << endl;       }       S.clear();     }     return 0;   }
/*    * author: zhaoyiping    * time: 2021-06-04 23:08:02    */   #include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   // vector<int> g[MAXN];   long long a[MAXN];   long long c[MAXN];   int fa[MAXN][20];   int deep[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q >> a[0] >> c[0];     for (int i = 1; i <= q; i++) {       int op;       cin >> op;       if (op == 1) {         int p, aa, cc;         cin >> p >> aa >> cc;         a[i] = aa;         c[i] = cc;         fa[i][0] = p;         deep[i] = deep[p] + 1;         for (int j = 1; j < 20; j++) {           fa[i][j] = fa[fa[i][j - 1]][j - 1];         }       } else {         int v;         long long w;         cin >> v >> w;         int beg = v;         for (int i = 19; i >= 0; i--)           if (a[fa[beg][i]])             beg = fa[beg][i];         long long tt = 0;         long long ans = 0;         for (int i = deep[v] - deep[beg]; i >= 0; i--) {           int now = v;           for (int j = 0; j < 20; j++) {             if ((1 << j) & i)               now = fa[now][j];           }           if (a[now] >= w) {             tt += w;             ans += c[now] * w;             a[now] -= w;             w = 0;             break;           } else {             tt += a[now];             ans += c[now] * a[now];             w -= a[now];             a[now] = 0;           }         }         cout << tt <<     << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string toBinary(long long n) {     string r;     while (n != 0) {       r = (n % 2 == 0 ?  0  :  1 ) + r;       n /= 2;     }     return r;   }   int main() {     int total;     cin >> total;     while (total--) {       string binaryNum;       long long num;       cin >> num;       binaryNum = toBinary(num);       long long length = binaryNum.length();       long long counter = 1;       long long ans = 0;       long long powers = 2;       long long value = 0;       ans = ans + num;       while (counter < length) {         value = num / powers;         ans = ans + value;         powers = powers * 2;         counter++;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:667772160 )   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   string str;   int main() {     int n;     scanf( %d , &n);     getchar();     getline(cin, str);     int ans = 0, cont = 0;     for (int i = 0; i < n; i++) {       if (isalpha(str[i])) {         if (isupper(str[i])) cont++;       } else {         ans = max(ans, cont);         cont = 0;       }     }     ans = max(ans, cont);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int M = 1000005;   const int nmax = 500010;   const int MOD = (1e9) + 7;   int nextX[] = {1, -1, 0, 0};   int nextY[] = {0, 0, 1, -1};   int n, m, t;   int f[1010][1010];   char s[1010][1010];   bool good(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> t;     for (int i = 1; i <= n; i++) cin >> s[i] + 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) f[i][j] = -1;     queue<pair<int, int> > que;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int nr = 0;         for (int k = 0; k < 4; k++) {           int x = i + nextX[k];           int y = j + nextY[k];           if (!good(x, y)) continue;           if (s[i][j] == s[x][y]) nr++;         }         if (nr > 0) {           que.push({i, j});           f[i][j] = 0;         }       }     while (!que.empty()) {       int x = que.front().first;       int y = que.front().second;       que.pop();       for (int k = 0; k < 4; k++) {         int nxt_x = x + nextX[k];         int nxt_y = y + nextY[k];         if (!good(nxt_x, nxt_y)) continue;         if (s[nxt_x][nxt_y] != s[x][y] && f[nxt_x][nxt_y] == -1) {           f[nxt_x][nxt_y] = f[x][y] + 1;           que.push({nxt_x, nxt_y});         }       }     }     for (int i = 1; i <= t; i++) {       int x, y;       long long int p;       cin >> x >> y >> p;       if (f[x][y] == -1 || p < f[x][y])         cout << s[x][y] <<   n ;       else {         long long int diff = p - f[x][y];         if (diff % 2 == 0)           cout << s[x][y] <<   n ;         else if (s[x][y] ==  1 )           cout <<  0 n ;         else           cout <<  1 n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, c0, d0, hsl;   int a[15], b[15], c[15], d[15];   int dp[1005][15];   bool dpf[1005][15];   int proc(int x, int num) {     if (num == 0) {       return 0;     } else if (dpf[x][num]) {       return dp[x][num];     } else {       int &ret = dp[x][num];       ret = 0;       dpf[x][num] = true;       for (int i = 0; (i <= (a[num] / b[num])) && (x >= c[num] * i); i++) {         ret = max(ret, proc(x - c[num] * i, num - 1) + d[num] * i);       }       return ret;     }   }   int main() {     scanf( %d %d %d %d , &n, &m, &c0, &d0);     for (int i = 1; i <= m; i++) {       scanf( %d %d %d %d , &a[i], &b[i], &c[i], &d[i]);     }     hsl = 0;     for (int i = 0; i <= n; i++) {       hsl = max(hsl, proc(i, m) + ((n - i) / c0) * d0);     }     printf( %d n , hsl);   }
#include <bits/stdc++.h>   using namespace std;   long long l, w, k;   int main() {     cin >> l >> w >> k;     if (k > l + w - 2) {       cout << -1;       return 0;     }     if (k + 1 <= max(l, w)) {       long long e = max(l, w);       long long t = min(l, w);       long long j = (t / (k + 1)) * max(l, w);       long long u = (e / (k + 1)) * min(l, w);       if (j > u)         cout << j;       else         cout << u;     } else {       long long e = min(l, w);       cout << (e / (k + 2 - max(l, w)));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T maxs(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T mins(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const int N = 1e6 + 5;   int a[N];   int p[N];   pair<int, int> rnk[N];   int root(int first) {     if (p[first] == first) return first;     return p[first] = root(p[first]);   }   int solve() {     int n;     cin >> n;     vector<int> v(n + 1), r(n + 1);     for (int i = 1; i < n + 1; i++) {       char c;       cin >> c;       if (c ==  ? )         v[i] = -1;       else         v[i] = c - 48;     }     int j1 = n + 1;     int j2 = n + 1;     for (int i = n; i > 0; i--) {       if (v[i] == 0) {         j1 = i;       } else if (v[i] == 1) {         j2 = i;       }       a[i] = max(j1, j2) - i;       rnk[i] = {a[i], i};     }     sort(rnk + 1, rnk + 1 + n);     for (int i = 1; i <= n + 1; i++) p[i] = i;     int j = 1;     for (int i = 1; i <= n; i++) {       while (j <= n && rnk[j].first < i) {         p[rnk[j].second] = rnk[j].second + 1;         j++;       }       int cnt = 0;       int l = 1;       while (1) {         int j = root(l);         if (j > n) break;         cnt++;         l = j + i;       }       cout << cnt <<    ;     }     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct e {     int a, b;   };   e p[100005];   int n, k;   bool use[100005];   priority_queue<int, vector<int>, std::greater<int> > Q;   bool criteriu(e a, e b) { return a.b > b.b; }   long long af;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].a);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].b);     }     sort(p + 1, p + n + 1, criteriu);     for (int i = 1; i <= n; i++) {       if (!use[p[i].a]) {         use[p[i].a] = true;       } else {         Q.push(p[i].b);       }     }     for (int i = 1; i <= k; i++) {       if (!use[i]) {         af += Q.top();         Q.pop();       }     }     printf( %lld n , af);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   const int MOD = 1e9 + 7;   long long a[maxn];   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       ans += a[i] * (n - a[i] + 1);       if (i == 1) continue;       long long t1 = a[i - 1], t2 = a[i];       if (t1 > t2) swap(t1, t2);       ans -= t1 * (n - t2 + 1);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000][1000];   int main(int argc, const char* argv[]) {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int r[1000];     int c[1000];     for (int i = 0; i < 1000; i++) {       r[i] = c[i] = i;     }     for (int i = 0; i < k; i++) {       char cc;       int x, y;       cin >> cc >> x >> y;       if (cc ==  c ) {         swap(c[x - 1], c[y - 1]);       } else if (cc ==  r ) {         swap(r[x - 1], r[y - 1]);       } else {         cout << a[r[x - 1]][c[y - 1]] << endl;         ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     long long cur = 9;     long long ans = 0;     long long dig = 1;     cin >> n;     while (n > 0) {       ans += min(n * dig, cur * dig);       n -= cur;       cur *= 10;       dig++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 1e3 + 10;   bool f[2][mx];   int nxt[mx], bef[mx];   int d[mx];   int main() {     int n, x, u;     scanf( %d %d , &n, &x);     memset(bef, -1, sizeof bef);     memset(nxt, -1, sizeof nxt);     for (int i = 1; i <= n; i++) {       scanf( %d , &u);       if (u != 0) {         nxt[i] = u;         bef[u] = i;       }     }     int lx = 0;     int c = 0;     for (int i = 1; i <= n; i++) {       if (bef[i] == -1) {         u = i;         int len = 0;         int lenx = 0;         while (u != -1) {           if (u == x || lenx > 0) lenx++;           len++;           u = nxt[u];         }         if (lenx == 0)           d[c++] = len;         else           lx = lenx;       }     }     int rw = 0;     f[0][0] = true;     for (int i = 0; i < c; i++) {       rw ^= 1;       for (int s = 0; s < mx; s++) {         f[rw][s] = f[rw ^ 1][s];         if (s >= d[i]) f[rw][s] |= f[rw ^ 1][s - d[i]];       }     }     vector<int> ans;     for (int s = 0; s < n; s++)       if (f[rw][s]) printf( %d n , s + lx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int L = 20;   int h[N], par[N][L];   int getLca(int u, int v) {     if (h[v] < h[u]) swap(u, v);     int k = h[v] - h[u];     for (int i = 0; i < L; i++)       if (k >> i & 1) v = par[v][i];     if (u == v) return v;     for (int i = L - 1; i >= 0; i--)       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     return par[u][0];   }   int dis(int u, int v) { return h[u] + h[v] - 2 * h[getLca(u, v)]; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 5, mx = 2, ans = 2;     for (int i = 2; i <= 4; i++) h[i] = par[i][0] = 1;     int q;     cin >> q;     while (q--) {       int v;       cin >> v;       h[n] = h[v] + 1;       par[n][0] = v;       for (int i = 1; i < L; i++) par[n][i] = par[par[n][i - 1]][i - 1];       n++;       h[n] = h[v] + 1;       par[n][0] = v;       for (int i = 1; i < L; i++) par[n][i] = par[par[n][i - 1]][i - 1];       if (h[v] == h[mx]) mx = n, ans++;       ans = max(ans, dis(n, mx));       n++;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     string str;     cin >> t;     while (t--) {       cin >> str;       sort(str.begin(), str.end());       int sz = str.size();       if (str[0] == str[sz - 1])         cout << -1 << endl;       else         cout << str << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const long long INF = 1e15;   const int mod = 1e9 + 7;   const double Pi = acos(-1);   void Fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int n, cnt = 0;   long long x, y;   bool Deg[200005];   vector<int> Adj[200005];   void DFS(int node, int p = -1) {     int c = 0;     for (auto x : Adj[node]) {       if (x != p) {         DFS(x, node);         if (Deg[x]) {           c++;         }       }     }     cnt += min(2, c);     if (c < 2) {       Deg[node] = true;     }   }   signed main() {     Fastio();     cin >> n >> x >> y;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       Adj[u].emplace_back(v);       Adj[v].emplace_back(u);     }     if (x >= y) {       for (int i = 1; i <= n; i++) {         if (Adj[i].size() == n - 1) {           cout << y * (n - 2) + x;           return 0;         }       }       cout << y * (n - 1);       return 0;     }     DFS(1);     cout << x * cnt + y * (n - 1 - cnt);   }