#include #include using namespace std; using namespace atcoder; using ll=int; using ld=long double; ld pie=3.14159265359; ll inf=1001; ll mod=998244353; int main(){ ll n; cin >> n; vectora(n),b(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < n; i++) { cin >> b[i]; } ll ans=0; for (ll i = 1; i < n; i++) { if (a[i]+min(b[i],b[i-1])<=a[i-1]+max(b[i],b[i-1])) { continue; } ll right=i-1; ll left=-1; while (right-left>1) { ll mid=(right+left)/2; if (a[i]+min(b[i],b[mid])<=a[mid]+max(b[i],b[mid])) { left=mid; }else{ right=mid; } } ans+=i-right; } cout << ans << endl; }