- Time limit: 0.10 s
- Memory limit: 256 MB
We define a valid bracket sequence as a string that is either:
- The empty string;
- A string
(B)
, whereB
is a valid bracket sequence. LR
, the concatenation of two stringsL
andR
which are both valid bracket sequences.
Let be a valid bracket sequence of length . We define to be the -th character of the sequence . For two indices and , , we say that and are matching brackets if:
- and ;
- , or the subsequence is a valid bracket sequence.
Let be a string of lowercase English letters. We define to be the -th character of string . We say that a valid bracket sequence matches if:
- has the same length as ;
- for any pair of indices and , , if and are matching brackets, then .
We say that a bracket sequence is lexicographically smaller than a bracket sequence if there is an index , , such that for each , and . Character ''(''
is considered lexicographically smaller than character '')''
.
For a given string consisting of lowercase letters, find the lexicographically smallest valid bracket seuqnece that matches , or print -1
if no such bracket sequence exists.
Input
The input consists of a string of lowercase letters on one line.
Output
Output either a string with characters that represents the lexicographically smallest bracket sequence that matches the input string, or -1
if no such bracket sequence exists.
Constraints
Example 1
Input:
abbaaa
Output:
(()())
Example 2
Input:
abab
Output:
-1