malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string itosm(long long x) {     if (x == 0) return  0 ;     string ans =   ;     while (x > 0) {       ans += ((x % 10) +  0 );       x /= 10;     }     reverse(ans.begin(), ans.end());     return ans;   }   long long stoim(string str) {     long long ans = 0;     long long k = 1;     int p = 0;     if (str[0] ==  - ) p++;     for (int i = str.length() - 1; i >= p; i--) {       ans += (str[i] -  0 ) * k;       k *= 10;     }     return ans;   }   const long long infll = 1e18 + 3;   const int inf = 1009000999;   const long double eps = 1e-7;   const int maxn = 1e6 + 1146;   const int baseint = 1000200013;   const long long basell = 1e18 + 3;   const long double PI = acos(-1.0);   const long long mod = 1e9 + 7;   long long a[maxn];   long long t[maxn];   long long f[maxn];   long long n, r, k;   bool check(long long x) {     for (int i = 0; i < n; i++) f[i] = x - a[i], t[i] = 0;     long long sum = 0, ans = 0;     for (int i = 0; i < n; i++) {       if (f[i] - sum > 0) {         long long d = f[i] - sum;         sum += d;         ans += d;         t[2 * r + i] += d;         if (ans > k) return 0;       }       sum -= t[i];     }     return 1;   }   void solve() {     cin >> n >> r >> k;     for (int i = 0; i < n; i++) cin >> a[i];     long long sum = 0;     for (int i = 0; i < n; i++) {       if (i - r - 1 >= 0) sum -= a[i - r - 1];       t[i] = sum;       sum += a[i];     }     sum = 0;     for (int i = n - 1; i >= 0; i--) {       sum -= a[i + r + 1];       sum += a[i];       t[i] += sum;     }     for (int i = 0; i < n; i++) a[i] = t[i];     long long l = 0, r = 1.2e18, mid;     while (l < r) {       mid = (l + r + 1) / 2;       if (check(mid))         l = mid;       else         r = mid - 1;     }     cout << l;   }   int main() {     ios_base::sync_with_stdio(0);     ;     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i, j, ll, l;     cin >> n;     string a[n], s;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n,          [&](const string &a, const string &t) { return a.size() < t.size(); });     for (i = 0; i < n - 1; i++) {       if (a[i + 1].find(a[i]) == string::npos) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     for (i = 0; i < n; i++) cout << a[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse2 )   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> cnt(n + 1, 0);     bool ch = 1;     for (long long i = 0; i < n - 1; i++) {       long long a, b;       cin >> a >> b;       if (a == n && b == n) ch = 0;       cnt[a]++;       cnt[b]++;     }     if (cnt[n] != n - 1) ch = 0;     vector<vector<long long> > g(n + 1);     vector<long long> v1;     vector<long long> v2;     for (long long i = n - 1; i >= 1; i--) {       if (cnt[i])         v1.push_back(i);       else         v2.push_back(i);     }     long long s2 = v2.size();     long long j = 0;     for (long long i = 0; i < v1.size(); i++) {       long long d = cnt[v1[i]] - 1;       long long p = n;       while (d && j < s2) {         g[p].push_back(v2[j]);         p = v2[j];         if (p > v1[i]) ch = 0;         j++;         d--;       }       if (d) ch = 0;       g[p].push_back(v1[i]);     }     if (j != s2) ch = 0;     if (ch) {       cout <<  YES             <<   n ;       for (long long i = 1; i <= n; i++) {         for (auto it : g[i]) {           cout << i <<     << it <<   n ;         }       }     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[25][510];   int g[25][25];   int main() {     int n, m, i, j, l1, l2, fuck, temp, k;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %s , str[i]);     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         temp = 0;         l1 = strlen(str[i]);         l2 = strlen(str[j]);         for (k = 0; k < l1 && k < l2; k++)           if (str[i][k] != str[j][k]) break;         k = min(k, l1);         k = min(k, l2);         g[i][j] = k;       }     }     int tot = (1 << n), ans = 0;     for (i = 0; i < tot; i++) {       fuck = 0;       for (j = 0; j < n; j++) {         if ((i & (1 << j))) fuck++;       }       if (fuck != m) continue;       temp = 0;       for (j = 0; j < n; j++) {         if ((i & (1 << j)) == 0) continue;         for (k = j + 1; k < n; k++) {           if ((i & (1 << k)) == 0) continue;           temp += g[j][k];         }       }       ans = max(ans, temp);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[10010] = {0};   int D;   int N, M, P;   int g;   int fact[20010] = {0};   int fp = 0;   int Hash[20010] = {0};   int place[10010] = {0};   int F[20010] = {0};   long long power(long long a, long long k, long long Mod) {     long long o = 1;     for (; k > 0; k >>= 1) {       if (k & 1) o = o * a % Mod;       a = a * a % Mod;     }     return o;   }   int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }   int getplace(int k) {     for (int l = 1, r = fp; l <= r;) {       int mid = (l + r) >> 1;       if (fact[mid] == k) return mid;       if (fact[mid] > k)         r = mid - 1;       else         l = mid + 1;     }     return 0;   }   int main() {     cin >> N >> M >> P;     for (int i = 1; i * i <= P - 1; i++) {       if ((P - 1) % i != 0) continue;       fact[++fp] = i;       if (i * i != (P - 1)) fact[++fp] = (P - 1) / i;     }     sort(fact + 1, fact + fp + 1);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       A[i] %= P;       for (int j = 1; j <= fp; j++) {         if (power(A[i], fact[j], P) == 1) {           A[i] = (P - 1) / fact[j];           break;         }       }     }     D = P - 1;     for (int i = 1; i <= M; i++) {       int B;       scanf( %d , &B);       D = gcd(D, B);     }     P = (P - 1) / D;     fp = 0;     for (int i = 1; i * i <= P; i++) {       if (P % i != 0) continue;       fact[++fp] = i;       if (i * i != P) fact[++fp] = P / i;     }     sort(fact + 1, fact + fp + 1);     int Ans = 0;     for (int i = 1; i <= N; i++) {       A[i] = gcd(A[i], P);       int place = getplace(A[i]);       if (Hash[place] == 0) Ans += P / fact[place];       F[place] = 1;       Hash[place] = 1;     }     for (int i = fp; i >= 1; i--) {       for (int j = i + 1; j <= fp; j++) {         if (fact[j] % fact[i] == 0) F[j] += F[i];       }     }     for (int i = 1; i <= fp; i++) {       if (Hash[i] == 1) {         int Need = -(F[i] - 1);         Ans += Need * (P / fact[i]);         for (int j = i + 1; j <= fp; j++)           if (fact[j] % fact[i] == 0) {             Hash[j] = 1;             F[j] += Need;           }       }     }     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, a[200005], p[200005];   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       sort(a + 1, a + n + 1);       for (int i = 1; i <= n; i++) {         p[i] = i - 1;       }       int sum, cnt, x, ans = 0;       for (int i = 1; i <= n; i++) {         sum = a[i], cnt = 1, x = i;         while (cnt < 3 && x >= 1) {           if (a[i] % a[x]) cnt++, sum += a[x];           while (p[x] && a[i] % a[p[x]] == 0) p[x] = p[p[x]];           x = p[x];         }         ans = max(ans, sum);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int n, m;   int h[maxn], in[maxn], q[maxn], sg[maxn], sum[maxn], vis[maxn];   vector<int> G[maxn];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &h[i]);     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       ++in[v];     }     int l = 1, r = 0;     for (int i = 1; i <= n; ++i)       if (!in[i]) q[++r] = i;     while (l <= r) {       int u = q[l++];       for (int i = 0; i < G[u].size(); ++i) {         int v = G[u][i];         if (!--in[v]) q[++r] = v;       }     }     for (int i = n; i; --i) {       int u = q[i];       for (int j = 0; j < G[u].size(); ++j) {         int v = G[u][j];         vis[sg[v]] = 1;       }       for (; vis[sg[u]]; ++sg[u])         ;       for (int j = 0; j < G[u].size(); ++j) {         int v = G[u][j];         vis[sg[v]] = 0;       }     }     for (int i = 1; i <= n; ++i) sum[sg[i]] ^= h[i];     int p = -1;     for (int i = n; ~i; --i)       if (sum[i]) {         p = i;         break;       }     if (p == -1) {       puts( LOSE );       return 0;     }     puts( WIN );     for (int i = 1; i <= n; ++i)       if (sg[i] == p) {         if ((sum[p] ^ h[i]) > h[i]) continue;         h[i] ^= sum[p];         for (int j = 0; j < G[i].size(); ++j) {           int v = G[i][j];           h[v] ^= sum[sg[v]];           sum[sg[v]] = 0;         }         break;       }     for (int i = 1; i <= n; ++i) printf( %d  , h[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, v[10004];   vector<array<int, 3> > ans;   void go(int x, int y, int z) {     v[x] -= x * z;     v[y] += x * z;     ans.push_back({x, y, z});   }   int main() {     int t;     cin >> t;     while (t--) {       ans.clear();       int sum = 0;       cin >> n;       for (int i = 1; i <= n; ++i) {         cin >> v[i];         sum += v[i];       }       if (sum % n) {         cout << -1 <<   n ;         continue;       }       for (int i = 2; i <= n; ++i) {         if (v[i] % i) {           go(1, i, i - v[i] % i);         }         go(i, 1, v[i] / i);       }       for (int i = 2; i <= n; ++i) {         go(1, i, sum / n);       }       assert((int)ans.size() <= 3 * n);       cout << ans.size() <<   n ;       for (auto &[x, y, z] : ans) {         cout << x <<     << y <<     << z <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Envelope {     int s, t, d, w;   };   const int NMAX = 100010, MMAX = 210, KMAX = 100010;   const long long LLINF = 0x7fffffffffffffffLL;   int n, m, k;   Envelope red[KMAX];   vector<int> v[NMAX];   int red_t[NMAX];   long long f[NMAX][MMAX];   bool cmp(int a, int b) {     if (red[a].w != red[b].w) return red[a].w > red[b].w;     if (red[a].d != red[b].d) return red[a].d > red[b].d;     return a < b;   }   set<int, decltype(cmp) *> s(cmp);   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d%d%d%d , &red[i].s, &red[i].t, &red[i].d, &red[i].w);       v[red[i].s].push_back(i);       v[red[i].t + 1].push_back(-i);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < v[i].size(); j++) {         if (v[i][j] < 0) {           s.erase(-v[i][j]);         } else {           s.insert(v[i][j]);         }       }       auto iter = s.begin();       red_t[i] = -1;       if (iter != s.end()) red_t[i] = *iter;     }     for (int i = 1; i <= n + 1; i++)       for (int j = 0; j <= m; j++) f[i][j] = LLINF;     f[1][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= m; j++) {         if (f[i][j] == LLINF) continue;         int cur = red_t[i];         long long &trans1 = f[red[cur].d + 1][j];         long long &trans2 = f[i + 1][j + 1];         long long &trans3 = f[i + 1][j];         if (cur == -1) {           trans3 = min(trans3, f[i][j]);           continue;         }         trans1 = min(trans1, f[i][j] + red[cur].w);         if (j != m) trans2 = min(trans2, f[i][j]);       }     }     long long ans = LLINF;     for (int i = 0; i <= m; i++) ans = min(ans, f[n + 1][i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[300005];   int n, m, s;   int edgeck[300005], Etype[300005];   pair<int, int> E[300005];   int vis[300005];   void bfs() {     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     while (!que.empty()) {       int now = que.front();       que.pop();       vis[now] = 1;       for (int i = 0; i < v[now].size(); i++) {         int Enum = v[now][i];         int nxt = -1;         if (edgeck[Enum] == -1) {           nxt = E[Enum].second;           if (nxt != now) {             edgeck[Enum] = 0;           } else {             nxt = E[Enum].first;             edgeck[Enum] = 1;           }           if (!vis[nxt]) {             vis[nxt] = 1;             que.push(nxt);           }         } else {           nxt = (edgeck[Enum] == 0 ? E[Enum].second : E[Enum].first);           if (vis[nxt]) continue;           vis[nxt] = 1;           que.push(nxt);         }       }     }     for (int i = 0; i < m; i++) {       if (edgeck[i] == -1) edgeck[i] = 0;     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (vis[i]) ++cnt;     }     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (Etype[i] != 2) continue;       if (edgeck[i] == 0)         printf( + );       else         printf( - );     }     puts(  );   }   void bfs2() {     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     while (!que.empty()) {       int now = que.front();       que.pop();       vis[now] = 1;       for (int i = 0; i < v[now].size(); i++) {         int Enum = v[now][i];         int nxt = -1;         if (edgeck[Enum] == -1) {           nxt = E[Enum].second;           if (nxt != now) {             edgeck[Enum] = 1;           } else {             nxt = E[Enum].first;             edgeck[Enum] = 0;           }         } else {           nxt = (edgeck[Enum] == 0 ? E[Enum].second : E[Enum].first);           if (vis[nxt]) continue;           vis[nxt] = 1;           que.push(nxt);         }       }     }     for (int i = 0; i < m; i++) {       if (edgeck[i] == -1) edgeck[i] = 0;     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (vis[i]) ++cnt;     }     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (Etype[i] != 2) continue;       if (edgeck[i] == 0)         printf( + );       else         printf( - );     }     puts(  );   }   int main() {     memset(edgeck, -1, sizeof(edgeck));     scanf( %d %d %d , &n, &m, &s);     for (int ty, a, b, i = 0; i < m; i++) {       scanf( %d %d %d , &ty, &a, &b);       v[a].push_back(i);       v[b].push_back(i);       if (ty == 1) {         edgeck[i] = 0;       } else {         Etype[i] = 2;       }       E[i] = {a, b};     }     bfs();     for (int i = 0; i < m; i++) {       if (Etype[i] != 2) continue;       edgeck[i] = -1;     }     bfs2();   }
#include<bits/stdc++.h>   using namespace std;      #define INF 1234567890   #define ll long long      int T;   int N, K;   int A[200201];      int main()   {    //ios::sync_with_stdio(0); cin.tie(0);    scanf( %d , &T);    while(T--)    {     scanf( %d %d , &N, &K);     for(int i=1; i<=N; i++)     {      if (i <= K) A[i] = i;      else A[i] = K-(i-K);     }     // for(int i=1; i<=N; i++)     //  printf( %d  , A[i]);     // printf(  n );        int cnt = A[N]-1; // prefix     for(int i=1; i<=cnt; i++)      printf( %d  , i);     for(int i=cnt+1; i<=K; i++)      printf( %d  , cnt+1+K-i);     printf(  n );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long linf = 1e18 + 5;   const int N = 3000 + 5;   int n, x, y, all, up[N], down[N], w[N];   vector<pair<int, int> > v[N];   void dfs(int root, int x, int w, int up, int down) {     ::up[x] = up;     ::down[x] = down;     ::w[x] = w;     for (__typeof(v[x].begin()) it = v[x].begin(); it != v[x].end(); it++)       if (it->first != root) {         all += it->second;         dfs(x, it->first, w, up + it->second, down + !it->second);       }   }   int solve(int x) {     all = 0;     w[x] = 0;     up[x] = 0;     down[x] = 0;     for (__typeof(v[x].begin()) it = v[x].begin(); it != v[x].end(); it++) {       all += it->second;       dfs(x, it->first, it->first, it->second, !it->second);     }     int ans = all, mni = -1;     for (int i = 1; i <= n; i++) {       if (all - up[i] + down[i] < ans) {         ans = all - up[i] + down[i];         mni = w[i];       }     }     int ans2 = ans;     for (int i = 1; i <= n; i++) {       if (w[i] != mni and ans - up[i] + down[i] < ans2) {         ans2 = ans - up[i] + down[i];       }     }     return ans2;   }   int main() {     ios ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       cin >> x >> y;       v[x].push_back(make_pair(y, 0));       v[y].push_back(make_pair(x, 1));     }     int ans = inf;     for (int i = 1; i <= n; i++) ans = min(ans, solve(i));     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, temp;     cin >> n;     vector<int> num;     while (n != 0) {       cin >> temp;       num.push_back(temp);       n--;     }     sort(num.begin(), num.end());     int smallest = 1;     for (int i = 0; i < num.size(); i++) {       if (smallest != num[i]) {         break;       }       smallest++;     }     cout << smallest;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[300001];   int m, n, res = 1, x;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     m = n;     printf( 1  );     for (int i = 1; i <= n; ++i) {       cin >> x;       a[x] = 1;       res++;       while (a[m] == 1 && m > 0) {         res--;         m--;       }       printf( %d  , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, a, b, ans = 0;     cin >> n >> a >> b;     if (b >= 0) {       if (b >= n) {         ans = b % n;         ans += a;       } else         ans = a + b;       if (ans > n) ans %= n;     } else if (n == -b) {       ans = a;     } else {       if (b == -1) {         a += b;         if (a == 0)           ans = n;         else           ans = a;       } else {         int k = 0;         while (k != b) {           a--;           k--;           if (a == 0) a = n;         }         if (a < 0)           ans = -a;         else           ans = a;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cycles;   vector<vector<int> > g;   vector<int> vis;   void dfs(int u) {     vis[u] = 1;     for (auto v : g[u]) {       if (vis[v]) {         if (vis[v] == 1) cycles++;         continue;       }       dfs(v);     }     vis[u] = 2;   }   long long gcd(long long a, long long b) {     long long x = max(a, b);     long long y = min(a, b);     if (y == 0) return x;     if (x % y == 0) return y;     return gcd(y, x % y);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int l = s.length();       int d = s[0] -  0 ;       int ans = (d - 1) * (4 + 3 + 2 + 1);       for (int i = 1; i <= l; i++) ans += i;       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long N = 1e5 + 10;   vector<vector<long long> > v1(N, vector<long long>(2));   vector<vector<long long> > v;   long long dfs(long long s, long long n, vector<long long>& level) {     long long val = 0;     for (auto u : v[s]) {       if (level[u] == 0) {         val = max(val, dfs(u, n, level));       } else if (level[u]) {         val = max(val, level[u]);       }     }     level[s] = val + 1;     return level[s];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       cin >> v1[i][0] >> v1[i][1];     }     long long low = 1, high = m, ans = -1;     while (low <= high) {       long long mid = (low + high) / 2;       v.clear();       v.resize(n + 1);       vector<long long> par(n + 1, -1), level(n + 1);       for (long long i = 1; i <= mid; i++) {         v[v1[i][0]].push_back(v1[i][1]);         par[v1[i][1]] = v1[i][0];       }       for (long long i = 1; i <= n; i++) {         if (par[i] == -1) {           if (dfs(i, n, level) == n) {             ans = mid;             high = mid - 1;           } else {             low = mid + 1;           }           break;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, m, k, s, t;   vector<int> g[N];   int dis[N];   bool spc[N];   bool ok(int lim) {     priority_queue<pair<int, int> > stk;     fill_n(dis, n, INT_MAX);     dis[s] = 0;     stk.push({-dis[s], s});     while (!stk.empty()) {       int d, u;       tie(d, u) = stk.top();       stk.pop();       if (d != -dis[u] || -d >= lim) continue;       for (auto v : g[u]) {         if (dis[v] > dis[u] + 1) {           dis[v] = dis[u] + 1;           if (spc[v]) dis[v] = 0;           stk.push({-dis[v], v});         }       }     }     return dis[t] < INT_MAX;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = (0); i < (k); ++i) {       int p;       scanf( %d , &p);       p--;       spc[p] = true;     }     for (int i = (0); i < (m); ++i) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     scanf( %d%d , &s, &t);     s--;     t--;     int ans = -1;     for (int l = 1, r = n, mid = l + r >> 1; l <= r; mid = l + r >> 1)       ok(mid) ? r = (ans = mid) - 1 : l = mid + 1;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int a[7];     for (int i = 0; i < 6; i++) {       a[i] = s[i] -  0 ;     }     int ans = 3;     for (int i = 0; i <= 9; i++) {       for (int j = 0; j <= 9; j++) {         for (int k = 0; k <= 9; k++) {           for (int x = 0; x <= 9; x++) {             for (int y = 0; y <= 9; y++) {               for (int z = 0; z <= 9; z++) {                 if (i + j + k == x + y + z) {                   int res = 0;                   if (i != a[0]) res++;                   if (j != a[1]) res++;                   if (k != a[2]) res++;                   if (x != a[3]) res++;                   if (y != a[4]) res++;                   if (z != a[5]) res++;                   ans = min(ans, res);                 }               }             }           }         }       }     }     for (int i = 0; i <= 9; i++) {       for (int j = 0; j <= 9; j++) {         for (int k = 0; k <= 9; k++) {           if (i + j + k == a[3] + a[4] + a[5]) {             int res = 0;             if (i != a[0]) res++;             if (j != a[1]) res++;             if (k != a[2]) res++;             ans = min(ans, res);           }         }       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 10;   int a[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n + n; i++) scanf( %d , &a[i]);     sort(a, a + n + n);     if (a[n] > a[n - 1])       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<vector<int>> g(n);     for (int i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       g[x].push_back(y);       g[y].push_back(x);     }     int ans = 1;     function<int(int, int)> dfs = [&](int v, int pv) {       if ((int)g[v].size() == 1) {         return 0;       }       vector<int> d;       for (int to : g[v]) {         if (to == pv) {           continue;         }         d.push_back(1 + dfs(to, v));       }       sort(d.begin(), d.end());       while ((int)d.size() >= 2) {         if (d.back() + d[(int)d.size() - 2] <= k) {           break;         }         ++ans;         d.pop_back();       }       return d.back();     };     for (int i = 0; i < n; ++i) {       if ((int)g[i].size() > 1) {         dfs(i, -1);         break;       }     }     cout << ans <<   n ;     return 0;   }