Under construction

Still being built. Things may change

Jerry's Trap

Interview

Time limit2sMemory limit1024 MB

Summary
Given platform heights, after each uniform shift x, print the sum of absolute values of all heights, with shifts accumulating.
Level

Medium4 of 10

Topics
Sorting, Prefix sum, Binary search
Solved
No attempts yet

Statement

Tom has finally managed to trap Jerry. The trap is a water tank with nn platforms fixed inside. The height of platform ii relative to the water level is aia_i.

Each platform is a danger to Jerry. If ai<0a_i < 0, the platform is underwater and its danger is −ai-a_i. If ai⩾0a_i \geqslant 0, Jerry can fall from the platform, and its danger is aia_i. So the danger of platform ii is exactly ∣ai∣|a_i|.

Tom has access to a control panel that changes the heights of all platforms by the same number xx, so the new height of platform ii becomes ai+xa_i + x. Tom can use the panel kk times before Jerry gets out of the trap. After each action, print the total danger of the trap, that is, the sum of the dangers of all platforms.

Input

The first line contains an integer nn (1⩽n⩽1000001 \leqslant n \leqslant 100000), the number of platforms. The second line contains nn integers aia_i separated by spaces (∣ai∣⩽1000000|a_i| \leqslant 1000000).

The third line contains an integer kk (1⩽k⩽1000001 \leqslant k \leqslant 100000), the number of times Tom changes the heights. The last line contains kk integers xix_i, where xix_i is the amount by which Tom changes the heights in the ii-th action (∣xi∣⩽1000000|x_i| \leqslant 1000000).

Output

After each action of Tom, print on a new line the total danger of the trap.

Hint

In the first example, after the first action the heights become 1,2,01, 2, 0. Then Tom lowers them by 22 more and gets −1,0,−2-1, 0, -2. After the last action the heights are 3,4,23, 4, 2.

In the second example, Tom lowers all heights by 11 five times in a row. Each action adds negative numbers, so the answer first decreases and then increases. At the end the heights are −4,−3,−2,−1,0-4, -3, -2, -1, 0, which gives the same answer as after the first action, when the heights were 0,1,2,3,40, 1, 2, 3, 4.

Examples2

  1. Example 1

    Input
    3
    2 3 1
    3
    -1 -2 4
    
    Expected output
    3
    3
    9
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    5
    -1 -1 -1 -1 -1
    
    Expected output
    10
    7
    6
    7
    10