#pragma GCC optimize("Ofast") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } inline double time() { return static_cast(chrono::duration_cast(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n),b(n); for(int i=0;i> a[i]; } for(int i=0;i> b[i]; } deque> dq1,dq2; ll res = -n; int r = 0; for(int l=0;l= a[r]+b[r]) ok = false; if(dq2.size() and dq2.front().first >= a[r]-b[r]) ok = false; if(!ok) break; while(dq1.size() and dq1.back().first <= a[r]+b[r]){ dq1.pop_back(); } dq1.push_back({a[r]+b[r],r}); while(dq2.size() and dq2.back().first <= a[r]-b[r]){ dq2.pop_back(); } dq2.push_back({a[r]-b[r],r}); r++; } } res += r-l; } cout << res << endl; }