{"problem":{"name":"Notebook","description":{"content":"We have an integer sequence $A$ and a notebook. The notebook has $10^9$ pages. You are given $Q$ queries. Each query is of one of the following four kinds: ADD $x$: append an integer $x$ to the tail ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc273_e"},"statements":[{"statement_type":"Markdown","content":"We have an integer sequence $A$ and a notebook. The notebook has $10^9$ pages.\nYou are given $Q$ queries. Each query is of one of the following four kinds:\n\nADD $x$: append an integer $x$ to the tail of $A$.\n\nDELETE: remove the last term of $A$ if $A$ is not empty; do nothing otherwise.\n\nSAVE $y$: erase the sequence recorded on the $y$\\-th page of the notebook, and record the current $A$ onto the $y$\\-th page.\n\nLOAD $z$: replace $A$ with the sequence recorded on the $z$\\-th page of the notebook.\n\nInitially, $A$ is an empty sequence, and an empty sequence is recorded on each page of the notebook. Process $Q$ queries successively in the given order and print the last term of $A$ after processing each query.\nThe use of fast input and output methods is recommended because of potentially large input and output.\n\n## Constraints\n\n*   $1 \\leq Q \\leq 5 \\times 10^5$\n*   $1 \\leq x, y, z \\leq 10^9$\n*   $Q$, $x$, $y$, and $z$ are integers.\n*   Each of the given queries is of one of the four kinds in the Problem Statement.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$Q$\n$\\mathrm{query}_1$\n$\\mathrm{query}_2$\n$\\vdots$\n$\\mathrm{query}_Q$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc273_e","tags":[],"sample_group":[["11\nADD 3\nSAVE 1\nADD 4\nSAVE 2\nLOAD 1\nDELETE\nDELETE\nLOAD 2\nSAVE 1\nLOAD 3\nLOAD 1","3 3 4 4 3 -1 -1 4 4 -1 4\n\nInitially, $A$ is an empty sequence, so $A = ()$, and an empty sequence is recorded on each page of the notebook.\n\n*   By the $1$\\-st query, $3$ is appended to the tail of $A$, resulting in $A = (3)$.\n*   By the $2$\\-nd query, the sequence recorded on the $1$\\-st page of the notebook becomes $(3)$. It remains that $A = (3)$.\n*   By the $3$\\-rd query, $4$ is appended to the tail of $A$, resulting in $A = (3, 4)$.\n*   By the $4$\\-th query, the sequence recorded on the $2$\\-nd page of the notebook becomes $(3, 4)$. It remains that $A = (3, 4)$.\n*   By the $5$\\-th query, $A$ is replaced by $(3)$, which is recorded on the $1$\\-st page of the notebook, resulting in $A = (3)$.\n*   By the $6$\\-th query, the last term of $A$ is removed, resulting in $A = ()$.\n*   By the $7$\\-th query, nothing happens because $A$ is already empty. It remains that $A = ()$.\n*   By the $8$\\-th query, $A$ is replaced by $(3,4)$, which is recorded on the $2$\\-nd page of the notebook, resulting in $A = (3, 4)$.\n*   By the $9$\\-th query, the sequence recorded on the $1$\\-st page of the notebook becomes $(3, 4)$. It remains that $A = (3, 4)$.\n*   By the $10$\\-th query, $A$ is replaced by $()$, which is recorded on the $3$\\-rd page of the notebook, resulting in $A = ()$.\n*   By the $11$\\-th query, $A$ is replaced by $(3, 4)$, which is recorded on the $1$\\-st page of the notebook, resulting in $A = (3, 4)$."],["21\nADD 4\nADD 3\nDELETE\nADD 10\nLOAD 7\nSAVE 5\nSAVE 5\nADD 4\nADD 4\nADD 5\nSAVE 5\nADD 2\nDELETE\nADD 1\nSAVE 5\nADD 7\nADD 8\nDELETE\nADD 4\nDELETE\nLOAD 5","4 3 4 10 -1 -1 -1 4 4 5 5 2 5 1 1 7 8 7 4 7 1"]],"created_at":"2026-03-03 11:01:14"}}