import sys input = sys.stdin.readline Q = int(input()) stack = [] history = [] # store actions invalid = 0 # count of invalid conditions for _ in range(Q): query = input().split() if query[0] == '1': c = query[1] if c == '(': stack.append(False) history.append(('push',)) elif c == '|': if stack: prev = stack[-1] stack[-1] = True history.append(('bar', prev)) else: history.append(('bar_empty',)) else: # ')' if not stack: invalid += 1 history.append(('bad_close',)) else: has_bar = stack.pop() if not has_bar: invalid += 1 history.append(('pop', has_bar)) else: op = history.pop() if op[0] == 'push': stack.pop() elif op[0] == 'bar': stack[-1] = op[1] elif op[0] == 'bar_empty': pass elif op[0] == 'bad_close': invalid -= 1 elif op[0] == 'pop': has_bar = op[1] if not has_bar: invalid -= 1 stack.append(has_bar) # check validity if invalid == 0 and not stack: print("Yes") else: print("No")