Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Justified Text

Limits 1s, 512 MB

Given a long string of text, you will have to print it following these rules:

  • Replace all consecutive spaces with a single space character.
  • No line should be longer than 9 characters (including the newline character at the end) and should contain as many words as possible.
  • You may start a newline only in between two words (replacing the space character between the words with a newline character).
  • No line should begin or end with any other space character. In case there is a non-newline space character at the beginning or ending of a line, remove it.
  • In case a word is longer than 8 characters, replace it with the word "#bigword".

Input

The input contains a long string consisting of lowercase alphabets, spaces (' '). A word in the input string will not be longer than 20 characters.

Output

Print the text following the rules.

Sample

InputOutput
january february march april may june july august september october november december
january
february
march
april
may june
july
august
#bigword
october
november
december

    Discussion

    Statistics


    17% Solution Ratio

    steinumEarliest, 3w ago

    steinumFastest, 0.0s

    steinumLightest, 0 B

    steinumShortest, 386B

    Submit

    Login to submit