Missing Separators

시간 제한1초메모리 제한2048 MB

요약
이어 붙은 문자열을 서로 다른 단어가 사전순으로 나열되도록 최대 개수로 분할한다.
난이도

보통10점 중 7점

유형
문자열, 동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

You have a dictionary, which is a list of distinct words sorted in alphabetical order. Each word consists of uppercase English letters.

You want to print this dictionary. However, there is a bug with the printing system, and all words in the list are printed next to each other without any separators between words. Now, you ended up with a string SS that is a concatenation of all the words in the dictionary in the listed order.

Your task is to reconstruct the dictionary by splitting SS into one or more words. Note that the reconstructed dictionary must consist of distinct words sorted in alphabetical order. Furthermore, you want to maximize the number of words in the dictionary. If there are several possible dictionaries with the maximum number of words, you can choose any of them.

입력

A single line consisting of a string SS (1≤∣S∣≤50001 ≤ |S| ≤ 5000). String SS consists of only uppercase English letters.

출력

First, output an integer in a single line representing the maximum number of the words in the reconstructed dictionary. Denote this number as nn.

Then, output nn lines, each containing a single string representing the word. The words must be distinct, and the list must be sorted alphabetically. The concatenation of the words in the listed order must equal SS.

If there are several possible dictionaries with the maximum number of words, output any of them.

예제3

  1. 예제 1

    입력
    ABACUS
    
    예상 출력
    4
    A
    BA
    C
    US
    
  2. 예제 2

    입력
    AAAAAA
    
    예상 출력
    3
    A
    AA
    AAA
    
  3. 예제 3

    입력
    EDCBA
    
    예상 출력
    1
    EDCBA