n = eval(input())

code = input().split()

# DP(N, <parentheses nested>)

a = int(code[0]); b = c = -10**18

for op, v in zip(code[1::2], list(map(int,code[2::2]))):

    if op is "+":

        d = max(b-v, c+v)

        a,b,c = max(a+v, d), d, c+v

    else:

        d = max(b+v, c-v)

        a,b,c = max(a-v, d), max(a-v, d), d

print(max(a, b, c))
n = eval(input())

code = input().split()

a = int(code[0]); b = c = -10**18

for op, v in zip(code[1::2], list(map(int,code[2::2]))):

    if op is "+":

        b = max(b-v, c+v)

        c += v

        a = max(a+v, b)

    else:

        c = max(b+v, c-v)

        a = b = max(a-v, c)

print(max(a, b, c))
n = eval(input())
code = input().split()
# DP(N, <parentheses nested>)
a = int(code[0])
b = c = -(10**18)
for op, v in zip(code[1::2], list(map(int, code[2::2]))):
    if op is "+":
        d = max(b - v, c + v)
        a, b, c = max(a + v, d), d, c + v
    else:
        d = max(b + v, c - v)
        a, b, c = max(a - v, d), max(a - v, d), d
print(max(a, b, c))

n = eval(input())
code = input().split()
a = int(code[0])
b = c = -(10**18)
for op, v in zip(code[1::2], list(map(int, code[2::2]))):
    if op is "+":
        b = max(b - v, c + v)
        c += v
        a = max(a + v, b)
    else:
        c = max(b + v, c - v)
        a = b = max(a - v, c)
print(max(a, b, c))

-# DP(N, <parentheses nested>) -        d = max(b - v, c + v) -        a, b, c = max(a + v, d), d, c + v +        b = max(b - v, c + v) +        c += v +        a = max(a + v, b) -        d = max(b + v, c - v) -        a, b, c = max(a - v, d), max(a - v, d), d +        c = max(b + v, c - v) +        a = b = max(a - v, c)