아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

The Evil League of Evil

시간 제한1초메모리 제한1024 MB

요약
괄호와 '?'로 이루어진 문자열에서 '?'를 괄호로 바꿔 올바른 괄호 부분열의 최대 길이를 가장 크게 만든다.
난이도

보통10점 중 6점

유형
그리디, 문자열, 누적 합
정답자
아직 제출이 없습니다

문제

Bad Horse is recruiting to The Evil League of Evil! He used his hoof to write down a long string ss, consisting of letters "'texttt{(}", "'texttt{)}" and "?", and sent it to all applicants. Each person willing to join Evil League has to replace all characters "?" with either opening bracket or closing bracket. The invitation to join The Evil League of Evil will be send to the person who's resulting string contains the longest possible subsequence, that is correct bracket sequence.

Subsequence of the string ss is the string that can be obtained by removing some characters (possibly none) from ss. For example, strings "'texttt{abc}", "ac", "bcc" and "abbcc" are subsequences of "abbcc", while "cb" and "ba" are not. Note, that the empty string is a subsequence of any string.

The sequence of brackets is called correct if:

  1. it's empty;
  2. it's a correct sequence of brackets, enclosed in a pair of opening and closing brackets;
  3. it's a concatenation of two correct sequences of brackets.

For example, the sequences "()()" and "((()))()" are correct, while ")(()", "(((((" and "())" are not.

Dr. Horrible was dreaming of joining Evil League of Evil for year, but his pacifism blocks him from doing bad things. He is also bad in solving problems and asks you to deal with the Horse's puzzle.

입력

The only line of the input contains the string ss (1⩽∣s∣⩽10,000,0001 \leqslant |s| \leqslant 10\\,000\\,000).

It's guaranteed that ss consists of letters "(", ")" and "?" only.

출력

Print the solution to the Evil Horse's puzzle that guarantees Doctor Horrible will be invited to join The Evil League of Evil. That is, replace "?" with either "(" or ")", to maximize the length of maximum correct bracket subsequence of the string. If there are many optimal answers, you may print any of them.

힌트

In the first sample, the resulting string contains correct bracket subsequence of length 44: "()()".

In the second sample, the resulting string contains correct bracket subsequence of length 44: "(())".

예제2

  1. 예제 1

    입력
    ?)))?)
    
    예상 출력
    ()))()
    
  2. 예제 2

    입력
    )(???)(
    
    예상 출력
    )((())(