func_code_string: #include <bits/stdc++.h>   using namespace std;   long long suml[100100], sumr[100100], l[100100], r[100100], A[100100],       B[100100], total, ans[100100];   int main() {     long long N;     cin >> N;     for (long long i = 1; i <= N; i++) {       scanf( %lld , A + i);     }     for (long long i = N; i > 0; i--) {       scanf( %lld , B + i);     }     for (long long i = 1; i <= N; i++) {       l[i] = i - 1;       r[i] = i + 1;     }     for (long long i = 1; i <= N; i++) {       long long x = B[i];       long long sum = suml[r[x]] + sumr[l[x]] + A[x];       sumr[l[x]] = suml[r[x]] = sum;       l[r[x]] = l[x];       r[l[x]] = r[x];       total = max(total, sum);       ans[i] = total;     }     for (long long i = N - 1; i >= 0; i--) {       printf( %lld n , ans[i]);     }   }   