malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace std;   bool solve(int);   int main() {     int test = 0;     while (solve(test++))       ;     return 0;   }   const int N = 100 * 1000 + 5;   const int INF = int(1e9);   int n, b, m;   pair<int, int> a[N];   struct edge {     int to, f, c, rev;   };   const int V = 1000 * 1000 + 3;   vector<edge> g[V];   int lev[V];   int head, tail, q[V];   inline bool bfs(int s, int t) {     memset(lev, 63, sizeof(lev));     head = tail = 0;     lev[s] = 0;     q[head++] = s;     while (head != tail) {       int v = q[tail++];       for (int i = 0; i < int(int(g[v].size())); ++i)         if (g[v][i].f < g[v][i].c && lev[g[v][i].to] > lev[v] + 1) {           lev[g[v][i].to] = lev[v] + 1;           q[head++] = g[v][i].to;         }     }     return lev[t] < INF / 2;   }   inline void add(int from, int to, int c) {     edge f = {to, 0, c, int(g[to].size())};     edge b = {from, 0, 0, int(g[from].size())};     g[from].push_back(f);     g[to].push_back(b);   }   int ptr[V];   int dfs(int v, int t, int f) {     if (v == t) return f;     for (; ptr[v] < int(g[v].size()); ptr[v]++) {       edge& e = g[v][ptr[v]];       if (e.f == e.c || lev[e.to] != lev[v] + 1) continue;       int df = dfs(e.to, t, min(f, e.c - e.f));       if (df > 0) {         e.f += df;         g[e.to][e.rev].f -= df;         return df;       }     }     return 0;   }   inline int dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       memset(ptr, 0, sizeof(ptr));       for (int f; (f = dfs(s, t, INF)) != 0; ans += f)         ;     }     return ans;   }   int cnt5[N][5];   int calc(int r, int rem) { return cnt5[r][rem]; }   bool solve(int) {     if (!(cin >> m >> b >> n)) return false;     for (int i = 0; i < int(n); ++i) {       scanf( %d %d , &a[i].first, &a[i].second);       a[i].first++;     }     a[n++] = pair<int, int>(b + 1, m);     a[n++] = pair<int, int>(1, 0);     int cv = 5;     int S = cv++;     int T = cv++;     for (int i = 0; i < int(5); ++i) add(i, T, m / 5);     for (int i = 0; i < int(N - 1); ++i) {       for (int j = 0; j < int(5); ++j) cnt5[i + 1][j] = cnt5[i][j];       cnt5[i + 1][(i + 1) % 5]++;     }     sort(a, a + n);     for (int i = 0; i < int(n - 1); ++i) {       int lf = a[i].first;       int rg = a[i + 1].first;       int cnt = a[i + 1].second - a[i].second;       if (rg - lf < cnt || cnt < 0) {         puts( unfair );         return true;       }       if (cnt == 0) continue;       int v[5];       for (int i = 0; i < int(5); ++i) {         v[i] = calc(rg - 1, i) - calc(lf - 1, i);         add(cv, i, v[i]);       }       add(S, cv, cnt);       cv++;     }     puts(dinic(S, T) == m ?  fair  :  unfair );     return true;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[100];   long long ans;   long long getval() {     long long val = 0;     for (int i = 0; i < n; ++i) {       int mn = 100500;       for (int j = i; j < n; ++j) {         mn = min(mn, a[j]);         val += mn;       }     }     return val;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) {       a[i] = i + 1;     }     do {       long long val = getval();       ans = max(ans, val);     } while (next_permutation(a, a + n));     cerr <<  ans =   << ans <<   n ;     do {       long long val = getval();       if (val == ans) {         if (m == 1) {           for (int i = 0; i < n; ++i) {             cout << a[i] <<    ;           }           cout <<   n ;           return 0;         }         --m;       }     } while (next_permutation(a, a + n));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t, x, y;     long long pos_ji, pos_ou;     while (~scanf( %lld%lld , &n, &t)) {       while (t--) {         scanf( %lld%lld , &x, &y);         long long ji = n / 2 * n + (n + 1) / 2 + 1;         long long ou = n / 2 * n + 1;         pos_ji = (x - 1) * n + y;         if (n % 2 != 0) {           if (pos_ji % 2 == 0)             printf( %lld n , ji + (pos_ji - 1) / 2);           else             printf( %lld n , (pos_ji + 1) / 2);         } else {           if (x % 2 != 0 && y % 2 != 0) {             printf( %lld n , (x / 2) * n + (y + 1) / 2);           } else if (x % 2 != 0 && y % 2 == 0) {             printf( %lld n , ou + (x / 2) * n + (y - 1) / 2);           } else if (x % 2 == 0 && y % 2 != 0) {             printf( %lld n , ou + n / 2 + (x - 2) / 2 * n + y / 2);           } else             printf( %lld n , n / 2 + (x - 2) / 2 * n + y / 2);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q, tipe, temp, x, k, s;   vector<int> v;   set<int> cek;   int val[100000 + 5];   map<pair<int, pair<int, int> >, int> temp2;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &tipe);       if (tipe == 1) {         scanf( %d , &temp);         if (!val[temp]) {           val[temp] = true;           cek.insert(temp);           temp2.clear();         }       } else {         scanf( %d %d %d , &x, &k, &s);         if (x % k != 0 or x >= s)           printf( -1 n );         else {           if (temp2[make_pair(x, make_pair(k, s))]) {             printf( %d n , temp2[make_pair(x, make_pair(k, s))]);             continue;           }           int xam = -1;           int res = -1;           auto its = cek.upper_bound(s - x);           int it = *its;           if (it <= 0 or it < (s - x) / k) {             for (auto b = cek.begin(); b != its and (*b) + x <= s; ++b) {               if (xam < ((*b) ^ x) and gcd(*b, x) % k == 0) {                 xam = ((*b) ^ x);                 res = *b;               }             }           } else {             for (int i = k; i <= 100000 and i + x <= s; i += k) {               if (val[i] and xam < (i ^ x)) {                 xam = (i ^ x);                 res = i;               }             }           }           temp2[make_pair(x, make_pair(k, s))] = res;           printf( %d n , res);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   pair<double, double> A[MAXN];   int n, r, ord[MAXN], st[MAXN];   bool comp(int a, int b) {     if (A[a].first != A[b].first) return A[a].first < A[b].first;     return A[a].second < A[b].second;   }   int ccw(pair<double, double> a, pair<double, double> b,           pair<double, double> c) {     double tmp = a.first * b.second + b.first * c.second + c.first * a.second -                  a.second * b.first - b.second * c.first - c.second * a.first;     if (tmp > 0) return 1;     if (tmp < 0) return -1;     return 0;   }   int main() {     scanf( %d , &n);     int i, m, ni;     for (i = 1; i <= n; i++) scanf( %lf%lf , &A[i].first, &A[i].second);     ni = n;     scanf( %d , &m);     for (i = 1; i <= m; i++) scanf( %lf%lf , &A[n + i].first, &A[n + i].second);     n += m;     for (i = 1; i <= n; i++) ord[i] = i;     sort(ord + 1, ord + n + 1, comp);     st[++r] = ord[1];     st[++r] = ord[2];     for (i = 3; i <= n; i++) {       while (r >= 2 && ccw(A[st[r - 1]], A[st[r]], A[ord[i]]) > 0) r--;       st[++r] = ord[i];     }     for (i = n - 1; i >= 1; i--) {       while (r >= 2 && ccw(A[st[r - 1]], A[st[r]], A[ord[i]]) > 0) r--;       st[++r] = ord[i];     }     r--;     for (i = 1; i <= r; i++)       if (st[i] > ni) {         printf( NO n );         return 0;       }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200001], s1[200001];   int n, m, sum, gang, ans[200001], cnt;   int main() {     scanf( %s , s1 + 1);     m = strlen(s1 + 1);     for (int i = 1; i <= m; i++) {       if (s1[i] ==  (  || s1[i] ==  ) ) s[++n] = s1[i];       if (s1[i] ==  # ) {         s[++n] =  ) ;         s[++n] =  # ;         cnt++;       }     }     sum = 0;     int now = cnt + 1;     for (int i = n; i; i--) {       if (s[i] ==  ) ) {         gang++;       }       if (s[i] ==  ( ) {         if (gang)           gang--;         else           sum++;       }       if (s[i] ==  # ) {         if (sum > 0) ans[now] = sum;         sum = 0;         now--;       }       if ((now > cnt) && (sum > 0)) exit(puts( -1 ));     }     if (gang) exit(puts( -1 ));     ans[now] = sum;     sum = 0;     for (int i = 1; i <= cnt; i++) printf( %d n , ans[i] + 1);   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long Tree[1000001];   long long arr[200001];   void add(long long x, long long val) {     for (; x <= n; x += x & (-x)) Tree[x] += val;     return;   }   long long get(long long x) {     long long sum = 0;     for (; x > 0; x -= x & (-x)) sum += Tree[x];     return sum;   }   void solve() {     long long x = 1;     if (get(1) == 0) {       cout << 1 <<   n ;       return;     }     while (x < n) {       long long curr_val = get(x) * 2;       if (get(x + 1) == curr_val) {         cout << x + 1 <<   n ;         return;       }       long long lo = x + 1;       long long hi = n;       long long lo_bound;       while (lo <= hi) {         if (lo == hi) {           lo_bound = lo;           break;         }         long long mi = (lo + hi) / 2;         if (get(mi) < curr_val)           lo = mi + 1;         else           hi = mi;       }       long long k = lo_bound - 1;       x = (x == k) ? (k + 1) : k;     }     cout << -1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long q;     memset(Tree, 0, sizeof Tree);     cin >> n >> q;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];       add(i, arr[i]);     }     long long x, y;     while (q--) {       cin >> x >> y;       add(x, y - arr[x]);       arr[x] = y;       solve();     }     return 0;   }
#include<bits/stdc++.h>   #include<unordered_map>   using namespace std;   typedef long long ll;   typedef vector<ll> vll;   const ll M = 1000000007;      bool compare(vll x, vll y) {       if (x[0] < y[0]) {           return true;       }       return false;   }   void solve() {       vector<vll> v(3);       ll n1, n2, n3;       cin >> n1 >> n2 >> n3;       vll v1(n1), v2(n2), v3(n3);       ll f1 = 0, f2 = 0;       ll tsum = 0;       for (ll i = 0; i < n1; i++) {           cin >> v1[i];           tsum += v1[i];       }       for (ll i = 0; i < n2; i++) {           cin >> v2[i];           tsum += v2[i];       }       for (ll i = 0; i < n3; i++) {           cin >> v3[i];           tsum += v3[i];       }       sort(v1.begin(), v1.end());       sort(v2.begin(), v2.end());       sort(v3.begin(), v3.end());       v[0] = v1;       v[1] = v2;       v[2] = v3;       sort(v.begin(), v.end(), compare);       // for (int i = 0; i < 3; i++) {           for (int j = 1; j < v[0].size(); j++) {               f1 += v[0][j];           }           for (int j = 1; j < v[1].size(); j++) {               f2 += v[1][j];           }       // }       ll sub = 0;       if (f1 == 0) {           sub = 2 * v[0][0];       } else if (f1 > 0 && f2 == 0) {           if (v[1][0] > f1) {               sub = 2 * v[0][0] + 2 * f1;           } else {               sub = 2 * v[1][0];           }       } else {           sub = 2 * min(f2, v[0][0]) + 2 * min(f1, v[1][0]);       }              if (v[2].size() == 1) {           sub = min(sub , 2 * v[2][0]);       }       cout << tsum - sub << endl;   }      int main() {       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);       // This macro supported by cc, cf, cses       #ifndef ONLINE_JUDGE           freopen( in.txt ,  r , stdin);           freopen( out.txt ,  w , stdout);       #endif       // int tt;       // cin >> tt;       // for(int i = 1; i <= tt; i++) {           solve();       // }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     cin.tie(0), cout.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int u = 0, l = 0, d = 0;       string s;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (s[i] >=  a  && s[i] <=  z ) {           l++;         }         if (s[i] >=  A  && s[i] <=  Z ) {           u++;         }         if (s[i] >=  0  && s[i] <=  9 ) {           d++;         }       }       for (int i = 0; i < s.size(); i++) {         if (s[i] >=  a  && s[i] <=  z  && l > 1) {           if (!u) {             s[i] =  A ;             u++;           } else if (!d) {             s[i] =  0 ;             d++;           }         } else if (s[i] >=  A  && s[i] <=  Z  && u > 1) {           if (!l) {             s[i] =  a ;             l++;           } else if (!d) {             s[i] =  0 ;             d++;           }         } else if (s[i] >=  0  && s[i] <=  9  && d > 1) {           if (!l) {             s[i] =  a ;             l++;           } else if (!u) {             s[i] =  A ;             u++;           }         }       }       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s2;     cin >> s;     cin >> s2;     vector<char> v, t;     for (int i = 0; i < s.length(); i++) {       v.push_back(s[i]);     }     vector<char>::iterator it;     int i = 0;     for (it = v.end() - 1; it >= v.begin(); it--) {       t.push_back(*it);     }     int cnt = 0, n = s.length();     for (int i = 0; i < n; i++) {       if (t[i] == s2[i]) cnt++;     }     if (cnt == n)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, sum;     cin >> n >> sum;     long long temp = 0;     long long cnt = 0;     while (temp < sum) {       if (temp + n <= sum) {         temp += n;         cnt++;       } else {         n--;       }     }     cout << cnt <<   n ;     ;     return 0;   }
#include <bits/stdc++.h>   namespace competitive_programming {   inline namespace utility {}   namespace debugging {}   namespace io {}   }  // namespace competitive_programming   namespace competitive_programming::utility {   class timer {    private:     std::chrono::time_point<std::chrono::steady_clock> begin, end;       public:     timer() : begin(), end() {}     ~timer() {}   };   }  // namespace competitive_programming::utility   constexpr bool test_cases = true;   void yes() { std::cout <<  YES n ; }   void no() { std::cout <<  NO n ; }   auto solve() -> void {     int64_t x, y;     std::cin >> x >> y;     if (x - y < 2)       no();     else       yes();   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.precision(10);     std::cerr.precision(10);     std::cout << std::fixed << std::boolalpha;     std::cerr << std::fixed << std::boolalpha;     competitive_programming::timer t;     int32_t cases = 1;     if (test_cases) std::cin >> cases;     while (cases--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string s[2000];   string t[2000];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int j = 0; j < m; j++) {       bool flag = true;       for (int i = 0; i < n - 1; i++) {         if (s[i][j] > s[i + 1][j]) {           flag = false;           break;         }       }       if (flag) {         for (int i = 0; i < n; i++) t[i] += s[i][j];         for (int k = j + 1; k < m; k++) {           flag = true;           for (int f = 0; f < n - 1; f++)             if (t[f] + s[f][k] > t[f + 1] + s[f + 1][k]) {               flag = false;               break;             }           if (flag) {             for (int f = 0; f < n; f++) t[f] += s[f][k];           }         }         break;       }     }     cout << m - t[0].length();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long a[n][m], f1 = 0;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           cin >> a[i][j];           if (a[i][j] > 4) f1 = 1;         }       }       if (f1) {         cout <<  NO  << endl;         continue;       }       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           long long c = a[i][j];           if ((i == 0 && j == 0) || (i == 0 && j == m - 1) ||               (i == n - 1 && j == m - 1) || (i == n - 1 && j == 0)) {             if (c > 2)               f1 = 1;             else               a[i][j] = 2;           } else if ((i == n - 1 || i == 0 || j == 0 || j == m - 1)) {             if (a[i][j] > 3)               f1 = 1;             else               a[i][j] = 3;           } else             a[i][j] = 4;         }       }       if (f1) {         cout <<  NO  << endl;         continue;       } else {         cout <<  YES  << endl;         for (long long i = 0; i < n; i++) {           for (long long j = 0; j < m; j++) {             cout << a[i][j] <<    ;           }           cout << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k, i;     cin >> n >> k;     vector<long long int> num(k + 1);     long long int maxi = 1e18;     long long int ind = -1;     for (i = 1; i <= k; i++) {       cin >> num[i];       if (n % num[i] < maxi) {         maxi = n % num[i];         ind = i;       }     }     cout << ind <<     << n / num[ind] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 2e5 + 10;   int pr[sz], si[sz], ar[sz][3];   bool us[sz];   bool comp(int a, int b) { return ar[a][2] > ar[b][2]; }   int find_se(int v) {     if (pr[v] == v)       return v;     else {       pr[v] = find_se(pr[v]);       return pr[v];     }   }   void unite(int v, int v2) {     if (v != v2) {       if (si[v] < si[v2]) swap(v, v2);       pr[v2] = v, si[v] += si[v2];     }   }   int main() {     int n, m, an = 0;     cin >> n >> m;     int p[m];     for (int a = 0; a < n; a++) {       pr[a] = a, si[a] = 1, us[a] = 0;     }     for (int a = 0; a < m; a++) {       p[a] = a;       for (int b = 0; b < 3; b++) scanf( %d , &ar[a][b]);       ar[a][0]--, ar[a][1]--;     }     sort(p, p + m, comp);     for (int a = 0; a < m; a++) {       int i = p[a];       int l = find_se(ar[i][0]), r = find_se(ar[i][1]), va = ar[i][2];       if (l == r) {         if (us[l] == 0) {           us[l] = 1, an += va;         }       } else if (us[l] == 1 and us[r] == 0) {         us[r] = 1, an += va;       } else if (us[l] == 0 and us[r] == 1) {         us[l] = 1, an += va;       } else if (us[l] == 0 and us[r] == 0) {         unite(l, r), an += va;       }     }     cout << an;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y;   int a[1000];   bool inrange(int v) { return (v >= x && v <= y); }   int main() {     ios ::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] = a[i - 1] + a[i];     }     cin >> x >> y;     for (int i = 1; i <= n; i++)       if (inrange(a[i - 1]) && inrange(a[n] - a[i - 1])) {         cout << i;         return 0;       }     cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, kangaroo[500000];   int main() {     cin >> n;     for (int _n = n, i = 0; i < _n; ++i) cin >> kangaroo[i];     sort(kangaroo, kangaroo + n);     int middle = (n / 2) - !(n % 2);     int i = middle, j = n - 1;     while (i >= 0 && j > middle) {       if (kangaroo[i] * 2 <= kangaroo[j]) j--;       i--;     }     cout << j + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long double PI = 3.141592653589793;   int main() {     ios_base::sync_with_stdio(false);     long long int t;     cin >> t;     long long int l = 0, r = 0;     set<long long int> le, ri;     vector<long long int> v(2e5 + 10);     while (t--) {       char a;       long long int b;       cin >> a >> b;       if (l == 0 && r == 0) {         v[b] = 1;         l++;         r++;         continue;       }       if (a ==  L ) {         l++;         le.insert(b);         v[b] = l;       } else if (a ==  R ) {         r++;         ri.insert(b);         v[b] = r;       } else {         auto k = le.find(b);         if (k != le.end())           cout << min(l - (v[b] - 1), r + (v[b] - 1)) - 1;         else           cout << min(r - (v[b] - 1), l + (v[b] - 1)) - 1;         cout <<   n ;       }     }     cerr <<  Time Lapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int c[104][104];   long long int dp[104][104 * 104];   long long int mul[104][104];   long long int pw(long long int x, long long int y) {     long long int ans(1);     while (y) {       if (y & 1) ans = (ans * x) % 1000000007;       x = (x * x) % 1000000007;       y >>= 1;     }     return ans;   }   int main() {     long long int n, m, k;     cin >> n >> m >> k;     c[1][0] = c[1][1] = 1;     for (long long int i(2); i <= 100; ++i) {       c[i][i] = c[i][0] = 1;       c[i][1] = i;       for (long long int j(2); j < i; ++j) {         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;       }     }     for (long long int i(0); i < n; ++i) {       for (long long int j(0); j <= n; ++j) {         mul[i][j] = pw(c[n][j], (m - i - 1) / n + 1);       }     }     dp[0][0] = 1;     for (long long int i(0); i < n; ++i) {       for (long long int j(0); j <= k; ++j) {         if (dp[i][j] == 0) continue;         for (long long int kk(0); kk <= n && j + kk <= k; ++kk) {           dp[i + 1][j + kk] =               (dp[i + 1][j + kk] + dp[i][j] * mul[i][kk]) % 1000000007;         }       }     }     cout << dp[n][k] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, len1, len2, ans;   string s;   int main() {     cin >> n;     getline(cin, s), getline(cin, s);     while (len1 < s.size()) {       len2 = len1 + n - 1;       while (len2 > len1)         if (s[len2] ==  .  || s[len2] ==  ?  || s[len2] ==  ! ) {           len1 = len2 + 2;           break;         } else           len2--;       if (len2 == len1) return puts( Impossible ), 0;       ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int n, ip[MAXN], p[MAXN], q[MAXN];   int tree[4 * MAXN], flag[4 * MAXN];   void push(int i, int L, int R) {     if (L < R) {       flag[2 * i] += flag[i];       flag[2 * i + 1] += flag[i];     }     tree[i] += flag[i];     flag[i] = 0;   }   void update(int i, int L, int R, int u, int v, int val) {     push(i, L, R);     if (R < u || v < L) return;     if (u <= L && R <= v) {       flag[i] += val;       push(i, L, R);       return;     }     int mid = (L + R) / 2;     update(2 * i, L, mid, u, v, val);     update(2 * i + 1, mid + 1, R, u, v, val);     tree[i] = max(tree[2 * i], tree[2 * i + 1]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;       ip[p[i]] = i;     }     int j = n - 1;     update(1, 0, n - 1, 0, ip[j], 1);     for (int i = 0; i < n; i++) {       scanf( %d , &q[i]);       q[i]--;       if (i > 0) printf(   );       printf( %d , j + 1);       if (i != n - 1) {         update(1, 0, n - 1, 0, q[i], -1);         while (true) {           if (tree[1] > 0) {             break;           } else {             j--;             update(1, 0, n - 1, 0, ip[j], 1);           }         }       }     }     printf(  n );     return 0;   }