#include // #include using namespace std; // using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(lint i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; using pint = pair; using vp = vector; int main() { lint N; cin >> N; vi v(N), w(N); vin(v); vin(w); lint a=0, b=0, c=0, x, y, z; set s, t; vi u(N, N-1); rep(i, N) { vp q; for (auto p : s) { tie(x, y) = p; if (x+w[i] < v[i]) break; q.pb({x, y}); chmin(u[y], i-1); } for (auto p : q) { s.erase(p); } vp r; for (auto p : t) { tie(x, y) = p; if (-x < v[i]+w[i]) break; r.pb({x, y}); chmin(u[y], i-1); } for (auto p : r) { s.erase(p); } s.insert({v[i]-w[i], i}); t.insert({-v[i]-w[i], i}); } for (int i = N-1; i > 0; i--) { chmin(u[i-1], u[i]); } // vout(u); rep(i, N) { a += u[i]-i; } std::cout << a << '\n'; }