#C12430. Longest Substring with At Most Two Distinct Characters

    ID: 41857 Type: Default 1000ms 256MiB

Longest Substring with At Most Two Distinct Characters

Longest Substring with At Most Two Distinct Characters

You are given a string s. Your task is to find the longest contiguous substring of s that contains at most two distinct characters. In other words, if we denote by \( D \) the set of distinct characters in a substring, then the condition is \( |D| \leq 2 \).

If there are multiple substrings satisfying this property with the same maximum length, return the one that appears first. For example, given the input "eceba", the longest valid substring is "ece".

Note: The definition of a substring here is a contiguous sequence of characters from the original string.

inputFormat

The input consists of a single line containing the string s (which may be empty). The string can contain any visible ASCII characters.

outputFormat

Output the longest substring of s that contains at most two distinct characters. The output should be printed on a single line.

## sample
eceba
ece