P10058 Reverse and Rotate

Description

Given a string $S$ and $n$ operations, each operation is one of the following three types: 1. `< x` means cyclically shift $S$ to the left by $x$ positions. For example, $\mathtt{abcde}$ becomes $\mathtt{cdeab}$ after `< 2`. 2. `> x` means cyclically shift $S$ to the right by $x$ positions. For example, $\mathtt{abcde}$ becomes $\mathtt{deabc}$ after `> 2`. 3. `rev` means reverse $S$. For example, $\mathtt{abcde}$ becomes $\mathtt{edcba}$ after `rev`. Find the string $S'$ obtained after performing these $n$ operations **in order**. Note: For $S=s_0s_1\cdots s_{k-1}$, cyclically shifting it left by $x$ positions becomes $s_{-x}S_{-x+1}\cdots S_{-x+k-1}$; cyclically shifting it right by $x$ positions becomes $s_{x}S_{x+1}\cdots S_{x+k-1}$. For $x\equiv y\pmod k$, we have $s_x=s_y$.

Input Format

The first line contains a string $S$. The second line contains an integer $n$. The next $n$ lines each contain one operation.

Output Format

Output one line containing a string $S'$, which is the string obtained after performing the $n$ operations **in order**.

Explanation/Hint

**[Sample 1 Explanation]** - The original string is $\mathtt{abcde}$. - After the first operation, the string becomes $\mathtt{deabc}$. - After the second operation, the string becomes $\mathtt{cbaed}$. - After the third operation, the string becomes $\mathtt{aedcb}$. **[Constraints]** Let $|S|$ denote the length of string $S$. | Test Point ID | Special Property | | :----------: | :----------: | | $1\sim3$ | $\vert S\vert,n,x \le 1000$ | | $4$ | There is no `rev` operation. | | $5$ | $S=\mathtt{aa...abb...b}$ | | $6\sim10$ | None. | For $100\%$ of the testdata, $1 \le |S|,n \le 10^6$, $0 \le x \le 10^9$, and $S$ consists only of lowercase letters. Translated by ChatGPT 5