#include using namespace std; struct Node { int prev; // previous node index in persistent stack char st; // 0: before '|', 1: after '|' }; struct State { bool ok; int top; // top node index (0 = empty) }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int Q; cin >> Q; vector nodes; nodes.reserve(Q + 5); nodes.push_back({0, 0}); // dummy node at index 0 vector hist(Q + 5); int len = 0; hist[0] = {true, 0}; // empty string auto append_char = [&](State cur, char c) -> State { if (!cur.ok) return {false, cur.top}; if (c == '(') { nodes.push_back({cur.top, 0}); return {true, (int)nodes.size() - 1}; } if (c == '|') { if (cur.top == 0) return {false, cur.top}; int t = cur.top; if (nodes[t].st != 0) return {false, cur.top}; nodes.push_back({nodes[t].prev, 1}); // replace top with state=1 return {true, (int)nodes.size() - 1}; } if (c == ')') { if (cur.top == 0) return {false, cur.top}; int t = cur.top; if (nodes[t].st != 1) return {false, cur.top}; return {true, nodes[t].prev}; // pop } return {false, cur.top}; }; for (int qi = 0; qi < Q; qi++) { int t; cin >> t; if (t == 1) { char c; cin >> c; State nxt = append_char(hist[len], c); hist[++len] = nxt; } else { // guaranteed S is non-empty len--; } State cur = hist[len]; cout << ((cur.ok && cur.top == 0) ? "Yes" : "No") << '\n'; } return 0; }