cswork / OAOpen practice workspace

AmazonOA #77

Get Time To Stabilize (Pipeline Service Outage)

Estimated MediumJudge-ready

Topics (AI-labelled)StringsDP Basics

Each second, based on the string at the start of that second, every failedService simultaneously deletes the character immediately to its left; the deleted character may itself be a failed service. Find the number of seconds that pass before the string stops changing.

Input

The first line is pipeline, and the second line is a single failedService character. Length 1..200000; this site uses lowercase letters.

Output

Output a single integer answer.

Example 1

Input:

database
a

Output:

2

Example 2

Input:

aaaa
a

Output:

1

Example 3

Input:

bbb
a

Output:

0

Example notes

Example 1: the three a are at indices 1, 3, 5; the leading segment has length 1 and the two gaps have length 2, so the answer is 2. Example 2: in the first second, the first three a are deleted simultaneously by their right neighbors, leaving only one, so the answer is 1. Example 3: there is no a and no deletion happens, so the answer is 0.

Editorial

Loading solution…