malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, pair<S, T> const& p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> const& v) {     int l = v.size();     for (int i = 0; i < l - 1; i++) out << v[i] <<    ;     if (l > 0) out << v[l - 1];     return out;   }   const int N = 10000001;   int lp[N], primes[N], pcnt;   void getSieve() {     for (int i = 2; i <= N; i++) {       if (lp[i] == 0) {         lp[i] = i;         primes[pcnt++] = i;       }       for (int j = 0; j < pcnt and primes[j] <= lp[i] and i * primes[j] <= N; j++)         lp[i * primes[j]] = primes[j];     }     return;   }   const int M = 1000100;   int k, a, cnt[N], mx;   long long cp[N];   int f(long long val) {     long long p, d, tot;     for (int i = 0; i < pcnt and primes[i] <= val; i++) {       d = p = primes[i], tot = 0;       while (d <= val and tot < cp[p]) {         tot += val / d;         d *= p;       }       if (tot < cp[p]) return 0;     }     return 1;   }   int main() {     getSieve();     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       scanf( %d , &a);       mx = max(mx, a);       cnt[1]++;       cnt[a + 1]--;     }     int p, num;     for (int i = 1; i <= mx; i++) {       cnt[i] += cnt[i - 1];       num = i;       while (num > 1) {         p = lp[num];         while (lp[num] == p) {           cp[p] += cnt[i];           num /= p;         }       }     }     long long lo = mx, hi = (1LL << 45), mid;     while (lo < hi) {       mid = (lo / 2) + (hi / 2);       if (f(mid))         hi = mid;       else         lo = mid + 1;     }     cout << hi << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double r, x, y, z, t;     cin >> r >> x >> y >> z >> t;     double d = (x - z) * (x - z) + (y - t) * (y - t);     d = sqrt(d);     double i;     for (i = 0; i < 10000000; i++) {       if ((i * r) >= d / 2) break;     }     cout << i << endl;   }
#include <bits/stdc++.h>   using namespace std;   int w1, w2, h1, h2;   int main() {     scanf( %d%d%d%d , &w1, &h1, &w2, &h2);     printf( %d n , (h1 + h2) * 2 + 4 + max(w1, w2) * 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ispalin(string a) {     string b = a;     reverse(b.begin(), b.end());     return a == b;   }   int main() {     string str;     cin >> str;     int N = str.size();     for (int i = 0; i <= N; i++) {       for (char xc =  a ; xc <=  z ; xc++) {         string str1;         for (int j = 0; j < i; j++) str1 += str[j];         str1 += xc;         for (int j = i; j < N; j++) str1 += str[j];         if (ispalin(str1)) {           cout << str1;           return 0;         }       }     }     cout <<  NA ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int h = n / 2;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i <= h) {           if (j >= h - i && j <= h + i) {             cout <<  D ;           } else {             cout <<  * ;           }         } else {           if (j >= i - h && j <= 3 * n / 2 - 1 - i) {             cout <<  D ;           } else {             cout <<  * ;           }         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 51;   long long ans[maxn], a[maxn];   long long poww(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a;       b /= 2;       a = a * a;     }     return res;   }   void init() {     ans[0] = 1;     a[0] = 1;     for (long long i = 1; i <= 38; i++) {       a[i] = poww(3, i);     }     for (long long i = 1; i <= 38; i++) {       ans[i] = ans[i - 1] + a[i];     }   }   int main() {     ios::sync_with_stdio(false);     init();     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long m = 0;       for (long long i = 38; i >= 1; i--) {         if (ans[i - 1] >= n) continue;         n -= a[i];         m += a[i];       }       if (n > 0) {         m += 1;       }       cout << m << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   char a[1001][1001];   int d[1001][1001];   int n, m, ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = n; i > 0; i--)       for (int j = m; j > 0; j--) {         int cur;         d[i][j] = d[i + 1][j] + d[i][j + 1] - d[i + 1][j + 1];         if (a[i][j] ==  W )           cur = 1;         else           cur = -1;         if (cur != d[i][j]) ans++;         d[i][j] = cur;       }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int64_t MOD = 1e9 + 7;   const int N = 2e5 + 5;      int64_t mpow(int64_t b,int64_t e,int64_t m){       int64_t r = 1;       while(e > 0){           if(e & 1){               r = (r*b)%m;           }           b = (b*b)%m;           e >>= 1;       }       return r;   }      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int64_t fact[N],ifact[N];       ifact[0] = fact[0] = 1;       for(int i=1;i<N;i++){           fact[i] = (i * fact[i-1]) % MOD;           ifact[i] = mpow(fact[i],MOD-2,MOD);       }       auto comb = [&](int x,int y){ // xCy           return (fact[x]*ifact[x-y]%MOD*ifact[y])%MOD;       };       int t;       cin >> t;       while(t--){           int n,l,r;           cin >> n >> l >> r;           int x = min(1-l,r-n);           int L=0,R=n+1;           int64_t res = (x*(((n%2)+1)*comb(n,n/2))%MOD)%MOD;           res %= MOD;           for(int i=x+1;;i++){               while(L+1-i < l) L++;               while(R-1+i > r) R--;               if(L > (n+1)/2 || n+1-R > (n+1)/2 || R-L-1 < 0) break;               if(n%2 == 1){                   if(L <= n/2) res = (res+comb(R-L-1,n/2-L))%MOD;                   if(L <= (n+1)/2) res = (res+comb(R-L-1,(n+1)/2-L))%MOD;               }else{                   res = (res+comb(R-L-1,n/2-L))%MOD;               }           }           cout << (res%MOD+MOD)%MOD <<   n ;       }   }
#include <bits/stdc++.h>   using namespace std;   int nxt() {     int x;     cin >> x;     return x;   }   int main() {     int n = nxt(), k = nxt();     vector<int> a(n);     generate(a.begin(), a.end(), nxt);     int s = accumulate(a.begin(), a.end(), 0);     int ans = 0;     while ((s + k * ans) * 1.0 / (n + ans) < k - 0.5) {       ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n;   int ans[100001];   const long long inf = 2250000000000;   inline long long cal(const pair<pair<long long, long long>, long long> &first) {     return first.first.first * first.first.first +            first.first.second * first.first.second;   }   inline long long mul(long long first, long long second) {     return first * first + second * second;   }   inline bool cmp(const pair<pair<long long, long long>, long long> &a,                   const pair<pair<long long, long long>, long long> &b) {     return cal(a) < cal(b);   }   pair<pair<long long, long long>, long long> a[100001];   void enter() {     read(n);     for (int i = 0; i < n; i++) {       read(a[i].first.first);       read(a[i].first.second);       a[i].second = i;     }     sort(a, a + n, cmp);   }   void add(long long &first, long long second) { first = first + second; }   void sub(long long &first, long long second) { first = first - second; }   void progress() {     long long first = 0, second = 0;     long long xx = 0, yy = 0;     for (int i = 0; i < n; i++) {       add(xx, a[i].first.first);       add(yy, a[i].first.second);       if (mul(first + a[i].first.first, second + a[i].first.second) <=           mul(first, second)) {         add(second, a[i].first.second);         add(first, a[i].first.first);         ans[a[i].second] = 1;       } else {         sub(second, a[i].first.second);         sub(first, a[i].first.first);         ans[a[i].second] = -1;       }     }     while (mul(first, second) > inf) {       for (int i = n - 1; i >= 0; i--) {         if (ans[a[i].second] == -1 &&             mul(first + 2 * a[i].first.first, second + 2 * a[i].first.second) <=                 inf) {           add(second, 2 * a[i].first.second);           add(first, 2 * a[i].first.first);           ans[a[i].second] = 1;         } else if (ans[a[i].second] == 1 &&                    mul(first - 2 * a[i].first.first,                        second - 2 * a[i].first.second) <= inf) {           sub(first, 2 * a[i].first.first);           sub(second, 2 * a[i].first.second);           ans[a[i].second] = -1;         }       }     }   }   int main() {     enter();     progress();     for (int i = 0; i < n; i++) {       write(ans[i]);       putchar(   );     }   }
#include <bits/stdc++.h>   using namespace std;   bool visited[100005] = {0};   vector<int> v[100005];   int color[100005];   int dfs(int s) {     int result = 0;     visited[s] = 1;     for (int i = 0; i < v[s].size(); i++) {       if (!visited[v[s][i]]) {         if (color[v[s][i]] != color[s])           result += (1 + dfs(v[s][i]));         else           result += dfs(v[s][i]);       }     }     return result;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < 100005; i++) visited[i] = 0;     for (int i = 2; i <= n; i++) {       int a;       cin >> a;       v[i].push_back(a);       v[a].push_back(i);     }     for (int i = 0; i < n; i++) {       cin >> color[i + 1];     }     cout << (1 + dfs(1)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void dfs(const vector<int> &next, vector<bool> &visited, vector<int> &end,            int x) {     visited[x] = true;     int y = next[x];     if (!visited[y]) {       dfs(next, visited, end, y);       end[x] = end[y];     } else       end[x] = x;   }   int main() {     int n;     scanf( %d , &n);     vector<int> next(n), deg(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &next[i]);       --next[i];       ++deg[next[i]];     }     vector<int> start, end, g_end(n, -1);     vector<bool> visited(n, false);     for (int i = 0; i < n; ++i)       if (deg[i] == 0) {         start.push_back(i);         dfs(next, visited, g_end, i);         end.push_back(g_end[i]);       }     for (int i = 0; i < n; ++i)       if (!visited[i]) {         start.push_back(i);         dfs(next, visited, g_end, i);         end.push_back(g_end[i]);       }     int cnt = int(start.size());     if (cnt == 1 && deg[start[0]] > 0)       printf( 0 n );     else {       printf( %d n , cnt);       for (int i = 0; i < cnt; ++i)         printf( %d %d n , end[i] + 1, start[(i + 1) % cnt] + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int AL = 26;   const int N = (int)1e6 + 9;   int powr(int n, int k) {     if (k == 0) return 1;     int v = powr(n, k / 2);     v = (v * 1ll * v) % MOD;     if (k & 1) v = (v * 1ll * n) % MOD;     return v;   }   int cnt[AL];   int f[N];   int inv[N];   int C(int a, int b) {     if (b == 0) return 1;     int v = f[a];     v = (v * 1ll * inv[b]) % MOD;     v = (v * 1ll * inv[a - b]) % MOD;     return v;   }   int ways(string a, string b) {     for (int j = 0; j < AL; j++) cnt[j] = 0;     for (auto x : a) {       cnt[x -  a ]++;     }     int answ = 0;     int mlt;     int sz = a.size();     int nsz;     int y;     bool ok;     for (int i = 0; i < b.size(); i++) {       nsz = sz - 1;       y = b[i] -  a ;       ok = false;       for (int t = 0; t < y; t++) {         if (cnt[t] > 0) ok = true;       }       if (ok) {         mlt = 1;         for (int r = AL - 1; r >= 0; r--) {           mlt = (mlt * 1ll * C(nsz, cnt[r])) % MOD;           nsz -= cnt[r];           nsz += (r == y);         }         answ = (answ + mlt) % MOD;       }       cnt[b[i] -  a ]--;       if (cnt[b[i] -  a ] < 0) break;       sz--;     }     return answ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     f[0] = 1;     inv[0] = 1;     for (int i = 1; i < N; i++) {       f[i] = (1ll * i * f[i - 1]) % MOD;       inv[i] = powr(f[i], MOD - 2);     }     string a, b;     cin >> a >> b;     cout << (ways(a, b) - ways(a, a) + MOD - 1) % MOD <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solution() {     long long n, x, m = 0, ans = 0;     cin >> n;     ans += 2 * n - 1;     while (n--) {       cin >> x;       ans += abs(x - m);       m = x;     }     cout << ans <<   n ;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     long long t;     t = 1;     while (t--) {       solution();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int n, r;       cin >> n >> r;       int arr[n];       for (int j = 0; j < n; j++) {         cin >> arr[j];       }       sort(arr, arr + n);       int shots = 0, act[n], p = 0;       act[0] = arr[0];       p++;       for (int j = 1; j < n; j++) {         if (arr[j] == arr[j - 1]) {         } else {           act[p] = arr[j];           p++;         }       }       for (int j = 0; j < p; j++) {         if (act[p - j - 1] - j * r <= 0) {           break;         }         shots++;       }       cout << shots << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int ch = 0, nch = 0;     int x;     int b;     if (n >= m) {       b = m;     } else {       b = n;     }     for (int i = 0; i < n; i++) {       cin >> x;       if (x % 2 == 0) {         ch++;       } else {         nch++;       }     }     for (int i = 0; i < m; i++) {       cin >> x;       if (x % 2 == 0) {         ch++;       } else {         nch++;       }     }     if (nch > ch) {       if (ch < b) {         cout << ch << endl;       } else {         cout << b << endl;       }     } else {       if (nch < b) {         cout << nch << endl;       } else {         cout << b << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int n;   pair<int, int> board[1001][1001];   int ans[1001][1001];   int dx[5] = {0, 1, -1, 0, 0};   int dy[5] = {0, 0, 0, 1, -1};   bool isValid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= n; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     memset(ans, -1, sizeof ans);     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> board[i][j].first >> board[i][j].second;     queue<pair<int, int> > q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (board[i][j].first == i && board[i][j].second == j) {           ans[i][j] = 0;           q.push({i, j});         }       }     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop();       int x = cur.first, y = cur.second;       for (int k = 1; k <= 4; k++) {         int cx = x + dx[k], cy = y + dy[k];         if (!isValid(cx, cy)) continue;         if (ans[cx][cy] != -1) continue;         if (board[cx][cy] != board[x][y]) continue;         ans[cx][cy] = k;         q.push({cx, cy});       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (ans[i][j] == -1 && board[i][j] == pair<int, int>(-1, -1)) {           int x = i, y = j;           for (int k = 1; k <= 4; k++) {             int cx = x + dx[k], cy = y + dy[k];             if (!isValid(cx, cy)) continue;             if (ans[cx][cy] != -1) continue;             if (board[cx][cy] != board[x][y]) continue;             q.push({cx, cy});             q.push({x, y});             ans[cx][cy] = k;             if (k == 1)               ans[x][y] = 2;             else if (k == 2)               ans[x][y] = 1;             else if (k == 3)               ans[x][y] = 4;             else if (k == 4)               ans[x][y] = 3;             while (!q.empty()) {               pair<int, int> cur = q.front();               q.pop();               int x = cur.first, y = cur.second;               for (int k = 1; k <= 4; k++) {                 int cx = x + dx[k], cy = y + dy[k];                 if (!isValid(cx, cy)) continue;                 if (ans[cx][cy] != -1) continue;                 if (board[cx][cy] != board[x][y]) continue;                 ans[cx][cy] = k;                 q.push({cx, cy});               }             }             break;           }         }       }     bool isValid = true;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (ans[i][j] == -1) isValid = false;       }     if (!isValid) {       cout <<  INVALID ;       return 0;     }     cout <<  VALID n ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         switch (ans[i][j]) {           case 0:             cout <<  X ;             break;           case 1:             cout <<  U ;             break;           case 2:             cout <<  D ;             break;           case 3:             cout <<  L ;             break;           case 4:             cout <<  R ;             break;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 21, inf = 1e7;   int n, k, a[1 << N], pre[1 << N], ns, cs[1 << N];   inline int cmax(int x, int y) {     if (x == -1 || y == -1) return x == -1 ? y : x;     return a[x] > a[y] ? x : y;   }   bool E[1 << N][N];   void UPD(int x) {     cs[x] = -1;     for (int i = (0); i <= (n - 1); ++i)       if (E[x][i]) {         int nx = cmax(cs[x], x ^ (1 << i));         if (nx != cs[x]) pre[x] = x ^ (1 << i), cs[x] = x ^ (1 << i);       }   }   int teshu[1 << N], g;   void change(int u, int v) {     int t = u ^ v;     t = log2(t), E[u][t] ^= 1, E[v][t] ^= 1;   }   bool op[1 << N], vis[1 << N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = (0); i <= ((1 << n) - 1); ++i)       cin >> a[i], op[i] = op[i >> 1] ^ (i & 1), cs[i] = -1;     for (int i = (0); i <= ((1 << n) - 1); ++i)       if (!op[i])         for (int j = (0); j <= (n - 1); ++j) E[i][j] = true;     for (int i = (0); i <= ((1 << n) - 1); ++i)       if (!op[i]) UPD(i);     while (k--) {       int x = -1, r = -1;       for (int i = (0); i <= ((1 << n) - 1); ++i)         if (!op[i] && cs[i] != -1 && (x == -1 || a[i] + a[cs[i]] >= r))           x = i, r = a[i] + a[cs[i]];       if (x == -1 || a[x] + a[cs[x]] <= 0) break;       ns += a[x], ns += a[cs[x]];       int rn = x;       while (rn != cs[x]) change(rn, pre[rn]), rn = pre[rn];       a[cs[x]] = a[x] = -inf;       teshu[++g] = x, teshu[++g] = cs[x];       cs[cs[x]] = -1, cs[x] = -1;       for (int i = (1); i <= (g); ++i) {         int x = teshu[i];         for (int j = (0); j <= (n - 1); ++j) {           int v = x ^ (1 << j);           cs[v] = -1;           if (!op[v]) UPD(v);         }       }       for (int i = (1); i <= (g); ++i) {         int u = teshu[i];         if (op[u] == 1)           cs[u] = pre[u] = -1;         else           pre[u] = -1, UPD(u);       }       for (int i = (1); i <= (g); ++i) vis[teshu[i]] = false;       for (int i = (1); i <= (g); ++i) {         int x = -1;         for (int j = (1); j <= (g); ++j)           if (!vis[teshu[j]]) x = teshu[j];         for (int j = (1); j <= (g); ++j)           if (!vis[teshu[j]] && cmax(cs[x], cs[teshu[j]]) != cs[x]) x = teshu[j];         vis[x] = true;         for (int j = (0); j <= (n - 1); ++j)           if (!E[x][j]) {             int v = x ^ (1 << j);             int nx = cmax(cs[x], cs[v]);             if (nx != cs[v]) pre[v] = x, cs[v] = cs[x];           }       }     }     cout << ns <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000 + 5;   int l[N];   int w[N];   int getw(long long s, long long e) {     if (e % 2) {       if (s % 2) {         return 2;       }       return 1;     }     if (s * 2 > e) {       if (s % 2 == e % 2) {         return 2;       }       return 1;     }     if (s * 4 > e) {       return 1;     }     return getw(s, e / 4);   }   int getl(long long s, long long e) {     if (s * 2 > e) {       return 1;     }     return getw(s, e / 2);   }   int main() {     int n;     cin >> n;     w[0] = 2, l[0] = 1;     for (int i = 1; i <= n; i++) {       long long s, e;       cin >> s >> e;       int x = getw(s, e), y = getl(s, e);       if (x == 1) {         w[i] = l[i - 1];       } else {         w[i] = w[i - 1];       }       if (y == 1) {         l[i] = l[i - 1];       } else {         l[i] = w[i - 1];       }     }     cout << (w[n] == 1) <<     << (l[n] == 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     long long k;     cin >> k;     long long sum = 0;     map<long long, long long> m;     vector<long long> ssum(k, 0), g(5005 * k, -1);     vector<vector<long long>> a(k);     vector<pair<long long, long long>> v;     for (long long i = 0; i < k; ++i) {       long long n;       cin >> n;       a[i].resize(n);       for (long long j = 0; j < n; ++j) {         cin >> a[i][j];         m[a[i][j]] = v.size();         v.emplace_back(a[i][j], i);         ssum[i] += a[i][j];       }       sum += ssum[i];     }     if (sum % k) {       cout <<  No n ;       return 0;     }     sum /= k;     for (long long i = 0; i < k; ++i) {       for (long long j = 0; j < (long long)a[i].size(); ++j) {         if (m.count(sum - ssum[i] + a[i][j])) {           long long id = m[sum - ssum[i] + a[i][j]], u = m[a[i][j]];           if (u != id && v[u].second == v[id].second) continue;           g[u] = id;         }       }     }     long long timer = 0;     vector<long long> dp(1 << k, 0), par(1 << k, 0), head(1 << k, -1);     vector<long long> vis(v.size() + 5, 0);     for (long long i = 0; i < k; ++i) {       for (auto j : a[i]) {         long long mask = 0, u = m[j];         ++timer;         if (vis[u] || g[u] == -1) continue;         while (~u && !vis[u]) {           vis[u] = timer;           u = g[u];         }         if (u == -1 || vis[u] != timer) continue;         long long c = 0, x = u, good = 1;         while (x != u || !c) {           if ((mask >> v[x].second) & 1) good = 0;           mask |= (1 << v[x].second);           x = g[x];           ++c;         }         if (good) {           dp[mask] = 1;           head[mask] = u;         }       }     }     dp[0] = 1;     for (long long i = 0; i < (1 << k); ++i) {       for (long long s = i; s; s = (s - 1) & i) {         if (dp[s] && dp[i ^ s]) {           dp[i] = 1;           par[i] = s;         }       }     }     if (!dp[(1 << k) - 1]) {       cout <<  No n ;       return 0;     }     vector<pair<long long, long long>> ans(k);     function<void(long long)> getans = [&](long long mask) {       if (~head[mask]) {         long long u = head[mask], x = g[u];         ans[v[x].second].first = v[x].first;         ans[v[x].second].second = v[u].second + 1;         while (u != x) {           ans[v[g[x]].second].first = v[g[x]].first;           ans[v[g[x]].second].second = v[x].second + 1;           x = g[x];         }       } else {         getans(par[mask]);         getans(mask ^ par[mask]);       }     };     getans((1 << k) - 1);     cout <<  Yes n ;     for (long long i = 0; i < k; ++i)       cout << ans[i].first <<     << ans[i].second <<   n ;   }