op = 0
S = "()(())"
a = ""
for i in S:
    if i == '(' and op > 0:
        a += i
    elif i == ')' and op > 1:
        a += i
    op += 1 if i == '(' else -1
print(a)

06f14b4423bfd59e092263303e5423468bb7f26c
<mask token>

<mask token>
for i in S:
    if i == '(' and op > 0:
        a += i
    elif i == ')' and op > 1:
        a += i
    op += 1 if i == '(' else -1
print(a)

op = 0
S = '()(())'
a = ''
for i in S:
    if i == '(' and op > 0:
        a += i
    elif i == ')' and op > 1:
        a += i
    op += 1 if i == '(' else -1
print(a)

op = 0
S = "()(())"
a = ""
for i in S:
    if i == '(' and op > 0:
        a += i
    elif i == ')' and op > 1:
        a += i
    op += 1 if i == '(' else -1
print(a)
