#C8536. Longest Ordered Substring

    ID: 52529 Type: Default 1000ms 256MiB

Longest Ordered Substring

Longest Ordered Substring

Given a string S, find the longest contiguous substring that meets the following criteria:

  • The substring is composed only of the characters a, b, c, d, and e.
  • The characters in the substring are in non-decreasing order. In other words, if the substring is \( s_1 s_2 \ldots s_k \), then \( s_i \leq s_{i+1} \) for all \( 1 \leq i < k \).

If there are multiple substrings with the maximum length, output the one that appears first in the string. If no valid substring exists, output an empty string.

Examples:

  • Input: abbebcddae → Output: abbe
  • Input: xyzabcde → Output: abcde
  • Input: (empty string) → Output:
  • Input: xyzfgh → Output:
  • Input: abcabcde → Output: abcde
  • Input: e → Output: e

inputFormat

The input consists of a single line containing the string S.

You should read the input from stdin.

outputFormat

Output the longest ordered substring as described. The output should be printed to stdout.

## sample
abbebcddae
abbe