Cookies

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

You are to hold a cookie party! You have prepared NN cookies numbered from 11 through NN. The sweetness of the cookie ii is A_iA\_i. You expect that MM children numbered from 11 to MM will attend the party. All of them will bring their homemade cookies, and the child ii will bring a cookie of sweetness B_iB\_i. Besides, you know the taste preference of each child. The child ii loves sweet cookies if S_i=S\_i=S and loves bitter cookies if S_i=S\_i=B.

The party will proceed in the following manner:

  • First, you are given an integer kk and put cookies 1,2,,k1,2,\cdots,k on the table.
  • Then, children 1,2,,M1,2,\cdots,M, in this order, come to the table. When the child ii comes to the table, the child first put his/her homemade cookie on the table. Then, if the child loves sweet cookies, he/she eats the sweetest cookie (a cookie with the largest sweetness) on the table. If the child loves bitter cookies, he/she eats the bitterest cookie (a cookie with the smallest sweetness) on the table. Note that each child eats exactly one cookie, and a child may eat his/her cookie.
  • Finally, you eat all the cookies left on the table.

You have not yet decided the value of kk. For each integer k=1,2,,Nk=1,2,\cdots,N, find the sum of the sweetness of cookies you will eat.

Note that only after you get the answer for k=ik=i can you know the value of A_i+1A\_{i+1}. See the input section for more details.

입력

Input is given from Standard Input in the following format:

NN

A_1A'\_1 A_2A'\_2 \cdots A_NA'\_N

MM

B_1B\_1 B_2B\_2 \cdots B_MB\_M

SS

Here A_iA'\_i is the encrypted value of A_iA\_i, and the real value can be calculated as A_i=(A_i+lastansmod109)A\_i=(A'\_i+lastans \mod 10^9), where lastanslastans denotes the answer for k=i1k={i-1} if i>1i>1 and 00 if i=1i=1.

출력

Print NN integers in one line. The ii-th integer should be the sum of the sweetness of cookies you will eat when k=ik=i.

제한

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0A_i10910 \leq A\_i \leq 10^9-1
  • 0A_i10910 \leq A'\_i \leq 10^9-1 (see the input section for the definition of this variable)
  • 1M2×1051 \leq M \leq 2 \times 10^5
  • 0B_i10910 \leq B\_i \leq 10^9-1
  • S=M|S|=M
  • S_iS\_i is either 'S' or 'B'.
  • All values in input are integers.

힌트

In first sample, A=(3,1,5)A=(3,1,5).

When k=2k=2, the party proceeds as follows:

  • You put 22 cookies of sweetness 33 and 11.
  • The child 11 puts the cookie of sweetness 44 and eats the cookie of sweetness 11.
  • The child 22 puts the cookie of sweetness 22 and eats the cookie of sweetness 44.
  • You eat cookies of sweetness 22 and 33.