malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 4e5 + 1;   int a[MAXN], b[MAXN];   const int MOD = 1e9 + 7;   int bit[MAXN];   void add(int pos, int val) {     while (pos < MAXN) {       (bit[pos] += val) %= MOD;       pos += pos & -pos;     }   }   int query(int pos) {     int val = 0;     while (pos) {       val += bit[pos];       val %= MOD;       pos -= pos & -pos;     }     return val;   }   map<pair<int, int>, int> bad;   int mn[MAXN * 2];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a[i], &b[i]);     }     int mx = 0;     int t;     scanf( %d , &t);     int y = 0;     memset(mn, -63, sizeof(mn));     for (int Z = 1; Z <= t; ++Z) {       int i;       scanf( %d , &i);       mn[b[i]] = a[i];       bad[make_pair(a[i], b[i])] = 1;       mx = max(mx, b[i]);       if (b[i] == mx) y = a[i];     }     for (int i = n + n; i >= 1; --i) mn[i] = max(mn[i], mn[i + 1]);     vector<pair<int, int> > r;     for (int i = 1; i <= n; ++i) {       if (b[i] <= mx) {         r.push_back(make_pair(a[i], b[i]));       }     }     sort(r.begin(), r.end());     int ans = 0;     int cnt = 0;     int tot = 0;     for (auto it : r) {       int val = 1;       val += tot;       val %= MOD;       val -= query(it.second);       val += MOD;       val %= MOD;       if (mn[it.second] < it.first && !bad[it]) (val += MOD - 1) %= MOD;       (tot += val) %= MOD;       (ans += val) %= MOD;       ans %= MOD;       add(it.second, val);       cnt++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> houses, shops;   int lasthouse = -1, lastshop = -1;   bool check(int k, int t, string s) {     int l = s.length(), min_index = -1, ans = 0, ct = 0;     int ans2 = t + 1;     if (lasthouse > lastshop) {       if (lastshop == -1) {         if (k < houses[lasthouse])           return false;         else {           if (lasthouse > t)             return false;           else {             return true;           }         }       } else {         if (k + shops[lastshop] >= houses[lasthouse]) {           ans2 = lasthouse + lasthouse - 1;         }       }     } else {       for (int i = lasthouse; i <= lastshop; i++) {         if (shops[i] + k >= houses[lasthouse]) {           ans2 = i + i - 1;           break;         }       }     }     for (int i = 0; i < l; i++) {       if (s[i] ==  H ) {         if (k > 0) {           k--;           ct = i + 1;         } else {           if (min_index == -1) min_index = i;         }       } else if (s[i] ==  S ) {         k++;         if (min_index != -1 && k >= houses[i + 1] - houses[min_index]) {           k -= (houses[i + 1] - houses[min_index]);           if (houses[l] - houses[i])             ans += 2 * (i - min_index);           else             ans += (i - min_index);           min_index = -1;           ct = i + 1;         }       }     }     ans += ct;     if ((min(ans, ans2) > t || min_index != -1)) return false;     return true;   }   int bin_search(int start, int end, string s, int t) {     if (start == end)       if (check(start, t, s))         return start;       else         return -1;     if (start > end) return -1;     int mid = (start + end) / 2;     if (check(mid, t, s)) {       return bin_search(start, mid, s, t);     } else {       return bin_search(mid + 1, end, s, t);     }   }   int main() {     int n, t;     cin >> n >> t;     string s;     cin >> s;     int l = s.length();     houses = vector<int>(l + 1, 0);     shops = vector<int>(l + 1, 0);     for (int i = 1; i <= l; i++) {       if (s[i - 1] ==  H ) {         houses[i] = 1;         lasthouse = i;       }       if (s[i - 1] ==  S ) {         shops[i] = 1;         lastshop = i;       }     }     for (int i = 1; i <= l; i++) {       houses[i] += houses[i - 1];       shops[i] += shops[i - 1];     }     cout << bin_search(0, l, s, t) <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[101];   void read(int &x) {     char ch;     x = 0;     while (!isdigit(ch = getchar()))       ;     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }   }   void init() {     read(n), read(m);     for (int i = 1; i <= n; ++i) read(a[i]);   }   void work() {     int ans = 1, now = 0;     for (int i = 1; i <= n; ++i) {       now += a[i];       if (now > m) {         ans++;         now = a[i];       }     }     printf( %d n , ans);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double x, y, z, s;   int n, a, b, c, v[300010], p[300010], l[300010], r[300010];   bool cmp(int x, int y) { return v[x] < v[y]; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &v[i]), l[i] = i - 1, r[i] = i + 1, p[i] = i;     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n; i++) {       x = y = 0, z = 1;       a = b = c = p[i];       for (int j = 1; j <= 45; j++) {         if (a) x += (a - l[a]) * z, a = l[a];         if (b <= n) y += (r[b] - b) * z, b = r[b];         z /= 2;       }       l[r[c]] = l[c], r[l[c]] = r[c];       s += x * y * v[c] / 2;     }     printf( %.6f n , s / n / n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, count = 1, ans = 0, a, b, freq[N] = {0}, pf, v;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a;         v = 0;         for (int j = 0; j < a; j++) {           cin >> b;           if (j < count && !v) {             if (!freq[b]) {               v = 1;               freq[b]++;             }           }         }         if (!v) {           pf = i + 1;         }         count++;       }       v = 0;       for (int i = 1; i <= n; i++) {         if (!freq[i]) {           v = i;           break;         }       }       if (v) {         cout <<  IMPROVE n  << pf <<     << v <<   n ;       } else {         cout <<  OPTIMAL n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[200005][2];   long long a[200005], b[200005];   void solve() {     long long n, c;     cin >> n >> c;     for (int i = 0; i < n - 1; i++) cin >> a[i];     ;     for (int i = 0; i < n - 1; i++) cin >> b[i];     ;     dp[1][1] = c;     for (int i = 2; i < n + 1; i++) {       dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + a[i - 2];       dp[i][1] = min(dp[i - 1][0] + c + b[i - 2], dp[i - 1][1] + b[i - 2]);     }     for (int i = 1; i < n + 1; i++) cout << min(dp[i][0], dp[i][1]) <<    ;     cout <<   n ;   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       if (n == 1)         cout << 8 << endl;       else if (!n)         cout << 1 << endl;       else if (n % 4 == 0)         cout << 6 << endl;       else if (n % 4 == 1)         cout << 8 << endl;       else if (n % 4 == 2)         cout << 4 << endl;       else if (n % 4 == 3)         cout << 2 << endl;     }   }
#include <bits/stdc++.h>   const int maxn = 100100;   int t, T, n, m, n0, n1;   int l[maxn], r[maxn], c[maxn], vis[maxn];   std::vector<int> v[maxn];   std::queue<int> q;   inline void dfs(int x) {     if (vis[x]) return;     vis[x] = 1;     for (auto i : v[x]) c[i] = !c[x], dfs(i);   }   int main() {     std::ios::sync_with_stdio(false), std::cin.tie(0);     std::cin >> t >> T >> n >> m;     n1 = 0;     n0 = T;     for (int i = 1; i <= n; ++i) {       std::cin >> l[i] >> r[i], c[i] = -1;       n0 = std::min(n0, r[i]);       n1 = std::max(n1, l[i]);     }     if (n1 + n0 > T) n0 = T - n1;     if (n1 + n0 < t) n1 = t - n0;     if (n0 < 0 || n1 < 0) {       puts( IMPOSSIBLE );       return 0;     }     for (int i = 1, x, y; i <= m; ++i) {       std::cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; ++i) {       if (n1 < l[i] || r[i] < n1) {         if (c[i] != -1 && c[i] != 0) {           puts( IMPOSSIBLE );           return 0;         }         c[i] = 0;       }       if (n0 < l[i] || r[i] < n0) {         if (c[i] != -1 && c[i] != 1) {           puts( IMPOSSIBLE );           return 0;         }         c[i] = 1;       }       if (c[i] >= 0) dfs(i);     }     for (int i = 1; i <= n; ++i)       if (c[i] == -1) c[i] = 0, dfs(i);     for (int i = 1; i <= n; ++i)       for (int j : v[i])         if (c[i] + c[j] != 1) {           puts( IMPOSSIBLE );           return 0;         }     std::cout <<  POSSIBLE  <<   n  << n0 <<     << n1 <<   n ;     for (int i = 1; i <= n; ++i) std::cout << c[i] + 1;   }
#include <bits/stdc++.h>   using namespace std;   int ans = 0;   vector<vector<int> > data;   void relax(int &a, int &b, int c) {     if (c > a) {       b = a;       a = c;     } else       b = max(b, c);   }   pair<int, int> dfs(int vertex, int last) {     int take = 0, take2 = 0, non = 0, non2 = 0;     for (int i = 0; i < data[vertex].size(); ++i) {       int to = data[vertex][i];       if (to == last) continue;       pair<int, int> res = dfs(to, vertex);       relax(take, take2, res.second);       relax(non, non2, max(res.second, res.first));     }     ans = max(ans, take2 + take + 1);     ans = max(ans, non2 + non + max(0, (int)data[vertex].size() - 2));     ans = max(ans, non + max(0, (int)data[vertex].size() - 1));     non += data[vertex].size() - 2;     return {take + 1, non};   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     data.assign(n, {});     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       data[u - 1].push_back(v - 1);       data[v - 1].push_back(u - 1);     }     dfs(0, -1);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a <<   n ;     err(++it, args...);   }   const int M = 1e9 + 7, N = 2e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[n][m], b[n][m];       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) cin >> a[i][j];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int c = 0;           if (i - 1 >= 0) c++;           if (i + 1 <= n - 1) c++;           if (j - 1 >= 0) c++;           if (j + 1 <= m - 1) c++;           b[i][j] = c;         }       }       bool red = false;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] > b[i][j]) {             red = true;             break;           }         }         if (red) break;       }       if (red)         cout <<  NO               <<   n ;       else {         cout <<  YES               <<   n ;         for (int i = 0; i < n; i++)           for (int j = 0; j < m; j++) cout << b[i][j] <<    n [j == m - 1];         ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1e9) + 7;   bool mark[2501][101];   long long a[2501][101];   long long dp(int x, int y) {     if (x > 0 && y == 0) return 0;     if (x == 0 && y == 0) return 1;     if (mark[x][y]) return a[x][y];     long long ans = 0;     for (int i = 0; i <= min(25, x); i++) ans += dp(x - i, y - 1);     a[x][y] = (ans % maxn);     mark[x][y] = 1;     return a[x][y];   }   int main() {     int t, counter;     string s;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> s;       counter = 0;       for (int j = 0; j < s.size(); j++) counter += int(s[j] -  a );       cout << (dp(counter, s.size()) + maxn - 1) % maxn << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   long long deg[123456];   long long N, S, i, s, e;   long long cnt;   long double ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N >> S;     for (i = 1; i < N; i++) {       cin >> s >> e;       deg[s - 1]++;       deg[e - 1]++;     }     for (i = 0; i < N; i++)       if (deg[i] == 1) cnt++;     ans = (long double)S * (long double)2 / (long double)cnt;     cout << fixed << setprecision(20) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   int read(T& x) {     int c = getchar(), f = (x = 0);     while (~c && (c < 48 || c > 57)) {       if (c ==  - ) {         f = 1;       }       c = getchar();     }     if (!~c) {       return 0;     }     while (c > 47 && c < 58) {       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     }     if (f) {       x = -x;     }     return 1;   }   template <class T, class U>   inline int read(T& a, U& b) {     return read(a) && read(b);   }   template <class T, class U, class V>   inline int read(T& a, U& b, V& c) {     return read(a) && read(b) && read(c);   }   inline int read(double& _, double& __) { return scanf( %lf%lf , &_, &__); }   inline int read(char* _) { return scanf( %s , _); }   inline int read(double& _) { return scanf( %lf , &_); }   inline void println(long long _) { printf( %lld n , _); }   inline void println(int _) { printf( %d n , _); }   inline void println(long long _, long long __) { printf( %lld %lld n , _, __); }   inline void println(int _, int __) { printf( %d %d n , _, __); }   inline void println(double& __, int _) { printf( %.*lf n , _, __); }   template <class T>   inline void cmax(T& _, T __) {     if (_ < __) _ = __;   }   template <class T>   inline void cmin(T& _, T __) {     if (_ > __) _ = __;   }   const int maxn = 5e3 + 10, INF = 0x3f3f3f3f;   const long long LINF = (long long)INF << 32 | INF;   int link[maxn], ans[maxn];   bool vis[maxn];   vector<int> G[maxn];   int p[maxn], c[maxn], d[maxn], D;   bool leave[maxn];   bool DFS(int u) {     for (auto v : G[u])       if (!vis[v]) {         vis[v] = true;         if (link[v] == -1 || DFS(link[v])) {           link[v] = u;           return true;         }       }     return false;   }   int main() {     int n, m, cur = 0;     memset(link, -1, sizeof(link));     read(n, m);     for (int i = 1; i <= (n); i++) read(p[i]);     for (int i = 1; i <= (n); i++) read(c[i]);     read(D);     for (int i = 1; i <= (D); i++) read(d[i]), leave[d[i]] = true;     for (int i = 1; i <= (n); i++)       if (!leave[i]) G[p[i]].push_back(c[i]);     for (int i = D; i >= (1); i--) {       memset(vis, false, sizeof(vis));       while (DFS(cur)) memset(vis, false, sizeof(vis)), cur++;       ans[i] = cur;       G[p[d[i]]].push_back(c[d[i]]);     }     for (int i = 1; i <= (D); i++) println(ans[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     using namespace std;     ios_base::sync_with_stdio(false), cin.tie(nullptr);     int tt;     cin >> tt;     while (tt--) {       int N;       cin >> N;       string s;       cin >> s;       auto solve = [&](void) -> void {         for (int i = 0; i < N - 10; ++i) {           if (s[i] ==  8 ) {             cout <<  YES n ;             return;           }         }         cout <<  NO n ;       };       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long int calculate(long long int p, long long int q) {     long long int modx = 998244353, expo;     expo = modx - 2;     while (expo) {       {         if (expo & 1) p = (p * q) % modx;       }       q = (q * q) % modx;       expo >>= 1;     }     return p % modx;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) {         res = (res * x) % p;       }       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       long long int n, k;       cin >> n >> k;       string s;       long long int ans = 1;       cin >> s;       if (k == 0) {         cout << 1 <<   n ;         continue;       }       long long int i = 0, j = 0;       long long int dp[n + 5][k + 5];       memset(dp, 0, sizeof(dp));       for (int p = 1; p <= k; p++) {         dp[0][p] = dp[0][p - 1] + 1;       }       for (int p = 1; p <= n; p++) {         for (int q = 1; q <= k; q++)           dp[p][q] = (dp[p - 1][q] + dp[p][q - 1]) % 998244353;       }       long long int zero = 0, lastzero = 0, one = 0, b = 0;       while (i < n) {         if (s[i] ==  0 ) {           zero++;           if (one == k) lastzero++;         } else           one++;         if (one > k) {           for (int p = 0; p < zero; p++) {             ans = (ans + dp[p][k]) % 998244353;           }           long long int temp = 0;           if (b > 0) {             for (int p = 0; p < zero - lastzero; p++) {               temp = (temp + dp[p][k - 1]) % 998244353;             }           }           lastzero = 0;           b = 1;           ans = (998244353 + ans - temp) % 998244353;           while (j < i) {             if (s[j] ==  1 ) {               one--;               j++;               break;             }             j++;             zero--;           }         }         i++;       }       if (one == k) {         for (int p = 0; p < zero; p++) {           ans = (ans + dp[p][k]) % 998244353;         }         long long int temp = 0;         if (b > 0) {           for (int p = 0; p < zero - lastzero; p++) {             temp = (temp + dp[p][k - 1]) % 998244353;           }         }         ans = (998244353 + ans - temp) % 998244353;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dpr[107];   int dps[107];   int dpc[107];   int a[107];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n + 1; i++) scanf( %d , a + i);     dpr[1] = 1;     dps[1] = (a[1] == 2 || a[1] == 3) ? 0 : -1;     dpc[1] = (a[1] == 1 || a[1] == 3) ? 0 : -1;     for (int i = 2; i < n + 1; i++) {       dpr[i] = dpr[i - 1];       if (dps[i - 1] != -1) dpr[i] = min(dpr[i], dps[i - 1]);       if (dpc[i - 1] != -1) dpr[i] = min(dpr[i], dpc[i - 1]);       dpr[i] += 1;       if (a[i] != 2 && a[i] != 3)         dps[i] = -1;       else {         dps[i] = dpr[i - 1];         if (dpc[i - 1] != -1) dps[i] = min(dps[i], dpc[i - 1]);       }       if (a[i] != 1 && a[i] != 3)         dpc[i] = -1;       else {         dpc[i] = dpr[i - 1];         if (dps[i - 1] != -1) dpc[i] = min(dpc[i], dps[i - 1]);       }     }     int ans = 200;     ans = min(ans, dpr[n]);     if (dps[n] != -1) ans = min(ans, dps[n]);     if (dpc[n] != -1) ans = min(ans, dpc[n]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adjl[4009];   set<pair<int, int> > st;   int main() {     int n, m, a, b;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       adjl[a].push_back(b);       adjl[b].push_back(a);       st.insert(pair<int, int>(a, b));       st.insert(pair<int, int>(b, a));     }     int ans = 9999999;     for (int i = 1; i <= n; i++) {       if (adjl[i].size() >= 2) {         for (int j = 0; j < adjl[i].size(); j++) {           for (int k = j + 1; k < adjl[i].size(); k++) {             if (st.find(pair<int, int>(adjl[i][j], adjl[i][k])) != st.end()) {               if (ans > adjl[i].size() + adjl[adjl[i][j]].size() +                             adjl[adjl[i][k]].size() - 6)                 ans = adjl[i].size() + adjl[adjl[i][j]].size() +                       adjl[adjl[i][k]].size() - 6;             }           }         }       }     }     if (ans == 9999999)       cout << -1 << endl;     else       cout << ans << endl;   }
#include <bits/stdc++.h>   const int Maxn = 50005;   int N, A[Maxn];   double L[Maxn], P[Maxn], Sum[Maxn], Ans;   using namespace std;   bool Cmp(const int &i, const int &j) {     return (L[i] * P[i] * (1 - P[j] / 100)) > (L[j] * P[j] * (1 - P[i] / 100));   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %lf%lf , &L[i], &P[i]);       A[i] = i;     }     sort(A + 1, A + 1 + N, Cmp);     for (int i = 1; i <= N; ++i) Sum[i] = Sum[i - 1] + L[A[i]] * P[A[i]];     for (int i = 1; i <= N; ++i) Ans += L[i] * 10000;     for (int i = 2; i <= N; ++i) Ans += (100 - P[A[i]]) * Sum[i - 1];     cout << setprecision(12) << setiosflags(ios ::fixed) << Ans / 10000 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int fact[2 * 100005];   long long int func() {     fact[0] = fact[1] = 1;     for (long long int i = 2; i < 200001; i++) {       fact[i] = (fact[i - 1] * i) % 1000000007;     }     return 0;   }   set<pair<int, int> > m;   set<int> k;   set<pair<int, int> > h;   int arr[100005], pp[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x == 1) {         k.insert(i + 1);       } else {         h.insert(make_pair(x, i + 1));       }       arr[i + 1] = x;       pp[i + 1] = x;     }     set<int>::iterator it;     set<pair<int, int> >::iterator ii, iii;     set<pair<int, int> > ans;     int cnt = 0;     int mm = 0;     ii = h.begin();     iii = h.begin();     if (h.size() == 0) {       if (k.size() > 2) {         cout <<  NO ;         return 0;       }       cout <<  YES 1 n1 n1 2 ;       return 0;     }     for (ii = h.begin(); iii != h.end();) {       pair<int, int> p1 = *ii;       iii = ++ii;       if (iii == h.end()) break;       pair<int, int> p2 = *iii;       ans.insert(make_pair(p1.second, p2.second));       arr[p1.second]--;       arr[p2.second]--;       mm++;     }     if (k.size() && h.size()) {       pair<int, int> p = *(h.begin());       int x = *(k.begin());       ans.insert(make_pair(x, p.second));       arr[x]--;       arr[p.second]--;       k.erase(x);       mm++;     }     if (k.size() && h.size()) {       pair<int, int> p = *(--h.end());       int x = *(k.begin());       ans.insert(make_pair(x, p.second));       arr[x]--;       arr[p.second]--;       k.erase(x);       mm++;     }     for (int i = 1; i <= n; i++) {       if (arr[i] && k.find(i) == k.end()) m.insert(make_pair(arr[i], i));     }     int gg = 0;     for (it = k.begin(); it != k.end(); it++) {       if (arr[*it] == 0) continue;       m.erase(make_pair(arr[*it], *it));       if (m.size() == 0) break;       pair<int, int> p = *(m.rbegin());       ans.insert(make_pair(*it, p.second));       m.erase(make_pair(arr[p.second], p.second));       arr[p.second]--;       if (arr[p.second]) m.insert(make_pair(arr[p.second], p.second));     }     int sum = 0;     for (int i = 0; i < n; i++) {       sum += pp[i + 1];     }     if (sum < 2 * n - 2) {       cout <<  NO ;       return 0;     }     cout <<  YES   << mm << endl;     cout << ans.size() << endl;     for (set<pair<int, int> >::iterator i = ans.begin(); i != ans.end(); i++) {       cout << (*i).first <<     << (*i).second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   unsigned int gcd(unsigned int x, unsigned int y) {     unsigned int temp;     if (x < y) {       temp = x;       x = y;       y = temp;     }     for (unsigned int i = y; i > 0; i--) {       if ((x % i == 0) && (y % i == 0)) return i;     }     return x;   }   int main() {     int a, b, n;     cin >> a >> b >> n;     while (1) {       n -= gcd(n, a);       if (n < 0) {         cout <<  1 ;         break;       }       n -= gcd(n, b);       if (n < 0) {         cout <<  0 ;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i;     cin >> a >> b;     int n;     for (i = 0; i < 10; i++) {       if (a < b) {         a = a * 3;         b = b * 2;       } else if (a > b) {         cout << i;         break;       } else if (a == b) {         cout << i + 1;         break;       }     }     return 0;   }