malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<long long int> adj[101];   set<pair<long long int, long long int>> color[101];   long long int visited[101];   long long int x;   void bfs(long long int a, long long int b, long long int c) {     queue<long long int> q;     q.push(a);     while (!q.empty()) {       long long int p = q.front();       q.pop();       if (p == b) {         x = 1;         visited[p] = 1;       }       if (visited[p]) continue;       visited[p] = 1;       for (long long int i = 0; i < adj[p].size(); i++) {         if (color[c].find({p, adj[p][i]}) != color[c].end()) {           q.push(adj[p][i]);         }       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int i, j, k, l, m, n, p, t, a, b, c, q;     cin >> n >> m;     set<pair<long long int, long long int>> s;     for (i = 0; i < m; i++) {       cin >> a >> b >> c;       if (s.find({a, b}) == s.end()) {         s.insert({a, b});         adj[a].push_back(b);         adj[b].push_back(a);       }       color[c].insert({a, b});       color[c].insert({b, a});     }     cin >> q;     for (i = 0; i < q; i++) {       cin >> a >> b;       p = 0;       for (j = 1; j <= m; j++) {         x = 0;         bfs(a, b, j);         p += x;         memset(visited, 0, sizeof(visited));       }       cout << p <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, g;   int a[100010];   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   bool used[100010];   int main() {     scanf( %d%d , &n, &k);     g = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] %= k;       g = gcd(g, a[i]);       g = gcd(g, k - a[i]);     }     int cnt = 0;     for (int i = 0; i < k; i += g) {       if (used[i] == 1) break;       used[i] = 1;       cnt++;     }     printf( %d n , cnt);     for (int i = 0; i < k; i++)       if (used[i] == 1) printf( %d  , i);   }
#include <bits/stdc++.h>   using namespace std;   int a[109];   int main() {     int n, m;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) cin >> a[i];       int p = 0;       sort(a, a + n);       for (int i = 0; i < n; i++) {         int flag = 0;         while (a[i]) {           if (a[i] % 10 == 4 || a[i] % 10 == 7) flag++;           a[i] /= 10;         }         if (flag <= m) p++;       }       cout << p << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     for (int i = 0; i < a; i++) {       int c = 0;       int j;       cin >> j;       int f = j % 10;       if (j > 1) f = (f - 1) * 10;       if (j > 1000) {         f = f + 10;       } else if (j > 100) {         f = f + 6;       } else if (j > 10) {         f = f + 3;       } else if (j > 1 && j < 10) {         f = f + 1;       }       cout << f << endl;     }   }
#include<bits/stdc++.h>   using namespace std;   #define size(v) (int)v.size()   #define all(v) (v).begin(),(v).end()   using lint = long long;   using fint = long double;   const int INF = 1e9 + 9;   const int MOD = 998244353;      int n, a[200000];      int solve(){       int ret = 0;          // pp...p cc...c       lint psum = 0, sum = accumulate(a,a+n,0ll);       for(int i=0;i<n;++i){           psum += a[i];           if(psum > sum - psum)               ret++;       }          // cc...c pcpc...pc pp...p       //      i         ^ (lower bonud)       auto f = [&](vector<int> a,lint base){           vector<lint> pa, ev, od;           for(int i=0;i<size(a);++i) pa.push_back(a[i]);           for(int i=0;i<size(a)-1;i+=2) ev.push_back(a[i]);           for(int i=1;i<size(a)-1;i+=2) od.push_back(a[i]);           for(int i=1;i<size(pa);++i) pa[i] += pa[i-1];           for(int i=1;i<size(ev);++i) ev[i] += ev[i-1];           for(int i=1;i<size(od);++i) od[i] += od[i-1];           for(int i=0;i<size(a)-1;++i){               vector<lint> &oe = (i&1 ? od : ev);               lint dff = base + pa[size(a)-1] - pa[i] - pa[i];               int cnt = lower_bound(all(oe), oe[i/2] + (dff+1)/2) - lower_bound(all(oe), oe[i/2]);               if(dff > 0) ret = (ret + cnt) % MOD;           }       };          // Case1: cc...c pcpc...pc pp...p       if(1 < n) f(vector<int>(a,a+n), 0);       // Case2: cc...c pcpc...pc pp...p(c)       if(2 < n) f(vector<int>(a,a+n-1), -a[n-1]);       // Case3: (p)ccc...c pcpc...pc pp...p       if(2 < n) f(vector<int>(a+1,a+n), a[0]);       // Case4: (p)ccc...c pcpc...pc pp...p(c)       if(3 < n) f(vector<int>(a+1,a+n-1), a[0]-a[n-1]);          return ret;      }      int main(){       int tc; scanf( %d ,&tc);       while(tc--){           scanf( %d ,&n);           for(int i=0;i<n;++i)               scanf( %d ,a+i);           printf( %d n ,solve());       }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n;   long long A[N];   map<long long, long long> MP;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &A[i]);     MP.insert({A[1] - 1, 0});     for (int i = 2; i <= n; i++) {       long long B = -1;       while (MP.rbegin()->first >= A[i]) {         long long a = MP.rbegin()->first;         long long b = MP.rbegin()->second;         MP[a % A[i]] = max(MP[a % A[i]], b + a / A[i] * A[i] * (i - 1));         B = max(B, b + (a / A[i] - 1) * A[i] * (i - 1));         MP.erase(a);       }       if (B >= 0) MP[A[i] - 1] = max(MP[A[i] - 1], B);     }     long long MX = 0;     for (auto X : MP) MX = max(MX, X.first * n + X.second);     return !printf( %lld n , MX);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     long long a[n + 2];     a[0] = 0;     long long sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > a[i - 1])         sum += (a[i] - a[i - 1]) * (n - a[i] + 1);       else if (a[i] < a[i - 1])         sum += a[i] * (a[i - 1] - a[i]);     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int num[maxn];   int F[1010];   int fnd(int t) {     if (F[t] == t) return t;     return F[t] = fnd(F[t]);   }   void join(int a, int b) {     int t1 = fnd(a);     int t2 = fnd(b);     if (t1 != t2) F[t1] = t2;   }   int main() {     int n, m, k;     int cap[maxn];     cin >> n >> m >> k;     memset(num, 0, sizeof(num));     memset(F, 0, sizeof(F));     for (int i = 1; i <= n; ++i) F[i] = i;     for (int i = 1; i <= k; ++i) cin >> cap[i];     for (int i = 1, a, b; i <= m; ++i) {       cin >> a >> b;       join(a, b);     }     for (int i = 1; i <= n; ++i) num[fnd(i)]++;     int maxn = 0, lef = n;     int ans = 0;     for (int i = 1; i <= k; ++i) {       num[cap[i]] = num[fnd(cap[i])];       maxn = max(maxn, num[cap[i]]);       lef -= num[cap[i]];       ans += (num[cap[i]] - 1) * (num[cap[i]]) / 2;     }     ans += (lef + maxn) * (lef + maxn - 1) / 2;     ans -= maxn * (maxn - 1) / 2 + m;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000005;   int n, a[maxN], p[230], b[230];   bool bo[1 << 22];   void Init() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);   }   void Work() {     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= 20; ++j) {         while (p[j] <= n && (p[j] < i || ((a[p[j]] >> (j - 1)) & 1) == 0)) ++p[j];         b[j] = p[j];       }       sort(b + 1, b + 1 + 20);       int x = a[i];       if (!bo[x]) {         ++ans;         bo[x] = 1;       }       for (int j = 1; j <= 20; ++j) {         x |= a[b[j]];         if (!bo[x]) {           ++ans;           bo[x] = 1;         }       }     }     cout << ans << endl;   }   int main() {     Init();     Work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     while (T-- > 0) {       long long n, k;       cin >> n >> k;       int m;       for (m = 2; m <= n; m++) {         if (n % m == 0) break;       }       long long ans = n + m + (k - 1) * 2;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 3;   const long long linf = (long long)inf * inf + 2;   int N, K;   struct TrieNode {     TrieNode *children[26];     bool canWin, canLose;     TrieNode() {       canWin = canLose = false;       for (int i = 0; i < 26; ++i) children[i] = nullptr;     }   };   TrieNode *root;   struct Trie {     Trie() { root = new TrieNode(); }     void insert(string &key, int idx = 0, TrieNode *pCrawl = root) {       if (idx == (int)key.length()) return;       int charId = key[idx] -  a ;       if (pCrawl->children[charId] == nullptr)         pCrawl->children[charId] = new TrieNode();       insert(key, idx + 1, pCrawl->children[charId]);     }     void precompute(TrieNode *pCrawl = root) {       bool hasChildren = false;       for (int i = 0; i < 26; ++i)         if (pCrawl->children[i] != nullptr) {           hasChildren = true;           precompute(pCrawl->children[i]);           if (!pCrawl->children[i]->canWin) pCrawl->canWin = true;           if (!pCrawl->children[i]->canLose) pCrawl->canLose = true;         }       if (!hasChildren) pCrawl->canLose = true;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> K;     Trie myTrie = Trie();     string str;     for (int i = 0; i < N; ++i) {       cin >> str;       myTrie.insert(str);     }     myTrie.precompute();     bool canForceWin = root->canWin, canForceLose = root->canLose;     if (canForceWin && canForceLose)       cout <<  First n ;     else if (canForceWin)       cout << (K % 2 ?  First n  :  Second n );     else       cout <<  Second n ;     return 0;   }
#include <bits/stdc++.h>   const long long mod = 1000000007;   using namespace std;   int main() {     long long ax, ay, bx, by, tx, ty;     scanf( %I64d , &(ax));     scanf( %I64d , &(ay));     scanf( %I64d , &(bx));     scanf( %I64d , &(by));     scanf( %I64d , &(tx));     scanf( %I64d , &(ty));     long long n;     scanf( %I64d , &(n));     vector<pair<long long, long long>> bot(n);     vector<double> toT(n);     vector<pair<double, int>> toA(n), toB(n);     double sum = 0;     for (int(i) = 0; (i) < n; (i)++) {       scanf( %I64d , &(bot[i].first));       scanf( %I64d , &(bot[i].second));       toT[i] = sqrt((double)((bot[i].first - tx) * (bot[i].first - tx) +                              (bot[i].second - ty) * (bot[i].second - ty)));       sum += 2 * toT[i];       toA[i].first = sqrt((double)((bot[i].first - ax) * (bot[i].first - ax) +                                    (bot[i].second - ay) * (bot[i].second - ay)));       toA[i].first -= toT[i];       toA[i].second = i;       toB[i].first = sqrt((double)((bot[i].first - bx) * (bot[i].first - bx) +                                    (bot[i].second - by) * (bot[i].second - by)));       toB[i].first -= toT[i];       toB[i].second = i;     }     sort((toA).begin(), (toA).end());     sort((toB).begin(), (toB).end());     double ans = 1e18;     for (int i = 0; i < n; i++) {       int j = toA[i].second;       int k = toB[0].second;       double tmp = sum + toA[i].first;       ans = min(ans, tmp);       tmp = sum + toB[i].first;       ans = min(ans, tmp);       if (j != k)         tmp = sum + toA[i].first + toB[0].first;       else         tmp = sum + toA[i].first + toB[1].first;       j = toB[i].second;       ans = min(ans, tmp);       k = toA[0].second;       if (j != k)         tmp = sum + toA[0].first + toB[i].first;       else         tmp = sum + toA[1].first + toB[i].first;       ans = min(ans, tmp);     }     printf( %.10f , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   const long long M = 1e4;   const long long mod = 1e9 + 7;   const long long inf = 1e9;   long long read() {     long long s = 0;     register bool neg = 0;     register char c = getchar();     for (; c <  0  || c >  9 ; c = getchar()) neg |= (c ==  - );     for (; c >=  0  && c <=  9 ; s = s * 10 + (c ^ 48), c = getchar())       ;     s = (neg ? -s : s);     return s;   }   long long a, s[N + 5], r[N + 5];   long double val[N + 5];   vector<long long> p[63], q[63];   bool cmp(long long p1, long long p2) { return val[p1] < val[p2]; }   signed main() {     a = read();     for (long long i = (1); i <= (a); ++i) {       s[i] = read();       long long j = 0, x = s[i];       for (; x; ++j)         if (x & (1ll << j)) {           if ((x ^ (1ll << j))) q[j].push_back(i);           x ^= (1ll << j);         }       --j;       p[j].push_back(i);     }     long long L = 0;     for (long long i = (61); i >= (0); --i) {       if (!((long long)((p[i]).size()))) continue;       if (((long long)((p[i]).size())) > ((long long)((q[i]).size())) + 1) {         puts( No );         return 0;       }       sort(q[i].begin(), q[i].end(), cmp);       r[p[i][0]] = L;       val[p[i][0]] = val[L] - 1e18;       L = p[i][0];       for (long long j = (1); j <= (((long long)((p[i]).size())) - 1); ++j) {         long long k = p[i][j], t = q[i][j - 1];         val[k] = (val[t] + val[r[t]]) / 2;         r[k] = r[t];         r[t] = k;       }     }     puts( Yes );     for (long long i = L; i; i = r[i]) printf( %lld  , s[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, p, i, j, k, l;     double sum = 0;     int a[50];     long long b[51][51];     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     scanf( %d , &p);     for (i = 0; i < n; i++) {       double tmp = 0;       for (j = 0; j <= n; j++) {         for (k = 0; k <= p; k++) {           b[j][k] = 0;         }       }       b[0][0] = 1;       for (j = 0; j < n; j++) {         if (j == i) continue;         for (k = n - 1; k >= 0; k--) {           for (l = p; l >= 0; l--) {             if (b[k][l] == 0) continue;             if (l + a[j] <= p) b[k + 1][l + a[j]] += b[k][l];           }         }       }       for (j = 0; j <= n; j++) {         for (k = 0; k <= p - a[i]; k++) {           double tmp2 = b[j][k];           for (l = 1; l <= j; l++) tmp2 *= l;           for (l = 1; l <= n - j - 1; l++) tmp2 *= l;           tmp += tmp2;         }       }       for (j = 1; j <= n; j++) tmp /= j;       sum += tmp;     }     printf( %lf n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   const int MAX = 1e6 + 1;   int n, f[MAX], dep[MAX];   int u[MAX], pr[MAX];   int stk[2][N], q[N << 1];   bool mk[MAX], cmp[N];   vector<int> a, adj[MAX], dv[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       a.push_back(0);       cin >> a[i];     }     fill(f, f + MAX, 0);     fill(u, u + MAX, -1);     fill(cmp, cmp + N, 1);     for (int i = 0; i < n; i++) {       int p1 = -1, p2 = -1;       int x = a[i], y, z = 1;       if (x == 1) {         f[1]++;         dv[1].push_back(1);         continue;       }       for (int j = 2; j < a[i]; j++) {         if (j * j > a[i]) break;         if (x % j == 0) {           y = 0;           if (p1 == -1)             p1 = j;           else             p2 = j;           while (x % j == 0) {             x /= j;             y ^= 1;           }           if (y)             z *= j;           else {             if (p2 == j)               p2 = -1;             else               p1 = -1;           }         }       }       if (x != 1) {         if (p1 == -1)           p1 = x;         else           p2 = x;         z *= x;       }       a[i] = z;       u[z] = i;       stk[0][i] = max(p1, 0);       stk[1][i] = max(p2, 0);       for (int j = 0; j < 2; j++) cmp[i] &= (stk[j][i] != 0);       if (cmp[i])         for (int j = 0; j < 2; j++) dv[stk[j][i]].push_back(stk[j ^ 1][i]);       else {         dv[1].push_back(z);         dv[z].push_back(1);       }       f[z]++;     }     if (f[1]) {       cout << 1 <<   n ;       return 0;     }     int mx = -1;     for (int x = 0; x < MAX; x++) mx = max(mx, f[x]);     if (mx > 1) {       cout << 2 <<   n ;       return 0;     }     fill(mk, mk + MAX, 0);     for (int x = 0; x < MAX; x++) {       for (auto& y : dv[x])         if (!mk[y]) {           mk[y] = 1;           adj[x].push_back(y);         }       for (auto& y : dv[x]) mk[y] = 0;     }     fill(pr, pr + MAX, 0);     for (int x = 0; x < MAX; x++)       for (auto& y : adj[x]) pr[y]++;     int l, r, mn = MAX;     mx = -1;     for (int x = 0; x < MAX; x++)       if (pr[x]) mx = max(mx, x);     mx = sqrt(mx) + 1;     fill(q, q + (N << 1), 0);     for (int x = 0; x < MAX; x++)       if (pr[x]) {         if (x > mx) continue;         fill(mk, mk + MAX, 0);         fill(dep, dep + MAX, 0);         l = 0;         r = 0;         dep[x] = 0;         mk[x] = 1;         q[r++] = x;         q[r++] = x;         while (l != r) {           int y = q[l++];           int z = q[l++];           for (auto& w : adj[y]) {             if (w == z) continue;             if (mk[w]) {               mn = min(mn, dep[w] + 1 + dep[y]);               continue;             }             dep[w] = 1 + dep[y];             mk[w] = 1;             q[r++] = w;             q[r++] = y;           }         }       }     if (mn == MAX) mn = -1;     cout << mn <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   set<string> name;   map<string, int> id;   string pos[N];   string s, st, o;   int n, a[N], cnt;   void add(string x) {     if (name.find(x) != name.end()) return;     name.insert(x);     cnt++;     id[x] = cnt;     pos[cnt] = x;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> st;     add(st);     cin >> n;     getline(cin, st);     for (int i = 1; i <= n; ++i) {       getline(cin, st);       stringstream ss(st);       string tmp;       vector<string> v;       while (ss >> tmp) {         v.emplace_back(tmp);       }       add(v[0]);       if (v[1] ==  posted ) {         v[3].pop_back();         v[3].pop_back();         add(v[3]);         int u = id[v[0]], vv = id[v[3]];         if (u == 1 || vv == 1) {           a[u] += 15, a[vv] += 15;         }       }       if (v[1] ==  commented ) {         v[3].pop_back();         v[3].pop_back();         add(v[3]);         int u = id[v[0]], vv = id[v[3]];         if (u == 1 || vv == 1) {           a[u] += 10, a[vv] += 10;         }       }       if (v[1] ==  likes ) {         v[2].pop_back();         v[2].pop_back();         add(v[2]);         int u = id[v[0]], vv = id[v[2]];         if (u == 1 || vv == 1) {           a[u] += 5, a[vv] += 5;         }       }     }     sort(pos + 2, pos + cnt + 1, [](string x, string y) {       return a[id[x]] != a[id[y]] ? a[id[x]] > a[id[y]] : x < y;     });     for (int i = 2; i <= cnt; ++i) cout << pos[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3002;   int dfn[N], low[N], c;   bool ipt[N];   pair<int, int> edge[N];   vector<pair<int, int> > p[N];   void tarjan(int x, int pre) {     dfn[x] = low[x] = ++c;     for (__typeof(p[x].begin()) it = p[x].begin(); it != p[x].end(); ++it) {       if (pre == (*it).second) continue;       int y = (*it).first;       if (dfn[y]) {         low[x] = min(low[x], dfn[y]);       } else {         tarjan(y, (*it).second);         low[x] = min(low[x], low[y]);         if (dfn[x] < low[y]) ipt[(*it).second] = 1;       }     }   }   int n, m, k, f[N];   void init() {     for (int i = 1; i <= n; ++i) f[i] = i;   }   int finds(int x) { return x == f[x] ? x : f[x] = finds(f[x]); }   void unions(int x, int y) {     x = finds(x);     y = finds(y);     f[x] = y;   }   bool vis[N];   int dfs(int x, int y, int deep) {     if (x == y) return deep;     vis[x] = true;     for (__typeof(p[x].begin()) e = p[x].begin(); e != p[x].end(); ++e)       if (!vis[e->first]) {         int g = dfs(e->first, y, deep + 1);         if (g != -1) return g;       }     return -1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int x, y;     for (int i = 0; i < m; ++i) {       cin >> edge[i].first >> edge[i].second;       x = edge[i].first;       y = edge[i].second;       p[x].push_back(make_pair(y, i));       p[y].push_back(make_pair(x, i));     }     init();     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i, -1);     for (int i = 0; i < m; ++i)       if (!ipt[i]) {         unions(edge[i].first, edge[i].second);       }     for (int i = 0; i <= n; ++i) p[i].clear();     for (int i = 0; i < m; ++i)       if (ipt[i]) {         p[finds(f[edge[i].first])].push_back(             make_pair(finds(f[edge[i].second]), -1));         p[finds(f[edge[i].second])].push_back(             make_pair(finds(f[edge[i].first]), -1));       }     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> x >> y;       for (int i = 0; i <= n; ++i) vis[i] = false;       cout << dfs(finds(f[x]), finds(f[y]), 0) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dir;   int n, m, k;   int go(int pos) {     if (pos == 1) {       dir = 1;       return pos + 1;     }     if (pos == n) {       dir = 0;       return pos - 1;     }     if (dir) return pos + 1;     return pos - 1;   }   int main() {     cin >> n >> m >> k;     string napr, isstop;     cin >> napr >> napr;     cin >> isstop;     if (napr ==  head )       dir = 0;     else       dir = 1;     for (int i = 0; i < isstop.size(); i++) {       if (isstop[i] ==  1 ) {         k = go(k);         if (dir == 0) {           if (k == n)             m = 1;           else             m = n;         } else {           if (k == 1)             m = n;           else             m = 1;         }       } else {         if (dir == 0) {           if (m < k) {             m--;             m = max(1, m);           } else {             m++;             m = min(m, n);           }         } else {           if (m > k) {             m++;             m = min(m, n);           } else {             m--;             m = max(1, m);           }         }         k = go(k);       }       if (m == k) {         cout <<  Controller   << i + 1;         return 0;       }     }     cout <<  Stowaway ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool palindrome(string s) {     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] != s[n - i - 1]) return 0;     }     return 1;   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     sort(s.begin(), s.end());     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       int x, y, n, cnt = 0, chk = 0, tmp, pos = -1, pos2 = -1, res;       map<pair<int, int>, int> mp, Tmp, Imp;       map<int, string> mp2;       string s =   , s2 =   , s3 =   ;       scanf( %d , &n);       cin >> s;       x = 0, y = 0;       Tmp[{x, y}]++;       mp[{x, y}]++;       for (int j = 0; j < s.size(); j++) {         s2 =   , s3 =   ;         if (s[j] ==  U ) {           y++;         } else if (s[j] ==  D ) {           y--;         } else if (s[j] ==  R ) {           x++;         } else if (s[j] ==  L ) {           x--;         }         if (j == 0) {           int tx = x, ty = y;         }         tmp = mp[{x, y}];         mp[{x, y}]++;         if (j == 0) {           Imp[{x, y}] = j;         }         if (mp[{x, y}] != tmp && tmp != 0) {           int dist;           if (x == 0 && y == 0 && pos == -1 && pos2 == -1) {             dist = abs((j + 1) - (Imp[{x, y}] + 1));           } else {             dist = abs((j + 1) - (Imp[{x, y}] + 2));           }           chk++;           if (chk == 1 || dist < res) {             res = dist;             if (x == 0 && y == 0 && pos == -1 && pos2 == -1) {               pos2 = Imp[{x, y}] + 1;               pos = j + 1;             } else {               pos2 = Imp[{x, y}] + 2;               pos = j + 1;             }           }         }         if (j != 0) {           Imp[{x, y}] = j;         }       }       if (chk == 0) {         printf( -1 n );       } else {         printf( %d %d n , min(pos, pos2), max(pos, pos2));       }     }     return 0;   }