using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("(ab)c");
//abbac
}
else if (InputPattern == "Input2") {
WillReturn.Add("past");
//past
}
else if (InputPattern == "Input3") {
WillReturn.Add("(d(abc)e)()");
//dabccbaeeabccbad
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
string S = InputList[0];
while (S.Contains('(')) {
int Sta, End;
DeriveStaEndPair(S, out Sta, out End);
string InStr = S.Substring(Sta, End - Sta + 1);
InStr = InStr.Replace("(", "").Replace(")", "");
InStr = InStr + new string(InStr.ToCharArray().Reverse().ToArray());
S = S.Remove(Sta, End - Sta + 1);
S = S.Insert(Sta, InStr);
}
Console.WriteLine(S);
}
// ネストしてない括弧のStaとEndを返す
static void DeriveStaEndPair(string pS, out int pSta, out int pEnd)
{
pSta = pEnd = -1;
var StaList = new List<int>();
var EndList = new List<int>();
for (int I = 0; I <= pS.Length - 1; I++) {
if (pS[I] == '(') StaList.Add(I);
if (pS[I] == ')') EndList.Add(I);
}
foreach (int EachInt in StaList) {
int Upper1 = ExecNibunhou_UpperBound(EachInt, StaList);
int Upper2 = ExecNibunhou_UpperBound(EachInt, EndList);
if (Upper1 > -1 && StaList[Upper1] < EndList[Upper2]) {
continue;
}
pSta = EachInt;
pEnd = EndList[Upper2];
return;
}
}
// 二分法で、Val超えで最小の値を持つ、添字を返す
static int ExecNibunhou_UpperBound(int pVal, List<int> pList)
{
// 最後の要素がVal以下の特殊ケース
if (pVal >= pList.Last()) {
return -1;
}
// 最初の要素がVal超えの特殊ケース
if (pVal < pList[0]) {
return 0;
}
int L = 0;
int R = pList.Count - 1;
while (L + 1 < R) {
int Mid = (L + R) / 2;
if (pList[Mid] > pVal) {
R = Mid;
}
else {
L = Mid;
}
}
return R;
}
}