import sys input = sys.stdin.readline def solve(): Q = int(input()) # Grammar: good = atom* # atom = "(" good "|" good ")" -- exactly one | per paren level # # State: top_good = is current trailing segment good? # stack = frames for open parens not yet closed # frame = (pipes_seen, accumulated_good, parent_top_good) # # S is good iff top_good=True and stack is empty top_good = True stack = [] history = [] # (prev_top_good, undo_type, undo_data) — one entry per char in S out = [] for _ in range(Q): query = input().split() if query[0] == '1': c = query[1] prev_top_good = top_good if c == '(': stack.append((0, True, top_good)) top_good = True history.append((prev_top_good, 'push', None)) elif c == '|': if not stack: top_good = False history.append((prev_top_good, 'none', None)) else: old_frame = stack[-1] p, acc, ptg = old_frame stack[-1] = (p+1, acc and top_good, ptg) top_good = True history.append((prev_top_good, 'modify', old_frame)) elif c == ')': if not stack: top_good = False history.append((prev_top_good, 'none', None)) else: old_frame = stack[-1] p, acc, ptg = stack.pop() if p != 1: top_good = False else: top_good = ptg and (acc and top_good) history.append((prev_top_good, 'pop', old_frame)) else: # query 2: delete last char of S prev_top_good, undo_type, undo_data = history.pop() if undo_type == 'push': stack.pop() elif undo_type == 'pop': stack.append(undo_data) elif undo_type == 'modify': stack[-1] = undo_data top_good = prev_top_good out.append('Yes' if (top_good and not stack) else 'No') sys.stdout.write('\n'.join(out) + '\n') solve()