malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pi = pair<int, int>;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   void setIO(string name =   ) {     cin.tie(0)->sync_with_stdio(0);     if (int((name).size())) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   const string yes =  YES n , no =  NO n ;   const int MOD = 1e9 + 7;   const int MX = 2e2 + 10;   const ll INF = 1e18;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char dc[4] = { D ,  R ,  U ,  L };   string S;   int K, A, B;   bool dp[MX][MX];   vi ans;   int main() {     setIO();     cin >> K >> A >> B >> S;     dp[0][0] = true;     for (int i = 1; i <= K; ++i)       for (int k = 1; k < MX; ++k)         for (int j = A; j <= B; ++j)           if (k - j >= 0) dp[i][k] |= dp[i - 1][k - j];     if (dp[K][int((S).size())] == false) return cout <<  No solution , 0;     int num = K, sub = int((S).size());     ans.push_back(sub);     while (num && sub) {       for (int i = A; i <= B; ++i) {         if (sub - i >= 0 && dp[num - 1][sub - i]) {           --num;           ans.push_back(sub - i);           sub -= i;           break;         }       }     }     reverse(begin(ans), end(ans));     for (int i = 0; i < int((ans).size()) - 1; ++i) {       for (int j = ans[i]; j < ans[i + 1]; ++j) {         cout << S[j];       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const int maxm = 100000 + 10;   vector<int> adj[maxn];   int fa[maxn][18], dep[maxn];   void trans(int prev, int u) {     dep[u] = dep[prev] + 1;     fa[u][0] = prev;     for (int i = 1; (1 << i) <= dep[u]; i++) {       fa[u][i] = fa[fa[u][i - 1]][i - 1];     }     int len = adj[u].size();     for (int i = 0; i < len; i++) {       int v = adj[u][i];       if (v == prev) continue;       trans(u, v);     }   }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     for (int i = 0; (1 << i) <= dep[v] - dep[u]; i++) {       if ((dep[v] - dep[u]) & 1 << i) v = fa[v][i];     }     if (u == v) return u;     for (int i = 18; i >= 0; i--) {       if ((1 << i) <= dep[u] && fa[u][i] != fa[v][i]) {         u = fa[u][i];         v = fa[v][i];       }     }     return fa[u][0];   }   int dis(int u, int v) {     int fff = lca(u, v);     return dep[u] + dep[v] - 2 * dep[fff];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       int j;       scanf( %d , &j);       adj[i].push_back(j);       adj[j].push_back(i);     }     dep[1] = 0;     trans(1, 1);     for (int i = 0; i < m; i++) {       int q[3];       for (int i = 0; i < 3; i++) scanf( %d , &q[i]);       int a[3], ttt = 0;       for (int i = 0; i < 3; i++) {         for (int j = i + 1; j < 3; j++) {           a[ttt++] = lca(q[i], q[j]);         }       }       int k = 0;       for (int i = 0; i < 3; i++)         if (dep[a[i]] > dep[a[k]]) k = i;       k = a[k];       int ans = 0;       for (int i = 0; i < 3; i++) ans = max(ans, dis(k, q[i]));       printf( %d n , ans + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gd(const string &a, const string &b) {     int d = 0;     for (int i = 0; i < (int)a.size(); i++)       if (a[i] != b[i]) d++;     return d;   }   string a[1005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int mind = 1000;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) mind = min(mind, gd(a[i], a[j]));     cout << min(6, (mind - 1) / 2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool a[4111][4111];   int n;   bool v[4111] = {0};   int p[4111] = {0};   int cnt = 0;   int ans[4111] = {0};   bool dfs_find(int i, int lt) {     v[i] = true;     for (int j = 1; j <= n; j++) {       if (a[i][j] > 0 && lt != j && i != j) {         if (v[j]) {           p[cnt++] = j;           return true;         } else {           p[cnt++] = j;           if (dfs_find(j, i)) {             return true;           }           cnt--;         }       }     }     return false;   }   void dfs(int i) {     for (int j = 1; j <= n; j++) {       if (i != j && a[i][j] > 0 && ans[j] == -1) {         ans[j] = ans[i] + 1;         dfs(j);       }     }   }   int main() {     memset(a, 0, sizeof(a));     memset(ans, -1, sizeof(ans));     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       a[x][y] = a[y][x] = 1;     }     p[cnt++] = 1;     dfs_find(1, 0);     ans[p[cnt - 1]] = 0;     for (int i = cnt - 2; i >= 0; i--) {       if (p[i] == p[cnt - 1]) break;       ans[p[i]] = 0;     }     for (int i = 1; i <= n; i++) {       if (ans[i] == 0) {         dfs(i);       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 501000;   const int INF = 0x3f3f3f3f;   vector<int> v[MAX_N], w[MAX_N];   struct skt {     int x, y;   };   int dis[MAX_N][2];   int tox[MAX_N][2], toy[MAX_N][2];   int n;   int b[MAX_N];   void bfs() {     int i;     queue<int> q;     skt t;     memset(dis, INF, sizeof(dis));     q.push(n);     dis[n][0] = 0;     dis[n][1] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (i = 0; i < v[x].size(); i++) {         int y = v[x][i];         int k = w[x][i];         if (dis[y][k] > max(dis[x][0], dis[x][1]) + 1) {           dis[y][k] = max(dis[x][0], dis[x][1]) + 1;           q.push(y);         }       }     }   }   int main(void) {     int m, i, x, y, t;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &x, &y, &t);       if (x == y) continue;       v[y].push_back(x);       w[y].push_back(t);     }     bfs();     if (dis[1][0] == INF || dis[1][1] == INF)       printf( -1 n );     else       printf( %d n , max(dis[1][0], dis[1][1]));     for (i = 1; i <= n; i++) {       if (dis[i][0] > dis[i][1])         b[i] = 0;       else         b[i] = 1;       printf( %d , b[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     long long sum = 0;     for (int i = 0; i < n; ++i) sum += a[i];     long long cntWhite = 0;     for (int i = 0; i < n; ++i) cntWhite += (a[i] + i % 2) / 2;     cout << min(cntWhite, sum - cntWhite) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   map<string, int> mp;   const int N = 1e5 + 5;   int a[N];   int cost[N];   int g[N];   int main() {     int n, k, m;     cin >> n >> k >> m;     for (int i = 1; i <= n; i++) {       cin >> s;       mp[s] = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int x;     int minn;     while (k--) {       scanf( %d , &x);       minn = 0x3f3f3f3f;       for (int i = 0; i < x; i++) {         scanf( %d , &g[i]);         minn = min(minn, a[g[i]]);       }       for (int i = 0; i < x; i++) {         cost[g[i]] = minn;       }     }     long long ans = 0;     for (int i = 0; i < m; i++) {       cin >> s;       ans += cost[mp[s]];     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   int n, k, ans, mx, edg[1010][1010], dis[1001];   vector<int> v, gr[100000];   bool vis[1001];   void dfs(int x, int l) {     vis[x] = true;     dis[x] = 0;     for (int i = 0; i < gr[x].size(); i++) {       int u = gr[x][i];       if (vis[u] == false) {         dfs(u, l + 1);       }       dis[x] = max(dis[x], dis[u] + 1);       mx = max(mx, dis[x]);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     int kk = k;     while (k--) {       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         edg[x][k] = i;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         bool t = false;         for (int z = 0; z < kk; z++) {           if (edg[i][z] > edg[j][z]) t = true;         }         if (t == false) gr[i].push_back(j);       }     }     for (int i = 1; i <= n; i++) {       dfs(i, 1);       memset(vis, 0, sizeof vis);     }     cout << mx + 1;   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( abc.in );   string str[2];   long long let[26][500001];   long long a, b, sum, m;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     cin >> a >> b;     cin >> str[0] >> str[1];     long long len_mx = str[1].size(), len_mn = str[0].size(), i, j, dif_len;     int p = 1;     if (str[0].size() > str[1].size())       p = 0, len_mx = str[0].size(), len_mn = str[1].size();     dif_len = str[p].size() - str[1 - p].size();     long long cmmmc = len_mx * len_mn / gcd(len_mx, len_mn);     m = a / (cmmmc / str[0].size());     long long cmmdc = gcd(len_mn, len_mx);     long long sx = 0;     if (dif_len == 0) {       for (i = 0; i < len_mx; i++)         if (str[0][i] != str[1][i]) sx += m;     } else {       for (i = 0; i < len_mx; i++) {         char c = str[p][i];         let[(long)(c -  a )][i % cmmdc]++;       }       for (i = 0; i < len_mn; i++) {         char c = str[1 - p][i];         sx += m * (str[p].size() / cmmdc - let[c -  a ][i % cmmdc]);       }     }     cout << sx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[40] = {0,   4,   22,  27,  58,  85,  94,  121, 166, 202, 265,                274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517,                526, 535, 562, 576, 588, 627, 634, 636, 645, 648};   int main() {     int t;     cin >> t;     cout << a[t] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long prod = 1;     while (b) {       if (b & 1) prod = (prod * a);       a = (a * a);       b >>= 1;     }     return prod;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> odd, even;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         if (x % 2 == 1) {           odd.push_back(i + 1);         } else           even.push_back(i + 1);       }       if (even.size() > 0)         cout << 1 << endl << even[0] << endl;       else {         if (odd.size() >= 2) {           cout << 2 << endl << odd[0] <<     << odd[1] << endl;         } else {           cout << -1 << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long maxn = 60;   const long long mod = 1e9 + 7;   const long double PI = acos((long double)-1);   long long pw(long long a, long long b, long long md = mod) {     long long res = 1;     while (b) {       if (b & 1) {         res = (a * res) % md;       }       a = (a * a) % md;       b >>= 1;     }     return (res);   }   long long n, t;   long long c[maxn][maxn];   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     long long ans = 0;     if (t == 1) ans--;     if (__builtin_popcountll(t) != 1) cout << 0, exit(0);     ;     c[0][0] = 1;     for (long long i = 1; i < maxn; i++) {       c[i][0] = 1;       for (long long j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];     }     t = __builtin_ctzll(t) + 1;     n += 1;     long long cnt = 0;     for (long long i = 50; i >= 0; i--) {       if (cnt > t) break;       if (n & (1LL << i)) ans += c[i][t - cnt], cnt++;     }     if (__builtin_popcountll(n) == t) ans++;     cout << ans;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   long long Set(long long N, long long pos) { return N = N | (1 << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }   void CI(long long &_x) { scanf( %I64d , &_x); }   void CO(long long &_x) { cout << _x; }   template <typename T>   void getarray(T a[], long long n) {     for (long long i = 0; i < n; i++) cin >> a[i];   }   template <typename T>   void prLLIarray(T a[], long long n) {     for (long long i = 0; i < n - 1; i++) cout << a[i] <<    ;     cout << a[n - 1] << endl;   }   const double EPS = 1e-9;   const long long INF = 0x7f7f7f7f;   long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};   long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};   long long dr4[4] = {0, 0, 1, -1};   long long dc4[4] = {-1, 1, 0, 0};   long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};   long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};   char grid[155][155];   int main() {     vector<pair<int, int> > V;     int n, m;     cin >> n >> m;     int last;     for (int i = 0; i < n; i++) {       int mini = 1 << 30, maxi = -1;       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  W ) {           last = i;           mini = min(mini, j);           maxi = max(maxi, j);         }       }       V.push_back(make_pair(mini, maxi));     }     int ans = 0, pos_x = 0, pos_y = 0;     for (int i = 0; i <= last; i++) {       int dir = i % 2;       if (dir == 0) {         int mm = pos_y;         mm = max(mm, V[i].second);         if (i < last) mm = max(mm, V[i + 1].second);         ans += mm - pos_y + 1;         pos_y = mm;       } else {         int mm = pos_y;         mm = min(mm, V[i].first);         if (i < last) mm = min(mm, V[i + 1].first);         ans += (pos_y - mm) + 1;         pos_y = mm;       }     }     cout << max(ans - 1, 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   long long f[555], n;   string g[] = { < ,  ^ ,  > ,  v };   string s, t;   int main() {     cin >> s >> t;     cin >> n;     if (n % 2 == 0) {       cout <<  undefined ;       return 0;     }     for (int i = 0; i < 4; i++)       if (s == g[i]) {         if (g[(i + (n % 4)) % 4] == t)           cout <<  cw ;         else           cout <<  ccw ;       }   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int v, id, tag;   } a[100010];   int cmp1(node x, node y) { return x.v < y.v; }   int cmp2(node x, node y) { return x.id < y.id; }   int ccount[100010];   int main() {     int n, tt;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].v), a[i].id = i;     sort(a + 1, a + n + 1, cmp1);     a[1].tag = tt = 1;     ccount[tt] = 1;     for (int i = 2; i <= n; i++) {       if (a[i].v != a[i - 1].v) tt++;       a[i].tag = tt;       ccount[tt]++;     }     sort(a + 1, a + n + 1, cmp2);     int nowh = 1, maxh = 0, block = 0;     for (int i = 1; i <= n; i++) {       ccount[a[i].tag]--;       maxh = max(maxh, a[i].tag);       while (!ccount[nowh]) nowh++;       if (nowh >= maxh) block++;     }     printf( %d n , block);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int n, k;   int C[N];   bool Dp[N][N][N];   vector<int> Ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , C + i);     Dp[n][0][0] = true;     for (int idx = n - 1; idx >= 0; idx--)       for (int Sum = 0; Sum <= k; Sum++)         for (int X = 0; X <= k; X++) {           Dp[idx][Sum][X] |= Dp[idx + 1][Sum][X];           Dp[idx][Sum][X] |= (Sum >= C[idx] && Dp[idx + 1][Sum - C[idx]][X]);           Dp[idx][Sum][X] |= (Sum >= C[idx] && X >= C[idx] &&                               Dp[idx + 1][Sum - C[idx]][X - C[idx]]);         }     for (int X = 0; X <= k; X++)       if (Dp[0][k][X]) Ans.push_back(X);     printf( %d n , Ans.size());     for (auto x : Ans) printf( %d  , x);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, f[5005][5005], g[5005], h[5005], cnt[5005];   long long ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       ++cnt[x];     }     m = 5000;     for (int i = 1; i <= m; ++i) {       memcpy(f[i], f[i - 1], sizeof f[i]);       g[i] = g[i - 1];       for (int j = 2, x = i; j <= x; ++j)         while (x % j == 0) {           x /= j;           ++f[i][j];           ++g[i];         }       for (int j = i; j; --j)         if (f[i][j] == f[i - 1][j])           h[i] += f[i][j];         else {           h[i] += f[i - 1][j];           break;         }     }     ans = 0x3f3f3f3f3f3f3f3fLL;     for (int i = 0; i <= m; ++i) {       long long sum = 0;       for (int j = i - 1, k = g[i]; ~j; --j) {         k = min(k, h[j + 1]);         sum += (long long)(g[i] + g[j] - k * 2) * cnt[j];       }       for (int j = i + 1, k = g[i]; j <= m; ++j) {         k = min(k, h[j]);         sum += (long long)(g[i] + g[j] - k * 2) * cnt[j];       }       ans = min(ans, sum);       sum = 0;       for (int j = i - 1, k = h[i]; ~j; --j) {         k = min(k, h[j + 1]);         sum += (long long)(h[i] + g[j] - k * 2) * cnt[j];       }       for (int j = i, k = h[i]; j <= m; ++j) {         k = min(k, h[j]);         sum += (long long)(h[i] + g[j] - k * 2) * cnt[j];       }       ans = min(ans, sum);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, m, k, par[N], portal[N];   long long dist[N];   vector<pair<int, int> > gr[N];   vector<pair<int, pair<int, int> > > edges;   vector<pair<long long, pair<int, int> > > new_edges;   inline int get(int x) {     if (par[x] < 0) return x;     return par[x] = get(par[x]);   }   inline bool unin(int x, int y) {     x = get(x);     y = get(y);     if (x == y) return false;     par[x] += par[y];     par[y] = x;     return true;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       gr[a].push_back({c, b});       gr[b].push_back({c, a});       edges.push_back({c, {a, b}});     }     for (int i = 1; i <= n; i++) {       dist[i] = 1e18;       par[i] = -1;     }     set<pair<long long, int> > q;     scanf( %d , &k);     for (int i = 0; i < k; i++) {       int p;       scanf( %d , &p);       dist[p] = 0;       portal[p] = p;       q.insert({0, p});     }     while (!q.empty()) {       auto pp = *q.begin();       q.erase(pp);       int v = pp.second;       for (auto pp : gr[v]) {         int cost = pp.first, to = pp.second;         if (dist[to] > dist[v] + cost) {           q.erase({dist[to], to});           dist[to] = dist[v] + cost;           portal[to] = portal[v];           q.insert({dist[to], to});         }       }     }     for (int i = 1; i <= n; i++) gr[i].clear();     for (auto edge : edges) {       int cost = edge.first, a = edge.second.first, b = edge.second.second;       if (portal[a] == portal[b]) continue;       new_edges.push_back({dist[a] + dist[b] + cost, {portal[a], portal[b]}});     }     sort(new_edges.begin(), new_edges.end());     long long ans = dist[1];     for (auto edge : new_edges) {       long long cost = edge.first;       int a = edge.second.first, b = edge.second.second;       if (unin(a, b)) {         ans += cost;       }     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int i, j;     cin >> n >> k;     int arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     int one, two;     int m = 0;     for (i = 0; i < k; i++) {       one = 0, two = 0;       for (j = i; j < n; j = j + k) {         if (arr[j] == 1)           one++;         else           two++;       }       m = m + min(one, two);     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long inf = numeric_limits<long long>::max();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int cases;     cin >> cases;     while (cases--) {       int n;       cin >> n;       if (n % 2 == 0)         cout << 1;       else         cout << 7;       n -= 2;       n /= 2;       while (n--) cout << 1;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5010;   vector<int> ne[maxn];   int cnt[maxn], n;   int dp[maxn], res[maxn];   void dfs(int v, int prev = -1) {     cnt[v] = 1;     vector<int> w;     int last = n - 1;     for (int i = 0; i < (int)ne[v].size(); i++) {       int u = ne[v][i];       if (u != prev) {         dfs(u, v);         cnt[v] += cnt[u];         w.push_back(cnt[u]);         last -= cnt[u];       }     }     if (last > 0) {       w.push_back(last);     }     fill(dp, dp + n, 0);     dp[0] = 1;     for (int i = 0, sum = 0; i < (int)w.size(); sum += w[i], i++) {       for (int s = sum; s >= 0; s--) {         if (dp[s]) {           dp[s + w[i]] = 1;         }       }     }     for (int i = 1; i + 1 < n; i++) {       res[i] |= dp[i];     }   }   int main(void) {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       ne[a].push_back(b);       ne[b].push_back(a);     }     dfs(1);     int res_n = 0;     for (int i = 1; i + 1 < n; i++) {       res_n += res[i];     }     printf( %d n , res_n);     for (int i = 1; i + 1 < n; i++) {       if (res[i]) {         printf( %d %d n , i, n - i - 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, x;     cin >> a >> b >> x;     string s =   ;     if (a >= b) {       s.push_back( 0 );       a--;     } else {       s.push_back( 1 );       b--;     }     while (x) {       if (x == 1) {         if (s.back() ==  1 ) {           while (b) s.push_back( 1 ), b--;           while (a) s.push_back( 0 ), a--;         } else {           while (a) s.push_back( 0 ), a--;           while (b) s.push_back( 1 ), b--;         }       } else if (s.back() ==  1 ) {         s.push_back( 0 );         a--;       } else {         s.push_back( 1 );         b--;       }       x--;     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a[2222];   int dis[2222];   int main() {     for (int i = 0; i < 2222; ++i) dis[i] = -1;     dis[0] = 0;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         char c;         cin >> c;         if (c ==  # ) a[i].push_back(n + j), a[n + j].push_back(i);       }     queue<int> q;     q.push(0);     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = 0; i < a[p].size(); ++i)         if (dis[a[p][i]] == -1) {           q.push(a[p][i]);           dis[a[p][i]] = dis[p] + 1;         }     }     cout << dis[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   int b;   queue<pair<int, int> > qu;   void OUT() {     if (ans.size() == 201) ans.pop_back();     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);   }   int solve(int last, int i) {     if (last == 0) return 0;     qu.push(pair<int, int>(last, i));     return (last + b - 1) / b;   }   int main() {     int n, a, k, cnt = 0, last2 = 0;     string s;     scanf( %d %d %d %d , &n, &a, &b, &k);     cin >> s;     s +=  1 ;     int last = 0;     string tmp = s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         for (last = max(last, i - b + 1); last <= i; last++) tmp[last] =  1 ;       }     }     s = tmp;     last = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 )         cnt += solve(last, i), last = 0;       else         last++;     }     while (cnt >= a) {       ans.push_back(qu.front().second);       cnt--;       if (qu.front().first > b)         qu.front().second -= b, qu.front().first -= b;       else         qu.pop();     }     OUT();   }