AtCoder Regular Contest 148
B
dp
AtCoder
⌀ 975
原题
← AC →
翻译中…

Problem Statement

翻译中…

For a string $T$ of length $L$ consisting of d and p, let $f(T)$ be $T$ rotated $180$ degrees. More formally, let $f(T)$ be the string that satisfies the following conditions.

翻译中…
  • $f(T)$ is a string of length $L$ consisting of d and p.
  • For every integer $i$ such that $1 \leq i \leq L$, the $i$-th character of $f(T)$ differs from the $(L + 1 - i)$-th character of $T$.
翻译中…

For instance, if $T =$ ddddd, $f(T) =$ ppppp; if $T =$ dpdppp, $f(T)=$ dddpdp.

翻译中…

You are given a string $S$ of length $N$ consisting of d and p. You may perform the following operation zero or one time.

翻译中…
  • Choose a pair of integers $(L, R)$ such that $1 \leq L \leq R \leq N$, and let $T$ be the substring formed by the $L$-th through $R$-th characters of $S$. Then, replace the $L$-th through $R$-th characters of $S$ with $f(T)$.
翻译中…

For instance, if $S=$ dpdpp and $(L,R)=(2,4)$, we have $T=$ pdp and $f(T)=$ dpd, so $S$ becomes ddpdp.

翻译中…

Print the lexicographically smallest string that $S$ can become.

翻译中…

What is lexicographical order? A string $S = S_1S_2\ldots S_{|S|}$ is said to be lexicographically smaller than a string $T = T_1T_2\ldots T_{|T|}$ if one of the following 1. and 2. holds. Here, $|S|$ and $|T|$ denote the lengths of $S$ and $T$, respectively. $|S| \lt |T|$ and $S_1S_2\ldots S_{|S|} = T_1T_2\ldots T_{|S|}$. There is an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ that satisfies the following two conditions: $S_1S_2\ldots S_{i-1} = T_1T_2\ldots T_{i-1}$. $S_i$ is smaller than $T_i$ in alphabetical order.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 5000$
  • $S$ is a string of length $N$ consisting of d and p.
  • $N$ is an integer.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
S

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
6
dpdppd
Output #1
dddpdd
Let $(L, R) = (2, 5)$. Then, we have $T =$ `pdpp` and $f(T) =$ `ddpd`, so $S$ becomes `dddpdd`. This is the lexicographically smallest string that can be obtained, so print it.
Input #2
3
ddd
Output #2
ddd
It may be optimal to skip the operation.
Input #3
11
ddpdpdppddp
Output #3
ddddpdpdddp
题目信息
题号
arc148_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。