atcoder#ARC148B. [ARC148B] dp
[ARC148B] dp
Score : points
Problem Statement
For a string of length consisting of d
and p
, let be rotated degrees. More formally, let be the string that satisfies the following conditions.
- is a string of length consisting of
d
andp
. - For every integer such that , the -th character of differs from the -th character of .
For instance, if ddddd
, ppppp
; if dpdppp
, dddpdp
.
You are given a string of length consisting of d
and p
.
You may perform the following operation zero or one time.
- Choose a pair of integers such that , and let be the substring formed by the -th through -th characters of . Then, replace the -th through -th characters of with .
For instance, if dpdpp
and , we have pdp
and dpd
, so becomes ddpdp
.
Print the lexicographically smallest string that can become.
What is lexicographical order?
A string is said to be lexicographically smaller than a string if one of the following 1. and 2. holds. Here, and denote the lengths of and , respectively.
- and .
- There is an integer that satisfies the following two conditions:
- .
- is smaller than in alphabetical order.
Constraints
- is a string of length consisting of
d
andp
. - is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
6
dpdppd
dddpdd
Let . Then, we have pdpp
and ddpd
, so becomes dddpdd
.
This is the lexicographically smallest string that can be obtained, so print it.
3
ddd
ddd
It may be optimal to skip the operation.
11
ddpdpdppddp
ddddpdpdddp