#10. Distortion!!
Distortion!!
Problem Statement
You are given a string composed only of the characters 'd' and 'p'. You may perform at most one operation on the string:
- Select a subinterval of the string and perform a rotation on that interval.
The rotation operation consists of two steps:
- Reverse the characters within the interval: Swap and for all such that and .
- Invert the characters: Replace all
'd'characters with'p'and all'p'characters with'd'.
Your goal is to perform at most one such operation (or no operation at all) to obtain the lexicographically smallest possible string.
Lexicographical order: This is the natural ordering of strings, comparing characters one by one from left to right.
Input
The first line contains an integer , the length of the string .
The second line contains a string consisting only of characters 'd' and 'p'.
Output
Output a single string, representing the lexicographically smallest string that can be obtained by performing at most one operation.
Example
Input 1
6
dpdppd
Output 1
dddpdd
Input 2
3
ddd
Output 2
ddd
Input 3
11
ddpdpdppddp
Output 3
ddddpdpdddp
Explanation
- In Example 1, rotating the interval results in the lexicographically smallest string.
- If the original string is already in its smallest lexicographical form, you may choose to make no changes.
Constraints
相关
在下列比赛中: