malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long arr[200200];   int main() {     string a, b;     cin >> a >> b;     long long x = 0, y = 0;     for (int i = 0; i <= b.size() - a.size(); i++) x += (b[i] -  0 );     for (int i = 0; i < a.size(); i++) {       y += (a[i] ==  0 ) ? x : (b.size() - a.size() + 1) - x;       x += b[b.size() - a.size() + 1 + i] - b[i];     }     cout << y;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Heap(int A[], int n, int l, int r) {     int x, i, j;     x = A[l];     i = l;     while (1) {       j = 2 * i;       if (j > r) break;       if (j < r && A[j + 1] >= A[j]) j++;       if (x >= A[j]) break;       A[i] = A[j];       i = j;     }     A[i] = x;   }   void HeapSort(int A[], int n) {     int l, r, temp;     l = n / 2;     while (l >= 0) {       Heap(A, n, l, n - 1);       l--;     }     r = n - 1;     while (r >= 1) {       temp = A[0];       A[0] = A[r];       A[r] = temp;       r--;       Heap(A, n, 0, r);     }   }   int mini(int a, int b, int c = 1000000010) {     if (a <= b && a <= c)       return a;     else if (b <= c && b <= a)       return b;     else       return c;   }   int maxi(int a, int b) {     if (a > b)       return a;     else       return b;   }   unsigned long long int fac(unsigned long long int a) {     unsigned long long int r = 1;     for (int i = 2; i <= a; i++) r *= i;     return r;   }   bool issimple(unsigned long long n) {     for (unsigned long long i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   unsigned long long nod(unsigned long long a, unsigned long long b) {     unsigned long long temp;     while (b) {       a %= b;       temp = a;       a = b;       b = temp;     }     return a;   }   unsigned long long nok(unsigned long long a, unsigned long long b,                          unsigned long long nod) {     return a / nod * b;   }   int main() {     int x, y, count, t, i, n, k, m;     bool flag;     cin >> t;     while (t--) {       cin >> n;       count = n / 2 + n % 2;       cout << count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long dot(complex<long long> c1, complex<long long> c2) {     return imag(c1 * conj(c2));   }   double dot(complex<double> c1, complex<double> c2) {     return imag(c1 * conj(c2));   }   long long point(complex<long long> c1, complex<long long> c2) {     return real(c1 * conj(c2));   }   double point(complex<double> c1, complex<double> c2) {     return real(c1 * conj(c2));   }   void solve() {     long double n, pi2, alpha, res;     pi2 = acos(0.0);     cin >> n;     alpha = pi2 * (n - 1.0) / n;     res = tan(alpha);     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, cases;     cin >> cases;     cout << fixed << setprecision(10);     for (t = 0; t < cases; t++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 47 == 0 || n % 744 == 0 || n % 4 == 0 || n % 7 == 0 || n % 44 == 0 ||         n % 444 == 0 || n % 777 == 0 || n % 74 == 0 || n % 447 == 0 ||         n % 474 == 0 || n % 477 == 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 45;   int nd, nm, G[N][N];   int cntClique, pts[N], res[N], cnt[N];   map<string, int> H;   int n;   vector<int> v;   bool dfs(int pos, int num) {     for (int i = pos + 1; i <= n; ++i) {       if (cnt[i] + num <= cntClique) return false;       if (G[pos][i]) {         int ok = 1;         for (int id = 1; id <= num; ++id) {           if (!G[i][pts[id]]) {             ok = 0;             break;           }         }         if (ok) {           pts[num + 1] = i;           if (dfs(i, num + 1)) return true;         }       }     }     if (num > cntClique) {       for (int i = 1; i <= num; ++i) {         res[i] = pts[i];       }       cntClique = num;       return true;     }     return false;   }   void maxClique() {     cntClique = -1;     for (int i = n; i > 0; --i) {       pts[1] = i;       dfs(i, 1);       cnt[i] = cntClique;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(G, 1, sizeof G);     cin >> nd >> nm;     for (int i = 1; i <= nd; ++i) {       int op;       string s;       cin >> op;       if (op == 1) {         v.clear();       } else {         cin >> s;         if (!H.count(s)) {           H[s] = ++n;         }         int y = H[s];         for (auto& x : v) {           G[x][y] = 0;           G[y][x] = 0;         }         v.push_back(y);       }     }     maxClique();     if (cntClique < 0) {       cout <<  0 ;     } else {       cout << cntClique;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void _print(long long int t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   bool cmp(pair<long long int, long long int> a,            pair<long long int, long long int> b) {     if (a.first != b.first)       return a.first > b.first;     else       return a.second > b.second;   }   long long int binarySearch(vector<long long int> v, long long int l,                              long long int r, long long int x) {     while (l <= r) {       long long int mid = l + (r - l) / 2;       if (v[mid] == x)         return mid;       else if (v[mid] < x)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   long long int power(long long int x, long long int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return power(x * x, n / 2);     else       return x * power(x * x, (n - 1) / 2);   }   long long int ModularExpo(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   void solve() {     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) cout << i + 2 <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 100001;   int n, m, x, y, b, r, p, l, ri;   long long ans;   vector<int> B, R, P;   int bef(int x, int c) {     if (!c) return (lower_bound(B.begin(), B.end(), x) - B.begin() - 1);     return (lower_bound(R.begin(), R.end(), x) - R.begin() - 1);   }   int aft(int x, int c) {     if (!c) return (lower_bound(B.begin(), B.end(), x) - B.begin());     return (lower_bound(R.begin(), R.end(), x) - R.begin());   }   long long get(int x) {     long long mn = ri - B[x];     for (int i = x; i < b && B[i] < ri; i++) {       long long left = B[i] - l, right = 0;       if (i + 1 != b && B[i + 1] < ri) right = ri - B[i + 1];       mn = min(mn, left + right);     }     return mn;   }   long long get1(int x) {     long long mn = ri - R[x];     for (int i = x; i < r && R[i] < ri; i++) {       long long left = R[i] - l, right = 0;       if (i + 1 != r && R[i + 1] < ri) right = ri - R[i + 1];       mn = min(mn, left + right);     }     return mn;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       char c;       cin >> x >> c;       if (c ==  B )         B.push_back(x);       else if (c ==  R )         R.push_back(x);       else         P.push_back(x);     }     b = B.size();     r = R.size();     p = P.size();     if (!P.size()) {       if (b) ans = B[b - 1] - B[0];       if (r) ans += R[r - 1] - R[0];       cout << ans;       return 0;     }     x = bef(P[0], 0);     y = bef(P[0], 1);     if (x >= 0) ans += P[0] - B[0];     if (y >= 0) ans += P[0] - R[0];     x = aft(P[p - 1], 0);     y = aft(P[p - 1], 1);     if (x != B.size()) ans += B[b - 1] - P[p - 1];     if (y != R.size()) ans += R[r - 1] - P[p - 1];     for (int i = 0; i < p - 1; i++) {       l = P[i];       ri = P[i + 1];       long long dist = ri - l;       int x = aft(l, 0), y = aft(l, 1);       if ((x == b || B[x] > ri) && (y == r || R[y] > ri)) {         ans += dist;         continue;       }       long long mn = 2 * dist;       long long k = dist;       if (x < b && B[x] < ri) k += get(x);       if (y < r && R[y] < ri) k += get1(y);       ans += min(mn, k);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2 * int(1e9);   const long long INFll = 1ll * int(1e9) * int(1e9);   const int MOD = 1000000007;   template <typename T>   ostream& operator<<(ostream& out, pair<T, T>& a) {     out << a.first <<     << a.second;     return out;   }   template <typename T>   istream& operator>>(istream& in, pair<T, T>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<pair<T, T> > a) {     for (int i = 0; i < a.size(); ++i) out << a[i] << endl;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& a) {     for (int i = 0; i < a.size(); ++i) in >> a[i];     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> a) {     for (int i = 0; i < a.size(); ++i)       if (i == a.size() - 1)         out << a[i];       else         out << a[i] <<    ;     return out;   }   struct IN {     bool any;     operator bool() const { return any; }   } CIN;   inline IN& operator>>(IN& in, int& x) {     x = 0, in.any = 0;     char c;     while ((c = getchar()) > 0) {       if (c < 48 || c > 57)         if (in.any)           return in;         else           continue;       in.any = 1, x = x * 10 + c -  0 ;     }     return in;   }   int main() {     ios_base::sync_with_stdio(0);     int q;     CIN >> q;     while (q--) {       int n, m;       CIN >> n >> m;       vector<vector<int> > a(n, vector<int>(m));       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) CIN >> a[i][j];       int sum = 0;       for (int j = 0; j < m; ++j) sum += abs(a[n / 2][j] - a[n / 2 - 1][j]);       if (sum / long double(m) > 17)         cout <<  YES n ;       else         cout <<  NO n ;       if (0) cerr << sum / long double(m) << endl;     }     if (0)       cerr << fixed << setprecision(0)            <<  TIME =   << clock() / (long double)CLOCKS_PER_SEC * 1000 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void dir(char& smb, int& x, int& y) {     if (smb ==  L )       x--;     else if (smb ==  R )       x++;     else if (smb ==  U )       y++;     else       y--;   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     map<pair<int, int>, int> mpp;     int x = 0, y = 0;     mpp[make_pair(0, 0)] = 0;     int mn = n + 5, l = -1, r = n + 1;     for (int i = 1; i < n + 1; i++) {       char smb = s[i - 1];       dir(smb, x, y);       auto it = mpp.find(make_pair(x, y));       if (it != mpp.end()) {         pair<pair<int, int>, int> p = *it;         int ind = p.second;         if (i - ind - 1 < mn) {           mn = i - ind - 1;           l = ind;           r = i - 1;         }       }       mpp[make_pair(x, y)] = i;     }     if (l == -1)       cout <<  -1 n ;     else       cout << l + 1 <<     << r + 1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc;     cin >> tc;     while (tc--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x1, y1, x2, y2;     cin >> n >> m >> x1 >> y1 >> x2 >> y2;     int x = abs(x1 - x2), y = abs(y1 - y2);     if (x <= 4 && y <= 4 && x + y <= 6)       cout <<  First  << endl;     else       cout <<  Second  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   template <typename T>   void print(vector<T> v) {     for (T &i : v) cout << i <<    ;     cout <<   n ;   }   void solve() {     unsigned long long int n, x;     cin >> n >> x;     vector<unsigned long long int> v(n);     for (unsigned long long int &i : v) cin >> i;     sort(v.begin(), v.end());     unsigned long long int sum = 0;     for (unsigned long long int i : v) {       sum += i * x;       if (x > 1) x--;     }     cout << sum <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tcs = 1;     while (tcs--) solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     long long n, m;     int dig[10];     char cn[12], cm[12];     while (scanf( %s n%s , &cn, &cm) != EOF) {       if (strlen(cn) != strlen(cm)) {         printf( WRONG_ANSWER n );         continue;       }       n = atol(cn);       m = atol(cm);       for (int i = 0; i < 10; i++) dig[i] = 0;       if (n < 10) {         if (n == m)           printf( OK n );         else           printf( WRONG_ANSWER n );       } else {         while (n) {           dig[n % 10]++;           n /= 10;         }         long long ret = 0;         for (int i = 1; i <= 9; i++) {           if (dig[i]) {             ret *= 10;             ret += i;             dig[i]--;             break;           }         }         for (int i = 0; i <= 9; i++) {           while (dig[i]) {             ret *= 10;             ret += i;             dig[i]--;           }         }         if (ret == m)           printf( OK n );         else           printf( WRONG_ANSWER n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a1, a2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> a1 >> a2;     int res = 0;     if (a1 == 1 && a2 == 1) {       cout << 0 <<   n ;       return 0;     }     while (a1 > 0 && a2 > 0) {       if (a1 < a2)         ++a1, a2 -= 2;       else         ++a2, a1 -= 2;       ++res;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b = 1, c = 2, o = 1, j, k;     cin >> a;     int p = a / 2;     for (k = 0; k < a; k++) {       for (j = 0; j < p; j++) {         cout << c <<    ;         c += 2;       }       for (j = 0; j < a - p * 2; j++) {         cout << b <<    ;         b += 2;       }       for (int j = 0; j < p; j++) {         cout << c <<    ;         c += 2;       }       cout << endl;       if (p == 0) o = 0;       if (o == 0)         p++;       else         p--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int ar[30005];   int dp1[30005][205][2], dp2[30005][205][2][5];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &ar[i]), ar[i] += ar[i - 1];     fill(dp1[0][0], dp1[n][k] + 2, -1000000000);     fill(dp2[0][0][0], dp2[n][k][1] + 5, -1000000000);     dp1[0][0][0] = 0;     dp1[0][0][1] = 0;     for (int i = 0; i < 2; i++)       for (int j = -2; j <= 2; j++) dp2[1][1][i][j + 2] = j * ar[1];     for (int i = 1; i <= n; i++)       for (int j = 0; j <= k; j++)         for (int l = 0; l < 2; l++) {           int &tmp = dp1[i][j][l];           if (!j)             tmp = 0;           else {             tmp = max(tmp, dp1[i - 1][j][l]);             int l1 = (!l ? 0 : 2), l2 = l1 - 2;             if (j == 1)               l1--, l2++;             else if (j == k)               l1 = 1, l2 = -1;             tmp = max(tmp, dp2[i][j][0][l1 + 2]);             tmp = max(tmp, dp2[i][j][1][l2 + 2]);           }           for (int r = -1 - (l != 0); r <= 2 - (l != 0); r++)             dp2[i + 1][j + 1][(l != 0)][r + 2] =                 max(dp2[i][j + 1][(l != 0)][r + 2], tmp) +                 r * (ar[i + 1] - ar[i]);         }     printf( %d n , max(dp1[n][k][0], dp1[n][k][1]));   }
#include <bits/stdc++.h>   using namespace std;   void aayush() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     aayush();     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       if (n % 4 == 0) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, h;   pair<int, int> arr[100010];   int res[100010];   int ptr = -1;   int cnt, bits;   int main() {     cin >> n >> h;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i].first);       arr[i].second = i;       res[i] = 1;     }     sort(arr, arr + n);     int ans = arr[n - 1].first + arr[n - 2].first - arr[0].first - arr[1].first;     for (int i = n - 2; i >= 0; i--) {       int mx = arr[i].first + arr[n - 1].first + h;       if (i < n - 2) mx = max(mx, arr[n - 1].first + arr[n - 2].first);       int init = min(7, i);       int col[7];       if (i <= 6) {         col[i] = 2;         for (int j = i + 1; j < min(n, 7); j++) col[j] = 1;       }       for (int j = 0; j < (1 << init); j++) {         for (int k = 0; k < init; k++) {           col[k] = ((j & (1 << k)) ? 1 : 2);         }         int mn = 1000000000;         for (int k = 0; k < min(n, 7); k++) {           for (int l = k + 1; l < min(n, 7); l++) {             int val = arr[k].first + arr[l].first;             if (col[k] != col[l]) val += h;             mn = min(mn, val);           }         }         int dif = mx - mn;         if (dif < ans) {           ans = dif;           ptr = i;           cnt = init;           bits = j;         }       }     }     if (ptr != -1) {       for (int i = 0; i < cnt; i++) {         res[arr[i].second] = ((bits & (1 << i)) ? 1 : 2);       }       res[arr[ptr].second] = 2;       for (int i = ptr + 1; i < n; i++) res[arr[i].second] = 1;     }     cout << ans << endl;     for (int i = 0; i < n; i++) {       if (i) printf(   );       printf( %d , res[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b) {     return (a % 1000000007 + b % 1000000007) % 1000000007;   }   inline long long mul(long long a, long long b) {     return (a % 1000000007 * b % 1000000007) % 1000000007;   }   long long pwr(long long a, long long b) {     if (!b) return 1ll;     long long t = pwr(a, b / 2);     t = mul(t, t);     if (b & 1) t = mul(t, a);     return t;   }   long long modinv(long long a, long long b = 1000000007) {     return pwr(a, b - 2);   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, a, b, c, d;       cin >> n >> a >> b >> c >> d;       int x = a - b, y = a + b;       int p = c - d, q = c + d;       int mn = x * n, flag = 1;       for (int i = 1; i <= n; i++) {         if (mn <= q && mn >= p) {           flag = 0;           break;         }         if (mn < p) {           int diff = p - mn;           mn += min(diff, 2 * b);         }       }       if (mn <= q && mn >= p) {         flag = 0;       }       if (flag)         cout <<  No n ;       else         cout <<  Yes n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, i, a1, b1, y, y1, ans, ans1, ans2, x;     cin >> n >> a >> b;     for (i = 1; i <= n; i++) {       cin >> x;       y = x * a;       ans = y % b;       if (a != 0)         cout << ans / a <<    ;       else         cout << x <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int dp[100005][30] = {0};   int A[40][40] = {0};   int main() {     string s, b;     cin >> s;     int k;     cin >> k;     for (int i = 0; i < k; i++) {       cin >> b;       int x, y;       x = b[0] -  a ;       y = b[1] -  a ;       A[x][y] = A[y][x] = 1;     }     int n = s.length();     for (int i = 1; i <= n; i++)       for (int k = 0; k < 26; k++) {         dp[i][k] = dp[i - 1][k];         for (int j = 0; j < 26; j++)           if (!A[k][j] && s[i - 1] -  a  == k)             dp[i][k] = max(dp[i][k], dp[i - 1][j] + 1);       }     int res = 0;     for (int i = 0; i < 26; i++) {       res = max(res, dp[n][i]);     }     cout << n - res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const long long oo = ((long long)1e18) + 7;   int N, M, T, K, Q;   vector<int> G[MAXN];   int num[MAXN];   int dep[MAXN];   int pa[MAXN][25];   int LOG = 20;   int cnt = 0;   int child[MAXN];   int DFS(int u, int par, int depth) {     num[u] = ++cnt;     dep[num[u]] = depth;     pa[num[u]][0] = num[par];     for (auto v : G[u])       if (v != par) {         child[num[u]] += DFS(v, u, dep[num[u]] + 1);       }     return child[num[u]];   }   int LCA(int u, int v) {     if (u == v) return u;     if (dep[u] < dep[v]) swap(u, v);     for (int i = LOG; i >= 0; i--)       if (dep[pa[u][i]] >= dep[v]) u = pa[u][i];     if (u == v) return u;     for (int i = LOG; i >= 0; i--)       if (pa[u][i] != pa[v][i]) {         u = pa[u][i];         v = pa[v][i];       }     return pa[u][0];   }   int findParent(int u, int k) {     if (k == 0) return u;     int i = 0;     while (k > 0) {       if (k & 1) u = pa[u][i];       i++;       k >>= 1;     }     return u;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( 519E                 .inp ,                r )) {       freopen(            519E             .inp ,            r , stdin);       freopen(            519E             .out ,            w , stdout);     }     cin >> N;     for (int i = 1; i < N; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= N; i++) child[i] = 1;     dep[0] = -1;     DFS(1, 0, 0);     for (int k = 1; k <= LOG; k++)       for (int i = 1; i <= N; i++) pa[i][k] = pa[pa[i][k - 1]][k - 1];     cin >> Q;     while (Q--) {       int u, v;       cin >> u >> v;       u = num[u];       v = num[v];       if (dep[u] < dep[v]) swap(u, v);       int p = LCA(u, v);       if (u == v) {         cout << N <<   n ;         continue;       }       int diff1 = dep[u] - dep[p];       int diff2 = dep[v] - dep[p];       if ((diff1 + diff2) & 1) {         cout << 0 <<   n ;         continue;       }       int avg = (diff1 + diff2) >> 1;       int mid = findParent(u, avg);       if (mid == p) {         int fakeParent1 = findParent(u, diff1 - 1);         int fakeParent2 = findParent(v, diff2 - 1);         cout << (child[mid] - child[fakeParent1] - child[fakeParent2]) + N -                     child[mid]              <<   n ;         continue;       }       diff1 = dep[u] - dep[mid];       int fakeParent1 = findParent(u, diff1 - 1);       cout << child[mid] - child[fakeParent1] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool checkPal(string s) {     for (int i = 0, j = s.size() - 1; i <= j; i++, j--) {       if (s[i] != s[j]) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s;       map<char, int> m;       for (int j = 0; j < s.size(); j++) {         m[s[j]]++;       }       string ch =   ;       for (auto it = m.rbegin(); it != m.rend(); it++) {         pair<int, int> p = *it;         char c = p.first;         int cnt = p.second;         for (int j = 0; j < cnt; j++) {           ch += c;         }       }       if (!checkPal(ch)) {         cout << ch << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }