#P9458. Lexicographically Smallest String After Reversal

    ID: 22609 Type: Default 1000ms 256MiB

Lexicographically Smallest String After Reversal

Lexicographically Smallest String After Reversal

You are given a binary string \(s\) consisting of characters '0' and '1'. You are allowed to select any non-empty substring of \(s\) and reverse it exactly once. Formally, you can choose an interval \([l, r]\) where \(1 \leq l \leq r \leq |s|\) and construct a new string \(t\) such that:

[ t_i = \begin{cases} s_i, & \text{if } i < l \text{ or } i > r, \ s_{r - (i - l)}, & \text{if } l \leq i \leq r. \end{cases} ]

Your task is to determine the lexicographically smallest string you can obtain by applying the reversal operation exactly once. Note that you can choose a substring of length \(1\) (which does not change the string).

inputFormat

The input consists of a single line containing the binary string \(s\).

Note: The length of \(s\) is at least 1.

outputFormat

Output the lexicographically smallest string \(t\) that can be obtained by applying the reversal operation exactly once.

sample

1010
0101