SDE Path

Generate All Subsequences of a String

Medium

Generate All Subsequences of a String

Generate all possible subsequences (the power set) of a given array or string.

Input format

A single line containing a lowercase string (length ≤ 10).

Output format

Print every distinct non-empty subsequence on its own line, sorted lexicographically.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
abc
Expected output
a
ab
abc
ac
b
bc
c
Example 2
Input
aa
Expected output
a
aa