malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, SQ = 5555;   unordered_map<int, int> ed[N];   set<pair<int, int>> edge, bad;   int n, m, k, last, par[N];   struct Query {     int t, u, v;   } qu[SQ];   bool mark[N];   queue<int> q;   int gg(int u) { return ~par[u] ? par[u] = gg(par[u]) : u; }   void merge(int u, int v) {     u = gg(u);     v = gg(v);     if (u == v) return;     par[v] = u;   }   void upd(int u, int v) {     if (u > v) swap(u, v);     int a = gg(u), b = gg(v);     if (edge.erase({u, v})) {       if (!--ed[a][b]) ed[a].erase(b);       if (!--ed[b][a]) ed[b].erase(a);     } else {       edge.insert({u, v});       ed[a][b]++, ed[b][a]++;     }   }   void bfs(int root, bool st) {     q.push(root);     mark[root] = st;     while (!q.empty()) {       int u = q.front();       for (auto v : ed[u])         if (mark[v.first] ^ st) {           mark[v.first] = st;           q.push(v.first);         }       q.pop();     }   }   bool get(int u, int v) {     bfs(u = gg(u), true);     bool ans = mark[gg(v)];     return bfs(u, false), ans;   }   int main() {     scanf( %d%d , &n, &m);     while (m) {       bad.clear();       m -= (k = min(m, SQ));       for (int i = 0; i < k; i++) {         int t, u, v;         scanf( %d%d%d , &t, &u, &v);         if (u % n > v % n) swap(u, v);         bad.insert({u % n, v % n});         if (u-- > v--) swap(u, v);         qu[i] = {t, u, v}, bad.insert({u, v});       }       memset(par, -1, sizeof par);       for (int i = 0; i < n; i++) ed[i].clear();       for (auto x : edge)         if (!bad.count(x)) merge(x.first, x.second);       for (auto x : edge)         if (bad.count(x)) {           ed[gg(x.first)][gg(x.second)]++;           ed[gg(x.second)][gg(x.first)]++;         }       for (int i = 0; i < k; i++) {         (qu[i].u += last) %= n;         (qu[i].v += last) %= n;         if (qu[i].t & 1)           upd(qu[i].u, qu[i].v);         else           printf( %d , last = get(qu[i].u, qu[i].v));       }     }   }
#include <bits/stdc++.h>   using namespace std;   double a, b, m;   double vx, vy, vz;   double x0, z0;   int main() {     scanf( %lf %lf %lf , &a, &b, &m);     {       scanf( %lf %lf %lf , &vx, &vy, &vz);       double t = -(m / vy);       double sx = vx * t;       double sz = vz * t;       int d = (int)(sz / b);       if (d % 2 == 0) {         z0 = sz - d * b;       } else {         z0 = b - (sz - d * b);       }       if (sx < -a / 2) {         sx = -(sx + a / 2);       } else {         sx = sx + a / 2;       }       d = (int)(sx / a);       if (d % 2 == 0) {         x0 = sx - d * a;       } else {         x0 = a - (sx - d * a);       }       printf( %.10lf %.10lf n , x0, z0);     }     return 0;   }
#include <bits/stdc++.h>   double arr[1005][4];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int i;     long long population = k;     double maxRadius = -1, minRadius = 1e6;     for (i = 0; i < n; i++) {       scanf( %lf%lf%lf , &arr[i][0], &arr[i][1], &arr[i][2]);       population += arr[i][2];       arr[i][3] = sqrt((arr[i][0] * arr[i][0]) + (arr[i][1] * arr[i][1]));     }     if (population < 1000000)       printf( -1 n );     else {       int i, j;       for (i = 0; i < n; i++) {         for (j = 0; j < n - 1; j++) {           if (arr[j][3] > arr[j + 1][3]) {             double temp = arr[j][3];             arr[j][3] = arr[j + 1][3];             arr[j + 1][3] = temp;             temp = arr[j][0];             arr[j][0] = arr[j + 1][0];             arr[j + 1][0] = temp;             temp = arr[j][1];             arr[j][1] = arr[j + 1][1];             arr[j + 1][1] = temp;             temp = arr[j][2];             arr[j][2] = arr[j + 1][2];             arr[j + 1][2] = temp;           }         }       }       double radius = 0;       population = k;       for (i = 0; i < n; i++) {         if (population >= 1000000)           break;         else {           radius = arr[i][3];           population += arr[i][2];           for (j = i + 1; arr[j][3] == arr[i][3] && population < 1000000; j++) {             population += arr[j][2];           }           i = j - 1;         }       }       printf( %lf n , radius);     }     return 0;   }
#include <bits/stdc++.h>   const int MOD = int(1e9) + 7;   inline int add(int a, int b) {     return (a + b >= MOD) ? (a + b - MOD) : (a + b);   }   inline void inc(int &a, int b) { a = add(a, b); }   inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); }   inline void dec(int &a, int b) { a = sub(a, b); }   inline int mul(int a, int b) { return (a * 1ll * b) % MOD; }   using namespace std;   const int N = 100000;   vector<pair<int, int> > vet;   vector<int> aux;   vector<vector<int> > cycles[N + 1];   int P[N];   bool vis[N];   void dfs(int u) {     vis[u] = true;     aux.push_back(u);     u = P[u];     if (!vis[u]) dfs(u);   }   void debug() {     for (int i = 0; i <= N; i++)       if (!cycles[i].empty()) {         printf( %d:  , i);         for (__typeof((cycles[i]).begin()) it = (cycles[i]).begin();              it != (cycles[i]).end(); ++it) {           printf( ( );           for (__typeof((*it).begin()) it2 = (*it).begin(); it2 != (*it).end();                ++it2)             printf( %d  , *it2);           printf( )  );         }         puts(  );       }   }   bool solve(int testNumber) {     int n;     if (scanf( %d , &n) == EOF) return false;     for (int i = 0; i < n; i++) {       scanf( %d , &P[i]);       P[i]--;     }     for (int i = 0; i <= N; i++) cycles[i].clear();     vet.clear();     for (int i = 0; i < N; i++) vis[i] = false;     for (int i = 0; i < n; i++)       if (!vis[i]) {         aux.clear();         dfs(i);         cycles[((int)(aux).size())].push_back(aux);       }     for (int i = 0; i <= N; i++)       for (int j = 1; j < ((int)(cycles[i]).size()); j++)         for (int k = 0; k < i; k++)           vet.push_back(make_pair((cycles[i][0][k]), (cycles[i][j][k])));     for (int i = 0; i <= N; i++)       if (!cycles[i].empty())         for (int j = 1; j * j <= i; j++)           if (i % j == 0) {             if (j != i && !cycles[j].empty()) {               for (int k = 0; k < i; k++)                 vet.push_back(                     make_pair((cycles[j][0][k % j]), (cycles[i][0][k])));               break;             }             int x = i / j;             if (x != i && !cycles[x].empty()) {               for (int k = 0; k < i; k++)                 vet.push_back(                     make_pair((cycles[x][0][k % x]), (cycles[i][0][k])));               break;             }           }     if (cycles[1].empty() && !cycles[2].empty())       vet.push_back(make_pair((cycles[2][0][0]), (cycles[2][0][1])));     if (((int)(vet).size()) < n - 1)       puts( NO );     else {       puts( YES );       for (__typeof((vet).begin()) it = (vet).begin(); it != (vet).end(); ++it)         printf( %d %d n , it->first + 1, it->second + 1);     }     return true;   }   int main() {     for (int i = 1; solve(i); i++)       ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, l, a[1000009], b[1000009], f[1000009], ans, cn, t, x, y, z,       mx, mn, s;   char c[1000009], d[1000009], ch;   map<int, int> mp, mm;   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       ans = 1;       mp.clear();       mm.clear();       for (i = 1; i <= n; i++) {         scanf( %d , &f[i]);         mm[f[i]] = 1;       }       for (i = 1; i <= m; i++) {         scanf( %d , &b[i]);         if (mm[b[i]] == 0) {           ans = 0;         }       }       if (ans == 0) {         printf( Impossible n );       } else {         ans = 1;         mp.clear();         mm.clear();         for (i = 1; i <= m; i++) {           mp[b[i]] = 1;         }         for (i = 1; i <= n; i++) {           if (mp[f[i]] == 1) {             mm[f[i]]++;             if (mm[f[i]] == 2) {               ans = 0;               break;             }           }         }         if (ans == 0) {           printf( Ambiguity n );         } else {           printf( Possible n );           mp.clear();           for (i = 1; i <= n; i++) {             mp[f[i]] = i;           }           for (i = 1; i <= m; i++) {             a[i] = mp[b[i]];             if (i > 1) {               printf(   );             }             printf( %d , a[i]);           }           printf(  n );         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dr1[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dc1[] = {0, 1, 1, 1, 0, -1, -1, -1};   int dr[] = {1, -1, 0, 0};   int dc[] = {0, 0, 1, -1};   const int fx[] = {+1, -1, +0, +0};   const int fy[] = {+0, +0, +1, -1};   const int fx8[] = {+0, +0, +1, -1, -1, +1, -1, +1};   const int fy8[] = {-1, +1, +0, +0, +1, +1, -1, -1};   const int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1};   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   int x[10005];   int y[10005];   char d[10005][10005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a, b, c = 0, i, j, k, n, m, ans = 0;     string s[10005];     cin >> n >> m;     for (__typeof(n - 1) i = (0); i <= (n - 1); i++) {       cin >> s[i];     }     for (__typeof(n - 1) i = (0); i <= (n - 1); i++) {       bool wasbest = false;       for (__typeof(m - 1) j = (0); j <= (m - 1); j++) {         bool isbest = true;         a = s[i][j] -  0 ;         for (__typeof(n - 1) k = (0); k <= (n - 1); k++)           if (s[k][j] -  0  > a) isbest = false;         if (isbest) wasbest = true;       }       if (wasbest) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = (int)2e9 + 5;   const int MOD = (int)1e9 + 7;   const long double Pi = 3.141592653589793238;   const int N = (int)2e5 + 5;   long long qqaGJJ[N], ss[2][N], vRI[2][N], n, uVyh = 0;   int main() {     cin >> n;     for (int i = (int)(1); i <= (int)(n); i++) cin >> qqaGJJ[i];     reverse(qqaGJJ + 1, qqaGJJ + n + 1);     for (int i = (int)(1); i <= (int)(n); i++) {       if (i == 1) {         ss[0][i] = ss[1][0] = 0;         vRI[0][i] = vRI[1][i] = 0;       } else {         for (int k = (int)(0); k <= (int)(1); k++) {           ss[k][i] = ss[k][i - 1] +                      abs(qqaGJJ[i] - qqaGJJ[i - 1]) * (((i + k) % 2) ? 1 : -1);           vRI[k][i] = min(vRI[k][i - 1], ss[k][i]);         }       }     }     uVyh = ss[1][2];     for (int i = (int)(2); i <= (int)(n); i++) {       uVyh = max(uVyh, ss[(i + 1) % 2][i] - vRI[(i + 1) % 2][i - 1]);     }     cout << uVyh;   }
# include <bits/stdc++.h>   # define int long long   using namespace std;   const int N=505;   const int mo=998244353;   int a[2*N][N],b[N][N];   bool f[2*N];   int Pow(int x,int n) {       int ans=1;       while (n) {           if (n&1) ans=ans*x%mo;           x=x*x%mo;           n>>=1;       }       return ans;   }   vector<int>an;   signed main() {       int t; scanf( %lld ,&t);       while (t--) {           an.clear();           long long ans=1ll;           int n; scanf( %lld ,&n);           for (int i=1;i<=2*n;i++)               for (int j=1;j<=n;j++)                   scanf( %lld ,&a[i][j]);           int tot=0;           for (int i=1;i<=2*n;i++) f[i]=false;                 while (true) {               for (int i=1;i<=n;i++)                   for (int j=1;j<=n;j++)                       b[i][j]=0;               for (int i=1;i<=2*n;i++) if (!f[i]) {                       for (int j=1;j<=n;j++)                           b[j][a[i][j]]++;                   }                        bool cc; int uniq;               for (int i=1;i<=2*n;i++) if (!f[i]) {                       cc=false;                       for (int j=1;j<=n;j++) if (b[j][a[i][j]]==1) {                               cc=true; uniq=i; break;                           }                       if (cc) break;                   }                  if (cc)               {                   an.push_back(uniq);               }               else {                   for (int i=1;i<=2*n;i++) if (!f[i]) {                           uniq=i; break;                       }                   an.push_back(uniq);                   ans=ans*2ll%mo;               }               for (int i=1;i<=2*n;i++) if (!f[i]) {                       bool flag=true;                       for (int j=1;j<=n;j++) if (a[i][j]==a[uniq][j]) {                               flag=false; break;                           }                       if (!flag) f[i]=true;                   }               if (an.size()==n) break;           }           printf( %lld n ,ans);           for (int i=0;i<an.size();i++) printf( %lld  ,an[i]);           puts(  );       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     std::vector<std::vector<long long>> f(151, std::vector<long long>(151, 0));     f[0][0] = 1;     f[1][0] = 1;     f[1][1] = 1;     for (long long i = 2; i <= 150; ++i) {       for (long long j = 0; j <= i; ++j) {         f[i][j] = ((f[i - 2][j]) + ((j != 0) ? (f[i - 1][j - 1]) : 0));         f[i][j] %= 2;       }     }     long long n;     cin >> n;     cout << n <<   n ;     for (long long i = 0; i <= n; ++i) {       cout << f[n][i] <<    ;     }     cout <<   n ;     cout << n - 1 <<   n ;     for (long long i = 0; i <= n - 1; ++i) {       cout << f[n - 1][i] <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, sum = 1e6;     cin >> n;     long a[n];     for (long i = 0; i < n; cin >> a[i++])       ;     long opt;     for (long i = 1; i <= 1000; ++i) {       long s = 0;       for (long j = 0; j < n; ++j) {         if (i != a[j]) s += abs(i - a[j]) - 1;       }       if (s < sum) {         sum = s;         opt = i;       }     }     cout << opt <<     << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:247474112 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   long long mod = 1e9 + 7;   void time() {}   const long long N = 3100300;   const long long maxn = 1e5 + 5;   const long long despacito = 1e9 + 7;   long long n, m;   long long a[N], p[N], cnt[N], z[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     cin >> m;     for (long long i = 1; i <= m; i++) {       cin >> p[i];     }     for (long long i = 1; i <= n; i++) {       cnt[a[i]]++;     }     for (long long a = 1; a <= N; a++) {       if (!cnt[a]) continue;       for (long long b = a; b < N; b += a) {         if (b / a != a) {           z[b] += (long long)(cnt[a] * cnt[b / a]);         } else           z[b] += (long long)(cnt[a] * (cnt[a] - 1));       }     }     for (long long i = 1; i <= N; ++i) {       z[i] += z[i - 1];     }     for (long long i = 1; i <= m; ++i) {       long long ans = (long long)(n) * (n - 1) - z[p[i] - 1];       cout << ans <<   n ;     }     time();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   char a[maxn], b[maxn];   int pre[maxn], suf[maxn];   int main() {     scanf( %s%s , a + 1, b + 1);     int n = strlen(a + 1);     int m = strlen(b + 1);     int pos = 0;     for (int i = 1; b[i]; i++, pos++) {       while (pos <= n && a[pos] != b[i]) pos++;       pre[i] = pos;     }     pos = n + 1;     for (int i = m; b[i]; i--, pos--) {       while (pos > 0 && b[i] != a[pos]) {         pos--;       }       suf[i] = pos;     }     suf[m + 1] = n + 1;     int ans1, ans2, l = 0, r = m;     while (l <= r) {       int mid = l + r >> 1, i;       for (i = 0; i + mid <= m; ++i)         if (pre[i] < suf[i + mid + 1]) break;       if (i + mid <= m) {         ans1 = i, ans2 = i + mid + 1, r = mid - 1;       } else         l = mid + 1;     }     if (ans2 - ans1 > m)       putchar( - );     else {       for (int i = 1; i <= ans1; ++i) putchar(b[i]);       for (int i = ans2; b[i]; ++i) putchar(b[i]);     }     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s;       int cnt[26];       fill(cnt, cnt + 26, 0);       set<int> st;       int u = s.size();       for (int j = 0; j < u; j++) {         int y = s[j] -  a ;         cnt[y]++;         st.insert(y);       }       u /= 2;       vector<int> ans;       vector<int> v;       for (auto itr = st.begin(); itr != st.end(); itr++) {         v.push_back(*itr);       }       if (v.size() == 1) {         cout << s << endl;         continue;       }       if (v.size() == 2) {         if (v[0] - v[1] == -1)           cout <<  No answer  << endl;         else {           cout << s << endl;         }         continue;       }       if (v.size() == 3) {         if (v[0] == v[1] - 1 && v[1] == v[2] - 1)           cout <<  No answer  << endl;         else if (v[0] == v[1] - 1) {           for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a );           for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a );           for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a );           cout << endl;         } else if (v[1] == v[2] - 1) {           for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a );           for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a );           for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a );           cout << endl;         } else {           for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a );           for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a );           for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a );           cout << endl;         }         continue;       }       for (int j = 1; j < v.size(); j += 2) {         for (int k = 0; k < cnt[v[j]]; k++) cout << (char)(v[j] +  a );       }       for (int j = 0; j < v.size(); j += 2) {         for (int k = 0; k < cnt[v[j]]; k++) cout << (char)(v[j] +  a );       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   constexpr int SQRT = 1000;   struct query {     int x, y, pos;     short sqrt;     bool operator<(const query &b) const {       if (sqrt == b.sqrt) {         return ((sqrt & 1) ^ y < b.y);       }       return sqrt < b.sqrt;     }   };   query que[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> que[i].x >> que[i].y;       que[i].pos = i + 1, que[i].sqrt = que[i].x / SQRT;     }     sort(que, que + n);     for (int i = 0; i < n; i++) {       cout << que[i].pos <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const int mod = 1e9 + 7;   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0)       if (b & 1) {         res = (long long)(res * 1ll * a);         --b;       } else {         a = (long long)(a * 1ll * a);         b >>= 1;       }     return (long long)res;   }   vector<vector<int>> g;   vector<bool> used;   vector<long double> ver;   void dfs(int v, int prev) {     used[v] = true;     double cnt = 0, sum = 0;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to == prev) continue;       dfs(to, v);       sum += ver[to];       cnt++;     }     if (cnt == 0)       ver[v] = 0;     else       ver[v] = 1 + sum / cnt;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       if (n % 4 == 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct S {     int l, r, x;   };   vector<S> tree[8000];   int mk[1000100], step, ans;   int n;   pair<int, int> expand(int v) {     int inc = 0;     if (v > 1) {       while ((1 << inc) < v) ++inc;     }     int bef = (v - 1) + inc;     pair<int, int> at = make_pair(bef + 1, bef + 1);     if (!(v & (v - 1))) at.second = (bef + 2);     return at;   }   void answer(int lvl, int v) {     pair<int, int> at = make_pair(v, v);     while (lvl <= n) {       pair<int, int> next =           make_pair(expand(at.first).first, expand(at.second).second);       for (int i = 0; i < tree[lvl].size(); ++i) {         int l = tree[lvl][i].l, r = tree[lvl][i].r, x = tree[lvl][i].x;         if (at.first > r || at.second < l) continue;         if (mk[x] != step) ++ans, mk[x] = step;       }       at = next;       ++lvl;     }   }   void process() {     int m;     scanf( %d%d , &n, &m);     step = 0;     for (int i = 0; i < m; ++i) {       int type, t, l, r, c, v, x;       scanf( %d , &type);       if (type == 1)         scanf( %d %d %d %d , &t, &l, &r, &x), tree[t].push_back((S){l, r, x});       else         scanf( %d %d , &t, &v), ans = 0, ++step, answer(t, v),                                 printf( %d n , ans);     }   }   int main() { process(); }
#include <bits/stdc++.h>   using namespace std;   const int N = 75010;   struct edge {     int y, next;   } s[N];   struct loop {     vector<int> V;     int S;   } P[N];   struct node {     int x, y, d;     bool operator<(const node q) const { return x < q.x; }   };   vector<node> A;   vector<int> F[32768];   int first[N], len = 0, d[N], op[N], low[N], dfn[N], T = 0;   int sta[N], top = 0, totl;   int n, num, D;   map<long long, int> mp;   map<long long, int>::iterator it;   long long sum[20], tot = 0;   void ins(int x, int y) {     s[++len] = (edge){y, first[x]};     first[x] = len;   }   void Tarjan(int x) {     dfn[x] = ++T;     low[x] = T;     sta[++top] = x;     for (int i = first[x]; i != 0; i = s[i].next) {       if (!dfn[s[i].y]) {         Tarjan(s[i].y);         low[x] = min(low[x], low[s[i].y]);       } else         low[x] = min(low[x], dfn[s[i].y]);     }     if (low[x] == dfn[x]) {       bool tf = true;       totl++;       while (1) {         int now = sta[top];         top--;         P[totl].V.push_back(now);         if (P[totl].S & (1 << (d[now] - 1))) tf = false;         P[totl].S |= (1 << (d[now] - 1));         if (now == x) break;       }       if (first[x] == 0 || P[totl].V.size() == 1 && s[first[x]].y != x || !tf)         return;       if (!F[P[totl].S].size()) F[P[totl].S].push_back(totl);     }   }   int main() {     scanf( %d , &n);     D = (1 << n) - 1;     int size = 0, x, y;     mp.clear();     for (int i = 1; i <= n; i++) {       scanf( %d , &size);       while (size--) {         num++;         scanf( %d , &op[num]);         mp[1ll * op[num]] = num;         d[num] = i;         sum[i] += op[num];       }       tot += sum[i];     }     if (tot % n != 0) {       printf( No n );       return 0;     }     tot /= n;     for (int i = 1; i <= num; i++)       if (mp[tot - sum[d[i]] + op[i]]) ins(i, mp[tot - sum[d[i]] + op[i]]);     for (int i = 1; i <= num; i++)       if (!dfn[i]) Tarjan(i);     for (int i = 1; i <= D; i++)       for (int j = i & (i - 1); j; j = (j - 1) & i) {         if (F[j].size() && F[i ^ j].size()) {           F[i] = F[i ^ j];           for (int k = 0; k < F[j].size(); k++) F[i].push_back(F[j][k]);           break;         }       }     if (!F[D].size())       printf( No n );     else {       printf( Yes n );       for (int i = 0; i < F[D].size(); i++) {         x = F[D][i];         for (int j = 0; j < P[x].V.size() - 1; j++)           A.push_back((node){d[P[x].V[j]], op[P[x].V[j]], d[P[x].V[j + 1]]});         A.push_back((node){d[P[x].V[P[x].V.size() - 1]],                            op[P[x].V[P[x].V.size() - 1]], d[P[x].V[0]]});       }       sort(A.begin(), A.end());       for (int i = 0; i < A.size(); i++) printf( %d %d n , A[i].y, A[i].d);     }   }