Polish version    English version  
  History of OI -> IX OI 2001/2002


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Rules
For contestants
Helpful resources
Stats
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
IX Olimpiada Informatyczna 2001/2002

Task: min
Author: Piotr Chrz±stowski-Wachtel, Wojciech Guzicki
Minuses

III stage contest  

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:
  • reads from the text file min.in the description of the given expression of the form x1 +/- x2 +/- ... +/- xn,
  • 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,
  • describes in the text file min.out this arrangement brackets.

Input

In the first line of the text file min.in 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.

Output

In the first line of the output text file min.out 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.

Example

For the following input file min.in:
7
-
-
+
+
-
+
a correct answer is in the following output file min.out:
((-)-(--))-(-)



Print friendly version