malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const long long int MOD = 1e9 + 7;   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};   int dx4[] = {0, 0, 1, -1};   int dy4[] = {1, -1, 0, 0};   using namespace std;   void vok() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return ((a * b) / gcd(a, b));   }   vector<long long int> pp;   void gen() {     vector<bool> prime(33000, true);     prime[0] = prime[1] = false;     for (int p = 0; p * p <= 33000; p++) {       if (prime[p]) {         for (int i = p * p; i <= 33000; i += p) prime[i] = false;       }     }     for (int i = 0; i < 33000; i++)       if (prime[i]) pp.push_back(i);   }   long long int find(vector<int>& A, int n) {}   void solve() {     long long int n, m, x, y, a, b, k;     a = b = x = y = k = 0;     long long int ans = 0, res = 0;     string s1, s2;     cin >> s1 >> s2;     n = s1.size();     if (s1 == s2) {       cout <<  YES  << endl;       return;     }     if (n == 1 and s1 != s2) {       cout <<  NO  << endl;       return;     }     int dp[26]{0};     for (int i = 0; i < n; i++) {       dp[s1[i] -  a ]++;     }     for (int i = 0; i < n; i++) {       if (dp[s2[i] -  a ] >= 1) {         cout <<  YES  << endl;         return;       }     }     cout <<  NO  << endl;   }   int main() {     vok();     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 50005;   const int inf = 0x3f3f3f3f;   const long long INF = 1000000000000000000ll;   const long long mod = 998244353;   const double pi = acos(-1.0);   const double eps = 1e-6;   vector<int> rec;   struct OP {     char str[4];     int num;     void get() {       scanf( %s , str);       if (str[0] ==  a  || str[0] ==  d ) {         scanf( %d , &num);       }     }   } op[N];   struct node {     int l, r, cnt;     long long num[5];     int nt;     void init() {       memset(num, 0, sizeof(num));       cnt = 0;     }     node() {}     node(int l, int r, int nt) {       this->l = l;       this->r = r;       this->nt = nt;     }     void Equal(node tmp) {       for (int i = 0; i < 5; i++) {         num[i] = tmp.num[i];       }       nt = tmp.nt;       cnt = tmp.cnt;     }   };   struct segTree {     node tree[N * 4];     void build(int l, int r, int id) {       tree[id] = node(l, r, 1);       tree[id].init();       if (l == r) return;       int mid = ((l + r) >> 1);       build(l, mid, (id << 1));       build(mid + 1, r, (id << 1 | 1));     }     void pushUp(int id) {       tree[id].Equal(tree[(id << 1)]);       int nt = tree[(id << 1)].nt;       for (int i = 1, j = nt, cnt = 1; cnt <= 5;            i = (i + 1) % 5, j = (j + 1) % 5, cnt++) {         if (tree[(id << 1 | 1)].num[i] == 0) break;         tree[id].num[j] += tree[(id << 1 | 1)].num[i];       }       tree[id].cnt += tree[(id << 1 | 1)].cnt;       tree[id].nt = (tree[id].nt + tree[(id << 1 | 1)].cnt) % 5;     }     void update(int id, int pos, int val) {       int l = tree[id].l, r = tree[id].r;       if (l == r) {         tree[id].num[1] += val;         if (val > 0)           tree[id].nt++, tree[id].cnt++;         else           tree[id].nt--, tree[id].cnt--;         return;       }       int mid = ((l + r) >> 1);       if (pos <= mid)         update((id << 1), pos, val);       else         update((id << 1 | 1), pos, val);       pushUp(id);     }   } segT;   map<int, int> mp;   void discre() {     sort(rec.begin(), rec.end());     int siz = rec.size();     for (int i = 0; i < siz; i++) {       mp.insert(pair<int, int>(rec[i], i));     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       op[i].get();       if (op[i].str[0] ==  a ) rec.push_back(op[i].num);     }     discre();     if (rec.size() == 0) {       printf( 0 n );       return 0;     }     segT.build(0, rec.size() - 1, 1);     for (int i = 1; i <= n; i++) {       if (op[i].str[0] ==  a ) {         segT.update(1, mp[op[i].num], op[i].num);       } else if (op[i].str[0] ==  d ) {         segT.update(1, mp[op[i].num], -op[i].num);       } else {         printf( %lld n , segT.tree[1].num[3]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100010;   long long n, a[N];   double bit[N];   inline void add(long long x, double val) {     for (; x <= n; x += x & -x) bit[x] += val;   }   inline double ask(long long x) {     double sum = 0;     for (; x; x -= x & -x) sum += bit[x];     return sum;   }   int main() {     scanf( %lld , &n);     double tt = 0.0;     for (long long i = 1; i <= n; i++) {       scanf( %lld , a + i);       tt += (ask(n) - ask(a[i]));       add(a[i], 1.0);     }     double ans = 0.0;     for (long long i = 1; i <= n; i++) {       ans += (0.25 * i * (i - 1) + tt) * (n - i + 1);     }     memset(bit, 0, sizeof(bit));     double cur = 0.0;     for (long long i = 1; i <= n; i++) {       double tmp = ask(n) - ask(a[i]) + cur;       ans -= tmp;       add(a[i], i);       cur = tmp;     }     ans = ans / n / (n + 1) * 2.0;     printf( %.12lf n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int mas[100][100], n, used[100], p = 0, s = 0, to;   vector<vector<int> > g;   void dfs(int from) {     used[from] = 1;     for (int i = 0; i < 2; i++) {       to = g[from][i];       if (!used[to]) {         p += mas[from][to];         dfs(to);       }     }   }   int main() {     cin >> n;     g.resize(n);     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       g[a - 1].push_back(b - 1);       g[b - 1].push_back(a - 1);       mas[a - 1][b - 1] = c;       s += c;     }     dfs(0);     p += mas[to][0];     cout << min(p, s - p) << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long MN = 3005;   long long a[2], b[2], c[2], d[8], first[8], ra[2], rb[2], rc[2];   inline bool check(long long f3, long long f5, long long f6) {     for (long long i = 0; i < 2; i++) ra[i] = a[i], rb[i] = b[i], rc[i] = c[i];     ra[0] -= f5 + f6, rb[0] -= f3 + f6, rc[0] -= f3 + f5;     if (ra[0] < 0 || rb[0] < 0 || rc[0] < 0) return 0;     memset(first, 0, sizeof(first));     first[3] = f3, first[5] = f5, first[6] = f6;     first[7] = min({d[7], ra[0], rb[0], rc[0]});     ra[0] -= first[7], rb[0] -= first[7], rc[0] -= first[7];     first[4] = min(d[4], ra[0]);     first[2] = min(d[2], rb[0]);     first[1] = min(d[1], rc[0]);     long long sa = 0, sb = 0, sc = 0;     for (long long i = 1; i <= 7; i++) {       long long second = d[i] - first[i];       if (i & 1) sc += second;       if (i & 2) sb += second;       if (i & 4) sa += second;     }     if (sa > a[1] || sb > b[1] || sc > c[1]) return 0;     for (long long i = 7; i >= 1; i--) printf( %lld  , first[i]);     printf(  n );     return 1;   }   int32_t main() {     cin.tie(0), cin.sync_with_stdio(0);     long long t;     cin >> t;   outer:     while (t--) {       cin >> a[0] >> b[0] >> c[0] >> a[1] >> b[1] >> c[1];       for (long long i = 1; i <= 7; i++) cin >> d[8 - i];       long long tota = 0, totb = 0, totc = 0;       for (long long i = 1; i <= 7; i++) {         if (i & 1) totc += d[i];         if (i & 2) totb += d[i];         if (i & 4) tota += d[i];       }       if (tota > a[0] + a[1] || totb > b[0] + b[1] || totc > c[0] + c[1]) {         printf( -1 n );         continue;       }       for (long long i = 0; i <= d[3]; i++) {         for (long long j = 0; j <= d[5]; j++) {           for (long long k = 0; k <= d[6]; k++) {             if (check(i, j, k)) goto outer;           }         }       }       printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using std::sort;   int n;   char s[100000 + 1];   struct SH {     unsigned int s, h;   };   struct SH cnt[100000 + 1];   unsigned long long ans;   void read() {     scanf( %d , &n);     ans = 0;     for (int i = 1; i <= n; ++i) {       scanf( %s , s);       int l = strlen(s);       unsigned int sum = 0;       for (int j = 0; j < l; ++j)         if (s[j] ==  s )           ++sum;         else           ans += sum;       cnt[i].s = sum;       cnt[i].h = l - sum;     }   }   bool compareSH(struct SH &x, struct SH &y) { return x.s * y.h > y.s * x.h; }   void chief() {     sort(&cnt[1], &cnt[n] + 1, compareSH);     unsigned int sum = 0;     for (int i = 1; i <= n; ++i) {       ans += (unsigned long long)sum * cnt[i].h;       sum += cnt[i].s;     }   }   void write() { printf( %I64u n , ans); }   int main() {     read();     chief();     write();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Data {     long long l, r;   } a[200100];   long long n, s, rmax, lmin;   void Docfile() {     scanf( %lld%lld , &n, &s);     rmax = 0;     lmin = 1e18;     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i].l, &a[i].r);       rmax = max(rmax, a[i].r);       lmin = min(lmin, a[i].l);     }   }   bool cmp(Data &a, Data &b) {     return ((a.l < b.l) || ((a.l == b.l) && (a.r < b.r)));   }   void Xuli() {     sort(a + 1, a + 1 + n, cmp);     long long sum1, sum2, dem1, dem2, dem3, F[200100];     long long d = lmin, c = rmax, g, kq = 0;     while (d <= c) {       g = (d + c) / 2;       dem1 = dem2 = dem3 = sum1 = sum2 = 0;       F[0] = 0;       for (int i = 1; i <= n; i++) {         if (a[i].r < g) {           dem1++;           sum1 += a[i].l;         } else {           if (a[i].l > g) {             dem2++;             sum2 += a[i].l;           } else {             dem3++;             F[dem3] = F[dem3 - 1] + a[i].l;           }         }       }       if (dem1 > n / 2) {         c = g - 1;         continue;       }       if (dem2 > n / 2) {         d = g + 1;         continue;       }       if (dem1 < n / 2) sum1 += F[n / 2 - dem1];       if (dem2 < n / 2) sum2 += g * (n / 2 - dem2);       if (sum1 + sum2 + g <= s) {         kq = max(kq, g);         d = g + 1;       } else         c = g - 1;     }     printf( %lld n , kq);   }   int main() {     long t;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       Docfile();       Xuli();     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   int size(T& a) {     return (int)a.size();   }   template <typename T>   T sqr(T a) {     return a * a;   }   #pragma comment(linker,  /STACK:60777216 )   const int INF = int(1e9);   char s[10][10];   bool can(int i, int j) { return i >= 0 && i < 8 && j >= 0 && j < 8; }   bool statue(int i, int j, int t) {     for (int u = 0; u < 8; ++u) {       if (s[u][j] ==  S ) {         int dif = (i - u);         if (t == dif) {           return false;         }       }     }     return true;   }   struct pos {     int i, j, t;     pos() {}     pos(int i, int j, int t) : i(i), j(j), t(t) {}   };   int dist[8][8][200];   int dj[9] = {+1, +1, 0, -1, -1, -1, 0, 1, 0};   int di[9] = {0, +1, +1, +1, 0, -1, -1, -1, 0};   int main() {     queue<pos> q;     for (int i = (0); i < (8); ++i) gets(s[i]);     memset((dist), (255), sizeof(dist));     for (int i = (0); i < (8); ++i)       for (int j = (0); j < (8); ++j)         if (s[i][j] ==  M ) {           q.push(pos(i, j, 0));           dist[i][j][0] = 0;         }     while (size(q)) {       pos p = q.front();       q.pop();       if (s[p.i][p.j] ==  A ) {         cout <<  WIN ;         exit(0);       }       for (int u = (0); u < (9); ++u) {         int ni = p.i + di[u];         int nj = p.j + dj[u];         if (can(ni, nj) && statue(ni, nj, p.t) && statue(ni, nj, p.t + 1) &&             dist[ni][nj][p.t + 1] == -1) {           dist[ni][nj][p.t + 1] = 1;           q.push(pos(ni, nj, p.t + 1));         }       }     }     for (int i = (0); i < (8); ++i)       for (int j = (0); j < (8); ++j)         if (s[i][j] ==  A ) {           for (int t = (0); t < (200); ++t)             if (dist[i][j][t] != -1) {               cout <<  WIN ;               exit(0);             }         }     cout <<  LOSE ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int dot = -1;     for (int i = 0; i < (int)(s).size(); ++i) {       if (s[i] ==  . ) {         dot = i;       }     }     int deg = 0;     if (dot == -1) {       deg = (int)(s).size();       string t =  0.  + s;       s = t;     } else {       deg = dot;       string t =  0. ;       for (int i = 0; i < (int)(s).size(); ++i) {         if (s[i] !=  . ) {           t += s[i];         }       }       s = t;     }     int lst = (int)(s).size() - 1;     while (s[lst] ==  0 ) {       --lst;     }     s = s.substr(0, lst + 1);     if (s ==  0. ) {       cout <<  0 n ;       return 0;     }     int fst = 2;     while (s[fst] ==  0 ) {       ++fst;     }     s = s.substr(fst);     deg -= fst - 1;     cout << s[0];     if ((int)(s).size() > 1) {       cout <<  . ;       for (int i = 1; i < (int)(s).size(); ++i) {         cout << s[i];       }     }     if (deg) {       cout <<  E  << deg;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   namespace node_tre {   int tre[100005] = {};   void update(int x, int val) { tre[x] += val; }   int ask(int x) { return tre[x]; }   void cover(int x) { tre[x] = 0; }   };  // namespace node_tre   using namespace node_tre;   struct node {     int ty;     int id;     int tim;     int val;     int w;   } a[100005], b[100005];   int n;   int ans[100005];   int cnt;   map<int, int> has;   void cdq(int l, int r) {     if (r == l) return;     int mid = (l + r) >> 1;     cdq(l, mid);     cdq(mid + 1, r);     int indl = l, indr = mid + 1, indb = l;     while (indl <= mid && indr <= r) {       if (a[indl].tim <= a[indr].tim) {         if (a[indl].ty == 1) update(a[indl].val, a[indl].w);         b[indb++] = a[indl++];       } else {         if (a[indr].ty == 2) ans[a[indr].id] += ask(a[indr].val);         b[indb++] = a[indr++];       }     }     while (indl <= mid) b[indb++] = a[indl++];     while (indr <= r) {       if (a[indr].ty == 2) ans[a[indr].id] += ask(a[indr].val);       b[indb++] = a[indr++];     }     for (int i = l; i <= r; i++) {       a[i] = b[i];       cover(a[i].val);     }   }   int main() {     memset(ans, -1, sizeof(ans));     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].ty >> a[i].tim >> a[i].val;       a[i].id = i;       if (a[i].ty == 1) {         a[i].w = 1;         continue;       }       if (a[i].ty == 2) {         a[i].ty = 1;         a[i].w = -1;         continue;       }       if (a[i].ty == 3) {         ans[i] = 0;         a[i].ty = 2;         continue;       }     }     for (int i = 1; i <= n; i++) {       if (has[a[i].val] == 0) has[a[i].val] = ++cnt;       a[i].val = has[a[i].val];     }     cdq(1, n);     for (int i = 1; i <= n; i++)       if (ans[i] != -1) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int m, n, i, j, c;     int coordenadas[3][2];     scanf( %d%d , &n, &m);     char ciudad[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         scanf(  n%c , &ciudad[i][j]);       }     }     c = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (ciudad[i][j] ==  * ) {           coordenadas[c][0] = i;           coordenadas[c][1] = j;           c++;         }       }     }     if (coordenadas[0][0] != coordenadas[1][0] &&         coordenadas[0][0] != coordenadas[2][0])       printf( %d , coordenadas[0][0] + 1);     else if (coordenadas[1][0] != coordenadas[0][0] &&              coordenadas[1][0] != coordenadas[2][0])       printf( %d , coordenadas[1][0] + 1);     else       printf( %d , coordenadas[2][0] + 1);     printf(   );     if (coordenadas[0][1] != coordenadas[1][1] &&         coordenadas[0][1] != coordenadas[2][1])       printf( %d , coordenadas[0][1] + 1);     else if (coordenadas[1][1] != coordenadas[0][1] &&              coordenadas[1][1] != coordenadas[2][1])       printf( %d , coordenadas[1][1] + 1);     else       printf( %d , coordenadas[2][1] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     long long x = -1;     for (long long i = 97; i <= 122; ++i) {       char c = char(i);       long long cnt = 0;       for (long long i = 0; i < n; ++i) {         if (s[i] == c) {           long long c1 = 0;           while (s[i] == c && c1 < k && i < n) {             i++;             c1++;           }           if (c1 == k) {             cnt++;             i--;           }         }       }       x = max(x, cnt);     }     cout << x <<   n ;     return 0;   }
#include <bits/stdc++.h>   struct vertex {     long long x, y;     int adj[4], k;   } vv[30];   void dfs(int p, int v, long long x, long long y, long long a, int d) {     int i;     vv[v].x = x;     vv[v].y = y;     d = (d + 2) % 4;     for (i = 0; i < vv[v].k; i++)       if (vv[v].adj[i] != p) {         long long x_ = x, y_ = y;         d = (d + 1) % 4;         if (d == 0)           x_ += a;         else if (d == 1)           y_ += a;         else if (d == 2)           x_ -= a;         else           y_ -= a;         dfs(v, vv[v].adj[i], x_, y_, a / 2, d);       }   }   int main() {     int n, i, yes;     scanf( %d , &n);     yes = 1;     for (i = 0; i < n; i++) vv[i].k = 0;     for (i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       if (vv[u].k == 4 || vv[v].k == 4) {         yes = 0;         break;       }       vv[u].adj[vv[u].k++] = v;       vv[v].adj[vv[v].k++] = u;     }     printf( %s n , yes ?  YES  :  NO );     if (yes) {       dfs(-1, 0, 0, 0, 1LL << n, 0);       for (i = 0; i < n; i++) printf( %lld %lld n , vv[i].x, vv[i].y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 300000 + 10;   int n, m, s;   struct edge {     bool t;     int u, v;   } es[maxn];   bool vis[maxn];   vector<int> G[maxn];   char ans[maxn];   int cnt;   void dfsmax(int u) {     vis[u] = true;     cnt++;     for (int i = 0; i < G[u].size(); i++) {       edge& e = es[G[u][i]];       if (e.t) {         if (e.u == u) {           if (!vis[e.v]) {             ans[G[u][i]] =  + ;             dfsmax(e.v);           }         } else {           if (!vis[e.u]) {             ans[G[u][i]] =  - ;             dfsmax(e.u);           }         }       } else {         if (!vis[e.v]) {           dfsmax(e.v);         }       }     }   }   void dfsmin(int u) {     vis[u] = true;     cnt++;     for (int i = 0; i < G[u].size(); i++) {       edge& e = es[G[u][i]];       if (e.t) {         if (e.u == u) {           ans[G[u][i]] =  - ;         } else {           ans[G[u][i]] =  + ;         }       } else if (!vis[e.v]) {         dfsmin(e.v);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &s);     int tmp;     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &tmp, &es[i].u, &es[i].v);       G[es[i].u].push_back(i);       es[i].t = (tmp == 2);       if (tmp == 2) G[es[i].v].push_back(i), ans[i] =  + ;     }     cnt = 0;     dfsmax(s);     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (es[i].t) printf( %c , ans[i]);     }     printf(  n );     cnt = 0;     memset(vis, 0, sizeof(vis));     dfsmin(s);     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (es[i].t) printf( %c , ans[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int c[maxn], up[maxn], h[maxn];   bool visited[maxn];   set<int> s[maxn];   vector<int> g[maxn];   void dfs(int v, int par = -1) {     c[v] = v;     visited[v] = 1;     up[v] = h[v];     int cnt = 0;     for (auto u : g[v]) {       if (u == par)         cnt++;       else if (!visited[u]) {         h[u] = h[v] + 1;         dfs(u, v);         up[v] = min(up[v], up[u]);         if (s[c[u]].size() > s[c[v]].size()) c[v] = c[u];       } else         up[v] = min(up[v], h[u]);     }     if (cnt > 1) up[v] = min(up[v], h[v] - 1);     for (auto u : g[v]) {       if (h[u] == h[v] + 1 and c[u] != c[v]) {         for (auto it : s[c[u]]) {           if (s[c[v]].find(-it) != s[c[v]].end())             s[c[v]].erase(-it);           else             s[c[v]].insert(it);         }         s[c[u]].clear();       }     }     if (c[v] != v) {       for (auto it : s[v]) {         if (s[c[v]].find(-it) != s[c[v]].end())           s[c[v]].erase(-it);         else           s[c[v]].insert(it);       }       s[v].clear();     }     if (up[v] < h[v]) return;     if (s[c[v]].empty()) return;     int minimum = *s[c[v]].begin();     auto it = s[c[v]].end();     it--;     int maximum = *it;     if (minimum < 0 and maximum > 0) {       cout <<  No  << endl;       exit(0);     }   }   int par[maxn];   int get_par(int v) {     if (par[v] < 0) return v;     return par[v] = get_par(par[v]);   }   void merge(int v, int u) {     v = get_par(v), u = get_par(u);     if (v == u) return;     par[v] = u;   }   int main() {     ios_base::sync_with_stdio(false);     memset(par, -1, sizeof par);     int n, m, q;     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int v, u;       cin >> v >> u;       g[v].push_back(u);       g[u].push_back(v);       merge(v, u);     }     string answer =  Yes ;     for (int i = 0; i < q; i++) {       int v, u;       cin >> v >> u;       if (get_par(v) != get_par(u)) answer =  No ;       s[v].insert(i + 1);       s[u].insert(-i - 1);     }     if (answer ==  No ) return cout << answer << endl, 0;     for (int v = 1; v <= n; v++)       if (!visited[v]) dfs(v);     cout <<  Yes  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, tt[1005];   vector<int> a[1005];   void dfs(int u) {     if (tt[u] == 1) {       printf( %d  , u);       return;     }     tt[u] = 1;     for (int i = 0; i < a[u].size(); ++i) dfs(a[u][i]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       a[i].push_back(x);     }     for (int i = 1; i <= n; ++i) {       dfs(i);       for (int j = 1; j <= n; ++j) tt[j] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000005];   long long c[2000015];   long long n;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     long long ma = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       c[a[i]]++;       ma = max(ma, a[i]);     }     long long ans = 0;     for (int i = 0; i < 2000010; i++) {       if (c[i] % 2 == 1) {         c[i + 1] += c[i] / 2;         c[i] = 1;       } else {         c[i + 1] += c[i] / 2;         c[i] = 0;       }     }     for (int i = 0; i < 2000010; i++) {       ans += c[i];     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ct[300005];   vector<pair<int, int> > val;   int n, m;   bool check(int vl) {     for (int i = 0; i < 300005; i++) ct[i] = 0;     int count = 0;     for (int i = 0; i < m; i++) {       if (vl != val[i].first && vl != val[i].second) {         count++;         ct[val[i].first]++;         if (val[i].second != val[i].first) {           ct[val[i].second]++;         }       }     }     if (count == 0) return true;     for (int i = 1; i < 300001; i++) {       if (ct[i] == count) {         return true;       }     }     return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       val.push_back(make_pair(a, b));     }     int first = val[0].first;     int second = val[0].second;     if (check(first)) {       cout <<  YES n ;     } else if (check(second)) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }   }