malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int M = 128;   const int inf = 0x7fffffff;   const long long INF = 9E18;   const int mod = 1e9 + 7;   int tree[maxn << 2][2], a[maxn];   int in[maxn], out[maxn], dis[maxn];   int dfs_clock = 0;   vector<int> g[maxn];   void dfs(int u, int fa) {     dis[u] = dis[fa] ^ 1;     in[u] = ++dfs_clock;     for (int i = 0; i < g[u].size(); i++) {       int to = g[u][i];       if (to == fa) continue;       dfs(to, u);     }     out[u] = dfs_clock;   }   void pushdown(int rt, int odd) {     if (tree[rt][odd]) {       tree[rt << 1 | 1][odd] += tree[rt][odd];       tree[rt << 1][odd] += tree[rt][odd];       tree[rt][odd] = 0;     }   }   void update(int x, int y, int l, int r, int val, int odd, int rt) {     if (x <= l && r <= y) {       tree[rt][odd] += val;       return;     }     pushdown(rt, odd);     int mid = (l + r) >> 1;     if (x <= mid) update(x, y, l, mid, val, odd, rt << 1);     if (y > mid) update(x, y, mid + 1, r, val, odd, rt << 1 | 1);   }   int query(int p, int l, int r, int rt, int odd) {     if (l == r) {       return tree[rt][odd];     }     pushdown(rt, odd);     int mid = (l + r) >> 1;     if (p <= mid)       return query(p, l, mid, rt << 1, odd);     else       return query(p, mid + 1, r, rt << 1 | 1, odd);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     dis[0] = 0;     dfs(1, 0);     for (int i = 0; i < m; i++) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, val;         scanf( %d%d , &x, &val);         update(in[x], out[x], 1, n, val, dis[x], 1);         update(in[x], out[x], 1, n, -val, dis[x] ^ 1, 1);       } else {         int num;         scanf( %d , &num);         cout << query(in[num], 1, n, 1, dis[num]) + a[num] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n, q, ans;   int mat[maxn][maxn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int k;         scanf( %d , &k);         if (i == j) {           ans += k;         }       }     }     ans %= 2;     cin >> q;     for (int i = 0; i < q; i++) {       int c;       scanf( %d , &c);       if (c == 1 || c == 2) {         int bucket;         scanf( %d , &bucket);         ans = (ans + 1) % 2;       } else {         printf( %d , ans);       }     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 81;   const int inf = 1e9;   int n, c, a[N];   int dp[N][N][N * N];   vector<int> vc;   int main() {     scanf( %d , &n);     c = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       c += a[i];       if (a[i]) vc.push_back(i);     }     int m = n * (n - 1) / 2;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= c; j++) {         for (int k = 0; k <= m; k++) {           dp[i][j][k] = (j == 0 && k == 0) ? 0 : -inf;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= c; j++) {         for (int k = 0; k <= m; k++) {           if (j > i) continue;           int tmp = vc[j - 1];           for (int p = 1; p <= i; p++) {             int ops = abs(tmp - p);             if (k < ops) continue;             dp[i][j][k] =                 max(dp[i][j][k], dp[p - 1][j - 1][k - ops] + (p - j) * (i - p));           }         }       }     }     int mx = -inf;     for (int i = 0; i <= n * (n - 1) / 2; i++) {       mx = max(mx, dp[n][c][i]);       printf( %d  , mx);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   void cass() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int N = 10;   int n, a[N], res = 1e9, x[N];   string s;   void read() {     cin >> s;     n = 6;     for (int i = 0; i < s.length(); ++i) a[i + 1] = s[i] -  0 ;   }   void cmp() {     int sum1 = x[1] + x[2] + x[3];     int sum2 = x[4] + x[5] + x[6];     if (sum1 != sum2) return;     int dem = 0;     for (int i = 1; i <= n; ++i)       if (a[i] != x[i]) dem++;     res = min(res, dem);   }   void tried(int i) {     for (int j = 0; j <= 9; ++j) {       x[i] = j;       if (i == n)         cmp();       else         tried(i + 1);     }   }   int main() {     cass();     read();     tried(1);     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, q;   int main() {     cin >> n;     int i = 1;     while (q < n) {       if (i % 2)         q++, ans++;       else if (q < n - 1)         q += 2, ans++;       else         break;       i++;     }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>      #define pb push_back   #define x first   #define y second   #define all(a) (a).begin(), (a).end()      using namespace std;      typedef long long ll;   typedef pair<int, int> ii;      const int maxn = 3e5 + 5;      int n, m, X;   ll A[maxn];   int par[maxn];   set<pair<ll, ii>> adj[maxn];   map<ii, int> pos;   set<pair<ll, int>> s;   int exists = 1;      int find(int x) {return (x == par[x]) ? x : par[x] = find(par[x]);}      int merge(int x, int y) {    x = find(x), y = find(y);    if(x == y) return 0;        if(adj[x].size() < adj[y].size()) swap(x, y);    par[y] = x;    s.erase({A[y], y});    s.erase({A[x], x});    A[x] += A[y];    A[x] -= X;    s.insert({A[x], x});    if(A[x] < 0) exists = 0;    for(auto p : adj[y]) adj[x].insert(p);    return 1;   }      int main() {    scanf( %d %d %d , &n, &m, &X);    for(int i = 0;i < n;i++) scanf( %lld , A + i);    for(int i = 0;i < n;i++) par[i] = i;    for(int i = 0;i < m;i++) {     int x, y;     scanf( %d %d , &x, &y);     x--, y--;     if(x > y) swap(x, y);     pos[{x, y}] = i + 1;     adj[x].insert({A[y], {x, y}});     adj[y].insert({A[x], {x, y}});    }        vector<int> ans;    for(int i = 0;i < n;i++) s.insert({A[i], i});    for(int i = 0;i < n - 1;i++) {     auto it1 = s.end();it1--;     auto p1 = *it1;          while(1) {      auto it2 = adj[p1.y].end();it2--;      auto p2 = *it2;      int flag = merge(p2.y.x, p2.y.y);      if(flag) {       ans.pb(pos[{p2.y.x, p2.y.y}]);       break;      }      adj[p1.y].erase(it2);     }     if(!exists) {printf( NO n );return 0;}    }        printf( YES n );    for(int i : ans) printf( %d n , i);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200100;   struct seat {     int w, id;     bool operator<(const seat& st) const { return w < st.w; }     bool operator>(const seat& st) const { return w > st.w; }   };   seat st[maxn];   int n;   char tp[maxn * 2];   int main() {     while (scanf( %d , &n) == 1) {       for (int i = 1; i <= n; i++) {         scanf( %d , &st[i].w);         st[i].id = i;       }       scanf( %s , tp);       sort(st + 1, st + 1 + n);       priority_queue<seat, vector<seat>, less<seat>> que;       int cnt = 1;       for (int i = 0; i < n * 2; i++) {         if (tp[i] ==  0 ) {           printf( %d  , st[cnt].id);           que.push(st[cnt]);           cnt++;         } else {           printf( %d  , que.top().id);           que.pop();         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 9;   int arr[maxn];   int vis[maxn];   int n;   int mu;   long long re[111];   long long gcd(long long a, long long b) {     long long c = 1;     while (b) {       c = a % b;       a = b;       b = c;     }     return a;   }   int sol(int a) {     vis[a] = 1;     int e = arr[a];     if (vis[e]) {       if (e == mu) {         return 1;       } else {         return -1;       }     } else {       int g = sol(e);       if (g == -1)         return -1;       else         return g + 1;     }   }   int main() {     int a, b, c, d, e, f, g, h;     while (scanf( %d , &n) == 1) {       for (d = 1; d <= n; d++) {         scanf( %d , &arr[d]);       }       memset(vis, 0, sizeof(vis));       g = 0;       h = 0;       a = 0;       for (d = 1; d <= n; d++) {         if (!vis[d]) {           mu = d;           e = sol(d);           if (e == -1) {             g = -1;             break;           }           if (e % 2) {             re[a++] = e;           } else             re[a++] = e / 2;         }       }       if (g < 0) {         printf( -1 n );       } else {         long long res = 1, tmp;         for (d = 0; d < a; d++) {           tmp = gcd(res, re[d]);           res = res * re[d] / tmp;         }         cout << res << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int ar[500009], br[500009];   int main() {     long long int a, b, c, i, j = 999999999999, k, e, f, g, w, h, i1, j1;     string s, d;     cin >> a >> b >> c;     e = a;     c = c * 5;     j = a;     for (i = 1;; i++) {       a = e;       if (a - (i * b) < 0) {         break;       }       a = a - (i * b);       a = a - ((a / c) * c);       j = min(j, a);     }     for (i = 1;; i++) {       a = e;       if (a - (i * c) < 0) {         break;       }       a = a - (i * c);       a = a - ((a / b) * b);       j = min(j, a);     }     cout << j << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cerr << *i <<    ;     cerr << endl;   }   int main() {     for (long long N, M; cin >> N >> M;) {       for (int i = 0; i < (int)(N); ++i) {         long long S, F, T;         cin >> S >> F >> T;         if (S == F) {           cout << T << endl;           continue;         }         long long loop = (M - 1) * 2;         long long ans = 0;         if (S < F) {           ans = T / loop * loop;           T = T % loop;           if (S - 1 < T) ans += (M - 1) * 2;           ans += F - 1;         } else {           ans = T / loop * loop;           T = T % loop;           if (M - S + M - 1 < T) ans += (M - 1) * 2;           ans += M - 1;           ans += (M - F);         }         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[300001], d[300001];   long long b[300001], c[300001];   map<int, int> mp;   int main() {     int n, i, l, r, j, k;     long long s, _s;     for (scanf( %d , &n), i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = b[i - 1] + a[i];       c[i] = c[i - 1] + (a[i] > 0 ? a[i] : 0);       d[i] = d[i - 1] + (a[i] < 0);       if (!mp.count(a[i])) mp[a[i]] = i;     }     for (i = n, s = 1ll << 63; i; i--) {       j = mp[a[i]];       if (i == j) continue;       _s = c[i] - c[j - 1];       if (a[i] < 0) _s += 2 * a[i];       if (_s > s) {         s = _s;         l = j;         r = i;       }     }     printf( %I64d %d n , s, d[r - 1] - d[l] + l - 1 + n - r);     for (i = 1; i < l; i++) printf( %d  , i);     for (i = l + 1; i < r; i++) {       if (a[i] < 0) printf( %d  , i);     }     for (i = r + 1; i <= n; i++) printf( %d  , i);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> x_coord, y_coord;   vector<vector<int>> adj;   vector<bool> used;   int n;   void dfs(int v) {     used[v] = true;     for (auto u : adj[v]) {       if (!used[u]) {         used[u] = true;         dfs(u);       }     }   }   int main() {     scanf( %d , &n);     x_coord.resize(n);     y_coord.resize(n);     adj.resize(n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x_coord[i], &y_coord[i]);       for (int j = 0; j < i; j++) {         if (x_coord[j] == x_coord[i] || y_coord[j] == y_coord[i]) {           adj[i].push_back(j);           adj[j].push_back(i);         }       }     }     used.resize(n, false);     int cnt = 0;     for (int i = 0; i < n; i++) {       if (!used[i]) {         cnt++;         dfs(i);       }     }     printf( %d n , cnt - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int inf = 1e9;   int t, n, a[N], b[N];   int gao(int x) {     int res = b[1] - x;     for (int i = 2; i <= n; i++) {       res = b[i] - max(a[i] - res, 0);       if (res < 0) return -1;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) cin >> b[i];       int l = 0, r = b[1], ans = 0;       while (l <= r) {         int mid = l + r >> 1;         int ret = gao(mid);         if (ret == -1) {           r = mid - 1;         } else           l = mid + 1;         if (ret != -1 && ret + mid >= a[1]) {           ans = 1;         }       }       if (ans)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, mini = 0, maxi = 0;   int x[200005];   bool o[200005];   int main() {     cin >> n;     for (int i = 0; i < (n); i++) {       int a;       cin >> a;       x[a]++;     }     for (int i = 0; i < (n + 1); i++) {       while (i < n + 1 && x[i] == 0) i++;       if (i == n + 1) break;       mini++;       i += 2;     }     for (int i = 0; i < (n + 1); i++) {       while (i < n + 1 && x[i] == 0) i++;       if (i == n + 1) break;       for (int j = 0; j < (min(3, x[i])); j++) {         if (!o[i - 1]) {           o[i - 1] = true;           maxi++;         } else if (!o[i]) {           o[i] = true;           maxi++;         } else if (!o[i + 1]) {           o[i + 1] = true;           maxi++;         }       }     }     cout << mini <<     << maxi << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     char ar[n];     for (int i = 0; i < n; ++i) {       cin >> ar[i];     }     int co = 0;     vector<int> po;     for (int i = 0; i < n - 1; ++i) {       if (ar[i] ==  W ) {         ar[i] =  B ;         co++;         po.push_back(i + 1);         if (ar[i + 1] ==  B ) {           ar[i + 1] =  W ;         } else {           ar[i + 1] =  B ;         }       }     }     if (ar[n - 1] ==  B ) {       cout << co << endl;       for (int i = 0; i < po.size(); ++i) {         cout << po[i] <<    ;       }       cout << endl;     } else {       if (n % 2 == 0) {         cout << -1 << endl;       } else {         cout << co + (n - 1) / 2 << endl;         for (int i = 0; i < po.size(); ++i) {           cout << po[i] <<    ;         }         for (int i = 0; i < (n - 1) / 2; ++i) {           cout << 2 * i + 1 <<    ;         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long int mod = 1e9 + 7;   long long int pmod(long long int x, long long int n) {     long long int r = 1;     while (n) {       if (n & 1LL) r = (r * x) % mod;       x = (x * x) % mod;       n = n / 2;     }     return r;   }   void solve() {     long long int a, b;     cin >> a >> b;     if (a < b) {       cout << -1;       return;     }     long long int d1 = (a + b) / 2;     d1 /= b;     d1 = d1 * 2;     double ans = (double)(a + b) / d1;     cout << setprecision(10) << ans;   }   int main() {     fast();     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 2) cout << -1;     if (n == 3) cout << 210;     if (n >= 4) {       string s =  1 ;       int sign;       int z = 0;       if (n % 3 == 0) z = 100;       if (n % 3 == 1) z = 1;       if (n % 3 == 2) z = 10;       if (((n - 1) / 3) % 2 == 0)         sign = 1;       else         sign = -1;       for (int i = 1; i < n; i++) s +=  0 ;       bool OK = false;       for (char i =  0 ; i <=  9 ; i++) {         for (char j =  0 ; j <=  9 ; j++) {           s[n - 2] = j;           s[n - 3] = i;           if (((1 + s[n - 2] -  0  + s[n - 3] -  0 ) % 3 == 0) &&               (((s[n - 3] -  0 ) * 100 + (s[n - 2] -  0 ) * 10 + z * sign) % 7 ==                0)) {             cout << s;             OK = true;             break;           }         }         if (OK) break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long long k;     cin >> n >> k;     if (!k) {       cout <<  0 n ;       return 0;     }     vector<int> h(n);     for (int i = 0; i < n; i++) {       cin >> h[i];     }     h.push_back(h[0]);     long long** dp;     dp = new long long*[n + 79];     for (int i = 0; i < n + 2; i++) {       dp[i] = new long long[2 * n + 79];       for (int j = 0; j < 2 * n + 79; j++) {         dp[i][j] = 0;       }     }     dp[0][n + 1] = 1;     for (int i = 1; i <= n; i++) {       for (int score = 1; score <= 2 * n + 2; score++) {         if (h[i] != h[i - 1]) {           dp[i][score] += dp[i - 1][score - 1];           dp[i][score] += dp[i - 1][score + 1];           dp[i][score] += (dp[i - 1][score] * (k - 2ll)) % mod;         } else {           dp[i][score] = dp[i - 1][score] * k;         }         dp[i][score] %= mod;       }     }     long long ans = 0;     for (int score = n + 2; score <= 2 * n + 1; score++) {       ans += dp[n][score];     }     cout << (ans % mod) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, x, i, p;     char y;     string ch =   ;     cin >> n >> k;     for (i = 0; i < k; i++) {       p = 97 + i;       y = (char)p;       ch += y;     }     if (n == k)       cout << ch;     else {       x = n - k;       i = 0;       while (x--) {         ch += ch[i];         i++;       }       cout << ch;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const long long inf = 1e15 + 7;   bool check(long long n) { return __builtin_popcount(n + 1) == 1; }   vector<long long> res;   bool solve(long long n, long long k, long long par) {     if (n == 11 && k == 3) {       res[10] = par;       res[9] = 10;       res[8] = 9;       res[7] = 9;       return solve(7, 2, 10);     }     if (k <= 1) {       if ((!check(n) && k == 0) || (check(n) && k == 1)) return false;       res[0] = par;       for (long long i = 1; i < n; i++) res[i] = (i - 1) / 2;       return true;     }     if (k == 2 && check(n - 2)) {       res[n - 1] = par;       res[n - 2] = n - 1;       res[n - 3] = n - 2;       res[n - 4] = n - 2;       return solve(n - 4, k - 1, n - 1);     }     res[n - 1] = par;     res[n - 2] = n - 1;     return solve(n - 2, k - 1, n - 1);   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     long long n, k;     cin >> n >> k;     if (n == 1 && k == 0) {       cout <<  YES  << endl << 0;       return 0;     }     if (n % 2 == 0 || (n - 3) / 2 < k || (k == 0 && !check(n)) ||         (k == 1 && check(n)) || (k == 2 && n == 9)) {       cout <<  NO ;       return 0;     }     res.resize(n);     bool temp = solve(n, k, -1);     if (!temp) cout <<  Bad  << endl;     cout <<  YES  << endl;     for (long long i : res) cout << i + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[1001], x;   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &x);       a[x]++;     }     sort(a + 1, a + n + 1);     printf( %d n , a[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int binary_exp(long long int a, long long int n) {     long long int i = 1;     while (n > 0) {       if (n % 2 == 1) i = (i * a) % 1000000007;       a = (a * a) % 1000000007;       n /= 2;     }     return i;   }   long long int IsPrime(long long int n) {     if (n == 0 || n == 1) return n;     if (n % 2 == 0) return (long long int)2;     if (n % 3 == 0)       return (long long int)3;     else {       for (long long int i = 5; i * i <= n; i += 6) {         if (n % i == 0) return i;         if (n % (i + 2) == 0) return (i + 2);       }       return n;     }   }   void solve() {     int n, i, j, k, a, b, mex = 1, ans = 0;     cin >> n;     int ind[n + 1];     bool vis[n + 1];     memset(vis, false, sizeof(vis));     for (i = 1; i <= n; i++) {       cin >> k;       ind[k] = i;     }     for (i = 1; i <= n; i++) {       cin >> k;       vis[ind[k]] = true;       while (mex <= n && vis[mex]) mex++;       if (ind[k] > mex) ans++;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     ;     int t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 3e5 + 5, inf = 1e9 + 7;   long long int bigmod(long long int b, long long int p, long long int m) {     long long int rt = 1;     while (p) {       if (p & 1) rt = (rt * b) % m;       b = (b * b) % m;       p >>= 1;     }     return rt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, t = 0;     while (tc--) {       long long int x, n;       cin >> x >> n;       vector<long long int> prim;       for (int i = 2; i * i <= x; i++) {         if (x % i == 0) {           prim.push_back(i);           while (x % i == 0) x /= i;         }       }       if (x > 1) prim.push_back(x);       long long int rs = 1;       for (auto x : prim) {         long long int fact = x, pw = 0;         while (fact <= n) {           pw += n / fact;           if (n / x >= fact)             fact *= x;           else             break;         }         rs *= bigmod(x, pw, inf);         rs %= inf;       }       cout << rs <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int a[6];     for (int i = 0; i < 6; i++) scanf( %d , &a[i]);     int tot = a[0] + a[1] + a[2];     int ans = tot * tot - a[0] * a[0] - a[2] * a[2] - a[4] * a[4];     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const unsigned long long hash1 = 201326611;   const unsigned long long hash2 = 50331653;   const int N = 200000 + 10;   const int M = 20;   vector<int> g[N];   int n, vis[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     int u, v;     for (int i = 1; i < n; i++) {       cin >> u >> v;       vis[u]++;       vis[v]++;     }     int flag = 0;     for (int i = 1; i <= n; i++) {       if (vis[i] == 2) flag = 1;     }     if (flag)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }