cswork / OAOpen practice workspace

LinkedInOA #4

Find the Substring

Estimated EasyJudge-ready

Topics (AI-labelled)Strings

Find the first occurrence of the pattern in the text, where * stands for exactly one arbitrary character rather than a string of any length. Return −1 if there is none; indices start from 0.

Input

Two lines s and p. In the original, the text s is a..z, and the pattern p is a..z with at most one *; the original has no length bound, and this site uses 0≤length of each string≤200000. An empty pattern matches at 0.

Output

Output a single integer answer.

Example 1

Input:

abcabc
a*c

Output:

0

Example 2

Input:

aaaa
*b

Output:

-1

Example 3

Input:

abc

Output:

0

Example notes

The outputs of the three public examples are, in order: 0; -1; 0. Checked by independent enumeration or direct simulation.

Editorial

Loading solution…