{"problem":{"name":"Rotate Colored Subsequence","description":{"content":"You are given a string $S$ of length $N$ consisting of lowercase English letters. Each character of $S$ is painted in one of the $M$ colors: color $1$, color $2$, ..., color $M$; for each $i = 1, 2, \\","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc314_c"},"statements":[{"statement_type":"Markdown","content":"You are given a string $S$ of length $N$ consisting of lowercase English letters. Each character of $S$ is painted in one of the $M$ colors: color $1$, color $2$, ..., color $M$; for each $i = 1, 2, \\ldots, N$, the $i$\\-th character of $S$ is painted in color $C_i$.\nFor each $i = 1, 2, \\ldots, M$ in this order, let us perform the following operation.\n\n*   Perform a right circular shift by $1$ on the part of $S$ painted in color $i$. That is, if the $p_1$\\-th, $p_2$\\-th, $p_3$\\-th, $\\ldots$, $p_k$\\-th characters are painted in color $i$ from left to right, then simultaneously replace the $p_1$\\-th, $p_2$\\-th, $p_3$\\-th, $\\ldots$, $p_k$\\-th characters of $S$ with the $p_k$\\-th, $p_1$\\-th, $p_2$\\-th, $\\ldots$, $p_{k-1}$\\-th characters of $S$, respectively.\n\nPrint the final $S$ after the above operations.\nThe constraints guarantee that at least one character of $S$ is painted in each of the $M$ colors.\n\n## Constraints\n\n*   $1 \\leq M \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq C_i \\leq M$\n*   $N$, $M$, and $C_i$ are all integers.\n*   $S$ is a string of length $N$ consisting of lowercase English letters.\n*   For each integer $1 \\leq i \\leq M$, there is an integer $1 \\leq j \\leq N$ such that $C_j = i$.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $M$\n$S$\n$C_1$ $C_2$ $\\ldots$ $C_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc314_c","tags":[],"sample_group":[["8 3\napzbqrcs\n1 2 3 1 2 2 1 2","cszapqbr\n\nInitially, $S = $ `apzbqrcs`.\n\n*   For $i = 1$, perform a right circular shift by $1$ on the part of $S$ formed by the $1$\\-st, $4$\\-th, $7$\\-th characters, resulting in $S = $ `cpzaqrbs`.\n*   For $i = 2$, perform a right circular shift by $1$ on the part of $S$ formed by the $2$\\-nd, $5$\\-th, $6$\\-th, $8$\\-th characters, resulting in $S = $ `cszapqbr`.\n*   For $i = 3$, perform a right circular shift by $1$ on the part of $S$ formed by the $3$\\-rd character, resulting in $S = $ `cszapqbr` (here, $S$ is not changed).\n\nThus, you should print `cszapqbr`, the final $S$."],["2 1\naa\n1 1","aa"]],"created_at":"2026-03-03 11:01:14"}}