739. Word Segmentation

0

Medium

Given a string s and a dictionary of strings wordDict, determine if s can be segmented into a sequence of one or more dictionary words, separated by spaces. The same word from the dictionary can be used multiple times in the segmentation.

Input Format

The input consists of the following:
- An integer N representing the size of the wordDict dictionary.
- A line containing N space-separated words that are present in the wordDict dictionary.
- A line containing a string S.

Output Format

Print "True" if the string can be segmented into dictionary words, and "False" otherwise.

Example

Input

2 Coding Blocks CodingBlocks

Output

True

Constraints

1 <= N <= 300
1 <= wordDict.length <= 500
1 <= wordDict[i].length <= 20
Loading...

View Submissions

Console