#C13302. Can Form Substring

    ID: 42826 Type: Default 1000ms 256MiB

Can Form Substring

Can Form Substring

You are given two strings, S1 and S2. Your task is to determine whether S1 can be formed by concatenating several substrings (i.e. contiguous subsequences) of S2 in any order. Each substring of S2 can be used multiple times if needed.

In other words, you need to check if there exists a sequence of substrings \(s_1, s_2, \dots, s_k\) from S2 such that:

[ S1 = s_1 + s_2 + \cdots + s_k ]

Note:

  • If either S1 or S2 is empty, the answer is False.
  • If S1 contains characters not present in S2, then it is impossible to form S1 and the answer should be False.

Examples:

  • For S1 = "applebananaapple" and S2 = "bananapple", the answer is True.
  • For S1 = "applerapple" and S2 = "apple", the answer is False.
  • For S1 = "12345" and S2 = "54321", the answer is True.

inputFormat

The input is given via stdin and consists of two lines:

  1. The first line contains the string S1.
  2. The second line contains the string S2.

outputFormat

Print a single line to stdout containing either True or False, indicating whether S1 can be formed by concatenating substrings of S2 as described.

## sample
applebananaapple
bananapple
True