{"problem":{"name":"String Formation","description":{"content":"Takahashi has a string $S$ consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of $Q$ operations. In","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc158_d"},"statements":[{"statement_type":"Markdown","content":"Takahashi has a string $S$ consisting of lowercase English letters.\nStarting with this string, he will produce a new one in the procedure given as follows.\nThe procedure consists of $Q$ operations. In Operation $i$ $(1 \\leq i \\leq Q)$, an integer $T_i$ is provided, which means the following:\n\n*   If $T_i = 1$: reverse the string $S$.\n    \n*   If $T_i = 2$: An integer $F_i$ and a lowercase English letter $C_i$ are additionally provided.\n    *   If $F_i = 1$ : Add $C_i$ to the beginning of the string $S$.\n    *   If $F_i = 2$ : Add $C_i$ to the end of the string $S$.\n\nHelp Takahashi by finding the final string that results from the procedure.\n\n## Constraints\n\n*   $1 \\leq |S| \\leq 10^5$\n*   $S$ consists of lowercase English letters.\n*   $1 \\leq Q \\leq 2 \\times 10^5$\n*   $T_i = 1$ or $2$.\n*   $F_i = 1$ or $2$, if provided.\n*   $C_i$ is a lowercase English letter, if provided.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$S$\n$Q$\n$Query_1$\n$:$\n$Query_Q$\n\nIn the $3$\\-rd through the $(Q+2)$\\-th lines, $Query_i$ is one of the following:\n\n$1$\n\nwhich means $T_i = 1$, and:\n\n$2$ $F_i$ $C_i$\n\nwhich means $T_i = 2$.\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc158_d","tags":[],"sample_group":[["a\n4\n2 1 p\n1\n2 2 c\n1","cpa\n\nThere will be $Q = 4$ operations. Initially, $S$ is `a`.\n\n*   Operation $1$: Add `p` at the beginning of $S$. $S$ becomes `pa`.\n    \n*   Operation $2$: Reverse $S$. $S$ becomes `ap`.\n    \n*   Operation $3$: Add `c` at the end of $S$. $S$ becomes `apc`.\n    \n*   Operation $4$: Reverse $S$. $S$ becomes `cpa`.\n    \n\nThus, the resulting string is `cpa`."],["a\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1","aabc\n\nThere will be $Q = 6$ operations. Initially, $S$ is `a`.\n\n*   Operation $1$: $S$ becomes `aa`.\n    \n*   Operation $2$: $S$ becomes `baa`.\n    \n*   Operation $3$: $S$ becomes `aab`.\n    \n*   Operation $4$: $S$ becomes `aabc`.\n    \n*   Operation $5$: $S$ becomes `cbaa`.\n    \n*   Operation $6$: $S$ becomes `aabc`.\n    \n\nThus, the resulting string is `aabc`."],["y\n1\n2 1 x","xy"]],"created_at":"2026-03-03 11:01:14"}}