All problems

Problem 442

Interleaving String

Medium · 20 pts · String, Dynamic Programming

Problem

Decide whether string C can be formed by interleaving strings A and B: taking all characters of A and all characters of B, keeping the order of the characters within each string, and merging them into one sequence. For example, 'abc' and 'xy' can form 'axbyc' but not 'bacxy' (b would come before a). Let ok[i][j] mean that the first i characters of A and the first j of B can form the first i + j characters of C.

Input

Three lines: strings A, B and C (lowercase letters; A or B may be the single character '-' to mean an empty string).

Output

Print YES if C is an interleaving of A and B, otherwise NO.

Constraints

0 <= |A|, |B| <= 100; 0 <= |C| <= 200

Example input

aabcc
dbbca
aadbbcbcac

Example output

YES

Explanation

'aadbbcbcac' can be built from A = 'aabcc' and B = 'dbbca' by taking aa from A, dbbc from B, bc from A, a from B and c from A. So the answer is YES.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Perfect Squares Next: Longest String Chain