LogiQuest

254. Wildcard Matching

HardDynamic Programming

? matches any single character and * matches any sequence (including empty). Print YES if the pattern matches the whole string, else NO.

Input format

Line 1: s Line 2: pattern

Output format

YES or NO

Example 1

Input

aa
a

Output

NO

Example 2

Input

aa
*

Output

YES

Constraints

1 ≤ |s|, |p| ≤ 2000

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…