malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int n, m, h, t, u, v, src[MAXN], dst[MAXN], num[MAXN], used[MAXN];   vector<int> g[MAXN];   void out(vector<int> &v) {     for (int i = 0; i < v.size(); ++i) {       cout << v[i] <<    n [i == v.size() - 1];     }   }   bool check(int u, int v, int ver) {     int cnt = 0;     num[u] = num[v] = -1;     for (int i = 0; i < g[u].size() && i < h + t; ++i) {       int w = g[u][i];       if (w == v) continue;       used[w] = ver;       num[w] = 1;       ++cnt;     }     for (int i = 0; i < g[v].size() && i < h + t; ++i) {       int w = g[v][i];       if (w == u) continue;       if (used[w] == ver) {         num[w] = 2;         continue;       }       used[w] = ver;       num[w] = 1;       ++cnt;     }     int degu = g[u].size() - 1, degv = g[v].size() - 1;     if (h >= t != degu >= degv) swap(degu, degv);     return degu >= h && degv >= t && cnt >= h + t;   }   void solve() {     for (int mm = 0; mm < m; ++mm) {       if (check(src[mm], dst[mm], mm + 1)) {         cout <<  YES n ;         u = src[mm], v = dst[mm];         if (h >= t != g[u].size() >= g[v].size()) swap(u, v);         cout << u <<     << v << endl;         vector<int> ans;         for (int i = 0; i < g[u].size() && ans.size() < h; ++i) {           int v = g[u][i];           if (num[v] == 1) {             num[v] == -1;             ans.push_back(v);           }         }         for (int i = 0; i < g[u].size() && ans.size() < h; ++i) {           int v = g[u][i];           if (num[v] > 1) {             ans.push_back(v);             num[v] = -1;           }         }         out(ans);         ans.clear();         swap(u, v);         for (int i = 0; i < g[u].size() && ans.size() < t; ++i) {           int v = g[u][i];           if (num[v] != -1) ans.push_back(v);         }         out(ans);         return;       }     }     cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << setprecision(6) << fixed;     clog.copyfmt(cout);     cin >> n >> m >> h >> t;     for (int i = 0; i < m; ++i) {       cin >> u >> v;       src[i] = u, dst[i] = v;       g[u].push_back(v);       g[v].push_back(u);     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-13;   const long double PI = acos(-1);   const int INF = (int)1e9;   const long long INFF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MXN = (int)2e5 + 7;   char s[MXN];   int cnt[MXN];   int num[MXN], num2[MXN], a[MXN];   bool check() {     for (int i = 0; i < 1 << 6; i++) num2[i] = num[i];     for (int i = 0; i < 6; i++) {       for (int j = 0; j < 1 << 6; j++) {         if (j & (1 << i)) num2[j] += num2[j ^ (1 << i)];       }     }     for (int i = 0; i < 1 << 6; i++) {       int sum = 0;       for (int j = 0; j < 6; j++)         if (i & (1 << j)) sum += cnt[j];       if (sum < num2[i]) return false;     }     return true;   }   char ans[MXN];   int main() {     scanf( %s , s + 1);     int l = strlen(s + 1);     for (int i = 1; s[i]; i++) {       cnt[s[i] -  a ]++;       a[i] = (1 << 6) - 1;     }     int m;     scanf( %d , &m);     while (m--) {       int p;       scanf( %d %s , &p, s + 1);       a[p] = 0;       for (int i = 1; s[i]; i++) a[p] ^= (1 << (s[i] -  a ));     }     for (int i = 1; i <= l; i++) {       num[a[i]]++;     }     for (int i = 1; i <= l; i++) {       num[a[i]]--;       for (int j = 0; j < 6; j++) {         if (!cnt[j] || !(a[i] & (1 << j))) continue;         cnt[j]--;         if (check()) {           ans[i] = j +  a ;           break;         } else {           cnt[j]++;         }       }       if (!ans[i]) {         puts( Impossible );         return 0;       }     }     printf( %s n , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t = 1, i;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 0; i < n - 1; i++) {       if (a[i + 1] == a[i]) {         t++;       } else if (t > (n + 1) / 2) {         cout <<  NO ;         return 0;       } else         t = 1;     }     if (t > ((n + 1) / 2))       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int res[101] = {0};       for (int i = 0; i < n; i++) {         res[arr[i]]++;       }       int cnt[101] = {0};       for (int i = 0; i < 101; i++) {         if (res[i] >= 1) {           res[i]--;           cnt[i]++;         }       }       int f, s;       for (int i = 0; i < 101; i++) {         if (res[i] == 0) {           f = i;           break;         }       }       for (int i = 0; i < 101; i++) {         if (cnt[i] == 0) {           s = i;           break;         }       }       cout << f + s <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int K, P, cd;   int cal(int ct, vector<pair<int, int> > vt) {     int t = vt.size(), res = 0;     for (int st = 1; st < (1 << t); st++) {       int val = 1, sl = 0;       for (int j = 0; j < t; j++) {         if ((st >> j) % 2 == 1) val *= vt[j].first, sl++;       }       if (sl % 2 == 0)         res -= ct / val;       else         res += ct / val;     }     return ct - res;   }   void solve() {     vector<pair<int, int> > vt;     int x = P;     for (int i = 2; i * i <= P; i++) {       if (x % i == 0) {         int t = 0;         while (x % i == 0) t++, x /= i;         vt.push_back(pair<int, int>(i, t));       }     }     if (x > 1) vt.push_back(pair<int, int>(x, 1));     int t = vt.size();     int res0 = cal(cd, vt), r = 10000000, l = cd;     int ans;     while (1) {       int mid = (l + r) / 2;       int v = cal(mid, vt) - res0;       if (v == K) {         ans = mid;         break;       }       if (v > K) {         r = mid - 1;       } else         l = mid + 1;     }     while (1) {       int ok = 1;       for (int j = 0; j < vt.size(); j++) {         if (ans % vt[j].first == 0) {           ok = 0;           break;         }       }       if (ok)         break;       else         ans--;     }     cout << ans << endl;   }   int main() {     int T;     cin >> T;     for (int i = 0; i < T; i++) {       cin >> cd >> P >> K;       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 * 2 + 7;   int a[maxn], b[maxn], t[4 * maxn], n, W, H;   void build(int v, int l, int r) {     if (r - l == 1) {       t[v] = a[l];       return;     }     build(2 * v + 1, l, (l + r) / 2);     build(2 * v + 2, (l + r) / 2, r);     t[v] = max(t[2 * v + 1], t[2 * v + 2]);   }   int get(int v, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) return t[v];     if (ql >= r || qr <= l) return 0;     return max(get(2 * v + 1, l, (l + r) / 2, ql, qr),                get(2 * v + 2, (l + r) / 2, r, ql, qr));   }   void upd(int v, int l, int r, int pos, int x) {     if (r - l == 1) {       t[v] = x;       return;     }     if (pos < (l + r) / 2) {       upd(2 * v + 1, l, (l + r) / 2, pos, x);     } else {       upd(2 * v + 2, (l + r) / 2, r, pos, x);     }     t[v] = max(t[2 * v + 1], t[2 * v + 2]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int ww, hh;       scanf( %d %d , &ww, &hh);       a[i] = hh;       b[i] = ww;       W += ww;     }     build(0, 0, n);     for (int i = 0; i < n; i++) {       W -= b[i];       upd(0, 0, n, i, -10000);       H = get(0, 0, n, 0, n);       printf( %d  , H * W);       W += b[i];       upd(0, 0, n, i, a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long left;     long long right;     scanf( %lld%lld , &left, &right);     long long ans = 0LL;     for (int i = (62); i >= (0); --i) {       long long bitLeft = left & (1LL << i);       long long bitRight = right & (1LL << i);       if (bitRight && !bitLeft) {         ans = (1LL << (i + 1)) - 1LL;         printf( %lld n , ans);         return 0;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   long long k, pa, pb, dp[1107][1107];   int main() {     scanf( %lld%lld%lld , &k, &pa, &pb);     long long invb = 1, base = pb;     for (int t = 1000000007 - 2; t; t >>= 1, (base *= base) %= 1000000007)       if (t & 1) (invb *= base) %= 1000000007;     long long inva_b = 1;     base = pa + pb;     for (int t = 1000000007 - 2; t; t >>= 1, (base *= base) %= 1000000007)       if (t & 1) (inva_b *= base) %= 1000000007;     long long invab = pa * invb % 1000000007;     pa *= inva_b;     pa %= 1000000007;     pb *= inva_b;     pb %= 1000000007;     for (int i = k; ~i; --i)       for (int j = k; ~j; --j)         if (i + j >= k)           dp[i][j] = (i + j + invab) % 1000000007;         else           dp[i][j] =               pa * dp[i + 1][j] % 1000000007 + pb * dp[i][i + j] % 1000000007,           dp[i][j] %= 1000000007;     printf( %lld n , dp[1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class Ta, class Tb>   inline Tb cast(Ta a) {     stringstream ss;     ss << a;     Tb b;     ss >> b;     return b;   };   const double EPS = 1e-9;   const int INF = 1000000000;   const int MOD = 1000000007;   const int diri[8] = {-1, 0, 1, 0, -1, 1, 1, -1};   const int dirj[8] = {0, 1, 0, -1, 1, 1, -1, -1};   vector<int> tree;   int root(int n) {     if (tree[n] == -1) return n;     return tree[n] = root(tree[n]);   }   int main() {     int n, m;     cin >> n >> m;     vector<int> deg(n, 0);     tree = vector<int>(n, -1);     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       ++deg[x];       ++deg[y];       int a = root(x), b = root(y);       if (a != b) {         tree[b] = a;       }     }     int c = 0;     for (int i = 0; i < n; ++i)       if (deg[i] != 0 and tree[i] == -1) ++c;     if (deg[0] == 0 and c > 0) ++c;     int s = 0;     for (int i = 0; i < n; ++i)       if (deg[i] % 2 == 1) ++s;     if (c == 1)       cout << s / 2 << endl;     else {       vector<int> v(n, 0);       for (int i = 0; i < n; ++i)         if (deg[i] % 2 == 1) v[root(i)] = 1;       int t = 0;       for (int i = 0; i < n; ++i) t += v[i];       cout << c + s / 2 - t << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, h;     string s;     cin >> n >> s;     m = (s[3] -  0 ) * 10 + s[4] -  0 ;     if (m > 59) {       s[3] =  0 ;     }     if (n == 24) {       h = (s[0] -  0 ) * 10 + s[1] -  0 ;       if (h > 23) {         if (s[0] -  0  > 2)           s[0] =  0 ;         else if (s[1] -  0  > 3)           s[1] =  0 ;       }     } else {       h = (s[0] -  0 ) * 10 + s[1] -  0 ;       if (h == 0) s[1] =  1 ;       if (h > 12) {         if (s[0] -  0  > 1)           s[0] =  0 ;         else if (s[1] -  0  > 2)           s[1] =  2 ;         if (s[0] ==  0  && s[1] ==  0 ) s[0] =  1 ;       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     priority_queue<int, vector<int>, greater<int>> pq;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       pq.push(x);     }     int ans = 0;     for (int i = 0; i < k; i++) {       ans += pq.top();       pq.pop();     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   map<int, int> v[N];   int rec(int node, int w) {     auto it = v[node].lower_bound(w);     if (it == v[node].begin()) {       return 1;     }     it--;     return (*it).second + 1;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int ans = 0;     while (m--) {       int a, b, w;       cin >> a >> b >> w;       int val = rec(a, w);       if (rec(b, w + 1) > val) {         continue;       }       v[b][w] = val;       auto it = v[b].upper_bound(w);       while (it != v[b].end() && (*it).second <= val) {         it = v[b].erase(it);       }       ans = max(ans, val);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b;     scanf( %lld%lld , &a, &b);     long long int c = a, d = b;     long long int cnt = 0, rem;     while (c >= 1 && d >= 1) {       if (d == 1) {         printf( %lld , cnt + c);         return 0;       }       if (c >= d) {         cnt += c / d;         c = c % d;       } else {         cnt += d / c;         d = d % c;       }     }     printf( %lld n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)5e5 + 9;   vector<int> T[N];   bool use[2 * N];   int p;   int l[N], r[N];   void dfs(int u, int par) {     if (par == -1) {       l[u] = 1;       r[u] = T[u].size() + 2;       use[1] = true;       use[T[u].size() + 2] = true;       p = T[u].size() + 3;       vector<pair<int, int> > srt;       int fl = 2;       for (auto x : T[u]) {         if (x == par) continue;         dfs(x, u);         srt.push_back(make_pair(r[x], x));       }       sort(srt.begin(), srt.end());       reverse(srt.begin(), srt.end());       for (int i = 0; i < srt.size(); i++) {         l[srt[i].second] = fl++;       }       return;     }     vector<int> rr;     for (auto x : T[u]) {       if (x == par) {         continue;       }       while (use[p]) p++;       use[p] = true;       rr.push_back(p);     }     while (use[p]) p++;     r[u] = p;     use[p] = true;     vector<pair<int, int> > srt;     for (int i = 0; i < T[u].size(); i++) {       if (T[u][i] == par) continue;       dfs(T[u][i], u);       srt.push_back(make_pair(r[T[u][i]], T[u][i]));     }     sort(srt.begin(), srt.end());     reverse(srt.begin(), srt.end());     for (int i = 0; i < srt.size(); i++) {       l[srt[i].second] = rr[i];     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int x, y;     for (int i = 1; i < n; i++) {       cin >> x >> y;       T[x].push_back(y);       T[y].push_back(x);     }     dfs(1, -1);     for (int i = 1; i <= n; i++) cout << l[i] <<     << r[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   using namespace std;   const long double two = 2;   const long double INF = 2e18 + 100;   const long long MOD = 998244353;   const long long N = 1e5 + 10;   const long long nul = 0;   const long long SIZE = 1e6 * 3;   struct exam {     long long s, d, c, ind;     exam(long long s1, long long d1, long long c1, long long ind1) {       s = s1;       d = d1;       c = c1;       ind = ind1;     }   };   vector<long long> ans;   vector<exam> smth;   bool lol(long long st, long long len, long long fin, long long ind) {     long long i = st;     while (len--) {       while (ans[i] != 0 && i < fin) i++;       if (i == fin) return 0;       ans[i] = ind + 1;     }     return 1;   }   bool comp(exam a, exam b) {     if (a.d < b.d)       return 1;     else       return 0;   }   signed main() {     long long n, m;     cin >> n >> m;     ans.resize(n, 0);     smth;     for (long long i = 0; i < m; i++) {       long long s, d, c;       cin >> s >> d >> c;       s--;       d--;       ans[d] = m + 1;       smth.push_back(exam(s, d, c, i));     }     sort((smth).begin(), (smth).end(), comp);     bool flag = 0;     for (long long i = 0; i < m; i++) {       if (lol(smth[i].s, smth[i].c, smth[i].d, smth[i].ind) == 0) flag = 1;     }     if (flag)       cout << -1 << endl;     else {       for (long long i : ans) cout << i <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool sol(long long n, long long m, long long a, long long l, long long r,            long long& b, long long& c) {     if (abs(n * a - m) <= r - l) {       long long diff = m - n * a;       b = diff > 0 ? r : l;       c = b - diff;       return true;     }     return false;   }   int main() {     int T;     cin >> T;     while (T--) {       long long l, r, m;       cin >> l >> r >> m;       for (long long a = l; a <= r; a++) {         long long n0 = m / a, n1 = m / a + 1;         long long b, c;         if (n0 > 0 && sol(n0, m, a, l, r, b, c)) {           printf( %lld %lld %lld n , a, b, c);           break;         }         if (n1 > 0 && sol(n1, m, a, l, r, b, c)) {           printf( %lld %lld %lld n , a, b, c);           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     string a, b, c =   ;     cin >> a >> b;     for (int i = 0; i < a.length(); i++) {       if (a[i] + 1 < b[i]) {         c += a[i] + 1;         for (int j = i + 1; j < a.length(); j++) c +=  z ;         break;       } else if (a[i] + 1 == b[i]) {         bool big = 0;         for (int j = i + 1; j < a.length(); j++) {           if (a[j] !=  z ) big = 1;         }         if (big) {           c += a[i];           for (int j = i + 1; j < a.length(); j++) c +=  z ;           break;         } else {           c += a[i] + 1;           for (int j = i + 1; j < a.length(); j++) c +=  a ;           break;         }       } else         c += a[i];     }     if (c != a && c != b)       cout << c;     else       cout <<  No such string ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[5] = {10, 15, 60, 4, 19};   int result = 0;   int getMin(int r, int g, int b) {     if (r < g) {       if (r < b) {         return r;       } else {         return b;       }     } else {       if (g < b) {         return g;       } else {         return b;       }     }   }   int getMax(int r, int g, int b) {     if (r > g) {       if (r > b) {         return r;       } else {         return b;       }     } else {       if (g > b) {         return g;       } else {         return b;       }     }   }   int getMin(int a, int b) {     if (a < b) {       return a;     } else {       return b;     }   }   void solve(int r, int g, int b) {     int count = 0;     int sum = r + g + b;     int min = getMin(r, g, b);     int max = getMax(r, g, b);     int mid = sum - (min + max);     result = getMin(sum / 2, min + mid);   }   void print(int arr[], int n) {     for (int i = 0; i < n; i++) {       printf( %d  , arr[i]);     }   }   void merge(int a[], int l, int m, int r) {     int n1 = m - l + 1;     int n2 = r - m;     int *L = new int[n1];     int *R = new int[n2];     for (int i = 0; i < n1; i++) {       L[i] = arr[l + i];     }     for (int i = 0; i < n2; i++) {       R[i] = arr[m + 1 + i];     }     int i = 0, j = 0, k = l;     while (i < n1 && j < n2) {       if (L[i] < R[j]) {         arr[k] = L[i];         k++;         i++;       } else {         arr[k] = R[j];         j++;         k++;       }     }     while (i < n1) {       arr[k] = L[i];       k++;       i++;     }     while (j < n2) {       arr[k] = R[j];       k++;       j++;     }   }   void merge(int a[], int l, int r) {     if (l < r) {       int m = l + (r - l) / 2;       merge(arr, l, m);       merge(arr, m + 1, r);       merge(arr, l, m, r);     }   }   int main() {     int n;     int r, g, b;     char ch;     int min = 9999999, max = -9999999;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &r);       if (r > max) {         max = r;       }       scanf( %d , &g);       if (g > max) {         max = g;       }       scanf( %d , &b);       if (b > max) {         max = b;       }       solve(r, g, b);       printf( %d n , result);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     long long a = -1, b = -1;     int flag = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  [ ) {         a = i;         flag = 1;         break;       }     }     if (flag == 0) {       cout <<  -1 ;       return 0;     }     flag = 0;     for (int i = a; i < s.length(); i++) {       if (s[i] ==  : ) {         a = i;         flag = 1;         break;       }     }     if (flag == 0) {       cout <<  -1 ;       return 0;     }     flag = 0;     for (int i = s.length() - 1; i >= 0; i--) {       if (s[i] ==  ] ) {         b = i;         flag = 1;         break;       }     }     if (flag == 0) {       cout <<  -1 ;       return 0;     }     flag = 0;     for (int i = b; i >= 0; i--) {       if (s[i] ==  : ) {         b = i;         flag = 1;         break;       }     }     if (flag == 0) {       cout <<  -1 ;       return 0;     }     if (a >= b) {       cout <<  -1 ;       return 0;     }     long long ans = 4;     for (int i = a + 1; i <= b - 1; i++) {       if (s[i] ==  | ) ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[500005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t, n, m, q, i, j, k, x, y = 2, z;     cin >> n >> k;     set<long long int> s;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n - 1; i++) {       x = a[i] + k;       if (x + k <= a[i + 1]) s.insert(x);       x = a[i + 1] - k;       if (a[i] + k <= x) s.insert(x);     }     cout << s.size() + 2;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 405;   char G[405][405], P[405][405];   bitset<MAXN> nolet[405][27];   int main() {     int N, M;     scanf( %d%d , &N, &M);     for (int i = 0; i < N; ++i) {       scanf( %s , G[i]);       for (int c = 0; c < 26; ++c)         for (int j = 0; j < M; ++j)           if (G[i][j] -  a  != c) nolet[i][c].set(j);     }     int R, C;     scanf( %d%d , &R, &C);     for (int i = 0; i < R; ++i) {       scanf( %s , P[i]);     }     for (int i = 0; i < N; ++i) {       bitset<MAXN> no;       for (int r = 0; r < R; ++r)         for (int c = 0; c < C; ++c) {           if (P[r][c] ==  ? ) continue;           int ii = (i + r) % N;           auto b = nolet[ii][P[r][c] -  a ];           no |= (b >> c) | (b << (M - c));         }       for (int j = 0; j < M; ++j) printf( %d , !no[j]);       printf(  n );     }   }
#include <bits/stdc++.h>   int a[100000];   int main() {     int y, k, n, i;     while (scanf( %d %d %d , &y, &k, &n) != EOF) {       int flag = 0;       int l = n / k;       for (i = 1; i <= l; i++) {         a[i] = i * k;         if (a[i] > y) {           printf( %d  , a[i] - y);           flag = 1;         }       }       if (flag == 0) printf( -1 );       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char a[n][5];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 5; j++) {         cin >> a[i][j];       }     }     int flag = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 4; j++) {         if ((a[i][j] ==  O ) && (a[i][j + 1] ==  O )) {           a[i][j] =  + ;           a[i][j + 1] =  + ;           flag = 1;           break;         }       }       if (flag) break;     }     if (flag) {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= 5; j++) {           cout << a[i][j];         }         cout << endl;       }     } else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int p;   int a[300010];   int ans;   int main() {     int i, j, k;     scanf( %d , &n);     ans = 1;     a[n + 1] = -1;     printf( 1 );     for (k = 1; k <= n; ++k) {       scanf( %d , &p);       if (a[p + 1] == -1) {         i = p - 1;         a[p] = -1;         while ((i > 0) && (a[i] == 1)) {           a[i] = -1;           --ans;           --i;         }       } else {         if (!a[p]) {           a[p] = 1;           ++ans;         }       }       printf(  %d , ans);     }   }