LogiQuest

221. Palindrome Partitions

MediumBacktracking

Print every way to split the string into palindromic pieces, one partition per line with pieces separated by spaces, in lexicographic order of the piece lists.

Input format

A single line of lowercase letters.

Output format

All partitions.

Example 1

Input

aab

Output

a a b
aa b

Example 2

Input

a

Output

a

Constraints

1 ≤ length ≤ 12

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…