malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long mod2 = 998244353;   long long fpow(long long x, long long y) {     x = x % 1000000007;     long long sum = 1;     while (y) {       if (y & 1) sum = sum * x;       sum %= 1000000007;       y = y >> 1;       x = x * x;       x %= 1000000007;     }     return sum;   }   long long inv(long long a, long long m = 1000000007) {     long long c = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += c;     return x;   }   long long gcd(long long a, long long b) {     if (!a) return b;     return gcd(b % a, a);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     long long n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long res = 1;     for (int i = 0; i < 10; i++) {       long long ele = a[rng() % n];       vector<long long> div, cnt;       for (long long j = 1; j * j <= ele; j++) {         if ((ele % j) == 0) {           if (j * j == ele) {             div.push_back(j);             cnt.push_back(0);           } else {             div.push_back(j);             cnt.push_back(0);             div.push_back(ele / j);             cnt.push_back(0);           }         }       }       sort(div.begin(), div.end());       for (int j = 0; j < n; j++) {         long long g = gcd(ele, a[j]);         cnt[lower_bound(div.begin(), div.end(), g) - div.begin()]++;       }       for (int j = 0; j < div.size(); j++) {         for (int k = j + 1; k < div.size(); k++) {           if (div[k] % div[j] == 0) cnt[j] += cnt[k];         }         if (2 * cnt[j] >= n) res = max(res, div[j]);       }     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   #define int long long   #define mod 1000000007    #define inv 500000004      using namespace std;      int ksm(int a, int b) {    int ans = 1, base = a % mod;    while (b) {     if (b & 1) ans = (ans * base) % mod;     base = (base * base) % mod;     b /= 2;    }    return ans % mod;   }      struct Edge{    int to;    int next;   };      Edge edge[405];   int head[205], cnt = 0;      void add(int u, int v) {    cnt++;    edge[cnt].to = v;    edge[cnt].next = head[u];    head[u] = cnt;   }      int n, fa[205][25], f[205][205], dep[205];      void dfs(int u, int fath) {    for (int i = head[u]; i; i = edge[i].next) {     int v = edge[i].to;     if (v == fath) continue;     dep[v] = dep[u] + 1;     fa[v][0] = u;     for (int j = 1; j <= 22; j++) {      fa[v][j] = fa[fa[v][j - 1]][j - 1];     }     dfs(v, u);    }   }      int lca(int x, int y) {    if (dep[x] < dep[y]) swap(x, y);    for (int i = 22; i >= 0; i--) {     if (dep[fa[x][i]] >= dep[y]) {      x = fa[x][i];     }    }    if (x == y) return x;    for (int i = 22; i >= 0; i--) {     if (fa[x][i] != fa[y][i]) {      x = fa[x][i]; y = fa[y][i];     }    }    return fa[x][0];   }      signed main() {    cin >> n;    for (int i = 1; i < n; i++) {     int u, v;     cin >> u >> v;     add(u, v); add(v, u);    }    for (int i = 1; i <= n; i++) f[0][i] = 1;    for (int i = 1; i <= n; i++) {     for (int j = 1; j <= n; j++) {      f[i][j] = ((f[i - 1][j] + f[i][j - 1]) % mod * inv % mod) % mod;     }    }    int ans = 0;    for (int rt = 1; rt <= n; rt++) {     memset(dep, 0, sizeof dep);     memset(fa, 0, sizeof fa);     dep[rt] = 1;     dfs(rt, 0);     for (int i = 1; i <= n; i++) {      for (int j = 1; j <= i - 1; j++) {       int LCA = lca(i, j);       ans = (ans % mod + f[dep[i]-dep[LCA]][dep[j]-dep[LCA]] % mod) % mod;      }      }    }    cout << (ans % mod * ksm(n, mod - 2) % mod) % mod;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline bool umin(T1& x, const T2& y) {     return x > y ? x = y, true : false;   }   template <typename T1, typename T2>   inline bool umax(T1& x, const T2& y) {     return x < y ? x = y, true : false;   }   const int N = (int)5e2 + 5;   const int INF = (int)1e9 + 17;   const long long LLINF = (long long)1e18 + 17;   const int mod = 998244353;   inline void add(int& x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }   inline int mul(int x, int y) { return 1ll * x * y % mod; }   int n, m;   int cnt[N];   int nxt[N][N];   int prv[N][N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     cin >> n >> m;     prv[0][0] = 1;     for (int total = (0); total < (n); ++total) {       for (int maxEqual = (0); maxEqual < (total + 1); ++maxEqual) {         for (int equal = (0); equal < (total + 1); ++equal) {           if (prv[maxEqual][equal] == 0) continue;           add(nxt[max(maxEqual, equal + 1)][equal + 1], prv[maxEqual][equal]);           add(nxt[max(maxEqual, 1)][1], prv[maxEqual][equal]);         }       }       memcpy(prv, nxt, sizeof nxt);       memset(nxt, 0, sizeof nxt);     }     for (int maxEqual = (0); maxEqual < (n + 1); ++maxEqual) {       for (int equal = (0); equal < (maxEqual + 1); ++equal) {         add(cnt[maxEqual], prv[maxEqual][equal]);       }     }     int answer = 0;     for (int a = (0); a < (n + 1); ++a)       for (int b = (0); b < (n + 1); ++b) {         if (a * b >= m) continue;         add(answer, mul(cnt[a], cnt[b]));       }     if (answer % 2 == 0)       answer /= 2;     else       answer = (answer + mod) / 2;     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const long long INF = (long long)1 << 60;   long long x[maxn], y[maxn], n;   inline long long sqr(long long x) { return x * x; }   long long p[maxn], cnt;   long long ans;   bool cmpy(int a, int b) { return y[a] < y[b]; }   void solve(int l, int r) {     if (l == r) return;     int m = (l + r) >> 1;     solve(l, m);     solve(m + 1, r);     cnt = 0;     for (int i = l; i <= r; i++) {       if (sqr(x[m] - x[i]) >= ans) continue;       p[cnt++] = i;     }     sort(p, p + cnt, cmpy);     for (int i = 0; i < cnt; i++) {       for (int j = i + 1; j < cnt && sqr(y[p[j]] - y[p[i]]) < ans; j++)         ans = min(ans, sqr(y[p[j]] - y[p[i]]) + sqr(x[p[j]] - x[p[i]]));     }   }   int main() {     scanf( %lld , &n);     y[0] = 0;     for (int i = 1; i <= n; i++) scanf( %lld , &y[i]), x[i] = i, y[i] += y[i - 1];     ans = INF;     solve(1, n);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxsize = 100005;   const int inf = 1061109567;   vector<int> edge[maxsize];   vector<pair<int, int> > base[maxsize];   int nnext[maxsize];   int n;   int deepth[maxsize];   int siz[maxsize];   int last = 0;   int ans[10 * maxsize];   int cnt = 0;   void dfs1(int u) {     if (edge[u].size() == 0) {       deepth[u] = 1;       return;     }     int maxi = 0;     for (auto v : edge[u]) {       siz[v] = siz[u] + 1;       dfs1(v);       maxi = max(deepth[v], maxi);       base[u].push_back({deepth[v], v});     }     deepth[u] = maxi + 1;     sort(base[u].begin(), base[u].end());     return;   }   void dfs2(int u) {     for (auto v : base[u]) {       nnext[last] = v.second;       last = v.second;       printf( %d  , v.second);       dfs2(v.second);     }     return;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u;       scanf( %d , &u);       edge[u].push_back(i + 1);     }     dfs1(0);     printf( 0  );     dfs2(0);     puts(  );     int gg = 0;     while (nnext[gg]) {       int r = siz[gg] - siz[nnext[gg]] + 1;       for (int i = 0; i < r; i++) ans[cnt++] = nnext[gg];       gg = nnext[gg];     }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) printf( %d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0, i;     char str[10], o[5];     scanf( %d , &n);     scanf( %s , o);     for (i = 0; i < n; i++) {       scanf( %s , str);       if (str[5] == o[0] && str[6] == o[1] && str[7] == o[2]) cnt++;       if (str[0] == o[0] && str[1] == o[1] && str[2] == o[2]) cnt++;     }     if (cnt % 2)       printf( contest n );     else       printf( home n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void input(vector<long long>& v, long n) {     for (long long i = 0; i < n; i++) {       long long in;       cin >> in;       v.push_back(in);     }   }   void output(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   long long max_of_three(long long a, long long b, long long c) {     if (a >= b && a >= c)       return a;     else if (b >= a && b >= c)       return b;     else       return c;   }   long long max_of_4(long long a, long long b, long long c, long long d) {     if (a >= b && a >= c && a >= d)       return a;     else if (b >= a && b >= c && b >= d)       return b;     else if (c >= a && c >= d && c >= b)       return c;     else       return d;   }   map<long long, long long> frequency(vector<long long> v) {     map<long long, long long> m;     for (long long i = 0; i < v.size(); i++) {       if (m.find(v[i]) != m.end())         m[v[i]]++;       else {         m.insert({v[i], 1});       }     }     return m;   }   long long max_occuring_int(std::map<long long, long long> m) {     long long max_x = 0;     long long i = 0, n = m.size();     std::map<long long, long long>::iterator it = m.begin();     for (i = 0; i < n; i++) {       if (it->second > max_x) max_x = it->second;       it++;     }     return max_x;   }   vector<long long> give_unique_in_vector(vector<long long> v) {     sort((v).begin(), (v).end());     auto it = unique((v).begin(), (v).end());     v.resize(std::distance(v.begin(), it));     vector<long long> x = v;     return x;   }   bool isVowel(char c) {     return (c ==  a  | c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  ||             c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y );   }   string removeWord(string str, string word) {     if (str.find(word) != string::npos) {       size_t p = -1;       string tempWord = word +    ;       while ((p = str.find(word)) != string::npos)         str.replace(p, tempWord.length(),   );       tempWord =     + word;       while ((p = str.find(word)) != string::npos)         str.replace(p, tempWord.length(),   );     }     return str;   }   long long calc(long long i, long long j, long long n) {     return (i + 1 - 1) * n + j + 1;   }   bool compare_descending(long long a, long long b) { return a > b; }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> v;     input(v, n);     long long max_change_of_min = *min_element((v).begin(), (v).end()) + k;     long long price = max_change_of_min;     for (long long i = 0; i < (long long)(n); ++i) {       long long low = v[i] - k;       long long high = v[i] + k;       if (low <= 0) low = 1;       if (price >= low && price <= high) {       } else {         cout <<  -1 n ;         return;       }     }     cout << price << endl;     ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     cin >> test;     while (test--) solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 100001, inf = 2147483647;   const long long mod = 1 ? 998244353 : 1000000007, linf = 9223372036854775807;   const double pi = acos(-1);   inline long long mi(long long a, long long b, long long mm = mod) {     a %= mm;     long long u = 1;     while (b) {       if (b & 1) u = u * a % mm;       a = a * a % mm, b >>= 1;     }     return u;   }   inline long long gcd(long long a, long long b) {     long long c = a % b;     while (c) a = b, b = c, c = a % b;     return b;   }   inline void mem(int* a, int p = 0, int len = maxn) {     for (int i = 0; i < len; i++) a[i] = p;   }   struct p {   } e;   int t, n, a[maxn], b[maxn], x, m;   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       x = 0;       b[0] = 10000, b[1] = 0;       cin >> n >> m;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           cin >> a[0], x += abs(a[0]), b[0] = min(b[0], abs(a[0])),                                        b[1] += a[0] < 0;       cout << x - 2 * b[0] * (b[1] % 2) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   int A[5005];   int DP[5005][5005];   void Read() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &A[i]);   }   void precalcDP() {     for (int i = 1; i <= N; i++) {       for (int j = i; j <= N; j++) DP[i][j - i] = A[j];       for (int k = 0; (1 << k) <= N; k++)         for (int j = 0; j < N; j++)           if ((j & (1 << k)) != 0) DP[i][j] ^= DP[i][j ^ (1 << k)];     }     for (int j = 1; j <= N; j++) {       for (int i = 1; j + i <= N; i++)         DP[i][j] = max(DP[i][j], max(DP[i][j - 1], DP[i + 1][j - 1]));     }   }   void Query(int a, int b) {     int dist = b - a;     printf( %d n , DP[a][dist]);   }   int main() {     Read();     precalcDP();     int Q;     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       int x, y;       scanf( %d%d , &x, &y);       Query(x, y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, t, s, x, y, h[100005], hh[100005], d, l;   int main() {     cin >> n;     for (i = 0; i < n; i++) scanf( %d , h + i);     m = h[n - 1];     for (i = n - 2; i >= 0; i--) {       if (h[i] <= m)         hh[i] = m - h[i] + 1;       else         m = h[i];     }     for (i = 0; i < n; i++) printf( %d  , hh[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h, r, spheres = 0;     cin >> r >> h;     spheres = (h / r) * 2;     if (h % r < r / 2.)       spheres += 1;     else {       spheres += 2;       if (h % r > 1.732 * r / 2.) spheres += 1;     }     cout << spheres;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0, y = 0;     string a, b;     cin >> a >> b;     if (a.size() > b.size()) {       n = a.size();     } else {       n = b.size();     }     for (int i = 0; i < n; i++) {       if (b[x] == a[y]) {         x++;         y++;       } else {         x++;       }       if (b[x] == 0 || a[y] == 0) {         cout << (y + 1);         break;       }     }   }
#include <bits/stdc++.h>   long long x, n, d1, d2, now;   int main() {     scanf( %lld %lld , &n, &x);     d1 = x;     d2 = x;     long long l, r, ans = 0l;     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &l, &r);       if (l <= d1 && r >= d2) continue;       if (r < d1) {         ans += (d1 - r);         d2 = d1;         d1 = r;       } else if (l > d2) {         ans += (l - d2);         d1 = d2;         d2 = l;       } else {         d1 = (d1 < l) ? l : d1;         d2 = (d2 > r) ? r : d2;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e10;   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long moves = (n + m - 2) + (n * m) - 1;     for (long long i = 0; i < m + n; i++) {       cin >> k;     }     cout << moves <<   n ;     for (long long i = 0; i < n - 1; i++) {       cout <<  U ;     }     for (long long i = 0; i < m - 1; i++) {       cout <<  L ;     }     string r(m - 1,  R );     string l(m - 1,  L );     for (long long i = 0; i < n; i++) {       if (i % 2) {         cout << l;       } else         cout << r;       if (i != n - 1) cout <<  D ;     }     cout <<   n ;   }   int32_t main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int X, Y;   int n;   int cnt;   bool used[1000][1000];   bool edge[1000][1000][4];   const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};   vector<int> ans;   void dfs(int x, int y) {     if (x < 0 || x >= X || y < 0 || y >= Y || used[x][y]) return;     used[x][y] = true;     cnt++;     for (int i = 0; i < 4; i++) {       if (!edge[x][y][i]) {         dfs(x + DX[i], y + DY[i]);       }     }   }   int main() {     scanf( %d%d%d , &X, &Y, &n);     for (int i = 1; i <= n; i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         for (int j = y1; j < y2; j++) {           edge[x1 - 1][j][0] = true;           edge[x1][j][2] = true;         }       } else if (y1 == y2) {         for (int j = x1; j < x2; j++) {           edge[j][y1 - 1][1] = true;           edge[j][y1][3] = true;         }       }     }     for (int i = 0; i < X; i++)       for (int j = 0; j < Y; j++)         if (!used[i][j]) {           cnt = 0;           dfs(i, j);           ans.push_back(cnt);         }     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   char s[100];   bool ops[256];   int relabel[N * 6];   int va[N * 6][2];   int typ[N * 6];   bool vis[N * 6], beres[N * 6];   string detail[N * 6];   map<string, int> ex;   map<pair<pair<int, int>, int>, int> rel;   vector<string> ans;   char usea;   int usev;   string nxtvar() {     while (true) {       string cur = string() + usea + to_string(usev);       if (!ex.count(cur)) {         ex.insert(make_pair(cur, 0));         return cur;       }       if (++usev == 1000) {         usev = 0;         ++usea;       }     }   }   int strcnt;   int gid(const string& str) {     auto it = ex.find(str);     if (it != ex.end()) return it->second;     ex.insert(make_pair(str, ++strcnt));     detail[strcnt] = str;     return strcnt;   }   int nid(const string& str) {     detail[++strcnt] = str;     return ex[str] = strcnt;   }   void dfs(int u) {     if (vis[u]) return;     vis[u] = true;     if (typ[u] == 0) {       relabel[u] = u;       return;     }     if (typ[u] == -1) {       if (beres[u]) {         if (typ[va[u][0]]) {           beres[va[u][0]] = true;         } else {           if (detail[va[u][0]] !=  res ) ans.push_back( res=  + detail[va[u][0]]);           return;         }       }       dfs(va[u][0]);       relabel[u] = relabel[va[u][0]];       return;     }     dfs(va[u][0]);     dfs(va[u][1]);     pair<pair<int, int>, int> spec(         make_pair(relabel[va[u][0]], relabel[va[u][1]]), typ[u]);     relabel[u] = u;     if (!rel.count(spec)) {       rel.insert(make_pair(spec, u));       detail[u] = nxtvar();       ans.push_back((beres[u] ? string( res ) : detail[u]) +  =  +                     detail[relabel[va[u][0]]] + char(typ[u]) +                     detail[relabel[va[u][1]]]);     } else       relabel[u] = rel[spec];   }   int main() {     usea =  a ;     usev = 0;     ops[ $ ] = true;     ops[ ^ ] = true;     ops[ # ] = true;     ops[ & ] = true;     int t;     scanf( %d , &t);     while (t--) {       scanf( %s , s);       char *p1 = s, *p2;       while (*p1 !=  = ) ++p1;       string a(s, p1);       p2 = p1;       while (!ops[*p2] && *p2) ++p2;       if (ops[*p2]) {         string b(p1 + 1, p2), c(p2 + 1);         int bi = gid(b), ci = gid(c);         int ai = nid(a);         typ[ai] = *p2;         va[ai][0] = bi;         va[ai][1] = ci;       } else {         string b(p1 + 1);         int bi = gid(b);         int ai = nid(a);         typ[ai] = -1;         va[ai][0] = bi;       }     }     int resi = gid( res );     beres[resi] = true;     dfs(resi);     printf( %lu n , ans.size());     for (auto str : ans) puts(str.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read(vector<long long> &v) {     for (int i = 0; i < v.size(); i++) cin >> v[i];   }   void print(vector<long long> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   long long n, m, a, b, temp, x, y;   string str;   set<string> strings;   unordered_map<string, vector<int>> mp;   bool check(int l, int r) {     for (auto s : strings) {       if (r - l + 1 < s.size()) continue;       auto it = lower_bound(mp[s].begin(), mp[s].end(), l);       if (it == mp[s].end()) continue;       int val = *it;       if (val <= (r - s.size() + 1)) return 0;     }     return 1;   }   int start;   int solve() {     int l = 0;     int r = 0;     int ans = 0;     for (int l = 0; l < str.size(); l++) {       while (r < l) r++;       if (!check(l, r)) {         if (r - l > ans) {           ans = r - l;           start = l;         }         continue;       }       while (r < str.size()) {         if (check(l, r))           r++;         else           break;       }       if (r - l > ans) {         ans = r - l;         start = l;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> str;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       strings.insert(s);     }     for (auto s : strings) {       string temp;       if (s.size() > str.size()) continue;       for (int i = 0; i <= str.length() - s.length(); i++) {         temp = str.substr(i, s.length());         if (temp == s) mp[s].push_back(i);       }     }     long long ans = solve();     cout << ans <<     << start;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y;   int n;   pair<long long, long long> a[200001];   vector<long long> numbers;   map<long long, int> matchs;   long long matchsReverse[400001];   int increase[400001];   int decrease[400001];   long long answer[400001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       a[i] = make_pair(x, y);       numbers.push_back(x);       numbers.push_back(y);     }     sort(numbers.begin(), numbers.end());     int last = -1, num = 0;     for (int i = 0; i < numbers.size(); i++) {       if (last != numbers[i]) {         num++;         matchs[numbers[i]] = num;         matchsReverse[num] = numbers[i];         last = numbers[i];       }     }     for (int i = 0; i < n; i++) {       a[i] = make_pair(matchs[a[i].first], matchs[a[i].second]);       increase[a[i].first]++;       decrease[a[i].second]++;     }     long long cnt = 0;     for (int i = 1; i <= 400000; i++) {       answer[cnt] += matchsReverse[i] - 1 - matchsReverse[i - 1];       answer[cnt + increase[i]]++;       cnt += increase[i];       cnt -= decrease[i];     }     for (int i = 1; i <= n; i++) cout << answer[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int pos[200000 + 10], b[200000 + 10];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x) {         pos[x] = 0;       }     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i]) {         pos[b[i]] = i;       }     }     int start = 1;     int end = b[n];     bool flag = true;     for (int i = n - 1, j = end - 1; j > 0; j--, i--) {       if (b[i] != j) {         flag = false;       }     }     if (flag) {       start = end + 1;     }     if (start != 1) {       for (int i = start; i <= n; i++) {         if (pos[i] > i - start) {           start = 1;           break;         }       }     }     int ans = n - start + 1;     ans += pos[start];     int mx = 0;     for (int i = start + 1; i <= n; i++) {       int t = pos[i] - pos[start];       mx = max(mx, t - i + start);     }     cout << ans + mx <<   n ;   }