#C3521. Lexicographically Smallest Binary String
Lexicographically Smallest Binary String
Lexicographically Smallest Binary String
Given a binary string \(S\) of length \(N\), you are allowed to repeatedly perform the following operations:
- Replace any occurrence of
00
with01
. - Replace any occurrence of
11
with10
.
The goal is to transform \(S\) into the lexicographically smallest string possible. The operations are applied in a single left-to-right pass during each iteration until no more applicable adjacent pairs remain. Note that the replacements are performed on the original string during each pass.
Example: For \(N=5\) and \(S=11000\), one valid transformation results in the string "10010".
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains an integer \(N\), the length of the binary string.
- The second line contains the binary string \(S\) of length \(N\), consisting only of characters '0' and '1'.
outputFormat
Print a single line to standard output (stdout) containing the lexicographically smallest binary string that can be obtained after applying the operations repeatedly.
## sample5
11000
10010
</p>