#K80487. Clean the Message

    ID: 35541 Type: Default 1000ms 256MiB

Clean the Message

Clean the Message

You are given a message as a string which may contain leading or trailing spaces as well as multiple consecutive spaces between words. Your task is to clean the message by:

  • Removing any leading and trailing whitespace.
  • Replacing any sequence of multiple spaces between words with a single space.

Formally, if the input string is \(s\), you need to output the string \(t\) defined as:

\[ t = \texttt{join}(\{w: w \in s.split()\}, \ " \" ) \]

For example, the message " Hello, this is a sample message! " should be transformed into "Hello, this is a sample message!".

inputFormat

The input consists of a single line containing the message string. This string may include leading or trailing spaces and multiple consecutive spaces between words.

outputFormat

Output a single line containing the cleaned message, where all extra spaces are reduced to a single space and there is no leading or trailing whitespace.

## sample
  Hello,   this   is a   sample   message!   
Hello, this is a sample message!