Intertwined Strings

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 512M

Author:
Problem type

Fael has two strings, S and T, and she wants to find all the possible results after she intertwines the strings. Intertwining two strings S and T is when all the characters of S and T are used to create a new string such that the order of the characters are preserved. For example, one possibility of intertwining ABC and DEF could be ABDECF.

Constraints

1 \le |S|, |T| \le 12

|X| denotes the length of string X.

Subtask 1 [10%]

1 \le |S|, |T| \le 2

Subtask 2 [90%]

No additional constraints.

Input Specification

The first line of input contains two space-separated strings, S and T.

Output Specification

Output every possible intertwined string on its own line. Order does not matter, but duplicates should not be printed.

Sample Input

AB CD

Sample Output

ABCD
ACBD
CABD
CADB
ACDB
CDAB

Comments