func_code_string: #include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return (a.first - a.second) > (b.first - b.second);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> hand(n);     vector<long long> pile(n);     unordered_map<long long, long long> hand_map(n);     unordered_map<long long, long long> pile_map(n);     for (long long i = 0; i < n; i++) {       cin >> hand[i];       hand_map[hand[i]]++;     }     for (long long i = 0; i < n; i++) {       cin >> pile[i];       pile_map[pile[i]]++;     }     long long flag = 0;     long long last = pile[n - 1];     long long index;     for (long long i = n - 1; i > 0; i--) {       if (pile[i] == 1) {         index = i;         break;       }       if (pile[i] - 1 == pile[i - 1] && pile[i] != 0) {       } else {         flag = 1;         break;       }     }     long long shift = 0;     if (flag == 1) {       for (long long i = 0; i < n; i++) {         if (pile[i] != 0) shift = max(shift, i + 2 - pile[i]);       }       cout << shift + n;     } else {       long long last = pile[n - 1];       for (long long i = 0; i < n; i++) {         if (pile[i] == 1) {           break;         }         if (pile[i] != 0) {           shift = max(shift, i + 2 - (pile[i] - pile[n - 1]));         }       }       if (shift == 0) {         cout << shift + n - pile[n - 1];       } else {         cout << index + 1 + n;       }     }     return 0;   }   