#C9362. Lexicographically Smallest String After One Substring Reversal

    ID: 53447 Type: Default 1000ms 256MiB

Lexicographically Smallest String After One Substring Reversal

Lexicographically Smallest String After One Substring Reversal

You are given a binary string S of length n. You are allowed to reverse exactly one contiguous substring (possibly of length 1, which leaves the string unchanged). Your task is to determine the lexicographically smallest string that can be obtained by performing such an operation.

Note: A binary string consists only of the characters '0' and '1'. The lexicographical order is defined in the usual way (i.e. '0' is considered smaller than '1').

Input Constraints: \( 1 \le n \le 10^5 \).

Explanation: Even if the given string is already in its lexicographically smallest form, you must still perform exactly one reversal. In that case, you may reverse a substring of length 1, leaving the string unchanged.

inputFormat

The input is read from standard input and consists of two lines:

  • The first line contains a single integer n, the length of the binary string.
  • The second line contains a binary string S of length n.

outputFormat

Print to standard output the lexicographically smallest string that can be obtained by reversing exactly one substring of the given binary string.

## sample
1
0
0