func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 200100;   int n, l, r, m, a[N], b[N], c, pos, mi, ma;   pair<int, int> t[4 * N];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v].first = a[tl];       t[v].second = b[tl];       return;     }     int tm = (tl + tr) / 2;     build(2 * v, tl, tm);     build(2 * v + 1, tm + 1, tr);     t[v].first = max(t[2 * v].first, t[2 * v + 1].first);     t[v].second = min(t[2 * v].second, t[2 * v + 1].second);     return;   }   void get(int v, int tl, int tr, int l, int r) {     if (l > r) return;     if (tl == l && tr == r) {       ma = max(ma, t[v].first);       mi = min(mi, t[v].second);       return;     }     int tm = (tl + tr) / 2;     get(2 * v, tl, tm, l, min(r, tm));     get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = 1e9 - 2;     for (int i = 1; i <= n; i++) cin >> b[i];     b[n + 1] = -1e9 - 2;     build(1, 1, n);     long long ans = 0;     for (int i = 1; i <= n; i++)       if (a[i] - b[i] < 1) {         l = i;         r = n + 1;         while (l < r) {           c = (l + r) / 2;           mi = 1e9 + 2;           ma = -1e9 - 2;           get(1, 1, n, i, c);           if (mi > ma)             l = c + 1;           else             r = c;         }         pos = l;         l = i;         r = n + 1;         while (l < r) {           c = (l + r) / 2;           mi = 1e9 + 2;           ma = -1e9 - 2;           get(1, 1, n, i, c);           if (mi >= ma)             l = c + 1;           else             r = c;         }         ans += max(l - pos, 0);       }     cout << ans <<   n ;     return 0;   }   