Sum or subtract numbers from an input list

Given a list of nn integers v0,,vn1v_0,\ldots,v_{n-1}, and a string ss of length nn and with characters ’+’ and ’-’, we need to print the result of summing or subtracting each viv_i depending on whether the ii’th character of ss is ’+’ or ’-’.

Input

The input begins with a positive natural number nn on a first line. On a second line there are nn integers v0,,vnv_0,\ldots,v_n. Afterwards, there’s a sequence of lines, each with a string ss of length nn and characters ’+’ or ’-’.

Output

For each string ss, the program has to print (i{0n1}s[i]=+vi)(i{0n1}s[i]=vi)(\sum_{i\in\{0\ldots n-1\}\wedge s[i]='+'}v_i)\;-\;(\sum_{i\in\{0\ldots n-1\}\wedge s[i]='-'}v_i)

Problem information

Author: PRO1

Generation: 2026-01-25T15:18:25.246Z

© Jutge.org, 2006–2026.
https://jutge.org