malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int ALPHA = 26 + 1;   struct Trie {     Trie() { nodes.resize(2); }     struct Node {       Node() { memset(next, 0, sizeof(next)); }       int next[ALPHA];       int finish = -1;     };     int alloc() {       nodes.push_back(Node());       return nodes.size() - 1;     }     void addWord(const string& s, int id) {       int v = root;       for (char c : s) {         c = tolower(c) -  a ;         if (!nodes[v].next[c]) {           int x = alloc();           nodes[v].next[c] = x;         }         v = nodes[v].next[c];       }       nodes[v].finish = id;     }     vector<Node> nodes;     const int root = 1;   };   int n;   string ciph;   int m;   Trie trie;   vector<int> solved;   vector<int> toTake;   bool solve(int pos) {     if (pos == n) {       return true;     }     if (solved[pos] == -1) {       solved[pos] = false;       int v = trie.root;       int i = pos;       while (i < ciph.length() && trie.nodes[v].next[ciph[i] -  a ]) {         v = trie.nodes[v].next[ciph[i] -  a ];         ++i;         if (trie.nodes[v].finish != -1) {           if (solve(i)) {             solved[pos] = true;             toTake[pos] = trie.nodes[v].finish;           }         }       }     }     return solved[pos];   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     solved.resize(n, -1);     toTake.resize(n, -1);     cin >> ciph;     cin >> m;     vector<string> words(m);     for (int i = 0; i < m; ++i) {       cin >> words[i];       trie.addWord(words[i], i);     }     reverse(ciph.begin(), ciph.end());     solve(0);     vector<int> ans;     if (solved[0] == 1) {       int pos = 0;       while (pos != n) {         int id = toTake[pos];         ans.push_back(id);         pos += words[id].length();       }     } else {       assert(false);     }     reverse(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); ++i) {       if (i != 0) {         cout <<    ;       }       cout << words[ans[i]];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, m, cnt = 0;   int main() {     scanf( %lld%lld%lld , &x, &y, &m);     if (x >= m || y >= m) {       printf( 0 );       return 0;     }     if (x <= 0 && y <= 0) {       printf( -1 );       return 0;     }     while (x < m && y < m) {       if (x > y) swap(x, y);       if (x + y <= 0) {         cnt += abs(x) / y;         x = x + (abs(x) - abs(x) % y);       } else {         x += y;         cnt++;         ;       }     }     printf( %lld , cnt);     return 0;   }
#include <bits/stdc++.h>   char Src[1000001], Dst[1000001];   int main() {     int i, j, Cnts, Cntd, Lens, Lend;     scanf( %s %s , Src, Dst);     if (strlen(Src) != strlen(Dst)) {       puts( NO );       return 0;     }     if (strcmp(Src, Dst) == 0) {       puts( YES );       return 0;     }     if (strlen(Src) == 1) {       puts(Src[0] == Dst[0] ?  YES  :  NO );       return 0;     }     for (i = 0; Src[i] !=   0 ; ++i) {       if (Src[i] ==  1 ) {         break;       }     }     for (j = 0; Dst[j] !=   0 ; ++j) {       if (Dst[j] ==  1 ) {         break;       }     }     puts(Src[i] ==  1  && Dst[j] ==  1  ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T &x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T &x, L y) {     return y < x ? (x = y, 1) : 0;   }   const int maxn = 5e5 + 17;   list<int> a;   list<int>::iterator per[maxn];   int n;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 0, x; i < n; i++) cin >> x, a.push_back(x), per[i] = --a.end();     sort(per, per + n,          [](list<int>::iterator &i, list<int>::iterator &j) { return *i < *j; });     long long ans = 0, dam = 0;     for_each(per, per + max(0, n - 2), [&](list<int>::iterator &i) {       if (i == a.begin() || i == --a.end()) {         ans += (a.size() - 2) * (*i - dam);         dam = *i;       } else {         auto prv = i, nxt = i;         prv--, nxt++;         ans += min(*prv, *nxt) - dam;       }       a.erase(i);     });     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       std::vector<int> a(n);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       int minadd = 0;       int cur = a[0];       for (int i = 1; i < n; i++) {         if (cur > a[i]) {           minadd = std::max(minadd, cur - a[i]);         }         cur = std::max(cur, a[i]);       }       int nBits = 0;       while (minadd) {         nBits++;         minadd >>= 1;       }       printf( %d n , nBits);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Ans {     long long maxm, maxp, lmr, rml;     Ans() { maxm = maxp = lmr = rml = -(1ll << 60); }   } node[100010 << 2];   void Union(Ans &o, Ans a, Ans b) {     o.maxm = max(a.maxm, b.maxm);     o.maxp = max(a.maxp, b.maxp);     o.lmr = max(max(a.lmr, b.lmr), a.maxp + b.maxm);     o.rml = max(max(a.rml, b.rml), a.maxm + b.maxp);   }   long long h[100010], d[100010], n;   void build(int o, int l, int r) {     if (l == r) {       node[o].maxm = 2 * h[l] - (long long)d[l];       node[o].maxp = 2 * h[l] + (long long)d[l];       node[o].rml = -(1ll << 60);       node[o].lmr = -(1ll << 60);       return;     }     build((o << 1), l, ((l + r) >> 1));     build((o << 1 | 1), ((l + r) >> 1) + 1, r);     Union(node[o], node[(o << 1)], node[(o << 1 | 1)]);   }   Ans query(int L, int R, int o = 1, int l = 1, int r = n) {     Ans ret;     if (L > R) return ret;     if (L <= l && r <= R) return node[o];     if (R <= ((l + r) >> 1)) return query(L, R, (o << 1), l, ((l + r) >> 1));     if (L > ((l + r) >> 1))       return query(L, R, (o << 1 | 1), ((l + r) >> 1) + 1, r);     Union(ret, query(L, R, (o << 1), l, ((l + r) >> 1)),           query(L, R, (o << 1 | 1), ((l + r) >> 1) + 1, r));     return ret;   }   int Q;   Ans ansl, ansr;   int main() {     scanf( %d%d , &n, &Q);     for (int i = 1; i <= n; i++) {       cin >> d[i + 1];       d[i + 1] += d[i];     }     for (int i = 1; i <= n; i++) cin >> h[i];     build(1, 1, n);     while (Q--) {       int l, r;       scanf( %d %d , &l, &r);       if (l <= r) {         ansl = query(r + 1, n);         ansr = query(1, l - 1);         cout << max(max(ansr.rml, ansl.rml), ansr.maxp + d[n + 1] + ansl.maxm)              << endl;       } else {         cout << query(r + 1, l - 1).rml << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tot;   long long ans;   int main(int argc, char **argv) {     scanf( %d%d , &n, &m);     ++n;     for (int i = m + 1; (i << 1) <= n && i < n - m; ++i)       for (int j = m + 1; j < n - m; ++j) {         tot = (-i * i * 2 + i * j + i * n * 2 - j * n - 1) / (i + j);         ans += max(min(tot, n - m - 1) - m, 0) * ((i << 1) == n ? 1 : 2);       }     printf( %I64d n , ans * 3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A, B, C, N;   int main() {     scanf( %d%d%d%d , &A, &B, &C, &N);     if (A < C || B < C || A + B >= N + C)       puts( -1 );     else       printf( %d n , N - (A + B - C));   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> prices[1010];   int allp[1010];   int all;   int margin_price;   int above_cnt[1010], margin_cnt[1010], cnt[1010];   double f[1010][1010], g[1010][1010];   double comb[1010][1010];   int main() {     comb[1][0] = comb[1][1] = 1;     for (int i = 2; i <= 1000; i++) {       comb[i][0] = comb[i][i] = 1;       for (int j = 1; j < i; j++)         comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];     }     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int k;       scanf( %d , &k);       while (k--) {         int v;         scanf( %d , &v);         prices[i].push_back(v);         allp[++all] = v;       }     }     sort(allp + 1, allp + all + 1);     reverse(allp + 1, allp + all + 1);     margin_price = allp[n];     int need_margin = 0;     for (int i = 1; i <= n; i++)       if (allp[i] == margin_price) need_margin++;     for (int i = 1; i <= m; i++) {       for (int p : prices[i]) {         if (p > margin_price)           above_cnt[i]++;         else if (p == margin_price)           margin_cnt[i]++;         cnt[i]++;       }     }     f[0][0] = 1;     g[0][0] = 1;     for (int i = 1; i <= m; i++) {       for (int j = 0; j <= need_margin; j++) {         if (margin_cnt[i] == 0) {           f[i][j] += f[i - 1][j] / comb[cnt[i]][above_cnt[i]];           g[i][j] += g[i - 1][j];         } else if (margin_cnt[i] == 1) {           f[i][j] += f[i - 1][j] / comb[cnt[i]][above_cnt[i]];           g[i][j] += g[i - 1][j];           f[i][j + 1] += f[i - 1][j] / comb[cnt[i]][above_cnt[i] + 1];           g[i][j + 1] += g[i - 1][j];         } else {           assert(false);         }       }     }     printf( %.15f n , f[m][need_margin] / g[m][need_margin]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INF = 1000000005;   long long INFF = 1000000000000000005LL;   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   double pi = 3.1415926536;   int MOD = 1e9 + 7;   long long power(long long x, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * x;       x = (x * x);       n /= 2;     }     return res;   }   bool ok(int n, long long d) {     long long sum = (n * (n + 1) / 2);     if (sum < d) return false;     return (d % 2 == sum % 2);   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int i = 0;       while (!ok(i, abs(a - b))) i++;       cout << i <<   n ;     }   }
#include <bits/stdc++.h>   int a[1000000], b[1000000], n, k, f[1000000], c[1000000], i, j;   int max(int a, int b) {     if (a > b) return a;     return b;   }   int main() {     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       scanf( %d , &b[i]);       b[i] = b[i] * k;       c[i] = a[i] - b[i];     }     for (i = 0; i <= 20000; i++) f[i] = -0x37373737;     f[10000] = 0;     for (i = 1; i <= n; i++) {       if (c[i] > 0)         for (j = 20000; j >= c[i]; j--) f[j] = max(f[j - c[i]] + a[i], f[j]);       else         for (j = 0; j <= 20000 + c[i]; j++) f[j] = max(f[j - c[i]] + a[i], f[j]);     }     if (f[10000])       printf( %d , f[10000]);     else       printf( -1 );   }
#include <bits/stdc++.h>   using namespace std;   void input() {     int n;     cin >> n;     vector<int> v;     int i = 1;     int k = n - 1;     while (k--) {       cout <<  ?   << i <<     << i + 1 <<   n ;       fflush(stdout);       int x;       cin >> x;       v.push_back(x);       i++;     }     cout <<  ?   << 1 <<     << 3 <<   n ;     fflush(stdout);     int x;     cin >> x;     int a[n + 1];     a[1] = x - v[1];     for (int i = 2; i <= n; i++) {       a[i] = v[i - 2] - a[i - 1];     }     cout <<  !  ;     for (int i = 1; i <= n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   int main() {     input();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int an[101][21][21], n, k, md = 1e9 + 7, t[21][21];   vector<int> tr[101];   void go(int v = 1, int p = 0) {     an[v][0][1] = an[v][1][0] = 1;     for (int i = 0; i < (int)(tr[v].size()); ++i) {       int u = tr[v][i];       if (u == p) continue;       go(u, v);       for (int i = 0; i < (int)(21); ++i)         for (int j = 0; j < (int)(21); ++j)           for (int w = 0; w < (int)(21); ++w)             for (int z = 0; z < (int)(21); ++z) {               int a = i;               if (w && (w + 1 < a || !a)) a = w + 1;               if (a > 20) a = 0;               int b = 0;               if (!i && z)                 b = z + 1;               else if (i && z && k - i + 1 < z)                 b = z + 1;               if (!w)                 b = max(b, j);               else if (j && k - w + 1 < j)                 b = max(b, j);               if (b > 20) continue;               t[a][b] = ((long long)an[v][i][j] * an[u][w][z] + t[a][b]) % md;             }       for (int i = 0; i < (int)(21); ++i)         for (int j = 0; j < (int)(21); ++j) an[v][i][j] = t[i][j], t[i][j] = 0;     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < (int)(n); ++i) {       int a, b;       scanf( %d%d , &a, &b);       tr[a].push_back(b);       tr[b].push_back(a);     }     go();     int a = 0;     for (int i = 0; i < (int)(21); ++i)       if ((a += an[1][i][0]) >= md) a -= md;     printf( %d n , a);   }
#include <bits/stdc++.h>   using namespace std;   long long dp[100010];   int a[310], in[310];   long long tmp[310];   struct edge {     int to;     int next;   } e[310];   int box[100010], cnt;   long long T;   void init() {     memset(box, -1, sizeof(box));     memset(in, 0, sizeof(in));     memset(dp, 0, sizeof(dp));     cnt = 0;   }   void add(int from, int to) {     e[cnt].to = to;     e[cnt].next = box[from];     box[from] = cnt++;   }   long long dfs(int now) {     tmp[now] = a[now];     int t, v;     for (t = box[now]; t + 1; t = e[t].next) {       v = e[t].to;       long long tt = dfs(v);       tmp[now] += tt;     }     T -= tmp[now];     return tmp[now];   }   bool iscircle(int n) {     int qu[310], tmp[310];     int i, sum = 0, top = 0;     for (i = 1; i <= n; i++) {       tmp[i] = in[i];       if (tmp[i] == 0) qu[top++] = i;     }     for (i = 0; i < top; i++) {       int now = qu[i], t, v;       for (t = box[now]; t + 1; t = e[t].next) {         v = e[t].to;         tmp[v]--;         if (!tmp[v]) qu[top++] = v;       }     }     if (top < n) return true;     return false;   }   int main() {     int n, q, i, aa, b, j;     scanf( %d%d%I64d , &n, &q, &T);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     init();     for (i = 1; i <= q; i++) {       scanf( %d%d , &aa, &b);       in[aa]++;       add(b, aa);     }     bool tru = iscircle(n);     for (i = 1; i <= n; i++) {       if (!in[i]) {         dfs(i);         T += tmp[i];       }     }     if (tru || T < 0)       printf( 0 n );     else {       dp[0] = 1;       for (i = 1; i <= n; i++) {         for (j = tmp[i]; j <= T; j++)           dp[j] = (dp[j] + dp[j - tmp[i]]) % 1000000007;       }       printf( %I64d n , dp[T]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m[26];   int main() {     float a, c, d, b;     cin >> a >> b >> c >> d;     float sa = max((3 * a) / 10.0, a - (a / 250.0) * c);     float sb = max((3 * b) / 10.0, b - (b / 250.0) * d);     if (sa > sb)       cout <<  Misha ;     else if (sb > sa)       cout <<  Vasya ;     else       cout <<  Tie ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int n, m;   int first[maxn], second[maxn];   void solve() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) cin >> first[i] >> second[i];     int a, b;     a = first[1];     b = -1;     for (int i = 1; i <= m; ++i) {       if (first[i] != a && second[i] != a) {         if (first[i] != b && second[i] != b) {           if (b == -1)             b = first[i];           else             break;         }       }       if (i == m) {         puts( YES );         return;       }     }     a = -1;     b = second[1];     for (int i = 1; i <= m; ++i) {       if (first[i] != b && second[i] != b) {         if (first[i] != a && second[i] != a) {           if (a == -1)             a = first[i];           else             break;         }       }       if (i == m) {         puts( YES );         return;       }     }     a = -1;     b = second[1];     for (int i = 1; i <= m; ++i) {       if (first[i] != b && second[i] != b) {         if (first[i] != a && second[i] != a) {           if (a == -1)             a = second[i];           else             break;         }       }       if (i == m) {         puts( YES );         return;       }     }     a = first[1];     b = -1;     for (int i = 1; i <= m; ++i) {       if (first[i] != a && second[i] != a) {         if (first[i] != b && second[i] != b) {           if (b == -1)             b = second[i];           else             break;         }       }       if (i == m) {         puts( YES );         return;       }     }     puts( NO );   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const int P = 10, N = 1e5 + 10;   int inverse(int a, int m) {     int m0 = m, t, q;     int x0 = 0, x1 = 1;     if (m == 1) return 0;     while (a > 1) {       q = a / m;       t = m;       m = a % m, a = t;       t = x0;       x0 = x1 - q * x0;       x1 = t;     }     if (x1 < 0) x1 += m0;     return x1;   }   int fact[N], ifact[N], pot[N][P];   vector<int> primes(int n) {     vector<int> ans;     for (int d = 2; d * d <= n; d++)       if (n % d == 0) {         ans.push_back(d);         while (n % d == 0) {           n /= d;         }       }     if (n > 1) ans.push_back(n);     return ans;   }   int mod;   vector<int> p;   int expomod(long long int a, long long int e) {     int ans = 1;     while (e) {       if (e & 1) ans = ans * a % mod;       e /= 2;       a = a * a % mod;     }     return ans;   }   int comb(int m, int n) {     int ans = (long long int)fact[m] * ifact[n] % mod * ifact[m - n] % mod;     for (int i = 0; i < (int)(((int)(p).size())); i++) {       int pp = pot[m][i] - pot[n][i] - pot[m - n][i];       if (pp) ans = (long long int)ans * expomod(p[i], pp) % mod;     }     return ans;   }   int go(int n, int bal) {     long long int ans = 0;     for (int x = 0, y = bal; x + y <= n; x++, y++) {       ans += (long long int)comb(n, x) * comb(n - x, y) % mod;       if (ans >= mod) ans -= mod;     }     return ans;   }   int main() {     int n, l, r;     cin >> n >> mod >> l >> r;     p = primes(mod);     fact[0] = ifact[0] = 1;     for (int i = 1; i <= n; i++) {       int d = -1;       for (int j = 0; j < (int)(((int)(p).size())); j++)         if (i % p[j] == 0) {           d = j;           break;         }       if (d == -1)         fact[i] = i;       else {         fact[i] = fact[i / p[d]];         for (int j = 0; j < (int)(((int)(p).size())); j++)           pot[i][j] = pot[i / p[d]][j] + (j == d);       }       ifact[i] = inverse(fact[i], mod);     }     for (int i = 0; i < (int)(n); i++) {       fact[i + 1] = (long long int)fact[i] * fact[i + 1] % mod;       ifact[i + 1] = (long long int)ifact[i] * ifact[i + 1] % mod;       for (int j = 0; j < (int)(((int)(p).size())); j++)         pot[i + 1][j] += pot[i][j];     }     long long int ans = 0;     for (int i = 0; i < (int)(2); i++) {       ans += go(n, l + i);       ans -= go(n, r + 1 + i);     }     ans %= mod;     if (ans < 0) ans += mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[101][101];   int main() {     long long n, m;     cin >> n >> m;     long long mn = min(m, n);     cout << mn + 1 << endl;     for (long long i = 0; i <= mn; i++)       cout << i <<     << (mn - i) % (mn + 1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   char _;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long fpow(long long b, long long exp, long long mod) {     if (exp == 0) return 1;     long long t = fpow(b, exp / 2, mod);     if (exp & 1) return t * t % mod * b % mod;     return t * t % mod;   }   int num_boxes, req, start, vals[55], dp[55][2005];   char type[55];   int solve(int box, int sum) {     if (sum >= req) return 0;     if (dp[box][sum] != -1) return dp[box][sum];     int res = INT_MAX;     for (int i = 1; i <= num_boxes; i++)       if (vals[i] > vals[box] && type[i] != type[box])         if (solve(i, sum + vals[i]) != INT_MAX)           res = min(res, abs(i - box) + solve(i, sum + vals[i]));     return dp[box][sum] = res;   }   int main() {     scanf( %d %d %d , &num_boxes, &start, &req);     for (int i = 1; i <= num_boxes; i++) scanf(  %d , &vals[i]);     for (int i = 1; i <= num_boxes; i++) scanf(  %c , &type[i]);     memset(dp, -1, sizeof dp);     int res = solve(start, vals[start]);     for (int i = 1; i <= num_boxes; i++)       if (solve(i, vals[i]) != INT_MAX)         res = min(res, abs(i - start) + solve(i, vals[i]));     printf( %d n , (res == INT_MAX ? -1 : res));   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxE(T& a, const T& b) {     a = max(a, b);   }   template <typename T>   void minE(T& a, const T& b) {     a = min(a, b);   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& t_) {     out <<  [ ;     for (auto i : t_) out << i <<  ,  ;     out <<  ] ;     return out;   }   template <typename S, typename T>   ostream& operator<<(ostream& out, const pair<S, T>& rhs) {     out <<  (  << rhs.first <<  ,  << rhs.second <<  ) ;     return out;   }   int gcd(int a, int b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   map<int, int> t;   void proc(int l, int c) {     if (0)       cout <<  proc              <<  l             <<     << l <<                <<  c             <<     << c <<     << endl;     if (t.find(l) == t.end()) {       t[l] = c;       if (0) cout <<  init0  << endl;     } else if (t[l] > c) {       if (0) cout <<  relax1  << endl;       t[l] = c;     }     vector<pair<int, int> > tmp;     for (auto i : t) tmp.push_back(i);     for (auto i : tmp) {       int g = gcd(i.first, l);       if (t.find(g) == t.end() || t[g] > i.second + c) {         if (0)           cout <<  relax2                  <<  i                 <<     << i <<                    <<  g                 <<     << g <<                    <<  l                 <<     << l <<                    <<  c                 <<     << c <<                    <<  i.nd + c                 <<     << i.second + c <<     << endl;         t[g] = i.second + c;       }     }   }   int main() {     int n;     assert(scanf( %d , &n) == 1);     int l[n];     for (int i = 0; i < int(n); ++i) assert(scanf( %d , l + i) == 1);     int c[n];     for (int i = 0; i < int(n); ++i) assert(scanf( %d , c + i) == 1);     for (int i = 0; i < int(n); ++i) proc(l[i], c[i]);     if (t.find(1) == t.end())       printf( -1 n );     else       printf( %d n , t[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[1024], b[1024], c[1024], t[4], dd, d, have[1024];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     bool flag = 0;     for (int i = 0; i < n; i++) {       cin >> b[i];       if (b[i] != a[i]) {         c[d] = i;         d++;       } else {         have[a[i]]++;         have[b[i]]++;       }     }     dd = 0;     for (int i = 1; i <= n; i++) {       if (have[i] == 0) {         t[dd] = i;         dd++;       }     }     if (d == 1) {       a[c[0]] = t[0];     } else {       int br = 0, br1 = 0;       for (int i = 0; i < 2; i++) {         if (a[c[i]] != t[i]) br++;         if (b[c[i]] != t[i]) br1++;       }       if (br == 1 && br1 == 1) {         a[c[0]] = t[0];         a[c[1]] = t[1];       } else {         a[c[0]] = t[1];         a[c[1]] = t[0];       }     }     for (int i = 0; i < n - 1; i++) {       cout << a[i] <<    ;     }     cout << a[n - 1] << endl;     return 0;   }