malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   struct Node {     long long dis, mxdis;     int id;     bool operator<(const Node &rhs) const {       if (dis == rhs.dis) return mxdis < rhs.mxdis;       return dis < rhs.dis;     }   } p[MAXN];   struct NO {     long long dis, mxdis;     int id;     NO(long long x, long long y, int z) {       dis = x, mxdis = y;       id = z;     }     bool operator<(const NO &rhs) const { return mxdis > rhs.mxdis; }   };   priority_queue<NO> q;   long long l[MAXN], r[MAXN];   struct Node1 {     long long val;     int id;     bool operator<(const Node1 &rhs) const { return val < rhs.val; }   } a[MAXN];   int ans[MAXN];   int main() {     int n, m, i;     while (scanf( %d%d , &n, &m) == 2) {       for (i = 0; i < n; i++) {         scanf( %lld%lld , &l[i], &r[i]);         if (i > 0) {           p[i].dis = l[i] - r[i - 1];           p[i].mxdis = r[i] - l[i - 1];           p[i].id = i;         }       }       sort(p + 1, p + n);       for (i = 0; i < m; i++) {         scanf( %lld , &a[i].val);         a[i].id = i;       }       sort(a, a + m);       int left = 1;       while (!q.empty()) q.pop();       int ok = 1;       if (n > m + 1) {         printf( No n );         continue;       }       for (i = 0; i < m; i++) {         while (a[i].val >= p[left].dis && left < n) {           q.push(NO(p[left].dis, p[left].mxdis, p[left].id));           left++;         }         if (!q.empty()) {           NO x = q.top();           q.pop();           if (x.mxdis >= a[i].val)             ans[x.id] = a[i].id + 1;           else {             ok = 0;             break;           }         }       }       if (ok && q.empty() && left == n) {         printf( Yes n );         for (i = 1; i < n; i++) printf( %d%c , ans[i], (i == n - 1) ?   n  :    );       } else         printf( No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T modpow(T base, T exp) {     T result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base);       base = (base * base);       exp >>= 1;     }     return result;   }   int main() {     queue<string> poss;     long long int n, q;     string x, y, poss1;     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     map<string, vector<string> > m;     for (long long int(i) = (0); (i) < (q); (i)++) {       cin >> x >> y;       m[y].push_back(x);     }     map<string, vector<string> >::iterator it;     it = m.begin();     if ((*it).first !=  a ) {       cout << 0 << endl;       return 0;     } else {       for (long long int(i) = (0); (i) < (m[ a ].size()); (i)++)         poss.push((m[ a ])[i]);       int cnt = 2;       while (cnt != n) {         while ((poss.front()).length() != cnt + 1) {           string c = (poss.front()).substr(0, 1);           if (m.find(c) != m.end()) {             string str = poss.front();             poss.pop();             str = str.substr(1, str.length() - 1);             for (long long int(j) = (0); (j) < (m[c].size()); (j)++)               poss.push(m[c][j] + str);           } else             poss.pop();           if (poss.empty()) {             cout <<  0  << endl;             return 0;           }         }         cnt++;       }     }     cout << poss.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[100005];   map<long long int, int> m;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &arr[i]);     }     for (int i = 1; i <= n; i++) {       arr[i] += arr[i - 1];       m[arr[i]]++;     }     int maxVal = 0;     for (int i = 1; i <= n; i++) {       maxVal = max(maxVal, m[arr[i - 1]]);     }     printf( %d , n - maxVal);   }
#include <bits/stdc++.h>   using namespace std;   string solve() {     int a, b, n;     string number =   ;     cin >> a >> b >> n;     bool added;     added = false;     a *= 10;     for (int j = 1; j < 11; j++) {       if (a % b == 0) {         added = true;         break;       }       a++;     }     if (!added) return  -1 ;     number = to_string(a);     for (int i = 0; i < n - 1; i++) number +=  0 ;     return number;   }   int main(void) { cout << solve() <<   n ; }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[3003];   int cost[3003], par[3003];   bool vis[3003];   map<pair<int, int>, bool> mark;   void path(int x, int y) {     if (x == y) return;     cost[x] = 0;     path(par[x], y);   }   void dfs(int u) {     vis[u] = true;     for (int v : adj[u]) {       if (vis[v]) {         if (par[u] != v) {           cost[v] = 0;           if (!mark[{u, v}]) {             path(u, v);             mark[{u, v}] = mark[{v, u}] = true;           }         }       } else         par[v] = u, dfs(v);     }   }   void bfs(int src) {     queue<int> q;     q.push(src);     while (q.size()) {       int u = q.front();       q.pop();       for (int v : adj[u]) {         if (cost[v] == -1) {           cost[v] = cost[u] + 1;           q.push(v);         }       }     }   }   int main() {     int n, x, y;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     memset(cost, -1, sizeof cost);     par[1] = 1;     dfs(1);     memset(vis, false, sizeof vis);     for (int i = 1; i <= n; i++) {       if (cost[i] == 0) bfs(i);     }     for (int i = 1; i <= n; i++) cout << cost[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200010];   vector<int> v[70];   int main() {     int i, j, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &a[i]);       for (j = 1; j < 63; j++) {         if (a[i] % (1LL << j)) {           v[j].push_back(i);           break;         }       }     }     int ans = 0, tmp = 0;     for (i = 1; i < 63; i++) {       if (ans < v[i].size()) {         ans = v[i].size();         tmp = i;       }     }     printf( %d n , n - ans);     for (i = 1; i < 63; i++) {       if (i == tmp) continue;       for (auto j : v[i]) printf( %lld  , a[j]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[100010];   vector<int> qe[710000];   map<pair<int, int>, int> dp;   long long hehe[20];   long long find(int x, int y) {     int k = y, n = 1;     while (k) {       n++;       k /= 10;     }     return hehe[n] * x + y;   }   int get(char a[], int n) {     int ans = 0;     for (int i = 0; i < n; i++) {       ans = ans * 27 + a[i] -  a  + 1;     }     return ans;   }   int getans(int x, int y, int n1, int n2) {     int ans = 78974453;     int ll, rr, l, r;     for (int i = 0; i < qe[x].size(); i++) {       l = qe[x][i];       r = l + n1;       int p = int(lower_bound(qe[y].begin(), qe[y].end(), l) - qe[y].begin());       if (p < qe[y].size()) {         rr = qe[y][p] + n2;         if (r > rr) rr = r;         ans = min(ans, rr - l);       }       p--;       if (p >= 0) {         rr = qe[y][p] + n2;         if (r > rr) rr = r;         ans = min(ans, rr - qe[y][p]);       }     }     return ans;   }   int main() {     int n, i, j, k, m;     int x, y;     char s1[5], s2[5];     hehe[1] = 1;     for (i = 2; i <= 15; i++) hehe[i] = hehe[i - 1] * 10;     scanf( %s , a);     n = strlen(a);     for (i = 0; i < n; i++) {       for (j = 1; j < 5; j++) {         if (j + i > n) break;         k = get(a + i, j);         qe[k].push_back(i);       }     }     scanf( %d , &m);     while (m--) {       scanf( %s%s , s1, s2);       int xx = strlen(s1);       int yy = strlen(s2);       x = get(s1, xx);       y = get(s2, yy);       if (qe[x].size() > qe[x].size() ||           (qe[x].size() == qe[y].size() && x > y)) {         swap(x, y);         swap(xx, yy);       }       int &ans = dp[pair<int, int>(x, y)];       if (!ans) ans = getans(x, y, xx, yy);       printf( %d n , ans == 78974453 ? -1 : ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[100];   queue<int> q;   int main() {     ios::sync_with_stdio(false);     int n, m, k, t;     cin >> n >> m >> k;     for (int i = 0; i < k; ++i) cin >> p[i];     for (int i = 0; i < m * n; ++i) {       cin >> t;       q.push(t);     }     int an = 0;     for (int i = 0; i < m * n; ++i) {       for (int j = 0; j < k; ++j) {         if (p[j] == q.front())           for (int h = j; h > 0; --h) {             swap(p[h], p[h - 1]);             an++;           }       }       an++;       q.pop();     }     cout << an;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const string alf =  abcdefghijklmnopqrstuvwxyz ;   const int hashP = 239017;   const int N = 1e5 + 10;   const int MOD = 1e9 + 7;   const int MOD2 = 998244353;   const int INF = 1e9;   const long long INF2 = 1e18;   template <typename T>   bool umn(T &a, T b) {     return (a > b ? (a = b, 1) : 0);   }   template <typename T>   bool umx(T &a, T b) {     return (a < b ? (a = b, 1) : 0);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s = to_string(n);     long long dl = s.size();     long long ans = 0;     for (long long mask = 1; mask <= (1 << dl); mask++) {       long long ch = 0;       vector<long long> a;       for (int i = 0; i < dl; i++) {         long long c = (mask >> i) & 1;         a.push_back(c);       }       reverse(a.begin(), a.end());       for (int i = 0; i < dl; i++) {         ch *= 10;         long long c = a[i];         ch += c;       }       if (n >= ch) ans++;     }     cout << ans - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   FILE* stream;   mt19937 rng(1337);   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); i++) {       cin >> a[i];     }     vector<int> b(n);     for (int i = 0; i < int(n); i++) {       if (i % 2) {         b[i] = a[i - 1];       } else {         b[i] = -a[i + 1];       }     }     for (int i = 0; i < int(n); i++) cout << b[i] <<    ;     cout << endl;     return;   }   signed main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, a[4005], b[4005];     bitset<4005> adj[4005];     cin >> n >> m;     vector<int> tam(n + 1);     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i];       adj[a[i]][b[i]] = 1;       adj[b[i]][a[i]] = 1;       tam[a[i]]++;       tam[b[i]]++;     }     int res = 1e9;     for (int i = 0; i < m; i++) {       for (int j = i + 1; j < m; j++) {         vector<int> v = {a[i], b[i], a[j], b[j]};         sort(v.begin(), v.end());         v.erase(unique(v.begin(), v.end()), v.end());         if (v.size() != 3) continue;         if (adj[v[0]][v[1]] && adj[v[1]][v[2]] && adj[v[2]][v[0]]) {           res = min(res, tam[v[0]] + tam[v[1]] + tam[v[2]] - 6);         }       }     }     if (res == 1e9)       cout << -1 <<   n ;     else       cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, s[4], s_indx = 0, m, n, o, p;   int main() {     float x[8], y[8], x1, y1, x2, y2, sq = 0, r = 0, indx = 0, a, b, c, d,                                       square[3];     for (int i = 0; i < 8; i++) {       cin >> x[i] >> y[i];     }     for (i = 0; i <= 4 && indx == 0; i++) {       for (j = i + 1; j <= 5 && indx == 0; j++) {         for (k = j + 1; k <= 6 && indx == 0; k++) {           for (l = k + 1; l <= 7 && indx == 0; l++) {             x1 = (x[i] + x[j] + x[k] + x[l]) / 4;             y1 = (y[i] + y[j] + y[k] + y[l]) / 4;             a = sqrt(pow(x1 - x[i], 2) + pow(y1 - y[i], 2));             b = sqrt(pow(x1 - x[j], 2) + pow(y1 - y[j], 2));             c = sqrt(pow(x1 - x[k], 2) + pow(y1 - y[k], 2));             d = sqrt(pow(x1 - x[l], 2) + pow(y1 - y[l], 2));             if (a == b && a == c && a == d) {               indx = 1;             }           }         }       }     }     i -= 1;     j -= 1;     k -= 1;     l -= 1;     for (int x = 0; x < 8; x++) {       if (x != i && x != j && x != k && x != l) {         s[s_indx] = x;         s_indx += 1;       }     }     m = s[0];     n = s[1];     o = s[2];     p = s[3];     if (indx == 1) {       square[0] = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));       square[1] = sqrt(pow(x[i] - x[k], 2) + pow(y[i] - y[k], 2));       square[2] = sqrt(pow(x[i] - x[l], 2) + pow(y[i] - y[l], 2));       sort(square, square + 3);       if (square[0] == square[1]) {         sq = 1;       } else {         r = 1;       }       x2 = (x[m] + x[n] + x[o] + x[p]) / 4;       y2 = (y[m] + y[n] + y[o] + y[p]) / 4;       a = sqrt(pow(x2 - x[m], 2) + pow(y2 - y[m], 2));       b = sqrt(pow(x2 - x[n], 2) + pow(y2 - y[n], 2));       c = sqrt(pow(x2 - x[o], 2) + pow(y2 - y[o], 2));       d = sqrt(pow(x2 - x[p], 2) + pow(y2 - y[p], 2));       if (a == b && a == c && a == d) {         square[0] = sqrt(pow(x[m] - x[n], 2) + pow(y[m] - y[n], 2));         square[1] = sqrt(pow(x[m] - x[o], 2) + pow(y[m] - y[o], 2));         square[2] = sqrt(pow(x[m] - x[p], 2) + pow(y[m] - y[p], 2));         sort(square, square + 3);         if (square[0] == square[1] && sq == 0) {           sq = 2;         } else {           r = 2;         }       }       if (sq != 0 && r != 0) {         cout <<  YES  << endl;         if (sq == 1) {           cout << i + 1 <<     << j + 1 <<     << k + 1 <<     << l + 1 << endl;           cout << m + 1 <<     << n + 1 <<     << o + 1 <<     << p + 1 << endl;         } else {           cout << m + 1 <<     << n + 1 <<     << o + 1 <<     << p + 1 << endl;           cout << i + 1 <<     << j + 1 <<     << k + 1 <<     << l + 1 << endl;         }       } else {         cout <<  NO ;       }     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);   #define FF first   #define SS second   #define pb push_back   #define sz(x) (int)x.size()   #define oo 1e9   #define eps 1e-9   #define PI acos(-1.0)   #define lb lower_bound   #define ub upper_bound   #define all(a) (a).begin(), (a).end()   #define log2i(x) (64 - __builtin_clzll(1ll*(x)) - 1)   #define INF 0x7f7f7f7f   typedef long long ll;   typedef unsigned long long ull;   typedef pair<int, int> ii;   typedef pair<ii, ii> Li;   const int N = 2e5+7, M=100+7;   const int MOD = 1e9+7;   const int base=30;      int n, m, k, t;      int fac[N]{1}, invf[N]{1};      int add(int a, int b) {       a+=b; if(a>MOD) a-=MOD;       return a;   }   int mul(int a, int b) {return (1LL*a*b)%MOD;}   void gcd(int a, int b, int &x, int &y) {       if(!b) {x=1, y=0; return;}       int tx, ty; gcd(b, a%b, tx, ty);       x=ty, y=tx-(a/b)*ty;   }   int inv(int a) {       int x, y; gcd(a, MOD, x, y);       return (x%MOD+MOD)%MOD;   }   int nCk(int n, int k) {       if(n<k||k<0) return 0;       return mul(fac[n], mul(invf[n-k], invf[k]));   }      signed main() {       //freopen( test.inp ,  r , stdin);       //freopen( test.out ,  w , stdout);       //fastIO;       scanf( %d , &t);       for(int i=1;i<N;i++) {           fac[i]=mul(fac[i-1], i);           invf[i]=inv(fac[i]);       }       while(t--) {           scanf( %d%d%d , &n, &m, &k);           int r=min(1-m, k-n), ans=nCk(n, n/2);           if(n&1) ans=mul(ans, 2); ans=mul(ans, r);           for(int pos, neg, i=r+1; i<=r+n;i++) {               pos=max(0, m+i-1), neg=max(0, n-k+i);               int tmp=n-pos-neg;               if(tmp<0) break;               ans=add(ans, nCk(tmp, n/2-pos));               if(n&1) ans=add(ans, nCk(tmp, n/2-neg));           }           printf( %d n , ans);       }       return 0;   }   /* stuff you should look for       - int overflow, array   bounds       - special cases (n=1?)       - do smth instead of do nothing and stay organized       - WRITE STUFF DOWN       - DONT JUST STICK ON ONE APPROACH   */
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, m;     std::cin >> n >> m;     if (n == 1 && m == 2) {       std::cout <<  0  <<   n ;       std::cout <<  1 1  <<   n ;       std::cout <<  1 2  <<   n ;       std::cout <<  1 1  <<   n ;       return 0;     }     if (n == 2 && m == 1) {       std::cout <<  0  <<   n ;       std::cout <<  1 1  <<   n ;       std::cout <<  2 1  <<   n ;       std::cout <<  1 1  <<   n ;       return 0;     }     if ((n * m % 2 == 0 && n != 1 && m != 1)) {       std::cout << 0 <<   n ;       std::cout <<  1 1  <<   n ;       if (n % 2 == 0) {         for (int i = 0; i < n; i++) {           if (i % 2 == 0) {             for (int j = 0; j < m - 1; j++) {               std::cout << i + 1 <<     << j + 2 <<   n ;             }           }           if (i % 2 == 1) {             for (int j = 0; j < m - 1; j++) {               std::cout << i + 1 <<     << m - j <<   n ;             }           }         }         for (int i = 0; i < n; i++) {           std::cout << n - i <<     << 1 <<   n ;         }       } else {         for (int i = 0; i < m; i++) {           if (i % 2 == 0) {             for (int j = 0; j < n - 1; j++) {               std::cout << j + 2 <<     << i + 1 <<   n ;             }           }           if (i % 2 == 1) {             for (int j = 0; j < n - 1; j++) {               std::cout << n - j <<     << i + 1 <<   n ;             }           }         }         for (int i = 0; i < m; i++) {           std::cout << 1 <<     << m - i <<   n ;         }       }     } else {       std::cout <<  1  <<   n ;       std::cout << n <<     << m <<    ;       std::cout <<  1 1  <<   n ;       for (int i = 0; i < n; i++) {         if (i % 2 == 0) {           for (int j = 0; j < m; j++) {             std::cout << i + 1 <<     << j + 1 <<   n ;           }         }         if (i % 2 == 1) {           for (int j = 0; j < m; j++) {             std::cout << i + 1 <<     << m - j <<   n ;           }         }       }       std::cout <<  1 1  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int ar[50][50];   int dp[51][51];   bool leaf[50];   vector<int> adj[50];   vector<int> adjw[50];   vector<int> leafs;   int bad;   vector<int> pos;   int go(int rem, int now) {     if (rem == 0) {       return 0;     }     if (dp[rem][now] != -1) {       return dp[rem][now];     }     int low = 0;     int high = 12500000;     while (low < high) {       int mid = (low + high + 1) / 2;       int temp = rem;       for (int i = 0; i < n; i++) {         if (!leaf[i] || i == now) {           continue;         }         int cur = 0;         while (temp > 0 && ar[now][i] + go(rem - cur - 1, i) >= mid) {           cur++;           temp--;         }       }       if (temp == 0) {         low = mid;       } else {         high = mid - 1;       }     }     dp[rem][now] = low;     return low;   }   void dfs(int now, int from) {     if (leaf[now]) {       leafs.push_back(now);     }     for (int i = 0; i < pos.size(); i++) {       if (now == pos[i]) {         bad++;       }     }     for (int i = 0; i < adj[now].size(); i++) {       int to = adj[now][i];       if (to != from) {         dfs(to, now);       }     }   }   void dfs(int now, int from, int root, int dist) {     ar[root][now] = dist;     for (int i = 0; i < adj[now].size(); i++) {       int to = adj[now][i];       if (to != from) {         dfs(to, now, root, dist + adjw[now][i]);       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int maxw = 0;     for (int i = 1; i < n; i++) {       int a, b, w;       cin >> a >> b >> w;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);       adjw[a].push_back(w);       adjw[b].push_back(w);     }     for (int i = 0; i < n; i++) {       dfs(i, -1, i, 0);     }     for (int i = 0; i <= 50; i++) {       for (int j = 0; j <= 50; j++) {         dp[i][j] = -1;       }     }     for (int i = 0; i < n; i++) {       leaf[i] = adj[i].size() == 1;     }     int start, m;     cin >> start >> m;     start--;     for (int i = 0; i < m; i++) {       int x;       cin >> x;       x--;       pos.push_back(x);     }     int ans = 12500000;     for (int i = 0; i < adj[start].size(); i++) {       leafs.clear();       leafs.resize(0);       bad = 0;       dfs(adj[start][i], start);       if (bad == 0) {         continue;       }       int low = 0;       int high = 1250000;       while (low < high) {         int mid = (low + high + 1) / 2;         int temp = bad;         for (int z = 0; z < leafs.size(); z++) {           int cl = leafs[z];           if (cl == start) {             continue;           }           int cur = 0;           while (temp > 0 && ar[start][cl] + go(m - cur - 1, cl) >= mid) {             cur++;             temp--;           }         }         if (temp == 0) {           low = mid;         } else {           high = mid - 1;         }       }       ans = min(ans, low);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int maxn = 5e5 + 5;   int n, k;   vector<ii> g[maxn];   ll dp[maxn][2];   void solve(int u, int par) {     for (ii e : g[u]) {       int v = e.first;       ll w = e.second;       if (v - par) {         solve(v, u);       }     }     ll tot0 = 0;     vector<ll> pot;     for (ii e : g[u]) {       int v = e.first;       ll w = e.second;       if (v - par) {         tot0 += dp[v][0];         pot.emplace_back(w + dp[v][1] - dp[v][0]);       }     }     sort(pot.begin(), pot.end());     reverse(pot.begin(), pot.end());     dp[u][0] = dp[u][1] = tot0;     for (int i = 0; i < k and i < pot.size() and pot[i] > 0; i++) {       dp[u][0] += pot[i];     }     for (int i = 0; i < k - 1 and i < pot.size() and pot[i] > 0; i++) {       dp[u][1] += pot[i];     }   }   int main(int argc, char const *argv[]) {     int tc;     scanf( %d , &tc);     while (tc--) {       scanf( %d %d , &n, &k);       for (int i = 1; i <= n; i++) {         g[i].clear();       }       for (int i = 1; i < n; i++) {         int u, v, w;         scanf( %d %d %d , &u, &v, &w);         g[u].emplace_back(v, w);         g[v].emplace_back(u, w);       }       solve(1, -1);       printf( %lld n , dp[1][0]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[101] = {         0,     };     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       for (int j = 0; j < t; j++) {         int tmp;         scanf( %d , &tmp);         arr[tmp]++;       }     }     for (int i = 1; i <= 100; i++) {       if (arr[i] == n) printf( %d  , i);     }   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200015;   const int nil = 100005;   int n;   set<pair<int, int> > S;   set<pair<int, int> > T;   int w[Maxn];   vector<pair<int, int> > cand[Maxn];   pair<int, int> res[Maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       S.insert(pair<int, int>(x, y));     }     for (int i = 1; i <= n; i++) scanf( %d , &w[i]);     for (set<pair<int, int> >::iterator it = S.begin(); it != S.end(); it++) {       pair<int, int> p = *it;       if (S.find(pair<int, int>(p.first + 1, p.second)) == S.end() &&           S.find(pair<int, int>(p.first, p.second + 1)) == S.end()) {         cand[p.second - p.first + nil].push_back(p);         T.insert(p);       }     }     for (int i = n; i >= 1; i--) {       int diag = w[i] + nil;       if (cand[diag].empty()) {         printf( NO n );         return 0;       }       pair<int, int> p = cand[diag].back();       cand[diag].pop_back();       res[i] = p;       pair<int, int> u = pair<int, int>(p.first - 1, p.second);       if (S.find(u) != S.end() && T.find(u) == T.end()) {         cand[u.second - u.first + nil].push_back(u);         T.insert(u);       }       u = pair<int, int>(p.first, p.second - 1);       if (S.find(u) != S.end() && T.find(u) == T.end()) {         cand[u.second - u.first + nil].push_back(u);         T.insert(u);       }     }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d %d n , res[i].first, res[i].second);     return 0;   }