1362. Minuses

单点时限: 2.0 sec

内存限制: 256 MB

The operation of subtraction is not associative, e.g. (5-2)-1=2, but 5-(2-1)=4, therefore (5-2)-1<>5-(2-1). It implies that the value of the expression of the form 5-2-1 depends on the order of performing subtractions. In lack of brackets we assume that the operations are performed from left to right, i.e. the expression 5-2-1 denotes (5-2)-1. We are given an expression of the form

x1 +/- x2 +/- … +/- xn,

where each +/- denotes either + (plus) or - (minus), and x1,x2,…,xn denote (pairwise) distinct variables. In an expression of the form

x1-x2-…-xn

we want to insert brackets in such a way as to obtain an expression equivalent to the given one. For example, if we want to obtain an expression equivalent to the expression

x1-x2-x3+x4+x5-x6+x7

we may insert brackets into

x1-x2-x3-x4-x5-x6-x7

as follows:

((x1-x2)-(x3-x4-x5))-(x6-x7).

Note: Brackets that surround none or only one variable are not allowed.

Task

Write a program which:

1.reads the description of the given expression of the form x1 +/- x2 +/- … +/- xn,

2.determines the way brackets may be inserted into the expression x1-x2-…-xn so as to obtain an expression equivalent to the given one; at most n-1 pairs of brackets may be inserted,

3.describes this arrangement brackets.

输入格式

In the first line there is one integer n, 2<=n<=1 000 000. This is the number of variables in the given expression. In each of the following n-1 lines there is one character + or -. In the i-th line there is the sign appearing between xi-1 and xi in the given expression.

输出格式

In the first line your program should write the requested way of bracket insertion into the expression x1-x2-…-xn. Only brackets and minuses (without spaces between them) should be written, and the variables x1,x2,…,xn ought to be skipped. You may assume that for the test data there is always a solution. If there exist many possible solutions your program should write one of them.

样例

Input
7
Output
-
+
+
Input
+
Output
((-)-(--))-(-)

0 人解决,0 人已尝试。

0 份提交通过,共有 0 份提交。

9.9 EMB 奖励。

创建: 17 年,3 月前.

修改: 7 年,2 月前.

最后提交: N/A.

来源: POI

题目标签