#include using namespace std; int main(){ int N; cin >> N; vector P(N); for (int i = 0; i < N; i++){ cin >> P[i]; } vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector S(N + 1); S[0] = 0; for (int i = 0; i < N; i++){ S[i + 1] = S[i] + P[i]; } vector p(N); for (int i = 0; i < N; i++){ p[P[i] - 1] = i; } set st; st.insert(-1); st.insert(N); vector L(N), R(N); for (int i = 0; i < N; i++){ auto itr1 = prev(st.lower_bound(p[i])); L[i] = *itr1 + 1; auto itr2 = st.lower_bound(p[i]); R[i] = *itr2; st.insert(p[i]); } for (int i = 0; i < N; i++){ cout << L[i] << ' ' << R[i] << endl; } for (int i = 0; i < N; i++){ int Lcnt = p[i] - L[i] + 1; int Rcnt = R[i] - p[i]; if (Lcnt <= Rcnt){ long long ans = 0; for (int j = L[i]; j <= p[i]; j++){ auto itr = upper_bound(S.begin() + p[i] + 1, S.begin() + R[i] + 1, A[i] + S[j]); ans += itr - (S.begin() + p[i] + 1); } cout << ans << endl; } else { long long ans = 0; for (int j = p[i] + 1; j <= R[i]; j++){ auto itr = lower_bound(S.begin() + L[i], S.begin() + p[i] + 1, S[j] - A[i]); ans += (S.begin() + p[i] + 1) - itr; } cout << ans << endl; } } }