def kuohaopipei(str): a = 0 # 需要添加的右括号数 b = 0 # 需要添加的左括号数 for char in str: if char == '[': a += 1 elif char == ']': if a > 0: a -= 1 else: b += 1 result = '['*b + str +']'*a return result str = input().strip() print(kuohaopipei(str))