malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <class T>   void na(vector<T>& a, int n) {     a = vector<T>(n);     for (T& i : a) cin >> i;   }   template <class T>   void printVector(vector<T>& a) {     for (T& i : a) cout << i <<    ;     cout <<   n ;   }   template <class T>   vector<T> shrink(vector<T>& x) {     vector<T> vals = x;     sort((vals).begin(), (vals).end());     (vals).resize(unique((vals).begin(), (vals).end()) - (vals).begin());     for (T& i : x)       i = upper_bound((vals).begin(), (vals).end(), i) - vals.begin();     return vals;   }   const int N = 5555;   int n;   bool gmat[N][N];   vector<int> g[N];   bool found = false;   bool onstack[N], seen[N];   stack<int> stk;   vector<int> cycle;   void dfs(int u) {     onstack[u] = 1;     seen[u] = 1;     stk.push(u);     for (int v : g[u]) {       if (found) return;       if (onstack[v]) {         found = true;         int cur = u;         cycle.push_back(cur);         do {           stk.pop();           cur = stk.top();           cycle.push_back(cur);         } while (cur != v);         return;       }       if (!seen[v]) dfs(v);     }     onstack[u] = false;     stk.pop();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie();     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         char c;         cin >> c;         if (c ==  1 ) g[i].push_back(j), gmat[i][j] = 1;       }     for (int i = 1; i <= n && !found; ++i)       if (!seen[i]) dfs(i);     reverse((cycle).begin(), (cycle).end());     if (!found)       cout <<  -1 n ;     else {       int j = 1, k = 2;       while (k < ((int)(cycle).size())) {         if (gmat[cycle[k]][cycle[0]]) {           cout << cycle[0] <<     << cycle[j] <<     << cycle[k] <<   n ;           break;         }         ++k, ++j;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, f;   bool ju2(long long x, long long y) {     x -= c, y -= d;     long long div = e * e + f * f;     if (!div) return x == 0 && y == 0;     return (e * x + f * y) % div == 0 && (e * y - f * x) % div == 0;   }   bool ju1() {     if (ju2(a, b)) return 1;     if (ju2(-a, -b)) return 1;     if (ju2(-b, a)) return 1;     if (ju2(b, -a)) return 1;     return 0;   }   signed main() {     scanf( %lld%lld%lld%lld%lld%lld , &a, &b, &c, &d, &e, &f);     if (ju1())       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int acc[25 + 5][25 + 5];   char str[25 + 5][25 + 5];   int main() {     int N, M, ans = 0;     scanf( %d %d , &N, &M);     for (int i = 0; i < N; i++) scanf( %s , str[i]);     for (int i = 1; i < N + 1; i++)       for (int j = 1; j < M + 1; j++)         acc[i][j] = acc[i - 1][j] + acc[i][j - 1] - acc[i - 1][j - 1] +                     (str[i - 1][j - 1] ==  0  ? 1 : 0);     for (int r1 = 1; r1 < N + 1; r1++)       for (int c1 = 1; c1 < M + 1; c1++)         for (int r2 = r1; r2 < N + 1; r2++)           for (int c2 = c1; c2 < M + 1; c2++)             if (acc[r2][c2] - acc[r1 - 1][c2] - acc[r2][c1 - 1] +                     acc[r1 - 1][c1 - 1] ==                 (r2 - r1 + 1) * (c2 - c1 + 1))               ans = max(ans, 2 * ((r2 - r1 + 1) + (c2 - c1 + 1)));     printf( %d n , ans);     return 0;   }
#pragma GCC optimize( O3 )   #include <bits/stdc++.h>   // #include <ext/pb_ds/assoc_container.hpp>   // using namespace __gnu_pbds;   // gp_hash_table<int, int> mapka;      using namespace std;   #define PB push_back   #define MP make_pair   #define LL long long   #define int LL   #define FOR(i,a,b) for(int i = (a); i <= (b); i++)   #define RE(i,n) FOR(i,1,n)   #define REP(i,n) FOR(i,0,(int)(n)-1)   #define R(i,n) REP(i,n)   #define VI vector<int>   #define PII pair<int,int>   #define LD long double   #define FI first   #define SE second   #define st FI   #define nd SE   #define ALL(x) (x).begin(), (x).end()   #define SZ(x) ((int)(x).size())      template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }   template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }      template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<< = <<h<<endl; }   template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {     while(*sdbg!= , )cerr<<*sdbg++;     cerr<< = <<h<< , ; _dbg(sdbg+1, a...);   }      template<class T> ostream &operator<<(ostream& os, vector<T> V) {     os <<  [ ; for (auto vv : V) os << vv <<  , ; return os <<  ] ;   }   template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {     return os <<  (  << P.st <<  ,  << P.nd <<  ) ;   }      #ifdef LOCAL   #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)   #else   #define debug(...) (__VA_ARGS__)   #define cerr if(0)cout   #endif      vector<vector<int>> res;   int n,m;   vector<vector<PII>> d;   void licz(int s){     vector<vector<int>> kt(n);     vector<int> odl(n,2e9);     int naj = 2e9;     auto dod = [&](int v,int od){       if(odl[v] > od){         odl[v] = od;         kt[od % n].PB(v);       }     };     for(PII el:d[s]){       mini(naj,el.SE);       dod(el.FI, el.SE);     }     int gd = naj % n;     R(_,n){       debug(gd, SZ(kt));       R(i,SZ(kt[gd])){         int el = kt[gd][i];   //     for(int el:kt[gd]){         if(odl[el] == naj){           for(PII ed:d[el]){             dod((ed.FI + gd) % n, naj + ed.SE);           }           el++;           if(el == n)el -= n;           dod(el, naj + 1);         }       }       naj++;       gd++;       if(gd == n)gd = 0;     }     R(i,n)if(s != i){       res[s][i] = odl[i];     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(11);     cerr << fixed << setprecision(6);     cin >> n >> m;     res.resize(n,vector<int>(n));     d.resize(n);     R(i,m){       int a,b,c;       cin >> a >> b >> c;       d[a].PB({b,c});     }     R(i,n){       licz(i);     }     R(i,n){       R(j,n){         cout << res[i][j] <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[505][505];     int i, n, j, c = 0;     cin >> n;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cin >> a[i][j];       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (a[i][j] ==  X ) {           int m = i - 1;           int n = i + 1;           int o = j - 1;           int p = j + 1;           if (a[m][o] ==  X  && a[m][p] ==  X  && a[n][o] ==  X  &&               a[n][p] ==  X ) {             c++;           }         }       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[1000];   bool ok = false;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int sum = 0;     for (int i = 0; i < n; i++) sum += a[i];     int m;     cin >> m;     int l, r;     for (int i = 0; i < m; i++) {       cin >> l >> r;       if (sum >= l && sum <= r) {         cout << sum << endl;         exit(0);       }       if (sum < l) cout << l << endl, exit(0);     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int a, b, c;     cin >> a >> b >> c;     if (!c) return cout << (a == b ?  YES  :  NO ), 0;     if (c > 0 && b < a || c < 0 && b > a) return cout <<  NO , 0;     cout << ((a % c + c) % c == (b % c + c) % c ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 512345, lgN = 20, rootN = 1123;   const double eps = 1e-18;   int r[N], w[N];   vector<double> positive, negative;   double p[N];   int main() {     int n, c, d;     cin >> n >> c >> d;     for (int i = 1; i <= n; ++i) {       cin >> r[i] >> w[i];       r[i] -= c, w[i] -= d;       p[i] = (((double)r[i]) / (double)w[i]);     }     for (int i = 1; i <= n; ++i) {       double x = (((double)r[i]) / (double)w[i]);       if (w[i] > 0) {         positive.push_back(x);       } else if (w[i] < 0) {         negative.push_back(x);       }     }     sort(positive.begin(), positive.end());     sort(negative.begin(), negative.end());     long long first = 0, second = 0;     for (int i = 0; i < positive.size(); ++i) {       first += (lower_bound(negative.begin(), negative.end(), positive[i]) -                 negative.begin());     }     for (int i = 0; i < negative.size(); ++i) {       second += (lower_bound(positive.begin(), positive.end(), negative[i]) -                  positive.begin());     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       if (w[i] > 0) {         ans += ((long long)(negative.end() - upper_bound(negative.begin(),                                                          negative.end(), p[i]))) *                (lower_bound(negative.begin(), negative.end(), p[i]) -                 negative.begin());       } else if (w[i] < 0) {         ans += ((long long)(positive.end() - upper_bound(positive.begin(),                                                          positive.end(), p[i]))) *                (lower_bound(positive.begin(), positive.end(), p[i]) -                 positive.begin());       } else if (w[i] == 0) {         if (r[i] < 0)           ans += first;         else           ans += second;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, la, lb, x;     cin >> n >> la >> lb;     int apple[100];     for (int i = 1; i <= n; i++) apple[i] = 2;     for (int i = 1; i <= la; i++) {       cin >> x;       apple[x] = 1;     }     for (int i = 1; i <= lb; i++) {       cin >> x;       if (apple[x] != 1) apple[x] = 2;     }     for (int i = 1; i <= n; i++) cout << apple[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   bool vis[400];   set<int> sub[400];   vector<int> ga[400];   vector<int> path;   vector<int> ord;   int curr;   void DFS(int a) {     sub[a].insert(a);     for (int i = 0; i < ga[a].size(); i++) {       int b = ga[a][i];       if (vis[b]) continue;       vis[b] = true;       DFS(b);       for (__typeof(sub[b].begin()) it = sub[b].begin(); it != sub[b].end(); it++)         sub[a].insert(*it);     }   }   void SFD(int a) {     if (ord[curr] == a) {       curr++;       return;     }     while (1) {       if (curr == ord.size()) return;       bool upd = false;       for (int i = 0; i < ga[a].size(); i++) {         int b = ga[a][i];         if (vis[b] || sub[b].find(ord[curr]) == sub[b].end()) continue;         vis[b] = true;         path.push_back(b);         SFD(b);         path.push_back(a);         upd = true;         break;       }       if (!upd) return;     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       ga[a].push_back(b);       ga[b].push_back(a);     }     int x;     while (cin >> x) ord.push_back(x);     vis[1] = true;     DFS(1);     memset(vis, false, sizeof(vis));     path.push_back(1);     vis[1] = true;     SFD(1);     if (path.size() != n * 2 - 1)       cout << -1;     else {       for (int i = 0; i < path.size(); i++) cout << path[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300100;   int read() {     int x = 0, w = 1;     char ch = 0;     while (!isdigit(ch)) {       ch = getchar();       if (ch ==  - ) w = -1;     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * w;   }   vector<int> G[maxn];   int vis[maxn];   int fa[maxn], ans[maxn];   int findfa(int rt) { return rt == fa[rt] ? rt : fa[rt] = findfa(fa[rt]); }   void merge(int a, int b) {     if (findfa(a) != findfa(b)) fa[fa[a]] = fa[b];   }   int tmp = 0, tmp2 = 0;   void dfs(int rt, int col, int res) {     if (vis[rt] == col) return;     if (res > tmp) tmp = res, tmp2 = rt;     vis[rt] = col;     for (int to : G[rt]) merge(rt, to), dfs(to, col, res + 1);   }   int main() {     int n = read(), m = read(), q = read();     for (int i = 1; i <= n; i++) fa[i] = i;     while (m--) {       int u = read(), v = read();       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         tmp = 0, tmp2 = i;         dfs(i, i, 0);         tmp = 0;         dfs(tmp2, tmp2, 0);         ans[findfa(i)] = tmp;       }     while (q--) {       int opt = read();       if (opt == 1)         printf( %d n , ans[findfa(read())]);       else {         int u = read(), v = read();         u = findfa(u), v = findfa(v);         if (u == v) continue;         fa[u] = v;         ans[v] =             max(max(ans[v], ans[u]), (ans[u] + 1) / 2 + (ans[v] + 1) / 2 + 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, I;     cin >> n >> I;     map<long long, long long> mp;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       mp[x]++;     }     if (ceil(log2(mp.size())) * n <= I * 8) {       cout << 0;       return 0;     }     vector<long long> v(mp.size() + 1);     long long j = 1;     v[0] = 0;     for (auto i = mp.begin(); i != mp.end(); i++) {       v[j] = v[j - 1] + i->second;       j++;     }     long long x = pow(2, (I * 8) / n);     long long max_int = 0;     for (long long i = 0; i < v.size() - x; i++) {       max_int = max(max_int, v[i + x] - v[i]);     }     cout << n - max_int;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cc = 0;   unordered_map<long long, long long> c, rc;   vector<vector<long long> > graph(1e6);   vector<bool> visited(1e6, false);   vector<vector<long long> > answers(1e6);   void dfs(long long node) {     visited[node] = true;     answers[cc].push_back(node);     for (auto i : graph[node])       if (!visited[i]) dfs(i);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     vector<long long> nums(n);     for (int i = 0; i < (int)(n); i++) cin >> (nums)[i];     ;     vector<long long> nums_copy((nums).begin(), (nums).end());     sort((nums_copy).begin(), (nums_copy).end());     for (int i = 0; i < n; i++) c[i] = nums_copy[i], rc[nums_copy[i]] = i;     vector<long long> modified(n);     for (int i = 0; i < n; i++) modified[i] = rc[nums[i]];     for (int i = 0; i < n; i++) {       graph[i].push_back(modified[i]);     }     for (int i = 0; i < n; i++) {       if (!visited[i]) dfs(i), cc++;     }     cout << cc << endl;     for (int i = 0; i < cc; i++) {       long long k = answers[i].size();       cout << k <<    ;       for (int j = 0; j < k; j++) cout << answers[i][j] + 1 <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> addr;   void psh(string s) {     long long res = 0, cur = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  . ) {         res *= 256;         res += cur;         cur = 0;       } else {         cur *= 10;         cur += (s[i] -  0 );       }     }     res *= 256;     res += cur;     addr.push_back(res);   }   void outp(long long mask) {     int d = mask % 256;     mask /= 256;     int c = mask % 256;     mask /= 256;     int b = mask % 256;     mask /= 256;     int a = mask;     printf( %d.%d.%d.%d n , a, b, c, d);   }   set<long long> s;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       psh(s);     }     long long mask = 0;     for (int i = 31; i >= 0; i--) {       mask += (1ll << i);       s.clear();       for (int i = 0; i < n; i++) {         s.insert(addr[i] & mask);       }       if (s.size() == k) {         outp(mask);         return 0;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 51;   vector<int> g[N];   int n, sz[N], dp[N][N][N][N], s, m, ans = 1e9, cost[N][N], temp[N];   void dfs(int u, int p) {     for (auto i : g[u])       if (i != p) dfs(i, u), sz[u] += sz[i];   }   int calc(int from, int to, int behind, int front) {     if (!front) return 1e9;     if (g[to].size() == 1)       return behind ? calc(to, from, 0, behind) + cost[to][from] : cost[to][from];     int &ref = dp[to][from][behind][front], id = 0, x;     if (ref != -1) return ref;     for (auto i : g[to])       if (i != from)         for (int j = 1; j <= front; j++) calc(to, i, behind + front - j, j);     for (int i = 1; i <= front; i++) temp[i] = -1e9;     for (auto x : g[to]) {       if (x == from) continue;       for (int i = front; i; i--)         for (int j = 1; i - j >= 0; j++)           temp[i] =               max(temp[i], min(temp[i - j], calc(to, x, behind + front - j, j)));     }     return ref = temp[front] + cost[from][to];   }   int main() {     scanf( %d , &n);     memset(dp, -1, sizeof dp);     for (int i = 1, a, b, c; i < n; i++) {       scanf( %d%d%d , &a, &b, &c);       g[--a].push_back(--b);       g[b].push_back(a);       cost[a][b] = cost[b][a] = c;     }     temp[0] = 1e9;     scanf( %d%d , &s, &m);     for (int i = 0, a; i < m; i++) {       scanf( %d , &a);       sz[a - 1]++;     }     dfs(--s, -1);     for (auto i : g[s]) ans = min(ans, calc(s, i, m - sz[i], sz[i]));     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p;     cin >> n >> p;     int a[n], maxi = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       maxi = max(maxi, a[i] - i);     }     int b = 0;     for (int i = 0; i < n; i++) {       if (i >= p - 1) {         b = max(b, min(maxi - (a[i] - i), i));       }     }     b = max(0, p - b - 1);     cout << b <<   n ;     for (int i = 0; i < b; i++) {       cout << maxi + i << (i == b - 1 ?   n  :    );     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   typedef struct {     int pre[maxn];     void init(int n) {       for (int i = 0; i <= n + 1; ++i) pre[i] = i;     }     int find(int x) {       if (x == pre[x]) return x;       return pre[x] = find(pre[x]);     }     void merge(int x, int y) { pre[find(x)] = find(y); }   } DS;   DS lds, rds;   int n, m, q;   int M[maxn][maxn];   int D[maxn][maxn];   int U[maxn][maxn];   int L[maxn][maxn];   int R[maxn][maxn];   int a[maxn];   int id[maxn];   bool comp(int x, int y) { return a[x] < a[y]; }   int getMax(int n, int x) {     int ret = 0;     int l, r;     int i;     for (i = 1; i <= n; ++i) id[i] = i;     lds.init(n);     rds.init(n);     sort(id + 1, id + 1 + n, comp);     for (i = n; i > 0; --i) {       l = lds.find(id[i] - 1) + 1;       r = rds.find(id[i] + 1) - 1;       if (l <= x && x <= r) ret = max(ret, (r - l + 1) * a[id[i]]);       lds.merge(id[i], id[i] - 1);       rds.merge(id[i], id[i] + 1);     }     return ret;   }   void printMat(int x[][maxn]) {     int i, j;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= m; ++j) printf( %d  , x[i][j]);       putchar(  n );     }   }   int main() {     int i, j, k;     int ans;     int op, x, y;     scanf( %d %d %d , &n, &m, &q);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) scanf( %d , &M[i][j]);     memset(D, 0, sizeof(D));     memset(U, 0, sizeof(U));     memset(L, 0, sizeof(L));     memset(R, 0, sizeof(R));     for (i = 1; i <= n; ++i) {       for (j = 1; j <= m; ++j) {         if (M[i][j]) {           U[i][j] = U[i - 1][j] + 1;           L[i][j] = L[i][j - 1] + 1;         }       }     }     for (i = n; i > 0; --i) {       for (j = m; j > 0; --j) {         if (M[i][j]) {           D[i][j] = D[i + 1][j] + 1;           R[i][j] = R[i][j + 1] + 1;         }       }     }     while (q--) {       scanf( %d %d %d , &op, &x, &y);       if (op == 1) {         M[x][y] = !M[x][y];         for (j = y; j <= m; ++j) L[x][j] = M[x][j] ? L[x][j - 1] + 1 : 0;         for (i = x; i <= n; ++i) U[i][y] = M[i][y] ? U[i - 1][y] + 1 : 0;         for (j = y; j > 0; --j) R[x][j] = M[x][j] ? R[x][j + 1] + 1 : 0;         for (i = x; i > 0; --i) D[i][y] = M[i][y] ? D[i + 1][y] + 1 : 0;       } else {         ans = 0;         for (i = 1; i <= n; ++i) a[i] = L[i][y];         ans = max(ans, getMax(n, x));         for (i = 1; i <= n; ++i) a[i] = R[i][y];         ans = max(ans, getMax(n, x));         for (i = 1; i <= m; ++i) a[i] = U[x][i];         ans = max(ans, getMax(m, y));         for (i = 1; i <= m; ++i) a[i] = D[x][i];         ans = max(ans, getMax(m, y));         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using pii = pair<int, int>;   using vi = vector<int>;   struct res {     int x, t;     bool operator<(const res &z) const { return x < z.x; }     bool operator==(const res &z) const { return x == z.x && t == z.t; }   };   const res E = {-1, 0};   const int M = 1e9;   void q(int cnt, int x, int y) {     if (cnt) cout << cnt <<     << x + 1 <<     << y + 1 <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << setprecision(15);     int n, k, v;     cin >> n >> k >> v;     vi a(n);     for (int &x : a) cin >> x;     vector<vector<res>> dp(n + 1, vector<res>(k, E));     dp[0][0] = {0, 0};     for (int i = 1; i <= n; ++i) {       dp[i] = dp[i - 1];       for (res &r : dp[i]) r.t = 0;       for (int j = 0; j < k; ++j)         if (!(dp[i - 1][j] == E)) {           auto &l = dp[i][(j + a[i - 1]) % k];           l = max(l, {dp[i - 1][j].x + a[i - 1], 1});           dp[i][j] = max(dp[i][j], {dp[i - 1][j].x + a[i - 1] / k * k, 0});         }     }     if (dp[n][v % k] == E) return cout <<  NO n , 0;     vi b, g;     for (int i = n, c = v % k; i >= 1; --i) {       if (dp[i][c].t)         b.push_back(i - 1), c = (c - a[i - 1] % k + k) % k;       else         g.push_back(i - 1);     }     int cap = 0;     for (int x : b) cap += a[x];     int ad = 0;     for (int x : g) ad += a[x];     cap += ad / k * k;     if (cap < v) return cout <<  NO n , 0;     cout <<  YES n ;     int r, cur = 0, ot;     if (((int)(b).size())) {       r = b[0], cur = a[r];       for (int i = 1; i < ((int)(b).size()); ++i) {         q(M, b[i], r), cur += a[b[i]];       }       ot = r == 0 ? 1 : 0;     } else {       r = 0, ot = 1;       q(M, r, ot);     }     for (int x : g)       if (x != ot) q(M, x, ot);     q(cur / k, r, ot), cur %= k;     q((v - cur) / k, ot, r);   }