#ARC066C. [ARC066E] Addition and Subtraction Hard

[ARC066E] Addition and Subtraction Hard

Score : 900900 points

Problem Statement

Joisino has a formula consisting of NN terms: A1A_1 op1op_1 A2A_2 ...... opN1op_{N-1} ANA_N. Here, AiA_i is an integer, and opiop_i is an binary operator either + or -. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) into the formula. Opening parentheses can only be inserted immediately before an integer, and closing parentheses can only be inserted immediately after an integer. It is allowed to insert any number of parentheses at a position. Your task is to write a program to find the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • opiop_i is either + or -.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 op1op_1 A2A_2 ...... opN1op_{N-1} ANA_N

Output

Print the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses.

3
5 - 1 - 3
7

The maximum possible value is: 5(13)=75 - (1 - 3) = 7.

5
1 - 2 + 3 - 4 + 5
5

The maximum possible value is: 1(2+34)+5=51 - (2 + 3 - 4) + 5 = 5.

5
1 - 20 - 13 + 14 - 5
13

The maximum possible value is: 1(20(13+14)5)=131 - (20 - (13 + 14) - 5) = 13.