malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     long long ans = 0;     priority_queue<int, vector<int>, greater<int>> pq;     while (n--) {       int x;       cin >> x;       if (pq.size() && x > pq.top()) {         ans += x - pq.top();         pq.pop();         pq.push(x);       }       pq.push(x);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, k;     int h[1001] = {0};     scanf( %d%d , &n, &k);     int i, j;     for (i = 1; i <= n; i++) scanf( %d , &h[i]);     int min = 9999999, nn = 1;     for (i = 1; i <= n; i++) {       if (h[i] < 1 + k * (i - 1)) continue;       int ans = 0;       for (j = 1; j <= n; j++)         if (h[j] != h[i] + k * (j - i)) ans++;       if (ans < min) {         min = ans;         nn = i;       }       if (min == 0) break;     }     printf( %d n , min);     for (i = 1; i <= n; i++) {       if (h[i] > h[nn] + k * (i - nn))         printf( - %d %d n , i, h[i] - h[nn] - k * (i - nn));       else if (h[i] < h[nn] + k * (i - nn))         printf( + %d %d n , i, h[nn] + k * (i - nn) - h[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     vector<int> v(2 * n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < 2 * n; i++) {       if (i >= n) {         v[i] = a[i - n];       } else         v[i] = a[i];     }     int ans = 0, cnt = 0;     for (int i = 0; i < 2 * n; i++)       if (v[i] == 1) {         cnt++;         ans = max(ans, cnt);       } else         cnt = 0;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     int m;     scanf( %d , &m);     string s;     int val, ans = 0;     vector<int> u, p;     for (int i = 0; i < int(m); i++) {       cin >> val >> s;       if (s[0] ==  U )         u.push_back(val);       else         p.push_back(val);     }     long long sum = 0;     sort(u.begin(), u.end());     sort(p.begin(), p.end());     int i = 0;     while (i < int(u.size()) && a) {       sum += u[i];       i++;       a--;       ans++;     }     int j = 0;     while (j < int(p.size()) && b) {       sum += p[j];       j++;       b--;       ans++;     }     while (i < int(u.size()) || j < int(p.size())) {       if (!c) break;       c--;       ans++;       if (i == int(u.size()))         sum += p[j++];       else if (j == int(p.size()))         sum += u[i++];       else {         if (u[i] < p[j])           sum += u[i++];         else           sum += p[j++];       }     }     cout << ans <<     << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5, maxm = 1e5 + 5;   int first[maxn], n, k;   struct edge {     int to;     int next;   } E[maxm];   int vis[maxn];   int order[maxn], p;   int a[maxn];   bool dfs(int u) {     vis[u] = -1;     for (int e = first[u]; e != -1; e = E[e].next) {       int v = E[e].to;       if (vis[v] == -1)         return false;       else if (!vis[v] && !dfs(v))         return false;     }     vis[u] = 1;     order[p++] = u;     return true;   }   bool topo() {     p = 0;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < k; i++)       if (!vis[a[i]] && !dfs(a[i])) return false;     return true;   }   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       memset(first, -1, sizeof(first));       for (int i = 0; i < k; i++) scanf( %d , &a[i]);       int t, x, ecnt = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &t);         for (int j = 0; j < t; j++) {           scanf( %d , &x);           E[ecnt].to = x;           E[ecnt].next = first[i];           first[i] = ecnt++;         }       }       if (!topo())         cout <<  -1 n ;       else {         cout << p <<   n ;         for (int i = 0; i < p; i++) cout << order[i] <<    n [i == p - 1];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, cnt, f[400005];   int fnd(int x) { return f[x] == 0 ? x : f[x] = fnd(f[x]); }   int main() {     scanf( %d%d%d , &n, &m, &q);     cnt = n + m - 1;     for (int i = 1, x, y; i <= q; i++) {       scanf( %d%d , &x, &y);       y += n;       x = fnd(x);       y = fnd(y);       if (x != y) {         cnt--;         f[x] = y;       }     }     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 998244353;   struct node {     int dif;     long long need;     bool operator<(const node &f) const {       if (f.need != need)         return f.need > need;       else         return f.dif > dif;     }   } pro[M];   long long ans[M];   int main() {     int t;     scanf( %d , &t);     while (t--) {       memset(ans, 0, sizeof(ans));       long long n, t, a, b;       scanf( %lld%lld%lld%lld , &n, &t, &a, &b);       long long simple = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &pro[i].dif);         if (!pro[i].dif) simple++;       }       for (int i = 1; i <= n; i++) scanf( %lld , &pro[i].need);       sort(pro + 1, pro + n + 1);       long long time = 0;       if (pro[1].need) ans[0] = min(simple, (pro[1].need - 1) / a);       for (int i = 1; i <= n; i++) {         if (pro[i].dif)           time += b;         else           simple--, time += a;         if (simple == 0 || i == n) break;         ans[i] = min(simple, (pro[i + 1].need - time - 1) / a);       }       time = 0;       long long cnt = ans[0];       for (int i = 1; i <= n; i++) {         time += pro[i].dif == 0 ? a : b;         if (time > t)           break;         else {           if (time < pro[i + 1].need || i == n) {             cnt = max(cnt, i + ans[i]);           }         }       }       printf( %lld n , cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     map<int, bool> mp;     for (int i = 0; i < m; i++) {       int x;       cin >> x;       mp[x] = 1;     }     int pos = 1;     int ans = -1;     if (mp[pos]) {       cout << 1;       return 0;     }     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       if (pos == x or pos == y) {         if (pos != x)           pos = x;         else           pos = y;         if (mp[pos]) {           cout << pos;           return 0;         }       }     }     cout << pos;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010, maxm = maxn * 2;   int h[maxn], ne[maxm], e[maxm], cnt;   int d[maxn], dp[maxn][3], w[maxn], root;   int a[maxn];   int vis[maxn];   void solve() {     int T;     scanf( %d , &T);     while (T--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       for (int i = 1; i < n; i += 2) {         cout << -a[i + 1] <<     << a[i] <<    ;       }       cout << endl;     }     return;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFLL = 1e18;   const int MOD = 1e9 + 7;   const int MAXN = 2e5 + 5;   vector<int> G[MAXN];   int n;   long long s[MAXN];   long long a[MAXN];   void dfs(int v, int p) {     if (s[v] == -1) {       long long aux = INF;       for (auto u : G[v])         if (u != p) {           aux = min(aux, s[u]);         }       if (aux == -1 || aux - s[p] < 0) {         a[v] = -1;         return;       }       if (aux == INF) {         a[v] = 0;         return;       }       a[v] = aux - s[p];       s[v] = a[v] + s[p];     } else {       if (p == v)         a[v] = s[v];       else         a[v] = s[v] - s[p];     }     for (auto u : G[v])       if (u != p) dfs(u, v);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x;       scanf( %d , &x);       x--;       G[x].push_back(i);       G[i].push_back(x);     }     for (int i = 0; i < n; i++) scanf( %lld , &s[i]);     dfs(0, 0);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (a[i] < 0) {         printf( -1 n );         return 0;       }       ans += a[i];     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-6;   const int INF = 0x3fffffff;   const long long LINF = INF * 1ll * INF;   const double PI = acos(-1.0);   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long d[400005];   long long a, b, k, lcm;   long long bfs(long long a, long long target) {     queue<int> q;     memset(d, -1, sizeof(d));     q.push(a);     d[a] = 0;     while (!q.empty()) {       int st = q.front();       q.pop();       for (int i = 2; i <= k; i++) {         if (st % i == 0) continue;         int tmp = st - st % i;         if (tmp < 0) tmp += lcm;         if (d[tmp] <= 0) {           d[tmp] = d[st] + 1;           q.push(tmp);         }       }       int tmp = st - 1;       if (tmp < 0) tmp += lcm;       if (d[tmp] <= 0) {         d[tmp] = d[st] + 1;         q.push(tmp);       }     }     return d[target];   }   int main(void) {     cin >> a >> b >> k;     lcm = 1;     for (int i = 2; i <= k; i++) lcm = lcm / gcd(lcm, i) * i;     long long ans = 0;     if (a / lcm == b / lcm) {       if (a % lcm != b % lcm) ans = bfs(a % lcm, b % lcm);     } else {       if (a % lcm) ans += bfs(a % lcm, 0);       if (b % lcm) ans += bfs(0, b % lcm);       ans += (a / lcm - b / lcm - 1) * bfs(0, 0);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     t = 1;     while (t--) {       int n, k, mx = 0, mn = 101, j;       cin >> n >> k;       int a[n];       for (int i = 0; i < n; i += 1) {         cin >> a[i];         mx = max(mx, a[i]);         mn = min(mn, a[i]);       }       if (mx - mn > k)         cout <<  NO ;       else {         cout <<  YES  <<   n ;         for (int i = 0; i < n; i += 1) {           for (j = 0; j < a[i] - 1; j++) {             cout << (j % k) + 1 <<    ;           }           cout << (j % k) + 1 <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string a[100];   int m[100][26];   bool s1[100];   string makestr(string s1, string s2) {     char w =  * ;     string make =   ;     int s[26];     for (int i = 0; i < 26; ++i) s[i] = 0;     for (int i = 0; i < s1.length(); ++i) s[int(s1[i]) - 97] = 1;     for (int i = 0; i < s2.length(); ++i) {       if (s[int(s2[i]) - 97] == 1) {         w = s2[i];         break;       }     }     if (w ==  * )       return s1 + s2;     else {       int pref1 = 0;       int pref2 = 0;       while (s1[pref1] != w) ++pref1;       while (s2[pref2] != w) ++pref2;       if (pref1 < pref2) {         swap(s1, s2);         swap(pref1, pref2);       }       for (int i = 0; i < s1.length(); ++i) {         make += s1[i];       }       if (s2.length() - pref2 > s1.length() - pref1) {         for (int i = pref2 + s1.length() - pref1; i < s2.length(); ++i)           make += s2[i];       }       return make;     }   }   string dfs(string st) {     int u[26];     for (int i = 0; i < 26; ++i) u[i] = 0;     for (int i = 0; i < st.length(); ++i) u[int(st[i]) - 97] = 1;     for (int i = 1; i < n; ++i) {       if (s1[i]) {         for (int j = 0; j < 26; ++j)           if (m[i][j] && u[j]) {             st = makestr(st, a[i]);             s1[i] = false;             st = dfs(st);           }       }     }     return st;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       s1[i] = true;     }     for (int i = 0; i < n; ++i) {       string st = a[i];       for (int j = 0; j < st.length(); ++j) {         m[i][int(st[j] - 97)] = 1;       }     }     string st = dfs(a[0]);     for (int i = 1; i < n; ++i) {       if (s1[i]) {         st = makestr(st, dfs(a[i]));       }     }     cout << st;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   vector<int> v[1000];   map<vector<int>, int> mp;   const int N = 495;   int dp[N * N];   int ns[10][10];   vector<int> from[N * N];   int deg[N * N];   void solve(int i, int j) {     vector<int>& v1 = v[i];     vector<int>& v2 = v[j];     for (int a = 1; a <= 4; ++a)       if (v1[a]) {         for (int b = 1; b <= 4; ++b)           if (v2[b]) {             v1[a] -= 1;             v1[ns[a][b]] += 1;             int s = mp[v1];             v1[a] += 1;             v1[ns[a][b]] -= 1;             from[j * N + s].push_back(i * N + j);             deg[i * N + j] += 1;           }       }   }   int get(int i, int j) {     switch (dp[i * N + j]) {       case 0:         return 2;       case 1:         return 0;       default:         return 1;     }   }   int q[1000000];   int main() {     for (int i = 0; i < (10); ++i)       for (int j = 0; j < (10); ++j) ns[i][j] = (i + j) % 5;     int c = 0;     for (int i0 = 0; i0 < (9); ++i0)       for (int i1 = 0; i1 < (9); ++i1)         for (int i2 = 0; i2 < (9); ++i2)           for (int i3 = 0; i3 < (9); ++i3)             for (int i4 = 0; i4 < (9); ++i4) {               if (i0 + i1 + i2 + i3 + i4 == 8) {                 v[c++] = {i0, i1, i2, i3, i4};                 mp[v[c - 1]] = c - 1;               }             }     for (int i = 0; i < (N); ++i)       for (int j = 0; j < (N); ++j) solve(i, j);     int f = 0, e = 0;     int z = mp[{8, 0, 0, 0, 0}];     for (int i = 0; i < N; ++i) {       dp[i * N + z] = -1;       q[e++] = i * N + z;       dp[z * N + i] = 1;       q[e++] = z * N + i;     }     while (f < e) {       int c = q[f++];       for (int u : from[c])         if (!dp[u]) {           if (dp[c] == -1) {             dp[u] = 1;             q[e++] = u;           } else {             deg[u] -= 1;             if (!deg[u]) {               dp[u] = -1;               q[e++] = u;             }           }         }     }     int T;     scanf( %d , &T);     while (T--) {       int f, x;       scanf( %d , &f);       vector<int> v1(5), v2(5);       for (int i = 0; i < (8); ++i) {         scanf( %d , &x);         v1[x] += 1;       }       for (int i = 0; i < (8); ++i) {         scanf( %d , &x);         v2[x] += 1;       }       if (f) swap(v1, v2);       int ans = get(mp[v1], mp[v2]);       if (ans == 2)         puts( Deal );       else         puts(f ^ ans ?  Bob  :  Alice );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[1 << 18], vis[1 << 20], n, k, d, t;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &n, &k, &d);       int ans = k, cnt = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &A[i]);         if (!vis[A[i]]) cnt++;         vis[A[i]]++;         if (i >= d) {           if (i > d) {             vis[A[i - d]]--;             if (!vis[A[i - d]]) cnt--;           }           ans = min(ans, cnt);         }       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) vis[A[i]] = 0;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1123;   const double eps = 1e-6;   const int inf = (int)1e9 + 123;   using namespace std;   int n, m;   char a[N][N];   int mini = inf;   int d[N][N];   int sum(int x, int y, int x2, int y2) {     return d[x2][y2] - d[x - 1][y2] - d[x2][y - 1] + d[x - 1][y - 1];   }   bool check(int x, int y, int sx, int sy) {     if (sum(sx, sy, sx + x - 1, sy + y - 1) != x * y) return 0;     int sz = sum(sx, sy, sx + x - 1, sy + y - 1);     while (1) {       if (sx + x <= n && sum(sx + x, sy, sx + x, sy + y - 1) == y) {         sx++;         sz += y;         continue;       }       if (sy + y <= m && sum(sx, sy + y, sx + x - 1, sy + y) == x) {         if (sum(sx, sy + y, sx + x - 1, sy + y) != x) return 0;         sy++;         sz += x;         continue;       }       break;     }     if (d[n][m] != sz) return 0;     return 1;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] +                   (a[i][j] ==  X  ? 1 : 0);       }     int x = -1, y = -1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (a[i][j] ==  X ) {           x = i;           y = j;           break;         }       if (x != -1) break;     }     if (x == -1) {       cout << -1;       return 0;     }     int cnt = 0;     for (int i = x; i <= n; i++) {       if (a[i][y] ==  X )         cnt++;       else         break;     }     for (int i = 1; i <= m; i++)       if (y + i - 1 <= m && check(cnt, i, x, y) && mini > cnt * i) mini = cnt * i;     cnt = 0;     for (int i = y; i <= m; i++) {       if (a[x][i] ==  X )         cnt++;       else         break;     }     for (int i = 1; i <= n; i++)       if (x + i - 1 <= m && check(i, cnt, x, y) && mini > i * cnt) mini = i * cnt;     if (mini == inf) mini = -1;     cout << mini;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const int mod = 1e9 + 7;   long long a[50];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     a[0] = 0;     for (long long i = 1; i <= 31; i++) {       a[i] = 4 * a[i - 1] + 1;     }     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (n <= 30 && k > a[n])         cout <<  NO  << endl;       else if (k < 5) {         if (k == 3 && n == 2)           cout <<  NO  << endl;         else if (n == 2) {           if (k == 1 || k == 2)             cout <<  YES 1  << endl;           else             cout <<  YES 0  << endl;         } else {           cout <<  YES   << n - 1 << endl;         }       } else {         cout <<  YES  ;         long long now;         for (long long i = 1; i <= 31; i++) {           if (a[i] >= k) {             now = i;             break;           }         }         now--;         if (a[now + 1] - k <= (((1ll << now) - 1) * ((1ll << now) - 1)))           cout << n - now - 1 << endl;         else           cout << n - now << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int computeXOR(long long int n) {     if (n % 4 == 0) return n;     if (n % 4 == 1) return 1;     if (n % 4 == 2) return n + 1;     return 0;   }   void solve() {     vector<long long int> v;     map<long long int, long long int> mp;     long long int e, i, j, l, m, x, y, z, r, k, n;     cin >> n >> m;     x = computeXOR(n - 1);     r = x ^ n;     if (x == m)       cout << n << endl;     else if (r == m)       cout << n + 2 << endl;     else       cout << n + 1 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T = 1;     cin >> T;     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   void putin(char s[]);   int main() {     int i, total = 0;     char c, ori1[120], ori2[120], ori3[120], a[6][400], temp[700];     putin(ori1);     putin(ori2);     putin(ori3);     strcpy(a[0], ori1);     strcat(a[0], ori2);     strcat(a[0], ori3);     strcpy(a[1], ori2);     strcat(a[1], ori1);     strcat(a[1], ori3);     strcpy(a[2], ori3);     strcat(a[2], ori2);     strcat(a[2], ori1);     strcpy(a[3], ori1);     strcat(a[3], ori3);     strcat(a[3], ori2);     strcpy(a[4], ori2);     strcat(a[4], ori3);     strcat(a[4], ori1);     strcpy(a[5], ori3);     strcat(a[5], ori1);     strcat(a[5], ori2);     scanf( %d , &total);     getchar();     while (total) {       --total;       putin(temp);       for (i = 0; i < 6; ++i)         if (strcmp(temp, a[i]) == 0) {           printf( ACC );           break;         }       if (i == 6) printf( WA );       printf(  n );     }     return 0;   }   void putin(char s[]) {     char c;     int i = 0;     c = getchar();     while (c !=   n ) {       if (c >=  A  && c <=  Z )         s[i] = c + 32;       else if (c >=  a  && c <=  z )         s[i] = c;       else         --i;       ++i;       c = getchar();     }     s[i] =   0 ;     return;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const long long inf = (((long long)1) << 61) + 5;   const int N = 200005;   int a[N];   int b[N];   int f1[N];   int f2[N];   int bit[N];   int n;   int sum(int i) {     int s = 0;     while (i > 0) {       s += bit[i];       i -= i & -i;     }     return s;   }   void add(int i, int x) {     while (i <= n + 1) {       bit[i] += x;       i += i & -i;     }   }   int get(int x) {     int ans = n, l = 1, r = n;     while (l <= r) {       int mid = (l + r) >> 1;       if (sum(mid) >= x) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       int x = sum(a[i]);       int tmp = a[i] - x;       f1[n - i - 1] = tmp;       add(a[i] + 1, 1);     }     memset(bit, 0, sizeof bit);     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       int x = sum(b[i]);       int tmp = b[i] - x;       f2[n - i - 1] = tmp;       add(b[i] + 1, 1);     }     for (int i = 0; i < n; i++) {       f1[i] += f2[i];       f1[i + 1] += f1[i] / (i + 1);       f1[i] %= (i + 1);     }     memset(bit, 0, sizeof bit);     for (int i = 1; i <= n; i++) add(i, 1);     for (int i = n - 1; i >= 0; i--) {       int ans = get(f1[i] + 1);       printf( %d  , ans - 1);       add(ans, -1);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 1e5 + 5;   vector<int> g[max_n], path;   bool vis[max_n], x[max_n];   int s;   void dfs(int u) {     vis[u] = 1;     x[u] ^= 1;     path.push_back(u);     bool leaf = 1;     for (int v : g[u]) {       if (!vis[v]) {         if (!leaf) leaf = 0;         dfs(v);         x[u] ^= 1;         path.push_back(u);         if (x[v]) {           x[v] ^= 1;           path.push_back(v);           x[u] ^= 1;           path.push_back(u);         }       }     }     if (u == s && x[u]) {       x[u] ^= 1;       path.pop_back();     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     s = -1;     for (int i = 1; i <= n; i++) {       scanf( %d , &x[i]);       if (s == -1 && x[i]) s = i;     }     if (s != -1) dfs(s);     bool ok = 1;     for (int i = 1; i <= n; i++) {       if (x[i]) {         ok = 0;         break;       }     }     if (!ok) {       puts( -1 );       exit(0);     }     int sz = path.size();     printf( %d n , sz);     for (int i = 0; i < sz; i++) {       if (i != sz - 1)         printf( %d  , path[i]);       else         printf( %d n , path[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 0x3f3f3f3f, N = 1e2 + 5, mod = 1e9 + 7;   int ans, lst = OO, gt[26];   string s1, s2;   vector<int> idx[26];   int main() {     cin >> s1 >> s2;     for (int i = 0; i < s1.size(); ++i) idx[s1[i] -  a ].push_back(i);     for (int i = 0; i < s2.size(); ++i) {       int ch = s2[i] -  a ;       if (!idx[ch].size()) exit(puts( -1 ));       if (idx[ch].back() > lst && idx[ch][gt[ch]] <= lst)         gt[ch] =             lower_bound(idx[ch].begin(), idx[ch].end(), lst) - idx[ch].begin();       if (idx[ch].size() <= gt[ch] || idx[ch].back() <= lst) {         ++ans, memset(gt, 0, sizeof gt);         gt[ch] = 1, lst = idx[ch][0];       } else         lst = (idx[ch][gt[ch]++]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dfs(long long int n, int i, long long int b[]) {     int ans = i * (n / b[i]);     n = n % b[i];     if (n == 0)       return ans;     else       return (ans + min(i + dfs(b[i] - n, i - 1, b), dfs(n, i - 1, b)));   }   int main() {     long long int a[17], i, n;     a[1] = 1;     for (i = 2; i < 17; i++) a[i] = 10 * a[i - 1] + 1;     cin >> n;     int j = dfs(n, 16, a);     cout << j;   }