KONZERVE
문제
Mirko got a brand new air rifle for his birthday. To test its destructive power, he took cans of beans from his closet and rushed to the nearest playground.
He noted that there were three types of cans – black, white and grey, each containing different sorts of beans. Mirko lined up his cans in N columns, one behind another, so that the black cans are on the bottom of each column, grey cans are in the middle, with white cans on top. The columns may vary in height and not all columns need to contain cans of all three colours. However, the colours in a single column must be ordered as described.
After arranging the cans, Mirko fires M bullets from his air rifle horizontally, each one at some height. The rifle is very powerful so the pellet, after shattering the first can at that height, continues flying in the same direction and destroys any cans at that height. After the bullet smashes a can, any cans that were on top of it fall down. The height of a shot is an integer; a shot at height 1 hits all cans lying on the ground, a shot at height 2 hits all cans immediately above those etc.
[이미지 1]
In his game, Mirko awards himself 1 point for each black can shattered, 2 for each grey can, and 5 for each white can.
Write a program that, given the layout of the cans in columns and the heights of the shots in order, calculates the number of points received for each shot.
입력
The first line contains an integer N (1 ≤ N ≤ 300000), the number of columns.
The second line contains N non-negative integers, the number of black cans in each column.
The third line contains N non-negative integers, the number of grey cans in each column.
As one might imagine, the fourth line also contains N non-negative integers, the number of white cans in each column.
All numbers will be less than 106.
The fifth line contains an integer M (1 ≤ M ≤ 300000), the number of shots.
The sixth line contains M positive integers, the heights at which the shots are fired, in the order in which Mirko fires them. Each height will be less than 106.
출력
Output consists of exactly M lines, the number of points Mirko is awarded for each shot, in order in which he fires them.
예제
예제 1
6 2 1 2 0 3 1 1 2 2 2 2 0 1 0 1 2 0 3 2 2 4
12 7
예제 2
10 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 6 3 3 2 3 4 3
20 20 10 50 50 50