#C2536. Smallest Lexicographical String After Deletion

    ID: 45863 Type: Default 1000ms 256MiB

Smallest Lexicographical String After Deletion

Smallest Lexicographical String After Deletion

You are given a string (s) consisting of lowercase English letters. Your task is to remove exactly one character from (s) so that the resulting string is the smallest possible in lexicographical order.

The lexicographical order is the natural order of characters based on their ASCII values. Formally, for two strings (a) and (b), we say (a < b) if at the first position where they differ, the character in (a) is smaller than the corresponding character in (b).

A simple greedy approach works as follows: Traverse the string and find the first index (i) such that (s[i] > s[i+1]). Remove (s[i]). If no such index exists, remove the last character.

Your output should be the modified string that is lexicographically the smallest after exactly one deletion.

Constraints:

  • The string \(s\) will contain at least 2 characters.
  • \(s\) contains only lowercase English letters.

inputFormat

The input is given via standard input (stdin) and consists of a single line containing the string (s).

outputFormat

Output the smallest lexicographical string obtained by deleting exactly one character from (s) to standard output (stdout).## sample

abc
ab