malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool solve(vector<int> ps, vector<int> v) {     if (ps.empty()) return v[0] == 0;     int n = v.size();     vector<int> nps(ps.begin() + 1, ps.end());     vector<vector<int> > g(ps[0], vector<int>(n / ps[0]));     bool ans = true;     for (int i = 0; i < n; ++i) {       g[i % ps[0]][i % (n / ps[0])] = v[i];     }     for (int i = 1; i < ps[0]; ++i) {       for (int j = 0; j < n / ps[0]; ++j) {         g[i][j] -= g[0][j];       }       if (!solve(nps, g[i])) ans = false;     }     return ans;   }   int main() {     int N;     string S;     cin >> N >> S;     vector<int> ps;     int rad = 1, x = N;     for (int i = 2; i * i <= x; ++i) {       if (x % i == 0) {         rad *= i;         ps.push_back(i);         while (x % i == 0) x /= i;       }     }     if (x > 1) rad *= x, ps.push_back(x);     bool ans = true;     for (int i = 0; i < N / rad; ++i) {       vector<int> v;       for (int j = i; j < N; j += N / rad) {         v.push_back(S[j] -  0 );       }       bool res = solve(ps, v);       if (!res) ans = false;     }     cout << (ans ?  YES  :  NO ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 77;   int n;   char s[N];   vector<int> v, k, x;   int dp[N][N][N][2];   int count(vector<int> &list, int from, int w) {     int cnt = 0;     for (int i = from; i < list.size(); i++) {       if (list[i] < w) cnt++;     }     return cnt;   }   int cost(int vv, int kk, int xx, int w) {     return count(v, vv, w) + count(k, kk, w) + count(x, xx, w);   }   int main() {     scanf( %d , &n);     scanf( %s , s);     for (int i = 0; i < n; i++) {       if (s[i] ==  V )         v.push_back(i);       else if (s[i] ==  K )         k.push_back(i);       else         x.push_back(i);     }     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < N; k++)           for (int l = 0; l < 2; l++) dp[i][j][k][l] = 1e9;     dp[0][0][0][0] = 0;     for (int i = 0; i <= v.size(); i++) {       for (int j = 0; j <= k.size(); j++) {         for (int p = 0; p <= x.size(); p++) {           for (int c = 0; c < 2; c++) {             if (i < v.size())               dp[i + 1][j][p][1] =                   min(dp[i + 1][j][p][1], cost(i, j, p, v[i]) + dp[i][j][p][c]);             if (c == 0 && j < k.size())               dp[i][j + 1][p][0] =                   min(dp[i][j + 1][p][0], cost(i, j, p, k[j]) + dp[i][j][p][c]);             if (p < x.size())               dp[i][j][p + 1][0] =                   min(dp[i][j][p + 1][0], cost(i, j, p, x[p]) + dp[i][j][p][c]);           }         }       }     }     printf( %d n , min(dp[v.size()][k.size()][x.size()][0],                        dp[v.size()][k.size()][x.size()][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, flag = 0;     int a[5005];     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       if (a[a[a[i]]] == i) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   const double PI = 3.1415926535897932384626433;   const int KL = 1e4 + 10;   const long long MOD = 1e9 + 7;   using namespace std;   int n;   struct point {     long double x, y, z;   };   long double dis(point a, point b) {     long double dx = a.x - b.x;     long double dy = a.y - b.y;     long double dz = a.z - b.z;     return sqrt(dx * dx + dy * dy + dz * dz);   }   point a[KL], p;   long double t[KL], vp, vs;   bool ok(long double mid) {     long double ttt = 0.0;     int pos;     for (int i = 1; i <= n; i++) {       ttt += t[i];       if (ttt >= mid) {         pos = i;         break;       }     }     long double dx = a[pos].x - a[pos - 1].x;     long double dy = a[pos].y - a[pos - 1].y;     long double dz = a[pos].z - a[pos - 1].z;     long double d = dis(a[pos], a[pos - 1]);     long double dc = (mid - (ttt - t[pos])) * vs;     long double sm = dc / d;     dx = dx * sm;     dy = dy * sm;     dz = dz * sm;     point c = {dx + a[pos - 1].x, dy + a[pos - 1].y, dz + a[pos - 1].z};     long double ds = dis(c, p);     return (ds / mid <= vp);   }   void prnt(long double nm) { cout << fixed << setprecision(10) << nm <<    ; }   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       cin >> a[i].x >> a[i].y >> a[i].z;     }     cin >> vp >> vs >> p.x >> p.y >> p.z;     long double tt = 0.0;     for (int i = 1; i <= n; i++) {       t[i] = dis(a[i - 1], a[i]) / vs;       tt += t[i];     }     if (!ok(tt))       cout <<  NO  << endl;     else {       long double lo = 0;       long double hi = tt;       for (int i = 0; i < 100; i++) {         long double mid = (lo + hi) / 2;         if (ok(mid))           hi = mid;         else           lo = mid;       }       cout <<  YES  << endl;       cout << fixed << setprecision(10) << lo << endl;       if (lo == 0) {         prnt(a[0].x);         prnt(a[0].y);         prnt(a[0].z);         cout << endl;         return 0;       }       long double ttt = 0.0;       int pos;       for (int i = 0; i <= n; i++) {         ttt += t[i];         if (ttt >= lo) {           pos = i;           break;         }       }       long double dx = a[pos].x - a[pos - 1].x;       long double dy = a[pos].y - a[pos - 1].y;       long double dz = a[pos].z - a[pos - 1].z;       long double d = dis(a[pos], a[pos - 1]);       long double dc = (lo - (ttt - t[pos])) * vs;       long double sm = dc / d;       dx = dx * sm;       dy = dy * sm;       dz = dz * sm;       point c = {dx + a[pos - 1].x, dy + a[pos - 1].y, dz + a[pos - 1].z};       prnt(c.x);       prnt(c.y);       prnt(c.z);       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     vector<Node*> next;     Node() : next(26, nullptr) {}   };   Node* root = new Node;   void insert(string& s, int i, Node* c) {     if (i >= s.length()) return;     if (c->next[s[i] -  a ] == nullptr) {       c->next[s[i] -  a ] = new Node;     }     insert(s, i + 1, c->next[s[i] -  a ]);   }   bool traverseWin(Node* c) {     bool curWin = false;     for (auto n : c->next)       if (n != nullptr) {         if (!traverseWin(n)) curWin = true;       }     return curWin;   }   bool traverseLose(Node* c) {     bool curLose = false;     int i = 0;     for (auto n : c->next)       if (n != nullptr) {         ++i;         if (!traverseLose(n)) curLose = true;       }     return curLose || (i == 0);   }   int main(int, char**) {     std::ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       insert(s, 0, root);     }     bool w = traverseWin(root);     bool l = traverseLose(root);     if (!w) {       cout <<  Second  << endl;     } else {       if (!l) {         cout << (k % 2 == 0 ?  Second  :  First ) << endl;       } else {         cout <<  First  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a1, a2, b1, b2, c1, c2;   int main() {     cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;     if (a1 == 0 && b1 == 0 && c1 != 0 || a2 == 0 && b2 == 0 && c2 != 0) {       cout <<  0 n ;       return 0;     }     int m1 = b1 * a2, m2 = b2 * a1;     if (m1 == m2)       if (c1 * b2 != c2 * b1 || a1 * c2 != a2 * c1)         cout <<  0 n ;       else         cout <<  -1 n ;     else       cout <<  1 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ax, ay, bx, by, cx, cy;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> ax >> ay >> bx >> by >> cx >> cy;     if ((by - ay) * (cx - bx) == (cy - by) * (bx - ax))       cout <<  NO n ;     else if ((by - ay) * (by - ay) + (bx - ax) * (bx - ax) ==              (by - cy) * (by - cy) + (bx - cx) * (bx - cx))       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n(0);     scanf( %d , &n);     char first =  x , last =  y ;     int count(0);     if (n % 2 == 0) {       for (int k = 0; k < n / 2; k++) {         printf( %c%c , (count) % 2 +  a , (count) % 2 +  a );         ++count;       };       puts(  );       for (int k = 0; k < n / 2; k++) {         printf( %c%c , (count) % 2 +  c , (count) % 2 +  c );         ++count;       };       puts(  );       printf( %c , first);       for (int k = 0; k < n / 2 - 1; k++) {         printf( %c%c , (count) % 2 +  f , (count) % 2 +  f );         ++count;       };       printf( %c n , last);       printf( %c , first);       for (int k = 0; k < n / 2 - 1; k++) {         printf( %c%c , (count) % 2 +  m , (count) % 2 +  m );         ++count;       };       printf( %c n , last);     } else if (n % 2 == 1) {       char count =  b ;       printf( %c , first);       for (int k = 0; k < n / 2; k++) {         printf( %c%c , (count) % 2 +  a , (count) % 2 +  a );         ++count;       };       puts(  );       printf( %c , first);       for (int k = 0; k < n / 2; k++) {         printf( %c%c , (count) % 2 +  c , (count) % 2 +  c );         ++count;       };       puts(  );       for (int k = 0; k < n / 2; k++) {         printf( %c%c , (count) % 2 +  f , (count) % 2 +  f );         ++count;       };       printf( %c n , last);       for (int k = 0; k < n / 2; k++) {         printf( %c%c , (count) % 2 +  m , (count) % 2 +  m );         ++count;       };       printf( %c n , last);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:102400000,102400000 )   using namespace std;   const double PI = acos(-1.0);   int f_max(int a, int b) { return a > b ? a : b; }   int f_min(int a, int b) { return a < b ? a : b; }   int f_abs(int a) { return a > 0 ? a : -a; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int n, m;   int u, d, l, r;   int x, y;   int main() {     int q, w, e;     int i, j, k;     int ans, len;     while (~scanf( %d%d , &n, &m)) {       len = 0x7fffffff;       r = u = -0x7fffffff;       l = d = 0x7fffffff;       scanf( %d , &n);       for (i = 0; i < n; i++) {         scanf( %d%d , &x, &y);         u = f_max(u, y - x);         d = f_min(d, y - x);         l = f_min(l, x + y);         r = f_max(r, x + y);       }       scanf( %d , &m);       int mm;       for (i = 1; i <= m; i++) {         scanf( %d%d , &x, &y);         mm = 0;         mm = f_max(mm, u - (y - x));         mm = f_max(mm, (y - x) - d);         mm = f_max(mm, r - (x + y));         mm = f_max(mm, (x + y) - l);         if (mm < len) {           ans = i;           len = mm;         }       }       printf( %d n%d n , len, ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   long long mod = 1e9 + 7;   long long fmod(long long b, long long exp) {     long long res = 1;     while (exp) {       if (exp & 1ll) res = (res * b) % mod;       b = (b * b) % mod;       exp /= 2ll;     }     return res;   }   long long buc[101];   long long fac[N], inv[N];   long long dp[N], temp_dp[N];   long long ans[55][55];   string s, s1, s2;   int find(char c) {     if (c >=  A  && c <=  Z )       return (int)(c -  A  + 26);     else       return (c -  a );   }   inline void add(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1, n, i, j, m, q;     cin >> s;     n = s.length();     for (int i = 0; i < n; i++) buc[find(s[i])]++;     fac[0] = 1;     for (i = 1; i <= n; i++) fac[i] = (fac[i - 1] * 1ll * i) % mod;     inv[n] = fmod(fac[n], mod - 2);     for (int i = n - 1; i >= 0; i--) inv[i] = (inv[i + 1] * 1ll * (i + 1)) % mod;     long long num = (fac[n / 2] * fac[n / 2]) % mod;     for (int i = 0; i < 52; i++) num = (num * inv[buc[i]]) % mod;     dp[0] = 1;     for (int i = 0; i < 52; i++) {       if (!buc[i]) continue;       for (int j = n; j >= buc[i]; j--) add(dp[j], dp[j - buc[i]]);     }     for (i = 0; i < 52; i++) ans[i][i] = dp[n / 2];     for (i = 0; i < 52; i++) {       if (!buc[i]) continue;       for (int k = 0; k <= n; k++) temp_dp[k] = dp[k];       for (int k = buc[i]; k <= n; k++) sub(temp_dp[k], temp_dp[k - buc[i]]);       for (int j = i + 1; j < 52; j++) {         if (!buc[j]) continue;         for (int k = buc[j]; k <= n; k++) sub(temp_dp[k], temp_dp[k - buc[j]]);         ans[i][j] = (2ll * temp_dp[n / 2]) % mod;         ans[j][i] = ans[i][j];         for (int k = n; k >= buc[j]; k--) add(temp_dp[k], temp_dp[k - buc[j]]);       }     }     cin >> q;     int x, y;     while (q--) {       cin >> x >> y;       int l = find(s[x - 1]);       int r = find(s[y - 1]);       cout << (num * ans[l][r]) % mod <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const double PI = acos(-1.0);   const int INF = 0x3f3f3f3f;   const double eps = 1e-8;   const int MAXN = 1e3 + 10;   const long long MOD = 1e9 + 7;   int cases = 0;   using std::string;   const int dir[][2] = {{-1, 0}, {-1, -1}, {-1, 1}, {0, -1},                         {0, 1},  {1, -1},  {1, 0},  {1, 1}};   int next[MAXN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     while (m--) {       int t, k, d;       std::vector<int> tmp;       scanf( %d%d%d , &t, &k, &d);       int cnt = 0;       int res = 0;       for (int i = 1; i <= n; ++i) {         if (next[i] <= t) {           tmp.push_back(i);         }         if (tmp.size() == k) {           for (int u : tmp) {             next[u] = t + d;             res += u;           }           break;         }       }       printf( %d n , res == 0 ? -1 : res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int maxn = 3e5 + 5;   int level[maxn * 2], num[maxn * 2], par[maxn * 2];   char s[maxn * 2];   stack<int> stk;   int main() {     int n, cnt = 0;     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       if (stk.empty())         stk.push(i);       else {         int c = stk.top();         if (s[i] ==  )  && s[c] ==  ( )           stk.pop();         else           stk.push(i);       }       s[i + n] = s[i];       cnt = cnt + ((s[i] ==  ( ) ? (1) : (-1));     }     if (cnt) return 0 & printf( 0 n1 1 n );     int j = 1;     while (!stk.empty()) {       int c = stk.top();       if (s[c] ==  ) ) break;       stk.pop();       j = c;     }     for (int i = 1; i <= n * 2; i++) level[i] = -1, num[i] = 0;     while (!stk.empty()) stk.pop();     for (int i = j; i <= j + n - 1; i++) {       if (stk.empty()) {         stk.push(i);         level[i] = 1;         cnt++;       } else {         int c = stk.top();         if (s[i] ==  )  && s[c] ==  ( ) {           stk.pop();           par[c] = i;         } else {           stk.push(i);           level[i] = stk.size();         }       }     }     int i = j;     while (i <= j + n - 1) {       if (level[i] == 1) {         int r = par[i], k = i;         while (i < r) {           if (level[i] == 2) num[k]++;           i++;         }       }       i++;     }     i = j;     while (i <= j + n - 1) {       if (level[i] == 2) {         int r = par[i], k = i;         while (i < r) {           if (level[i] == 3) num[k]++;           i++;         }       }       i++;     }     int ans = 0, l, r;     for (int i = j; i <= j + n - 1; i++) {       if (level[i] == 1) {         if (ans < (num[i] + 1)) {           ans = num[i] + 1;           l = i % n;           r = par[i] % n;         }       } else if (level[i] == 2) {         if (ans < (cnt + num[i] + 1)) {           ans = cnt + num[i] + 1;           l = i % n;           r = par[i] % n;         }       }     }     if (ans < cnt) ans = cnt, l = 1, r = 1;     if (l == 0) l = n;     if (r == 0) r = n;     printf( %d n%d %d n , ans, l, r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, k, i, a, b, da, db, u, v, head[N], Next[N * 2], adj[N * 2], j, dp[N],       ans, dd, t;   void Push(int u, int v) {     Next[++k] = head[u];     head[u] = k;     adj[k] = v;   }   void dfs(int i, int fa) {     int j, mxx = 0;     dp[i] = 0;     for (j = head[i]; j; j = Next[j])       if (adj[j] != fa) {         dfs(adj[j], i);         if (dp[i] < dp[adj[j]] + 1) {           mxx = max(mxx, dp[i]);           dp[i] = dp[adj[j]] + 1;         } else           mxx = max(mxx, dp[adj[j]] + 1);       }     ans = max(ans, mxx + dp[i]);   }   void dis(int i, int fa, int d) {     int j;     for (j = head[i]; j; j = Next[j])       if (adj[j] != fa) dis(adj[j], i, d + 1);     if (i == b) dd = d;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d %d %d %d , &n, &a, &b, &da, &db);       for (i = 1; i <= n; ++i) head[i] = 0;       k = 0;       for (i = 1; i < n; ++i) {         scanf( %d %d , &u, &v);         Push(u, v);         Push(v, u);       }       if (db <= da * 2) {         puts( Alice );         continue;       }       ans = 0;       dfs(1, 0);       dis(a, 0, 0);       if (dd <= da || ans <= da * 2)         puts( Alice );       else         puts( Bob );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     int n, tmp;     vector<pair<int, int> > a;     cin >> n;     for (int i = 0; i < n; i++) cin >> tmp, a.push_back(make_pair(tmp, i + 1));     sort(a.begin(), a.end());     int c1 = 0, c2 = 0, s1 = 0, s2 = 0;     vector<int> t1, t2;     int l = 0, r = n - 1;     while (l <= r) {       if (s1 > s2) {         if (c2 - c1 <= 0) {           c2++;           s2 += a[r].first;           t2.push_back(a[r].second);           r--;         } else {           c1++;           s1 += a[l].first;           t1.push_back(a[l].second);           l++;         }       } else {         if (c2 - c1 <= 0) {           c2++;           s2 += a[l].first;           t2.push_back(a[l].second);           l++;         } else {           c1++;           s1 += a[r].first;           t1.push_back(a[r].second);           r--;         }       }     }     cout << c1 << endl;     for (int i = 0; i < c1; i++) cout << t1[i] <<    ;     cout << endl;     cout << c2 << endl;     for (int i = 0; i < c2; i++) cout << t2[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   int c[maxn], A[maxn], B[maxn];   int n, k, a, b, q, cmd;   void add(int *c, int p, int val) {     for (; p <= n; p += p & -p) c[p] += val;   }   int sum(int *c, int p) {     int ret = 0;     for (; p; p -= p & -p) ret += c[p];     return ret;   }   int main() {     cin >> n >> k >> a >> b >> q;     while (q--) {       int x, y;       scanf( %d , &cmd);       if (cmd == 1) {         scanf( %d%d , &x, &y);         add(A, x, -min(c[x], a));         add(B, x, -min(c[x], b));         c[x] += y;         add(A, x, min(c[x], a));         add(B, x, min(c[x], b));       } else {         scanf( %d , &x);         int ans = 0;         ans += sum(B, x - 1);         ans += sum(A, n) - sum(A, x + k - 1);         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2 * 1e6 + 10;   long long a[maxn], b[maxn], q[maxn], sz[maxn], n;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x * f;   }   long long b1, b2, n1;   signed main() {     n = read();     long long p = 0;     for (long long i = 1; i <= n; i++) {       a[i] = read();       if (a[i] > a[p]) p = i;       if (a[i] > b1)         b2 = b1, b1 = a[i], n1 = 1;       else if (a[i] == b1)         n1++;       else if (a[i] > b2)         b2 = a[i];     }     for (long long i = 1; i <= n; i++) b[i] = a[(i + p - 1) % n + 1];     long long l = 1, r = 0, ans = 0;     for (long long i = 1; i <= n; i++) {       while (l <= r && b[i] > b[q[r]]) r--, ans++;       if (r >= l) {         if (b[i] == b[q[r]])           ans += min(r, sz[r] + 1);         else           ans++;       }       q[++r] = i;       if (b[i] == b[q[r - 1]])         sz[r] = sz[r - 1] + 1;       else         sz[r] = 1;     }     p = 0;     for (long long i = 1; i < n; i++)       if (b[i] >= b[p]) {         p = i;         if (n1 > 1 && b[p] == b1)           ;         else if (n1 == 1 && b[p] == b2)           ;         else           ans++;       }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Max = 50;   int row[Max][Max] = {0}, dp[Max][Max][Max][Max] = {0}, a[Max][Max];   int main() {     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %1d , &a[i][j]);         row[i][j] = row[i][j - 1] + 1;         if (a[i][j] == 1) row[i][j] = 0;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int k = i; k <= n; k++) {           for (int l = j; l <= m; l++) {             dp[i][j][k][l] =                 dp[i][j][k - 1][l] + dp[i][j][k][l - 1] - dp[i][j][k - 1][l - 1];             int r = l - j + 1;             for (int z = k; z >= i; z--) {               r = min(r, row[z][l]);               dp[i][j][k][l] += r;             }           }         }       }     }     while (q--) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       cout << dp[a][b][c][d] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int n, k;   int siz[100086];   int c, x;   int id[100086];   int mx;   char s[100086];   inline int get(int l, int r) {     printf( ? %d , r - l + 1), fflush(stdout);     for (int i = l; i <= r; i++) printf(  %d , i), fflush(stdout);     puts(  );     fflush(stdout);     int x;     scanf( %d , &x);     return x;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &k);       for (int i = 1; i <= k; i++) siz[i] = 0;       for (int i = 1; i <= n; i++) id[i] = 0;       for (int i = 1; i <= k; i++) {         scanf( %d , &c);         while (c--) {           scanf( %d , &x);           id[x] = i;           siz[i]++;         }       }       mx = get(1, n);       int l = 1, r = n, mid;       while (l < r) {         mid = l + r >> 1;         x = get(l, mid);         if (x == mx)           r = mid;         else           l = mid + 1;       }       if (!id[l])         x = mx;       else {         printf( ? %d , n - siz[id[l]]), fflush(stdout);         for (int i = 1; i <= n; i++)           if (id[i] != id[l]) printf(  %d , i), fflush(stdout);         puts(  );         fflush(stdout);         scanf( %d , &x);       }       printf( ! ), fflush(stdout);       for (int i = 1; i <= k; i++) {         if (i == id[l])           printf(  %d , x);         else           printf(  %d , mx);         fflush(stdout);       }       puts(  );       fflush(stdout);       scanf( %s , s);       if (s[0] ==  I ) return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 3e5 + 5;   const long long INF = 1e14;   vector<long long> adj[33];   int dirx[] = {-1, 1, 0, 0};   int diry[] = {0, 0, -1, 1};   long long ans[33][2];   void dfs(int u, int p, int dir, long long dist) {     int d = 0;     for (long long i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p) continue;       if (dir == d) d++;       ans[v][0] = ans[u][0] + dist * dirx[d];       ans[v][1] = ans[u][1] + dist * diry[d];       dfs(v, u, d ^ 1, (dist >> 1));       d++;     }   }   int main() {     ios::sync_with_stdio(false);     int n;     int a, b;     cin >> n;     for (long long i = 0; i < n - 1; i++) {       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (long long i = 0; i < n; i++)       if (adj[i].size() > 4) {         cout <<  NO n ;         return 0;       }     ans[0][0] = 0;     ans[0][1] = 0;     dfs(0, -1, -1, (1 << 30));     cout <<  YES n ;     for (long long i = 0; i < n; i++)       cout << ans[i][0] <<     << ans[i][1] <<   n ;     return 0;   }