malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( avx )   using namespace std;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int MAXN = 100;   const int MOD = 1e9 + 7;   const long long MAXV = 1e6;   const double eps = 1e-12;   const long long INF = 1e16;   inline string toStr(long long x) {     string tmp =   ;     do tmp = char(x % 10 +  0 ) + tmp;     while (x /= 10);     return tmp;   }   inline long long toInt(string s) {     long long res = 0;     for (auto x : s) res = res * 10 + x -  0 ;     return res;   }   inline string toBinStr(long long x) {     string res =   ;     do res = (x % 2 ?  1  :  0 ) + res;     while (x >>= 1LL);     return res;   }   long long rnd(int k) {     if (!k) return rand() % MAXV + 1;     long long t = rand() % MAXV + 1;     return (rand() % t) + (MAXV - t);   }   long long random_gen(int sign) {     long long x = rnd(rand() % 2);     long long s = rand() % 2;     s = !s ? 1 : -1;     return sign == 1 ? x : sign == -1 ? -x : s * x;   }   inline void debugArray(int a[], int n) {     cerr <<  array =  ;     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   int n, m;   vector<int> row[MAXN];   bool color[MAXN];   string s[MAXN], actual[MAXN];   int main() {     cin >> n >> m;     for (int i = 0, _a = (n); i < _a; ++i) {       cin >> s[i];       for (int j = 0, _a = (m); j < _a; ++j)         if (s[i][j] ==  # ) row[i].push_back(j);     }     for (int i = 0, _a = (n); i < _a; ++i) {       actual[i] =   ;       for (int j = 0, _a = (m); j < _a; ++j) actual[i] +=  . ;     }     for (int i = 0, _a = (n); i < _a; ++i)       if (!color[i]) {         vector<int> need;         color[i] = true;         need.push_back(i);         for (int j = 0, _a = (n); j < _a; ++j)           if (!color[j])             for (int k = 0, _a = (m); k < _a; ++k)               if (s[i][k] ==  #  && s[j][k] ==  # ) {                 need.push_back(j);                 color[j] = true;                 break;               }         for (auto x : need)           for (auto y : row[i]) actual[x][y] =  # ;       }     bool good = true;     for (int i = 0, _a = (n); i < _a; ++i)       for (int j = 0, _a = (m); j < _a; ++j) good &= actual[i][j] == s[i][j];     puts(good ?  Yes  :  No );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   int n, k;   int clo[N];   string s;   bool block[N];   int dist(int a, int b) {     if (a > b) swap(a, b);     if (a == -1 || b == n) return n;     return min(b - a, n - (b - a));   }   char neg(char a) {     if (a ==  W )       return  B ;     else       return  W ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> s;     for (int i = 0; i < n; ++i) {       if (s[i] == s[(i - 1 + n) % n] || s[i] == s[(i + 1) % n]) {         block[i] = 1;       }     }     int cur = -1, l = n, r = -1;     for (int i = 0; i < n; ++i) {       clo[i] = n;       if (block[i]) {         l = min(l, i);         r = max(r, i);       }     }     for (int i = 0; i < n; ++i) {       if (block[i]) {         cur = i;       }       clo[i] = min(clo[i], dist(i, cur));     }     cur = -1;     for (int i = n - 1; i >= 0; --i) {       if (block[i]) {         cur = i;       }       clo[i] = min(clo[i], dist(i, cur));     }     for (int i = 0; i < n; ++i) {       clo[i] = min(clo[i], dist(i, l));       clo[i] = min(clo[i], dist(i, r));     }     for (int i = 0; i < n; ++i) {       if (clo[i] <= k) {         cout << ((clo[i] % 2 == 0) ? s[i] : neg(s[i]));       } else {         cout << ((k % 2 == 0) ? s[i] : neg(s[i]));       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int v, index;   } a[100005];   int n, h, big, small, tmp, diff, num;   int ans[100005];   int cmp(const void *i, const void *j) {     Node x = *(Node *)i;     Node y = *(Node *)j;     if (x.v == y.v) {       return x.index > y.index ? 1 : -1;     } else {       return x.v > y.v ? 1 : -1;     }   }   int main() {     while (scanf(  %d %d , &n, &h) != EOF) {       for (int i = 0; i < n; i++) {         scanf(  %d , &a[i].v);         a[i].index = i;       }       qsort(a, n, sizeof(a[0]), cmp);       num = 0, diff = (a[n - 1].v + a[n - 2].v) - (a[0].v + a[1].v);       for (int i = 1; i < n; i++) {         small = a[0].v + a[1].v + h;         if (i >= 2 && small > a[1].v + a[2].v) small = a[1].v + a[2].v;         if (i != n - 1 && small > a[0].v + a[i + 1].v)           small = a[0].v + a[i + 1].v;         if (i == n - 1)           big = a[i].v + a[0].v + h;         else           big = a[n - 1].v + a[i].v + h;         if (big < a[n - 1].v + a[n - 2].v) big = a[n - 1].v + a[n - 2].v;         if (diff > big - small) {           diff = big - small;           num = i;         }       }       fill(ans, ans + n, 1);       for (int i = 1; i <= num; i++) ans[a[i].index] = 2;       printf( %d n , diff);       for (int i = 0; i < n; i++) printf( %d%c , ans[i], i == n - 1 ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double PI = acos(-1.0);   const double e = 2.718281828459;   const int N = 200000;   inline int sgn(double a);   inline long long gcd(long long a, long long b);   inline long long mod_pow(long long x, long long n, long long mod);   vector<int> vv;   vector<int> vis[1005];   int main() {     memset(vis, 0, sizeof(vis));     int n, m;     string s;     string t;     cin >> n >> m;     cin >> s;     cin >> t;     int maxidx = 0;     int maxcount = 0;     for (int i = 0; i <= m - n; i++) {       int count = 0;       for (int j = 0; j < n; j++) {         if (s[j] != t[j + i]) {           vis[i].push_back(j + 1);         } else {           ++count;         }       }       if (maxcount < count) {         maxcount = count;         maxidx = i;       }     }     cout << vis[maxidx].size() << endl;     for (int i = 0; i < vis[maxidx].size(); i++) {       cout << vis[maxidx][i] <<    ;     }     return 0;   }   inline int sgn(double a) { return a < -eps ? -1 : a < eps ? 0 : 1; }   inline long long gcd(long long a, long long b) {     return a == 0 ? b : gcd(b % a, a);   }   long long mod_pow(long long x, long long n, long long mod) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n = n >> 1;     }     return res;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1e5 + 1e3 + 2;   const int mx = 20;   int n, q, N, ans;   int k[Maxn];   vector<int> V[Maxn];   vector<pair<int, int>> g;   int h[Maxn], par[mx][Maxn];   bool mark[Maxn];   int st[Maxn], en[Maxn], T;   set<pair<int, int>> ver, lca;   void dfs(int u, int DD = 0) {     st[u] = T++;     par[0][u] = DD;     for (int i = 1; i < mx; i++) par[i][u] = par[i - 1][par[i - 1][u]];     for (int i = 0; i < V[u].size(); i++) {       int v = V[u][i];       if (v != DD) h[v] = h[u] + 1, dfs(v, u);     }     en[u] = T++;   }   int LCA(int u, int v) {     if (h[v] < h[u]) swap(u, v);     for (int i = mx; i--;)       if (h[par[i][v]] >= h[u]) v = par[i][v];     if (v == u) return v;     for (int i = mx; i--;)       if (par[i][v] != par[i][u]) v = par[i][v], u = par[i][u];     return par[0][v];   }   bool check() {     bool res = true;     for (int i = 0; i < N; i++) mark[k[i]] = true;     for (int i = 0; i < N; i++)       if (mark[par[0][k[i]]]) res = false;     return res;   }   void solve() {     if (!check()) {       for (int i = 0; i < N; i++) mark[k[i]] = false;       ans = -1;       return;     }     ans = 0;     ver.clear();     lca.clear();     for (int i = 0; i < N; i++) ver.insert(make_pair(st[k[i]], k[i]));     set<pair<int, int>>::iterator it = ver.begin();     for (it++; it != ver.end(); it++) {       int v = (*it).second;       it--;       int u = (*it).second;       it++;       int DD = LCA(u, v);       lca.insert(make_pair(-h[DD], DD));     }     for (; ver.size() > 1;) {       ans++;       pair<int, int> p = (*lca.begin());       lca.erase(p);       int v = p.second;       it = ver.upper_bound(make_pair(st[v], n));       for (; it != ver.end() && ver.size(); it++) {         int u = (*it).second;         if (st[u] > en[v]) break;         if (mark[v]) ans++;         g.push_back(*it);       }       ans -= mark[v];       if (!mark[v] && g.size() < 2) {         g.clear();         ans--;         continue;       }       for (int i = 0; i < g.size(); i++)         ver.erase(g[i]), mark[g[i].second] = false;       g.clear();     }     for (int i = 0; i < N; i++) mark[k[i]] = false;   }   int main() {     cin >> n;     for (int u, v, i = 0; i < n - 1; i++) {       cin >> u >> v;       V[u].push_back(v);       V[v].push_back(u);     }     h[1] = 1;     dfs(1);     cin >> q;     for (int j = 0; j < q; j++) {       cin >> N;       for (int i = 0; i < N; i++) cin >> k[i];       solve();       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace ::std;   int n, m, k, ans;   int a[105][105];   int d[3][105];   int a1[105];   int main() {     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     ans = 2140000000;     if (n > 10) {       for (int i = 1; i <= n; i++) {         int an = 0;         for (int j = 1; j <= n; j++) {           int op = 0;           for (int k = 1; k <= m; k++)             if (a[i][k] != a[j][k]) op++;           an += min(op, m - op);         }         ans = min(ans, an);       }     } else {       for (int i = 0; i < (1 << n); i++) {         for (int j = 0; j < n; j++) {           if ((i & (1 << j)) != 0)             a1[j] = 1;           else             a1[j] = 0;         }         int an = 0;         for (int j = 1; j <= m; j++) {           int op = 0;           for (int k = 1; k <= n; k++)             if (a[k][j] != a1[k - 1]) op++;           an += min(op, n - op);         }         ans = min(ans, an);       }     }     if (ans > k)       printf( -1 );     else       printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   long long here[N + 100];   int n, m;   long double ter[N + 100];   int go(string &s1, string &s2) {     int val = 0;     for (int i = int(0); i < int(m); ++i)       if (s1[i] == s2[i]) val |= (1 << i);     return val;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(14);     cin >> n;     vector<string> vec(n);     for (int i = int(0); i < int(n); ++i) cin >> vec[i];     m = int((vec[0]).size());     for (int i = int(0); i < int(n); ++i)       for (int j = int(i + 1); j < int(n); ++j)         if (i != j) {           int mask = go(vec[i], vec[j]);           here[mask] |= (1LL << i) | (1LL << j);         }     int lim = (1 << m) - 1;     for (int mask = int(lim); mask >= int(0); mask--)       for (int i = int(0); i < int(m); ++i) here[mask] |= here[mask | (1 << i)];     ter[lim] = 0;     for (int i = int(lim - 1); i >= int(0); i--) {       ter[i] = __builtin_popcountll(here[i]);       long double val = 0;       for (int j = int(0); j < int(m); ++j)         if (1 - ((i >> j) & 1)) val += ter[i | (1 << j)];       ter[i] += val / (m - __builtin_popcount(i));     }     cout << ter[0] / n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6;   int n, k;   int root;   vector<int> G[MAXN + 10];   int res = 0;   int dfs(int u, int p = -1) {     if ((int)G[u].size() == 1) return 0;     vector<int> d;     for (int v : G[u]) {       if (v == p) continue;       d.push_back(dfs(v, u) + 1);     }     sort(d.begin(), d.end(), greater<int>());     while (d.size() > 1) {       int b = d.back();       d.pop_back();       int a = d.back();       d.pop_back();       if (a + b > k) {         res += d.size() + 1;         return b;       } else {         d.push_back(a);       }     }     return d[0];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     root = 1;     while ((int)G[root].size() == 1) ++root;     dfs(root);     res++;     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   int prec[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};   const int mod = 1000000000 + 7;   int n, k;   long long doIt(int m, int bse) {     int b[10];     for (int i = 0; i < 10; i++) b[i] = 0;     int res = 0;     while (!b[m]) {       int can = true;       for (int i = 0; i < m && can; i++) {         int cur = i;         int iter = m + 1;         while (iter && cur) {           cur = b[cur];           iter--;         }         can &= (cur == 0);       }       if (can) res++;       int ind = 0;       b[ind]++;       while (b[ind] >= bse) {         b[ind] = 0;         ind++;         b[ind]++;       }     }     return res % mod;   }   int main() {     cin >> n >> k;     k = min(k, 8);     long long res = 1;     if (k > 1) res = doIt(k, k) % mod;     for (int i = 0; i < n - k; i++) {       res = res * 1LL * (n - k);       res %= mod;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   int n, a, b;   int scores[MAXN], answer[MAXN];   pair<int, int> tmp_scores[MAXN];   void solve() {     if (a == b) {       for (int i = 0; i < a; ++i) printf( 1  );       for (int i = 0; i < b; ++i) printf( 2  );       printf(  n );       return;     }     if (b < a)       for (int i = 0; i < n; ++i) tmp_scores[i] = make_pair(scores[i], i);     else       for (int i = 0; i < n; ++i) tmp_scores[i] = make_pair(6 - scores[i], i);     sort(&tmp_scores[0], &tmp_scores[n]);     for (int i = 0; i < a; ++i) answer[tmp_scores[i].second] = 1;     for (int i = a; i < n; ++i) answer[tmp_scores[i].second] = 2;     for (int i = 0; i < n; ++i) printf( %d  , answer[i]);     printf(  n );   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; ++i) scanf( %d , &scores[i]);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   vector<vector<vector<ll>>> v;   vector<vector<ll>> mat;   vector<vector<ll>> matMal(vector<vector<ll>> mat1, vector<vector<ll>> mat2) {     vector<vector<ll>> mat3((int)(mat1).size(), vector<ll>((int)(mat1).size()));     for (int i = 0; i < (int)(mat1).size(); ++i) {       for (int j = 0; j < (int)(mat1).size(); ++j) {         ll sum = 0;         for (int k = 0; k < (int)(mat1).size(); ++k) {           sum = sum + (ll)mat1[i][k] * mat2[k][j] % 1000000007;         }         mat3[i][j] = sum % 1000000007;       }     }     return mat3;   }   vector<vector<ll>> matMult(vector<vector<ll>> matr, ll x) {     if (x == 1) return matr;     if (x % 2 == 1) return matMal(matMult(matr, x - 1), mat);     vector<vector<ll>> matTemp = matMult(matr, x / 2);     return matMal(matTemp, matTemp);   }   int main() {     int n, k, m;     vector<ll> anzb = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};     cin >> n >> k >> m;     mat.resize((1 << m) * (k + 1), vector<ll>((1 << m) * (k + 1)));     for (int i = 0; i < 1 << m; ++i) {       for (int j = 0; j < k + 1; ++j) {         if (i % 2 == 0) {           mat[(k + 1) * i + j][(k + 1) * (i / 2) + j] = 1;           mat[(k + 1) * i + j][(k + 1) * ((i + (1 << m)) / 2) + j] = 1;         } else if (j != 0) {           mat[(k + 1) * i + j][(k + 1) * (i / 2) + j - 1] = anzb[i / 2] + 1;           mat[(k + 1) * i + j][(k + 1) * ((i + (1 << m)) / 2) + j - 1] =               anzb[(i + (1 << m)) / 2] + 1;         }       }     }     mat = matMult(mat, n);     ll sum = 0;     for (int i = 0; i < 1 << m; ++i) {       sum = (sum + mat[(k + 1) * i + k][0]) % 1000000007;     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[105];   int main() {     int i, n, j = 0, k, l;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a + 1, a + n);     while (a[0] <= a[n - 1]) {       j++;       a[n - 1]--;       a[0]++;       sort(a + 1, a + n);     }     cout << j << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base ::sync_with_stdio(false);     int n;     cin >> n;     vector<pair<long long, long long>> news(n + 1);     for (int i = 1; i <= n; i++) cin >> news[i].first;     for (int i = 1; i <= n; i++) cin >> news[i].second;     long long ans = 0;     priority_queue<long long> q;     sort(news.begin() + 1, news.end());     long long val = news[1].first, sum = 0;     news.push_back(make_pair(2e9, 0));     for (int i = 1; i <= n + 1; i++) {       while (val < news[i].first && q.size() > 0) {         sum -= q.top();         q.pop();         ans += sum;         val++;       }       val = news[i].first;       q.push(news[i].second);       sum += news[i].second;     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const long long p = 998244353, g = 3, gv = 332748118, N = 1e6 + 5;   long long qpow(long long a, int b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % p;       a = a * a % p;       b >>= 1;     }     return ret;   }   long long inv(long long a) { return qpow(a, p - 2); }   int rev[N];   void getrev(int len) {     for (int i = 0; i < len; i++) {       rev[i] = rev[i >> 1] >> 1;       if (i & 1) rev[i] |= (len >> 1);     }   }   void ntt(vector<long long> &a, int len, int tp) {     a.resize(len);     for (int i = 0; i < len; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int i = 2; i <= len; i <<= 1) {       long long wn = qpow(tp == 1 ? g : gv, (p - 1) / i);       int stp = i >> 1;       for (int j = 0; j < len; j += i) {         long long w = 1;         for (int k = j; k < j + stp; k++) {           long long s1 = a[k], s2 = a[k + stp] * w % p;           w = w * wn % p;           a[k] = (s1 + s2) % p, a[k + stp] = (s1 + p - s2) % p;         }       }     }     if (tp == -1) {       long long lv = inv(len);       for (int i = 0; i < len; i++) a[i] = a[i] * lv % p;     }   }   vector<long long> operator*(vector<long long> a, vector<long long> b) {     int len = 1, n = a.size() + b.size() - 1;     while (len < n) len <<= 1;     getrev(len);     ntt(a, len, 1), ntt(b, len, 1);     for (int i = 0; i < len; i++) a[i] = a[i] * b[i] % p;     ntt(a, len, -1);     a.resize(n);     return a;   }   vector<long long> operator+(vector<long long> a, vector<long long> b) {     if (a.size() < b.size()) swap(a, b);     for (int i = 0; i < b.size(); i++) a[i] = (a[i] + b[i]) % p;     return a;   }   vector<long long> operator-(vector<long long> a) {     for (int i = 0; i < a.size(); i++) a[i] = (p - a[i]) % p;     return a;   }   vector<long long> operator-(vector<long long> a, vector<long long> b) {     return a + (-b);   }   vector<long long> operator*(long long b, vector<long long> a) {     for (int i = 0; i < a.size(); i++) a[i] = a[i] * b % p;     return a;   }   vector<long long> operator/(vector<long long> a, long long b) {     int v = inv(b);     for (int i = 0; i < a.size(); i++) a[i] = a[i] * v % p;     return a;   }   long long fac[N], finv[N], iv[N];   int main() {     int n;     long long m;     scanf( %d%lld , &n, &m);     n++;     fac[0] = fac[1] = iv[1] = finv[0] = finv[1] = 1;     for (int i = 2; i <= n; i++)       fac[i] = fac[i - 1] * i % p, iv[i] = (p - p / i) * iv[p % i] % p,       finv[i] = finv[i - 1] * iv[i] % p;     vector<long long> a, b, c;     a.resize(n), b.resize(n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a[i] = x * 1ll * fac[i] % p, b[n - i - 1] = finv[i];     }     c = a * b;     for (int i = 0; i < n; i++)       a[i] = c[n + i - 1] * 1ll * qpow(iv[i + 1], m % (p - 1)) % p,       b[n - i - 1] = i & 1 ? p - finv[i] : finv[i];     c = a * b;     for (int i = 0; i < n; i++) printf( %lld  , c[n + i - 1] * 1ll * finv[i] % p);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int arr[1000001], dp[(1 << 22)], N;   int main() {     scanf( %d , &N);     memset(dp, -1, sizeof dp);     for (int i = 0; i < N; i++) {       scanf( %d , &arr[i]);       dp[arr[i]] = arr[i];     }     for (int i = 0; i < (1 << 22); i++) {       for (int j = 0; j < 22; j++) {         if (i & (1 << j)) {           dp[i] = max(dp[i], dp[i ^ (1 << j)]);         }       }     }     for (int i = 0; i < N; i++) {       int need = dp[((1 << 22) - 1) ^ arr[i]];       printf( %d%c , need, i == N - 1 ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string convert(string s) {     int l = s.size();     if (l % 2 == 1) return s;     string s1 = s.substr(0, l / 2), s2 = s.substr(l / 2);     s1 = convert(s1);     s2 = convert(s2);     if (s1 < s2)       return s1 + s2;     else       return s2 + s1;   }   bool equivalent(string s1, string s2) {     s1 = convert(s1);     s2 = convert(s2);     return s1 == s2;   }   int main() {     string a, b;     cin >> a >> b;     if (equivalent(a, b))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct answer {     int b, c;     bool operator==(answer other) const { return b == other.b && c == other.c; }     bool operator!=(answer other) const { return !(*this == other); }   };   answer eval(string secret, string query) {     string left_s, left_q;     answer ans = {0, 0};     for (int i = 0; i < (int)(4); i++) {       if (secret[i] == query[i])         ans.b++;       else {         left_s.push_back(secret[i]);         left_q.push_back(query[i]);       }     }     while (!left_s.empty()) {       auto it = find(left_q.begin(), left_q.end(), left_s.back());       if (it != left_q.end()) {         left_q.erase(it);         ans.c++;       }       left_s.pop_back();     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<string> q(n);     vector<answer> anss(n);     for (int i = 0; i < (int)(n); i++) {       cin >> q[i] >> anss[i].b >> anss[i].c;     }     vector<string> answers;     for (int a = 0; a < 10; a++) {       for (int b = 0; b < 10; b++) {         if (a == b) continue;         for (int c = 0; c < 10; c++) {           if (a == c || b == c) continue;           for (int d = 0; d < 10; d++) {             if (a == d || b == d || c == d) continue;             string s;             s.push_back( 0  + a);             s.push_back( 0  + b);             s.push_back( 0  + c);             s.push_back( 0  + d);             bool ok = true;             for (int i = 0; i < (int)(n); i++) {               if (anss[i] != eval(s, q[i])) {                 ok = false;               }             }             if (ok) {               answers.push_back(s);             }           }         }       }     }     if (answers.empty()) {       cout <<  Incorrect data  << endl;     } else if (answers.size() > 1) {       cout <<  Need more data  << endl;     } else {       cout << answers[0] << endl;     }     return 0;   }