#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define forin for(int i = 1; i <= n; i++)
#define stforin for(int i = 0; i < n; i++)
#define forim for(int i = 1; i <= m; i++)
#define forjn for(int j = 1; j <= n; j++)
#define forch(j, n) for(int i = j; i <= n; i++)
#define forch2(i, j, n) for(int i = j; i <= n; i++)
#define forjm for(int j = 1; j <= m; j++)
#define lol long long
#define lb long double
#define endl '\n'
#define debug cout << "Completed" << endl;
#define fix(n, m) cout << fixed; cout.precision(b); cout << n << endl
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define bads cout << -1 << endl
#define pll pair<lol, lol>
#define mod 998244353
#define fst first
#define snd second
#define inf 1e15
#define tofix cin
; string sbuf;
ostringstream buf(sbuf);
istringstream atcin(sbuf);
lol gcd(lol a, lol b) {
    while (a != 0 && b != 0) if (a > b) a %= b; else b %= a;
    return a + b;
}
lol lcm(lol a, lol b) {
    return a / gcd(a, b) * b;
}
bool issqrt(lol n) {
    lb x = sqrt(n);
    if (x == (lol)x) return 1;
    return 0;
}
lol easy(lol n) {
    if (n == 1) return 0;
    for (int i = 2; i * i <= n; i++) if (n % i == 0) return 0;
    return 1;
}
string bin(lol v) {
    string ans;
    while (v != 0) {
        ans += to_string((v % 2));
        v /= 2;
    }
    return ans;
}
//priority_queue <pll, vector<pll>, greater<pll>> q
const long long N = 2e5 + 100;
lol ts, n, a[N], b[N], c[N], ans, ma, hmm, cl, x, y;
void solve() {
    cin >> n;
    stforin cin >> a[i];
    stforin cin >> b[i];
    for (int mk = 0; mk < (1 << (n - 1)); mk++) {
        vector<pll> gr;
        int l = 0;
        for (int i = 0; i < n - 1; i++) if (mk & (1 << i)) {
                gr.push_back({ l, i });
                l = i + 1;
            }
        gr.push_back({ l, n - 1 });
        for (auto el : gr) {
            x = el.first;
            y = el.second;
            ma = a[x];
            forch(x, y) ma = max(ma, a[i]);
            forch(x, y) c[i] = ma;
        }
        hmm = 0;
        stforin if (c[i] == b[i]) hmm++;
        ans = max(hmm, ans);
    }
    cout << ans << endl;
}
int main() {
    ts = 1;
    //cin >> ts;
    while(ts--) solve();
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |