malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 5;   vector<vector<pair<long long, long long> > > dis(maxn);   long long flag[maxn];   long long c1, c2;   bool ok;   void dfs(long long index, long long p) {     flag[index] = p;     for (long long i = 0; i < dis[index].size(); i++) {       if (flag[dis[index][i].first] != -1 &&           flag[dis[index][i].first] != (dis[index][i].second == p))         ok = false;       if (flag[dis[index][i].first] == -1) {         if (dis[index][i].second == p) {           c1++;         } else           c2++;         dfs(dis[index][i].first, dis[index][i].second == p);       }     }   }   signed main() {     long long t;     cin >> t;     memset(flag, -1, sizeof(flag));     while (t--) {       long long n, m;       cin >> n >> m;       long long x, y;       string s;       while (m--) {         cin >> x >> y >> s;         if (s[0] ==  c ) {           dis[x].push_back({y, 1});           dis[y].push_back({x, 1});         } else {           dis[x].push_back({y, 0});           dis[y].push_back({x, 0});         }       }       long long ans = 0;       ok = true;       for (long long i = 1; i <= n; i++) {         if (flag[i] == -1) {           c1 = 1, c2 = 0;           dfs(i, 1);           ans += max(c1, c2);         }       }       for (long long i = 1; i <= n; i++) {         dis[i].clear();         flag[i] = -1;       }       if (!ok)         cout <<  -1  << endl;       else         cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, Q;   vector<int> E[200005];   int P[21][200005], D[200005];   void dfs(int cur) {     for (__typeof(E[cur].begin()) it = E[cur].begin(); it != E[cur].end(); it++)       if (*it != P[0][cur]) D[*it] = D[cur] + 1, P[0][*it] = cur, dfs(*it);   }   int lca(int a, int b) {     int ret = 0, i, aa = a, bb = b;     if (D[aa] > D[bb]) swap(aa, bb);     for (i = 19; i >= 0; i--)       if (D[bb] - D[aa] >= 1 << i) bb = P[i][bb];     for (i = 19; i >= 0; i--)       if (P[i][aa] != P[i][bb]) aa = P[i][aa], bb = P[i][bb];     return (aa == bb) ? aa : P[0][aa];   }   int dist(int a, int b) { return D[a] + D[b] - 2 * D[lca(a, b)]; }   int hoge(int S, int T, int F) {     int ST = lca(S, T);     int FT = lca(F, T);     int SF = lca(S, F);     int STD = dist(S, T);     int FTD = dist(F, T);     int SFD = dist(S, F);     if (SFD + STD == FTD) return STD + 1;     if (SFD + FTD == STD) return FTD + 1;     if (D[ST] > D[SF]) {       return D[T] - D[ST] + 1;     } else if (D[FT] > D[SF]) {       return D[T] - D[FT] + 1;     } else {       return dist(SF, T) + 1;     }   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> Q;     for (i = 0; i < (N - 1); i++) {       cin >> x;       E[i + 1].push_back(x - 1);       E[x - 1].push_back(i + 1);     }     dfs(0);     for (i = 0; i < (19); i++)       for (x = 0; x < (N); x++) P[i + 1][x] = P[i][P[i][x]];     while (Q--) {       int A, B, C;       cin >> A >> B >> C;       A--, B--, C--;       cout << max({hoge(A, B, C), hoge(A, C, B), hoge(B, A, C)}) << endl;     }   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> p[2005 * 2005];   char a[2005][2005], cg[4] = { v ,  < ,  ^ ,  > };   int n, m, mox[4] = {-1, 0, 1, 0}, moy[4] = {0, 1, 0, -1};   int ispoint(int x, int y) {     return (x >= 0 && x < n && y >= 0 && y < m && a[x][y] ==  . );   }   int deg(int x, int y) {     int ans = 0;     for (int i = 0; i < 4; i++) {       int fx = x + mox[i];       int fy = y + moy[i];       if (ispoint(fx, fy)) ans++;     }     return ans;   }   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       for (int i = 0; i < n; i++) scanf( %s , a[i]);       int h = 0, sum = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (ispoint(i, j) && deg(i, j) == 1) p[sum++] = make_pair(i, j);       for (; h < sum; h++) {         int x = p[h].first, y = p[h].second;         for (int i = 0; i < 4; i++) {           int fx = x + mox[i];           int fy = y + moy[i];           if (ispoint(fx, fy)) {             a[x][y] = cg[i];             a[fx][fy] = cg[i ^ 2];             for (int i = 0; i < 4; i++) {               int ffx = fx + mox[i];               int ffy = fy + moy[i];               if (ispoint(ffx, ffy) && deg(ffx, ffy) == 1)                 p[sum++] = make_pair(ffx, ffy);             }             break;           }         }       }       int flag = 0;       for (int i = 0; i < n && !flag; i++)         for (int j = 0; j < m && !flag; j++)           if (a[i][j] ==  . ) flag = 1;       if (flag == 1)         printf( Not unique n );       else {         for (int i = 0; i < n; i++, printf(  n ))           for (int j = 0; j < m; j++) printf( %c , a[i][j]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long oo = 1e9 + 7;   const int mod = 1e9 + 7;   double x, y, tmp;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> x >> y;     tmp = log(x) / log(y);     if (tmp * y * 1.00 < x)       cout <<  < ;     else if (tmp * y * 1.00 > x)       cout <<  > ;     else       cout <<  = ;   }
#include <bits/stdc++.h>   using namespace std;   void myassert(bool expr) {     if (!expr) abort();   }   const int64_t posinf = 9223372036854775807LL;   const int64_t neginf = 9223372036854775808LL;   const int64_t bigprime = (1LL << 61) - 1LL;   const int64_t mult = 199;   const int64_t mult2 = 3571;   const int64_t mod = 1000000007LL;   const int64_t mod2 = 1000000009LL;   const long double pi = 3.1415926535897932384626433832795L;   template <typename T>   T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   char mtx[1024][1024];   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> mtx[i];       for (int j = 0; j < m; j++)         if (mtx[i][j] ==  b ) mtx[i][j] =  f ;     }     char lets[4] = { a ,  b ,  c ,  d };     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mtx[i][j] ==  f ) {           cout <<  NO ;           return 0;         }         if (mtx[i][j] !=  w ) continue;         if (mtx[i][j + 1] ==  f  && mtx[i][j + 2] ==  w ) {           mtx[i][j] = mtx[i][j + 1] = mtx[i][j + 2] =               lets[(i + (j + 1) / 2 * 2) % 4];         } else if (mtx[i + 1][j] ==  f  && mtx[i + 2][j] ==  w ) {           mtx[i][j] = mtx[i + 1][j] = mtx[i + 2][j] =               lets[(i + 1 + j / 2 * 2) % 4];         } else {           cout <<  NO ;           return 0;         }       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (mtx[i][j] ==  f  || mtx[i][j] ==  w ) {           cout <<  NO ;           return 0;         }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) cout << mtx[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.14159265358979;   vector<pair<int, int> > A[100001];   int main() {     int n, m, a, b;     scanf( %d%d , &n, &m);     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         q;     vector<int> ans;     for (int i = 0; i < m; ++i) {       scanf( %d%d , &a, &b);       A[min(a, n + 1 - b)].push_back(make_pair(max(a, n + 1 - b), i + 1));     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < A[i].size(); ++j) {         q.push(A[i][j]);       }       while (!q.empty()) {         pair<int, int> t = q.top();         if (t.first < i)           q.pop();         else           break;       }       if (!q.empty()) {         ans.push_back(q.top().second);         q.pop();       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, e;     cin >> s >> e;     int h1, m1, h2, m2;     h1 = (s[0] -  0 ) * 10 + (s[1] -  0 );     h2 = (e[0] -  0 ) * 10 + (e[1] -  0 );     m1 = (s[3] -  0 ) * 10 + (s[4] -  0 );     m2 = (e[3] -  0 ) * 10 + (e[4] -  0 );     long long int total1 = h1 * 60 + m1;     long long int total2 = h2 * 60 + m2;     long long int dif = (total2 - total1) / 2;     int ansh = dif / 60;     int ansm = dif % 60;     int fh = h1 + ansh;     int fm = m1 + ansm;     if (fm >= 60) {       fh += 1;       fm %= 60;     }     if (fh > 9) {       cout << fh <<  : ;     } else {       cout <<  0  << fh <<  : ;     }     if (fm > 9) {       cout << fm << endl;     } else {       cout <<  0  << fm << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 0;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] == s[i + 1]) {         c++;         if (c >= 6) break;       } else if (s[i] != s[i + 1]) {         c = 0;       }     }     if (c >= 6) {       cout <<  YES  << endl;     } else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   namespace Sa {   struct Node {     double x, y;     Node() {}     Node(double x, double y) : x(x), y(y) {}     Node operator-(Node a) const { return Node(x - a.x, y - a.y); }     double operator*(Node a) const { return x * a.y - y * a.x; }   } a[1], b[1];   double l, r, Mid, Ans, Now, x, y, Ax, T, N2;   int i, j, k, n, m;   inline double Getrand() { return rand() % 1000 / 1000.0; }   inline double Gety(double x) {     for (int i = 1; i < n; i++)       if (a[i + 1].x > x)         return (a[i + 1].y - a[i].y) / (a[i + 1].x - a[i].x) * (x - a[i].x) +                a[i].y;   }   inline bool Check(Node A) {     for (int i = 1; i < n; i++)       if ((A - a[i]) * (A - a[i + 1]) < 0) return 0;     return 1;   }   inline double Calc(double x) {     double l = 0, r = 0, Mid;     while (r - l > 1) {       Mid = (l + r) / 2.0;       if (Check(Node(x, Mid)))         r = Mid;       else         l = Mid;     }     l -= Gety(x);     if (l < Ans) Ans = l, Ax = x;     return l;   }   inline void SA(double T) {     for (; T > 0.00001; T *= 0.99) {       y = x + T * (Getrand() * 2 - 1);       if (y < a[1].x || y > a[n].x) continue;       N2 = Calc(x) - Calc(y);       if (N2 > 0 || exp(N2 / T) > Getrand()) x = y;     }     for (int i = 1; i <= 1000; i++) {       y = Ax + T * (Getrand() * 2 - 1);       if (y < a[1].x || y > a[n].x) continue;       Calc(y);     }   }   }  // namespace Sa   int main() {     int t = read();     while (t--) {       int n = read();       double T = n;       if (n * n < 4 * n) {         printf( N n );         continue;       }       double a = (T + sqrt(T * T - 4.0 * T)) / 2.0;       double b = (T - sqrt(T * T - 4.0 * T)) / 2.0;       printf( Y %.10f %.10f n , a, b);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long sum = 0, cyl = 0;       long long k = (n / m);       for (int i = 1; i <= 10; ++i) {         cyl += (m * i) % 10;       }       sum = (k / 10) * cyl;       cyl = 0;       for (int i = 1; i <= k % 10; ++i) {         cyl += m * (i) % 10;       }       cout << sum + cyl << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     if (a < max(c, d) || b < max(c, d)) {       printf( -1 n );     } else if (c == 0 && d == 0) {       for (int i = 0; i < a; i++) printf( 4 );       for (int i = 0; i < b; i++) printf( 7 );       printf(  n );     } else if (c == d) {       if (a == b && a == c) {         printf( -1 n );       } else if (a == c) {         for (int i = 0; i < c; i++) printf( 74 );         for (int i = 0; i < b - c; i++) printf( 7 );         printf(  n );       } else if (b == c) {         for (int i = 0; i < a - c; i++) printf( 4 );         for (int i = 0; i < c; i++) printf( 74 );         printf(  n );       } else {         for (int i = 0; i < a - c - 1; i++) printf( 4 );         for (int i = 0; i < c; i++) printf( 47 );         for (int i = 0; i < b - c; i++) printf( 7 );         printf( 4 );         printf(  n );       }     } else if (c - d == 1) {       for (int i = 0; i < a - c; i++) printf( 4 );       for (int i = 0; i < c; i++) printf( 47 );       for (int i = 0; i < b - c; i++) printf( 7 );       printf(  n );     } else if (d - c == 1) {       printf( 74 );       for (int i = 0; i < a - d; i++) printf( 4 );       for (int i = 0; i < d - 2; i++) printf( 74 );       for (int i = 0; i < b - d; i++) printf( 7 );       printf( 74 );       printf(  n );     } else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 10e-12;   int n, n1, n2;   int dig[10] = {       (1 << (1)) | (1 << (2)) | (1 << (3)) | (1 << (5)) | (1 << (6)) | (1 << (7)),       (1 << (3)) | (1 << (6)),       (1 << (1)) | (1 << (3)) | (1 << (4)) | (1 << (5)) | (1 << (7)),       (1 << (1)) | (1 << (3)) | (1 << (4)) | (1 << (6)) | (1 << (7)),       (1 << (2)) | (1 << (3)) | (1 << (4)) | (1 << (6)),       (1 << (1)) | (1 << (2)) | (1 << (4)) | (1 << (6)) | (1 << (7)),       (1 << (1)) | (1 << (2)) | (1 << (5)) | (1 << (4)) | (1 << (6)) | (1 << (7)),       (1 << (1)) | (1 << (3)) | (1 << (6)),       (1 << (1)) | (1 << (2)) | (1 << (3)) | (1 << (4)) | (1 << (5)) |           (1 << (6)) | (1 << (7)),       (1 << (1)) | (1 << (2)) | (1 << (3)) | (1 << (4)) | (1 << (6)) | (1 << (7)),   };   int main() {     ios::sync_with_stdio(false);     cin >> n;     n1 = n / 10;     n2 = n % 10;     int a, b;     a = b = 0;     for (int i = 0; i < 10; i++) {       if (((dig[n1]) & dig[i]) == dig[n1]) {         a++;       }       if (((dig[n2]) & dig[i]) == dig[n2]) {         b++;       }     }     cout << a * b <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, n, m;     while (cin >> n >> k) {       if (n * (n - 1) / 2 <= k) {         puts( no solution );       } else {         for (i = 0; i < n; i++) printf( 0 %d n , i);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q;     scanf( %d , &n);     bool grid[n + 1][n + 1], ans = false;     string s;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &grid[i][j]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         ans ^= (grid[j][i] && grid[i][j]);       }     }     scanf( %d , &q);     while (q--) {       int t;       scanf( %d , &t);       if (t == 1 || t == 2) {         scanf( %d , &t);         ans ^= 1;       } else         s += (ans +  0 );     }     printf( %s , s.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long k, ans, a[501], i, g, n;   long long check(long long x) {     k = 0;     if (x == 1) return 0;     for (long long i = 1; i <= n; i++)       if (a[i] / (x - 1) * x < a[i])         return 0;       else         k += (a[i] + x - 1) / x;     if (k < ans) ans = k;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i] / 2 + a[i] % 2;     sort(a + 1, a + n + 1);     for (i = 2; i <= sqrt(a[n]) + 2; i++) check(i);     for (i = 1; i <= sqrt(a[n]); i++) {       g = a[n] / i, check(g), check(g + 1), check(g + 2);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   inline int nxt() {     int x;     scanf( %d , &x);     return x;   }   const int N = 55;   int a[N][N];   char skdjflfsdj[N][N];   int score[N];   void add(int u, int v, int x) {     a[u][v] += x;     score[u] += x;   }   vector<int> all_out(int v, int n) {     vector<char> used(n);     vector<int> st = {v};     used[v] = 1;     vector<int> par(n, -1);     while (!st.empty()) {       int u = st.back();       st.pop_back();       for (int i = 0; i < n; ++i) {         if (!skdjflfsdj[i][u] && a[u][i]) {           if (!used[i]) {             used[i] = 1;             par[i] = u;             st.push_back(i);           }         }       }     }     return par;   }   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int n = nxt(), m = nxt();     for (int i = 0; i < m; ++i) {       int u = nxt() - 1, v = nxt() - 1;       add(u, v, 1);       skdjflfsdj[u][v] = skdjflfsdj[v][u] = 1;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < i; ++j) {         if (!skdjflfsdj[i][j]) {           if (rng() % 2) {             add(i, j, 1);           } else {             add(j, i, 1);           }         }       }     }     while (true) {       bool ok = false;       for (int i = 0; i < n; ++i) {         if (ok) {           break;         }         auto par = all_out(i, n);         for (int j = 0; j < n; ++j) {           if (i != j && par[j] > -1 && score[j] < score[i] - 1) {             for (int u = j; u != i; u = par[u]) {               add(u, par[u], 1);               add(par[u], u, -1);             }             ok = true;             break;           }         }       }       if (!ok) {         break;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cout << a[i][j];       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 256;   int getNum(char tch) {     int num = tch;     char ch[10];     int cnt = 0;     while (cnt < 8) {       ch[cnt++] = num % 2 +  0 ;       num /= 2;     }     num = 0;     for (int i = 0; i < 8; i++) {       num = num * 2 + (ch[i] -  0 );     }     return num;   }   int main() {     char ch[1000];     gets(ch);     int len = strlen(ch);     int pre = 0;     for (int i = 0; i < len; i++) {       int tmp = getNum(ch[i]);       cout << (pre - tmp + 10 * 256) % mod << endl;       pre = tmp;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[100001];     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a[i];     }     sort(a + 1, a + 1 + m);     int ans = 100000000;     for (int i = 1; i <= m - n + 1; i++) {       ans = min(ans, a[i + n - 1] - a[i]);     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma warning(disable : 6031)   #pragma warning(disable : 4101)   using namespace std;   const int INF = 1e9;   const long long LINF = 1e18;   const double PI = acos(-1);   const int MAXN = 1000006;   int n, m, v1, v2, Deg[MAXN], visited[MAXN];   vector<unordered_set<int>> G;   vector<int> C;   set<pair<int, int>> erased;   void find_component(int v) {     visited[v] = true;     C.push_back(v);     for (int c : G[v]) {       if (!visited[c]) {         find_component(c);       }     }   }   void eulerian_cycle(int v) {     stack<int> S;     vector<int> ans;     S.push(v);     while (!S.empty()) {       int s = S.top();       if (G[s].empty()) {         ans.push_back(s);         S.pop();       } else {         int c = *G[s].begin();         G[s].erase(G[s].begin());         G[c].erase(s);         S.push(c);       }     }     int ans_size = ((int)(ans).size());     for (int i = 1; i < ((int)(ans).size()); i += 2) {       if (ans[i] != 0 && ans[i + 1] != 0) {         if (ans[i - 1] != 0 && ans[(i + 2) % ans_size] != 0) {           if (ans[i] < ans[i + 1]) {             erased.erase({ans[i], ans[i + 1]});           } else {             erased.erase({ans[i + 1], ans[i]});           }         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     G.resize(n + 1);     while (m--) {       scanf( %d%d , &v1, &v2);       G[v1].insert(v2);       G[v2].insert(v1);       if (v1 < v2) {         erased.insert({v1, v2});       } else {         erased.insert({v2, v1});       }       Deg[v1]++;       Deg[v2]++;     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) {         assert(G[0].empty());         C.clear();         find_component(i);         if (((int)(C).size()) == 1) {           continue;         }         for (int v : C) {           if (Deg[v] % 2 == 1) {             G[0].insert(v);             G[v].insert(0);           }         }         eulerian_cycle(C.front());       }     }     printf( %d n , ((int)(erased).size()));     for (pair<int, int> p : erased) {       printf( %d %d n , p.first, p.second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void desperate_optimization(int precision) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.setf(ios::showpoint);     cout.precision(precision);   }   const int N = 2e5;   int arr[N + 5];   int pre[N + 5];   int mark[N + 5];   vector<int> lis;   void hora(int tc) {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       mark[i] = 1;       if (lis.size() == 0 || arr[lis.back()] < arr[i]) {         pre[i] = -1;         if (lis.size() != 0) pre[i] = lis.back();         lis.push_back(i);       } else {         int lo = 0;         int hi = lis.size() - 1;         int res = -1;         while (lo <= hi) {           int mid = (lo + hi) / 2;           if (arr[lis[mid]] >= arr[i]) {             res = mid;             hi = mid - 1;           } else             lo = mid + 1;         }         lis[res] = i;         pre[i] = -1;         if (res != 0) pre[i] = lis[res - 1];       }     }     int tmp = lis.back();     for (int i = 0; i < n; i++) {       if (pre[tmp] == pre[i] && arr[tmp] < arr[i]) tmp = i;     }     while (tmp != -1) {       mark[tmp] = 0;       tmp = pre[tmp];     }     int hi = 1e9;     int lo = -1;     bool ada = true;     for (int i = 0; i < n; i++) {       if (mark[i] == 0) {         if (lo >= arr[i]) ada = false;         lo = arr[i];       } else {         if (hi <= arr[i]) ada = false;         hi = arr[i];       }     }     if (ada == false) {       lis.clear();       for (int i = 0; i < n; i++) {         mark[i] = 0;         if (lis.size() == 0 || arr[lis.back()] > arr[i]) {           pre[i] = -1;           if (lis.size() != 0) pre[i] = lis.back();           lis.push_back(i);         } else {           int lo = 0;           int hi = lis.size() - 1;           int res = -1;           while (lo <= hi) {             int mid = (lo + hi) / 2;             if (arr[lis[mid]] <= arr[i]) {               res = mid;               hi = mid - 1;             } else               lo = mid + 1;           }           lis[res] = i;           pre[i] = -1;           if (res != 0) pre[i] = lis[res - 1];         }       }       int tmp = lis.back();       for (int i = 0; i < n; i++) {         if (pre[tmp] == pre[i] && arr[tmp] > arr[i]) tmp = i;       }       while (tmp != -1) {         mark[tmp] = 1;         tmp = pre[tmp];       }       int hi = 1e9;       int lo = -1;       bool ada = true;       for (int i = 0; i < n; i++) {         if (mark[i] == 0) {           if (lo >= arr[i]) ada = false;           lo = arr[i];         } else {           if (hi <= arr[i]) ada = false;           hi = arr[i];         }       }       if (ada == false)         cout <<  NO  <<   n ;       else {         cout <<  YES  <<   n ;         for (int i = 0; i < n; i++) cout << mark[i] <<    ;         cout <<   n ;       }     } else {       cout <<  YES  <<   n ;       for (int i = 0; i < n; i++) cout << mark[i] <<    ;       cout <<   n ;     }   }   int main() {     desperate_optimization(10);     int ntc = 1;     for (int tc = 1; tc <= ntc; tc++) hora(tc);     return 0;   }