QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#11491. Minuses

Statistics

Subtraction is not associative, e.g., $(5 - 2) - 1 = 2$, while $5 - (2 - 1) = 4$, and thus $(5 - 2) - 1 \neq 5 - (2 - 1)$. It follows that the value of an expression of the form $5 - 2 - 1$ depends on the order of subtractions. In the absence of parentheses, it is assumed that operations are performed from left to right, i.e., the expression $5 - 2 - 1$ means $(5 - 2) - 1$.

We are given an expression of the form $$x_1 \pm x_2 \pm \dots \pm x_n$$ where $\pm$ denotes either $+$ (plus) or $-$ (minus), and $x_1, x_2, \dots, x_n$ are distinct variables. We want to place parentheses in the expression of the form $$x_1 - x_2 - \dots - x_n$$ in such a way as to obtain an expression equivalent to the given one.

For example, to obtain an expression equivalent to $$x_1 - x_2 - x_3 + x_4 + x_5 - x_6 + x_7$$ we can place parentheses in $$x_1 - x_2 - x_3 - x_4 - x_5 - x_6 - x_7$$ for example, as follows: $$((x_1 - x_2) - (x_3 - x_4 - x_5)) - (x_6 - x_7)$$

Note: Parenthesizations where parentheses do not enclose any variable or enclose only a single variable are not allowed.

Task

Write a program that: reads the description of the given expression of the form $x_1 \pm x_2 \pm \dots \pm x_n$, determines how to insert parentheses into the expression $x_1 - x_2 - \dots - x_n$ to obtain an expression equivalent to the given one; you may insert at most $n - 1$ pairs of parentheses, * outputs this arrangement.

Input

The first line of standard input contains a single integer $n$, $2 \le n \le 1\,000\,000$. This is the number of variables in the given expression. Each of the next $n - 1$ lines contains a single character, $+$ or $-$. The $i$-th line contains the sign appearing in the given expression between $x_i$ and $x_{i+1}$.

Output

Your program should write to the first line of standard output the required way of inserting parentheses into the expression $x_1 - x_2 - \dots - x_n$. You must write only the parentheses and minus signs (without spaces between them), omitting the variables $x_1, x_2, \dots, x_n$. You may assume that a solution always exists for the test data. If there are multiple possible solutions, your program should output one of them.

Examples

Input 1

7
-
-
+
+
-
+

Output 1

((-)-(--))-(-)

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.