malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int k, tot;   int op[4];   char s;   long long ans = 0x3f3f3f3f3f3f3f3f;   long long a[5];   template <typename T>   inline void read(T& x) {     x = 0;     T op = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) op = -1;     for (; c <=  9  && c >=  0 ; c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;   }   void dfs(int p, int k) {     if (p == 4) {       ans = ans < a[k] ? ans : a[k];       return;     }     for (int i = 1; i <= 4; ++i) {       if (a[i] == -1) continue;       for (int j = 1; j <= 4; ++j) {         if (i == j || a[j] == -1) continue;         if (op[p]) {           a[i] += a[j];           long long t = a[j];           a[j] = -1;           dfs(p + 1, i);           a[j] = t;           a[i] -= a[j];         } else {           a[i] *= a[j];           long long t = a[j];           a[j] = -1;           dfs(p + 1, i);           a[j] = t;           a[i] /= a[j];         }       }     }   }   int main() {     for (int i = 1; i <= 4; ++i) {       read(a[i]);       if (!a[i]) k = 1;     }     while (tot < 3) {       scanf( %c , &s);       if (s ==  + ) op[++tot] = 1;       if (s ==  * ) {         op[++tot] = 0;         if (k) {           puts( 0 );           return 0;         }       }     }     dfs(1, 0);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double sqr(double x) { return x * x; }   struct CPoint {     double x, y, n, l;     double length() { return sqrt(sqr(x) + sqr(y)); }   };   CPoint a[100100], b[100100];   double length(CPoint p1, CPoint p2) {     return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y));   }   double calc(CPoint X, CPoint Y) { return X.length() + length(X, Y) + Y.l; }   int b_search(CPoint X, int l, int r) {     if (r - l <= 10) {       int i = -1;       double v = 100000000, tmp;       for (; l <= r; l++) {         tmp = calc(a[l], X);         if (tmp < v) {           v = tmp;           i = l;         }       }       return i;     }     int mid = (l + r) / 2;     double p1 = calc(a[mid - 1], X);     double p2 = calc(a[mid], X);     double p3 = calc(a[mid + 1], X);     if (p2 <= p3 && p2 <= p1) {       int i = b_search(X, l, mid);       int j = b_search(X, mid, r);       if (calc(a[i], X) < calc(a[j], X)) return i;       return j;     }     if (p1 <= p2 && p2 <= p3) return b_search(X, l, mid);     return b_search(X, mid, r);   }   int main() {     int N, M, i, j;     double A, B;     scanf( %d%d%lf%lf , &N, &M, &A, &B);     for (i = 0; i < N; i++) {       scanf( %lf , &a[i].y);       a[i].x = A;       a[i].n = i + 1;     }     for (i = 0; i < M; i++) {       scanf( %lf , &b[i].y);       b[i].x = B;       b[i].n = i + 1;     }     for (i = 0; i < M; i++) scanf( %lf , &b[i].l);     double v = 1000000000;     int ii = -1, jj = -1;     for (i = 0; i < M; i++) {       j = b_search(b[i], 0, N - 1);       if (v > calc(a[j], b[i])) {         jj = i + 1;         ii = j + 1;         v = calc(a[j], b[i]);       }     }     printf( %d %d , ii, jj);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, x, y;       cin >> n >> x >> y;       long long int maxi = x + y - 2 + 1;       maxi = min(maxi, n);       long long int mini = x + y - n;       if (mini <= 0)         mini = 1;       else         mini++;       mini = min(mini, n);       cout << mini <<     << maxi << endl;     }   }
#include <bits/stdc++.h>   const int base = 1000003;   int n, k, d[201][30001], v[201];   bool isv[30010];   int fa[30010], tmp[30010];   bool on[30010];   struct edge {     int to;     edge* next;   } E[60010], *ne = E, *first[30010];   void link(int u, int v) {     *ne = (edge){v, first[u]};     first[u] = ne++;   }   bool chk(int i, int f, int d, int* g) {     if (d != g[i]) return 0;     for (edge* e = first[i]; e; e = e->next)       if (e->to != f && !chk(e->to, i, d + 1, g)) return 0;     return 1;   }   int list[30010], len;   bool cmp(int i, int j) { return d[0][i] < d[0][j]; }   unsigned long long hval[30010], hadd;   std::map<unsigned long long, int> M;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < k; i++) {       int fd = 0;       for (int j = 0; j < n; j++)         scanf( %d , d[i] + j), !d[i][j] ? fd++, v[i] = j : 1;       if (fd != 1) return puts( -1 ), 0;       fd = 0;       for (int j = 0; j < i; j++)         if (v[j] == v[i]) {           fd = 1;           for (int x = 0; x < n; x++)             if (d[j][x] != d[i][x]) return puts( -1 ), 0;         }       if (fd) i--, k--;       isv[v[i]] = 1;     }     on[v[0]] = 1;     for (int i = 0; i < n; i++) fa[i] = -1;     for (int i = 1; i < k; i++) {       int x = v[i];       for (int j = 0; j <= d[0][x]; j++) tmp[j] = -1;       for (int j = 0; j < n; j++)         if (d[0][j] + d[i][j] == d[0][x]) {           if (tmp[d[0][j]] > -1) return puts( -1 ), 0;           tmp[d[0][j]] = j;         }       for (int j = 0; j <= d[0][x]; j++) {         if (tmp[j] < 0) return puts( -1 ), 0;         if (j) {           if (fa[tmp[j]] > -1 && fa[tmp[j]] != tmp[j - 1]) return puts( -1 ), 0;           fa[tmp[j]] = tmp[j - 1];           on[tmp[j]] = 1;         }       }     }     for (int i = 0; i < n; i++)       if (on[i] && fa[i] > -1) link(i, fa[i]), link(fa[i], i);     for (int i = 0; i < k; i++)       if (!chk(v[i], -1, 0, d[i])) return puts( -1 ), 0;     for (int i = 0; i < k; i++) hadd = hadd * base + 1;     for (int i = 0; i < n; i++) {       for (int j = k; j--;) hval[i] = hval[i] * base + d[j][i];       if (on[i]) M[hval[i]] = i;     }     for (int i = 0; i < n; i++)       if (!on[i]) list[len++] = i;     std::sort(list, list + len, cmp);     for (int* i = list; i < list + len; i++) {       unsigned long long h = hval[*i] - hadd;       if (!M.count(h)) return puts( -1 ), 0;       fa[*i] = M[h];       M[hval[*i]] = *i;     }     for (int i = 0; i < n; i++)       if (fa[i] > -1) printf( %d %d n , i + 1, fa[i] + 1);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 7;   int n;   int val[N];   struct edge {     int to, nex;   } e[N << 1];   int fir[N], eid;   int siz[N], fa[N], son[N];   int dfn[N], pos[N], inx;   int cnt[N], res[N];   long long mul[N], ans[N];   void addedge(int u, int v) {     e[++eid] = (edge){v, fir[u]};     fir[u] = eid;   }   void hld(int s) {     siz[s] = 1;     pos[dfn[s] = ++inx] = s;     for (int i = fir[s]; i; i = e[i].nex)       if (e[i].to != fa[s])         fa[e[i].to] = s, hld(e[i].to), siz[s] += siz[e[i].to],         son[s] = siz[e[i].to] > siz[son[s]] ? e[i].to : son[s];   }   void dfs(int s, int rem) {     for (int i = fir[s]; i; i = e[i].nex)       if (e[i].to != fa[s] && e[i].to != son[s]) dfs(e[i].to, 0);     if (son[s]) dfs(son[s], 1);     int c = val[s];     mul[cnt[c]] -= c, mul[++cnt[c]] += c, res[s] = max(res[son[s]], cnt[c]);     for (int i = fir[s]; i; i = e[i].nex) {       if (e[i].to == fa[s] || e[i].to == son[s]) continue;       for (int j = dfn[e[i].to], c; j < dfn[e[i].to] + siz[e[i].to]; ++j)         c = val[pos[j]], mul[cnt[c]] -= c, mul[++cnt[c]] += c,         res[s] = max(res[s], cnt[c]);     }     ans[s] = mul[res[s]];     if (rem) return;     memset(cnt, 0, sizeof(int) * (n + 2));     memset(mul, 0, sizeof(long long) * (res[s] + 2));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , val + i);     for (int i = 1, u, v; i < n; ++i)       scanf( %d%d , &u, &v), addedge(u, v), addedge(v, u);     hld(1);     dfs(1, 1);     for (int i = 1; i <= n; ++i) printf( %I64d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1010] = {0};     int n, i, s = 0, x, m = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       a[x]++;     }     for (i = 0; i <= 1000; i++) {       if (a[i]) m++;       if (a[i] > s) s = a[i];     }     cout << s <<     << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   int GLL(long long& x) { return scanf( %lld , &x); }   int GI(int& x) { return scanf( %d , &x); }   void IO() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(ios::badbit | ios::failbit);   }   void file() {     freopen( mountains.in ,  r , stdin);     freopen( mountains.out ,  w , stdout);   }   const int N = 1e5 + 7, M = 2 * N;   int to[M], nxt[M], head[N], ne, visited[N], vid;   int n, m;   void init() {     memset(head, -1, n * sizeof(head[0]));     ne = 0;   }   void addEdge(int u, int v) {     to[ne] = v;     nxt[ne] = head[u];     head[u] = ne++;   }   void BiEdge(int u, int v) {     addEdge(u, v);     addEdge(v, u);   }   long long A[100001], B[100001], C[100001];   void solve() {     int n;     cin >> n;     if (n % 2 == 0)       puts( -1 );     else {       for (int i = 0; i < n; i++) {         A[i] = B[i] = i;         C[i] = (A[i] + B[i]) % n;       }       for (int i = 0; i < n; i++) cout << A[i] <<    ;       cout << endl;       for (int j = 0; j < n; j++) cout << B[j] <<    ;       cout << endl;       for (int j = 0; j < n; j++) cout << C[j] <<    ;       cout << endl;     }   }   int main() {     IO();     long long t = 1;     solve();   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize(2)   #pragma GCC optimize(3)   const int N = 1e6 + 10, p1 = 1e9 + 7, p2 = 1e9 + 9;   int n, k, len;   char s[N << 1], ch;   int strhash[N][2], hashbase[2], hashpow[2] = {1, 1}, tmp[2];   std::map<std::pair<int, int>, int> mp;   std::set<int> st;   int main() {     int i, j, q;     srand(time(NULL));     scanf( %d%d , &n, &k);     len = n * k;     for (i = 1; i <= len; i++) {       do s[i] = getchar();       while (s[i] <  a  || s[i] >  z );       s[len + i] = s[i];     }     hashbase[0] = (long long)rand() * rand() % p1,     hashbase[1] = (long long)rand() * rand() % p2;     for (i = 1; i <= k; i++) {       if (i > 1)         hashpow[0] = (long long)hashpow[0] * hashbase[0] % p1,         hashpow[1] = (long long)hashpow[1] * hashbase[1] % p2;       strhash[1][0] = ((long long)strhash[1][0] * hashbase[0] % p1 + s[i]) % p1,       strhash[1][1] = ((long long)strhash[1][1] * hashbase[1] % p2 + s[i]) % p2;     }     for (i = 2; i <= len; i++)       strhash[i][0] =           ((strhash[i - 1][0] - (long long)s[i - 1] * hashpow[0] % p1 + p1) % p1 *                hashbase[0] % p1 +            s[i + k - 1]) %           p1,       strhash[i][1] =           ((strhash[i - 1][1] - (long long)s[i - 1] * hashpow[1] % p2 + p2) % p2 *                hashbase[1] % p2 +            s[i + k - 1]) %           p2;     scanf( %d , &q);     for (i = 1; i <= q; i++) {       tmp[0] = tmp[1] = 0;       for (j = 1; j <= k; j++) {         do ch = getchar();         while (ch <  a  || ch >  z );         tmp[0] = ((long long)tmp[0] * hashbase[0] % p1 + ch) % p1,         tmp[1] = ((long long)tmp[1] * hashbase[1] % p2 + ch) % p2;       }       if (mp[std::make_pair(tmp[0], tmp[1])]) return 233;       mp[std::make_pair(tmp[0], tmp[1])] = i;     }     int tmp;     for (i = 1; i <= k; i++) {       st.clear();       for (j = 0; j < n; j++) {         tmp = mp[std::make_pair(strhash[(i + j * k - 1) % len + 1][0],                                 strhash[(i + j * k - 1) % len + 1][1])];         if (!tmp || st.count(tmp))           break;         else           st.insert(tmp);       }       if (j == n) {         puts( YES );         for (j = 0; j < n; j++)           printf( %d  ,                  mp[std::make_pair(strhash[(i + j * k - 1) % len + 1][0],                                    strhash[(i + j * k - 1) % len + 1][1])]);         return 0;       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int t;     cin >> t;     while (t--) {       long long int a, b, c, d;       cin >> a >> b;       if (a % b == 0)         cout << 0 << endl;       else if (b > a)         cout << (b - a) << endl;       else {         c = a / b;         c++;         c = c * b;         cout << (c - a) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   const long long inf = 9e18 + 9;   const int mod = 1e9 + 7;   long long res;   int indeg[N], outdeg[N], diam[N], adj[N];   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, val;       cin >> u >> v >> val;       outdeg[u]++;       indeg[v]++;       diam[u] = val;       adj[u] = v;     }     for (int i = 1; i <= n; i++) {       if (outdeg[i] > 0 && indeg[i] == 0) {         res++;       }     }     cout << res <<   n ;     for (int i = 1; i <= n; i++) {       if (outdeg[i] > 0 && indeg[i] == 0) {         int ans = INT_MAX;         int curr = i;         while (outdeg[curr]) {           ans = min(ans, diam[curr]);           curr = adj[curr];         }         cout << i <<     << curr <<     << ans <<   n ;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     for (int i = 1; i <= t; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6, inf = 2e9 + 2;   vector<pair<int, int> > ad[N + 2], tree[N + 2];   int br[N + 2];   vector<int> bkad[N + 2];   int vis[N + 2], lev[N + 2];   void clear(int n, int m) {     for (int i = 1; i <= n; i++) {       tree[i].clear(), bkad[i].clear();       vis[i] = 0, lev[i] = 0;     }     for (int i = 1; i <= m; i++) br[i] = 0;   }   void dfs(int node, int par, int lv) {     vis[node] = 1, lev[node] = lv;     for (auto z : ad[node]) {       int x = z.first;       if (x == par) continue;       if (vis[x]) {         bkad[node].push_back(x);         bkad[x].push_back(node);       } else {         tree[node].push_back({x, z.second});         tree[x].push_back({node, z.second});         dfs(x, node, lv + 1);       }     }   }   int bridge(int node, int par, int nm) {     int mn = 1e9;     for (auto x : bkad[node]) mn = min(mn, lev[x]);     for (auto x : tree[node]) {       if (x.first == par) continue;       mn = min(mn, bridge(x.first, node, x.second));     }     if (mn >= lev[node] && par != -1) br[nm] = 1;     return mn;   }   vector<int> pth;   int vs[N + 2];   bool find(int nd, int tr) {     if (nd == tr) return true;     vs[nd] = 1;     for (auto x : ad[nd]) {       if (vs[x.first]) continue;       pth.push_back(x.second);       if (find(x.first, tr)) return true;       pth.pop_back();     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int s, t;     cin >> s >> t;     vector<vector<int> > ed(m + 1);     for (int i = 1; i <= m; i++) {       int u, v, w;       cin >> u >> v >> w;       ed[i] = {u, v, w};       ad[u].push_back({v, i});       ad[v].push_back({u, i});     }     find(s, t);     int ans = inf, one = -1, two = -1;     if ((int)pth.size() == 0) cout << 0 <<     << 0 << endl, exit(0);     vector<int> ok = pth;     for (auto x : ok) {       int u = ed[x][0], v = ed[x][1];       int id = 0;       for (auto z : ad[u]) {         if (z.second == x) {           ad[u].erase(ad[u].begin() + id);           break;         }         id++;       }       id = 0;       for (auto z : ad[v]) {         if (z.second == x) {           ad[v].erase(ad[v].begin() + id);           break;         }         id++;       }       pth.clear();       for (int i = 1; i <= n; i++) vs[i] = 0;       find(s, t);       if ((int)pth.size() == 0) {         if (ed[x][2] < ans) ans = ed[x][2], one = x, two = -1;       }       dfs(s, -1, 0);       bridge(s, -1, 0);       for (auto z : pth) {         if (br[z] == 0) continue;         if (ed[x][2] + ed[z][2] < ans)           ans = ed[x][2] + ed[z][2], one = x, two = z;       }       clear(n, m);       ad[ed[x][0]].push_back({ed[x][1], x});       ad[ed[x][1]].push_back({ed[x][0], x});     }     if (ans == inf)       cout << -1 << endl;     else {       cout << ans <<    ;       if (two == -1)         cout << 1 <<     << one << endl;       else         cout << 2 <<     << one <<     << two << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int mod = 1000000007;   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   int prime[100007];   void SieveOfEratosthenes(int n) {     memset(prime, -1, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == -1) {         for (int i = p * p; i <= n; i += p) prime[i] = p;       }     }   }   int lps(string s) {     int len = 0;     int n = s.length();     int dp[n];     dp[0] = 0;     for (int i = 1; i < n; i++) {       if (s[i] == s[len]) {         len++;         dp[i] = len;         continue;       }       if (len != 0) {         len = dp[len - 1];         i--;         continue;       }       dp[i] = 0;     }     return dp[n - 1];   }   long long power(unsigned long long x, unsigned long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   vector<pair<long long, long long>> pFactor;   void factorize(long long n) {     int count = 0;     while (!(n % 2)) {       n >>= 1;       count++;     }     if (count) pFactor.push_back({2, count});     for (long long i = 3; i <= sqrt(n); i += 2) {       count = 0;       while (n % i == 0) {         count++;         n = n / i;       }       if (count) pFactor.push_back({i, count});     }     if (n > 2) pFactor.push_back({n, 1});   }   int dp[405][405];   int solve(int a[], int n, int i, int t) {     if (i > n) {       return 0;     }     if (t > 2 * n) {       return INT_MAX;     }     if (dp[i][t] != -1) {       return dp[i][t];     }     int x = solve(a, n, i + 1, t + 1);     if (x != INT_MAX) {       x += abs(t - a[i]);     }     x = min(x, solve(a, n, i, t + 1));     dp[i][t] = x;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n + 1];       for (long long i = 1; i < n + 1; i++) cin >> a[i];       sort(a + 1, a + n + 1);       memset(dp, -1, sizeof(dp));       int x = solve(a, n, 1, 1);       cout << x << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long power(long long x, long long y) {     long long temp = 1;     while (y > 0) {       if (y % 2 == 1) temp = (x * temp) % 1000000007;       x = (x * x) % 1000000007;       y = y / 2;     }     return temp;   }   long long n;   string st;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     set<string> ans;     for (long long i = (long long)(1); i <= (long long)(n); i++) {       cin >> st;       while (1) {         long long len = st.length(), ind = -1;         for (long long i = (long long)(0); i <= (long long)(len - 2); i++) {           if (st[i] ==  k  && st[i + 1] ==  h ) {             ind = i;             break;           }         }         if (ind != -1) {           st = st.substr(0, ind) +  h  + st.substr(ind + 2);           continue;         }         for (long long i = (long long)(0); i <= (long long)(len - 1); i++) {           if (st[i] ==  u ) {             ind = i;             break;           }         }         if (ind != -1) {           st = st.substr(0, ind) +  oo  + st.substr(ind + 1);           continue;         } else           break;       }       ans.insert(st);     }     cout << ans.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Braka() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     Braka();     int n, k, ans = 0;     cin >> n >> k;     while (n--) {       set<char> st;       string s;       cin >> s;       for (int i = 0; i < s.length(); i++)         if (s[i] -  0  <= k) st.insert(s[i]);       if (st.size() == k + 1) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6;   int n, seg[MAXN], r[MAXN], v[MAXN], resp;   void update(int ini, int fim, int cur, int id, int aux) {     if (id < ini || fim < id) return;     if (ini == fim) {       seg[cur] = aux;       r[cur] = aux;       return;     }     int m = (ini + fim) / 2;     update(ini, m, 2 * cur, id, aux);     update(m + 1, fim, 2 * cur + 1, id, aux);     seg[cur] = seg[2 * cur] + seg[2 * cur + 1];     r[cur] = max(r[2 * cur + 1], seg[2 * cur + 1] + r[2 * cur]);   }   int BB(int ini, int fim, int cur, int k) {     if (ini == fim) return ini;     int m = (ini + fim) / 2;     if (r[2 * cur + 1] < k) return BB(ini, m, 2 * cur, k - seg[2 * cur + 1]);     return BB(m + 1, fim, 2 * cur + 1, k);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     ;     cin >> n;     for (int i = 0; i < n; i++) {       int auxid, auxx, aux;       cin >> auxid >> auxx;       if (!auxx)         update(1, n, 1, auxid, -1);       else {         cin >> aux;         v[auxid] = aux;         update(1, n, 1, auxid, 1);       }       resp = v[BB(1, n, 1, 1)];       if (r[1] < 1)         cout << -1 <<   n ;       else         cout << resp <<   n ;     }   }
#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       static int aa[100];       static char used[100];       int n, m, i, yes;       scanf( %d%d , &n, &m);       for (i = 0; i < n; i++) scanf( %d , &aa[i]);       memset(used, 0, (n - 1) * sizeof *used);       while (m--) {         scanf( %d , &i), i--;         if (!used[i]) used[i] = 1;       }       yes = 1;       for (i = 0; i < n; i++) {         int j, j_;         j_ = -1;         for (j = i; j < n; j++)           if (j_ == -1 || aa[j_] > aa[j]) j_ = j;         if (j_ != i) {           int k, good;           good = 1;           for (k = j_ - 1; k >= i; k--) {             int tmp;             if (!used[k]) {               good = 0;               break;             }             tmp = aa[k], aa[k] = aa[k + 1], aa[k + 1] = tmp;           }           if (!good) {             yes = 0;             break;           }         }       }       printf(yes ?  YES n  :  NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[200005];   queue<pair<int, int> > q;   int deg[200005], a, n;   bool v[200005];   set<int> s[200005];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);       deg[a]++, deg[b]++;     }     for (int i = 1; i <= n; i++)       if (deg[i] == 1) q.push(pair<int, int>(i, 0));     int c = 0, lst = -1;     while (!q.empty()) {       int x = q.front().first, d = q.front().second;       q.pop();       v[x] = true;       lst = x, c++;       for (auto y : g[x]) {         if (v[y]) continue;         deg[y]--;         s[y].insert(d + 1);         if (deg[y] == 1 and s[y].size() == 1) q.push(pair<int, int>(y, d + 1));       }     }     if (c < n - 1)       a = -1;     else {       if (c == n - 1)         for (int i = 1; i <= n; i++)           if (!v[i]) lst = i;       if (s[lst].size() > 2)         a = -1;       else {         for (auto e : s[lst]) a += e;       }     }     while (a % 2 == 0) a /= 2;     printf( %d n , a);   }
#include <bits/stdc++.h>   int x[100005];   using namespace std;   bool cmp(int a, int b) { return a < b; }   int main() {     int n, i, q, k;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x[i]);     }     sort(x, x + n, cmp);     scanf( %d , &q);     while (q--) {       int m;       scanf( %d , &m);       printf( %d n , upper_bound(x, x + n, m) - x);     }     return 0;   }