The only difference between easy and hard versions is the length of the string.

You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.

If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).

Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.


-----Input-----

The first line of the input contains one string $s$ consisting of at least $1$ and at most $200$ lowercase Latin letters.

The second line of the input contains one string $t$ consisting of at least $1$ and at most $200$ lowercase Latin letters.

It is guaranteed that $t$ is a subsequence of $s$.


-----Output-----

Print one integer — the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.


-----Examples-----
Input
bbaba
bb

Output
3

Input
baaba
ab

Output
2

Input
abcde
abcde

Output
0

Input
asdfasdf
fasd

Output
3

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation

Greedy algorithms


Solutions:
s = input()
t = input()
ans = 0
for i in range(len(s)):
	for j in range(i + 1, len(s) + 1):
		news = s[:i] + s[j:]
		count = 0
		f = 0
		for k in range(len(news)):
			if count >= len(t):
				f = 1
				break
			if news[k] == t[count]:
				count += 1
		if f == 1 or count == len(t):
			ans = max(ans, j - i)
print(ans)


s = input()
n = len(s)
t = input()
m = len(t)
rg = [0] * m
j = m - 1
for i in range(n):
	if s[n - 1 - i] == t[j]:
		rg[j] = n - 1 - i
		if j == 0:
			break
		j -= 1
lg = [0] * m
j = 0
for i in range(n):
	if s[i] == t[j]:
		lg[j] = i
		if j == m - 1:
			break
		j += 1
mx = max(rg[0], n - 1 - lg[-1])
for j in range(1, m):
	mx = max(mx, rg[j] - lg[j - 1] - 1)
print(mx)


s = input()
t = input()
r = [0] * len(t)
for i in range(len(t) - 1, -1, -1):
	p = len(s) - 1
	if i + 1 < len(t):
		p = r[i + 1] - 1
	while t[i] != s[p]:
		p -= 1
	r[i] = p
ans = p = 0
for i in range(len(s)):
	rp = len(s) - 1
	if p < len(t):
		rp = r[p] - 1
	ans = max(rp - i + 1, ans)
	if p < len(t) and t[p] == s[i]:
		p += 1
print(ans)


def f(s1, s2):
	find_num = 0
	find = s2[0]
	i = 0
	while find_num < len(s2):
		while i < len(s1) and s1[i] != find:
			i += 1
		if i == len(s1):
			return False
		find_num += 1
		if find_num != len(s2):
			find = s2[find_num]
		i += 1
	return True
s1 = input()
s2 = input()
flag = False
for length in range(len(s1) - len(s2), -1, -1):
	if flag:
		break
	for i in range(len(s1) - length + 1):
		s3 = s1[:i] + s1[i + length:]
		if f(s3, s2):
			print(length)
			flag = True
			break


str1 = input()
str2 = input()
(n, m) = (len(str1), len(str2))
(pos, i) = ([], 0)
for p in range(n):
	if i == m:
		break
	if str1[p] == str2[i]:
		pos.append(p)
		i += 1
pos = [-1] + pos + [n]
ans = 0
for i in range(1, m + 2):
	ans = max(ans, pos[i] - pos[i - 1] - 1)
i = 0
for p in range(n - 1, -1, -1):
	if i == m:
		break
	if str1[p] == str2[m - i - 1]:
		ans = max(ans, p - pos[m - i - 1] - 1)
		i += 1
print(ans)


from math import *

def nextInt():
	return int(input())

def nextInts():
	return list(map(int, input().split()))

def need(s, t):
	cur = 0
	res = [cur]
	for c in t:
		while s[cur] != c:
			cur += 1
		cur += 1
		res.append(cur)
	return res

def solve():
	s = input()
	t = input()
	x = need(s, t)
	s = ''.join(reversed(s))
	t = t[::-1]
	y = need(s, t)
	ans = 1000000000.0
	for i in range(len(x)):
		ans = min(ans, x[i] + y[len(x) - 1 - i])
	return len(s) - ans
print(solve())


import sys
input = sys.stdin.readline
s = input().strip()
t = input().strip()
(n, m) = (len(s), len(t))

def match(s, t, i, j):
	r = 0
	for x in range(len(s)):
		if i <= x <= j:
			continue
		if r < len(t) and s[x] == t[r]:
			r += 1
		if r == len(t):
			return True
	return False
ans = 0
for i in range(n):
	for j in range(i, n):
		if match(s, t, i, j):
			ans = max(ans, j - i + 1)
print(ans)


from sys import stdin
input = stdin.readline
s = input()
t = input()
n = len(t)
low = [0 for i in range(len(t))]
high = [0 for i in range(len(t))]
acc = 0
for i in range(n):
	acc_t = t[i]
	while acc_t != s[acc]:
		acc += 1
	low[i] = acc
	acc += 1
acc = len(s) - 1
for i in range(len(t)):
	acc_t = t[n - i - 1]
	while acc_t != s[acc]:
		acc -= 1
	high[n - i - 1] = acc
	acc -= 1
res = max(high[0], len(s) - low[n - 1] - 1)
for i in range(n - 1):
	res = max(res, high[i + 1] - low[i] - 1)
print(res)


firstStr = input()
secondStr = input()
substrLowerStarts = []
index = 0
for i in range(len(firstStr)):
	if index == len(secondStr):
		break
	if secondStr[index] == firstStr[i]:
		substrLowerStarts.append(i)
		index += 1
substrHigherStarts = []
index = len(secondStr) - 1
i = len(firstStr) - 1
while i > -1:
	if index == -1:
		break
	if secondStr[index] == firstStr[i]:
		substrHigherStarts.append(i)
		index -= 1
	i -= 1
firstPointer = 0
secondPointer = len(substrHigherStarts) - 2
maxDeletionLength = max(len(firstStr) - substrLowerStarts[len(substrLowerStarts) - 1] - 1, substrHigherStarts[len(substrHigherStarts) - 1])
while firstPointer < len(substrLowerStarts) - 1:
	maxDeletionLength = max(maxDeletionLength, abs(substrLowerStarts[firstPointer] - substrHigherStarts[secondPointer]) - 1)
	firstPointer += 1
	secondPointer -= 1
print(maxDeletionLength)


s = input()
t = input()
ls = len(s)
lt = len(t)
m = 0
for i in range(ls):
	for j in range(i, ls):
		p = 0
		for k in range(i):
			if p == lt:
				break
			if s[k] == t[p]:
				p = p + 1
		for k in range(j + 1, ls):
			if p == lt:
				break
			if s[k] == t[p]:
				p = p + 1
		if p == lt:
			m = max(m, j - i + 1)
print(m)


s = str(input())
t = str(input())
s = list(s)
t = list(t)
n = len(s)
ans = -1
for i in range(n):
	for j in range(i, n + 1):
		temp = s[0:i] + s[j:]
		id = 0
		for k in range(len(temp)):
			if temp[k] == t[id]:
				id += 1
			if id == len(t):
				ans = max(ans, j - i)
				break
print(ans)


s = input()
t = input()

def subseq(s, t):
	start = 0
	find = True
	for k in range(len(t)):
		if s[start:len(s)].find(t[k:k + 1]) == -1:
			find = False
		else:
			start += s[start:len(s)].find(t[k:k + 1]) + 1
	return find
ans = 0
found = False
i = len(s) - len(t)
while not found and i >= 0:
	for j in range(0, len(s) - i + 1):
		if subseq(s[0:j] + s[i + j:len(s)], t):
			ans = i
			found = True
	i -= 1
print(ans)


s = input().strip()
t = input().strip()

def check_sub(s, t):
	stop = 0
	cnt = 0
	for i in range(len(t)):
		for j in range(stop, len(s)):
			if t[i] == s[j]:
				stop = j + 1
				cnt += 1
				break
	if cnt != len(t):
		return False
	return True
index = 1
ans = 0
while index <= len(s):
	log = []
	for i in range(len(s)):
		if i + index > len(s):
			break
		if len(s) - index < len(t):
			break
		log.append(check_sub(s[:i] + s[i + index:], t))
	if any(log):
		ans = index
	else:
		break
	index += 1
print(ans)


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
(a, b) = (input(), input())
(a, b) = (b, a)
mx = 0
for i in range(0, len(b)):
	for j in range(i, len(b)):
		if isSubSequence(a, b[:i] + b[j + 1:], len(a), len(b[:i] + b[j + 1:])):
			mx = max(mx, j - i + 1)
print(mx)


def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
s = input()
t = input()
LengthT = len(t)
A = []
for i in range(len(s)):
	for j in range(i + 1, len(s) + 1):
		p = s[:i] + s[j:]
		if isSubSequence(t, p, LengthT, len(p)):
			A.append(j - i)
try:
	print(max(A))
except:
	print(0)


s = input()
t = input()

def check(s):
	ans = 0
	for i in s:
		if ans == len(t):
			break
		if i == t[ans]:
			ans += 1
	return ans == len(t)
ans = 0
for i in range(len(s)):
	for j in range(i + 1, len(s) + 1):
		if check(s[:i] + s[j:]):
			ans = max(j - i, ans)
print(ans)


def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
s = list(input())
t = input()
ans = 0
for i in range(len(s)):
	for j in range(i, len(s) + 1):
		a = ''.join(s[:i]) + ''.join(s[j:])
		if isSubSequence(t, a, len(t), len(a)):
			ans = max(ans, j - i)
print(ans)


big = input()
small = input()
left = [0] * (len(small) + 1)
left[0] = -1
wsk = -1
for i in range(1, len(small) + 1):
	while True:
		wsk += 1
		if big[wsk] == small[i - 1]:
			left[i] = wsk
			break
big = big[::-1]
small = small[::-1]
right = [0] * (len(small) + 1)
right[0] = -1
wsk = -1
for i in range(1, len(small) + 1):
	while True:
		wsk += 1
		if big[wsk] == small[i - 1]:
			right[i] = wsk
			break
wyn = 100000000
for i in range(len(left)):
	wyn = min(wyn, right[i] + left[len(left) - 1 - i] + 2)
print(len(big) - wyn)


def ud(s, t):
	p = 100000000000
	max3 = -10
	for k in range(0, len(t) + 1):
		st = 0
		m = 0
		while st < k:
			if s[m] == t[st]:
				st += 1
			m += 1
		max1 = m
		g = len(t) - k
		if m + g > p:
			continue
		st1 = len(t) - 1
		m = len(s) - 1
		while st1 >= k:
			if t[st1] == s[m]:
				st1 -= 1
			m -= 1
		max2 = m
		max3 = max(max3, max2 - max1 + 1)
		p = len(s) - max3
	return max3
s = input()
t = input()
if len(s) > 10 ** 3:
	print(len(s))
k = len(s) - len(t)
l = 0
r = k + 1
f = ud(s, t)
print(f)


from sys import stdin, stdout
import math
from math import gcd, sqrt

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
s1 = input()
N = len(s1)
s2 = input()
res = 0
for i in range(N):
	for j in range(i, N):
		s = s1[:i] + s1[j + 1:]
		if isSubSequence(s2, s, len(s2), len(s)):
			res = max(res, j - i + 1)
print(res)


import sys
s = sys.stdin.readline()
t = sys.stdin.readline()
(sn, tn) = (len(s), len(t))
(left, right) = ([0] * tn, [0] * tn)
(prev, last) = (-1, sn)
for i in range(tn):
	left[i] = prev = s.find(t[i], prev + 1)
	right[tn - i - 1] = last = s.rfind(t[tn - i - 1], 0, last)
ans = max(right[0], sn - left[-1] - 1)
res = max((right[i + 1] - left[i] - 1 for i in range(tn - 1)))
print(max(ans, res))


from sys import stdin, stdout
input = stdin.readline
(s, t) = list(map(str, stdin.read().split()))
(n, m) = (len(s), len(t))
a = [0] * m
b = [0] * m
pos = 0
for i in range(n):
	if s[i] == t[pos]:
		a[pos] = i
		pos += 1
		if pos == m:
			break
pos = m - 1
for i in range(n - 1, -1, -1):
	if s[i] == t[pos]:
		b[pos] = i
		pos -= 1
		if pos == -1:
			break
res = max(b[0], n - (a[-1] + 1))
for i in range(m - 1):
	res = max(res, b[i + 1] - 1 - (a[i] + 1) + 1)
print(res)


s = input()
t = input()
(f, b) = ([], [])
cur = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == t[cur]:
		b.append(i)
		cur -= 1
	if cur == -1:
		break
b.sort()
cur = 0
for i in range(len(s)):
	if s[i] == t[cur]:
		f.append(i)
		cur += 1
	if cur == len(t):
		break
ans = max(b[0], len(s) - f[-1] - 1)
bbb = 0
bbb ^= 1
bbb += 1
for i in range(len(f) - 1):
	ans = max(ans, abs(b[i + 1] - 1 - f[i]))
print(ans)


def cal(t, s):
	i = 0
	j = 0
	l = len(t)
	l1 = len(s)
	while i < l and j < l1:
		if t[i] == s[j]:
			i += 1
		j += 1
	if i == l:
		return 1
		return 0
s = input()
t = input()
M = -100000000000.0
for i in range(len(s)):
	for j in range(i, len(s)):
		if cal(t, s[:i] + s[j + 1:]):
			M = max(M, j - i + 1)
print(M if M != -100000000000.0 else 0)


from sys import stdin
s = stdin.readline().strip()
s1 = stdin.readline().strip()
dp = [-1 for i in range(len(s1) + 1)]
dp1 = [-1 for i in range(len(s1) + 1)]
x = 0
for i in range(len(s)):
	if s[i] == s1[x]:
		dp[x + 1] = i
		x += 1
		if x >= len(s1):
			break
x = len(s1) - 1
y = 1
dp[0] = -1
dp1[0] = len(s)
for i in range(len(s) - 1, -1, -1):
	if s[i] == s1[x]:
		dp1[y] = i
		x -= 1
		y += 1
		if x < 0:
			break
ans = 0
for i in range(len(s1) + 1):
	ans = max(dp1[len(s1) - i] - dp[i] - 1, ans)
	ans = max(dp[len(s1) - i] - dp1[i] - 1, ans)
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	s = list(inp())
	t = list(inp())
	left = [0] * len(s)
	j = 0
	for i in range(0, len(s)):
		if j >= len(t):
			left[i] = left[i - 1]
			continue
		if s[i] == t[j]:
			j += 1
			if i == 0:
				left[i] = 1
				continue
			left[i] = left[i - 1] + 1
		else:
			if i == 0:
				continue
			left[i] = left[i - 1]
	right = [0] * len(s)
	j = len(t) - 1
	for i in range(len(s) - 1, -1, -1):
		if j < 0:
			right[i] = right[i + 1]
			continue
		if t[j] == s[i]:
			j -= 1
			if i == len(s) - 1:
				right[i] = 1
				continue
			right[i] = right[i + 1] + 1
		else:
			if i == len(s) - 1:
				continue
			right[i] = right[i + 1]
	ans = 0
	for i in range(0, len(s)):
		if left[i] == len(t):
			ans = max(ans, len(s) - (i + 1))
			break
	for i in range(len(s) - 1, -1, -1):
		if right[i] == len(t):
			ans = max(ans, i)
			break
	right = right[::-1]
	for i in range(0, len(s) - 1):
		ind = bl(right, len(t) - left[i])
		ind = len(right) - ind - 1
		if ind >= i + 2:
			ans = max(ans, ind - i - 1)
	print(ans)
testcase(1)


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)
(t, s) = (input(), input())
dp1 = [-1 for i in range(len(s))]
dp2 = [-1 for i in range(len(s))]
j = 0
for i in range(len(s)):
	while t[j] != s[i]:
		j += 1
	dp1[i] = j
	j += 1
j = len(t) - 1
for i in reversed(range(len(s))):
	while t[j] != s[i]:
		j -= 1
	dp2[i] = j
	j -= 1
ans = max(dp1[0], len(t) - dp1[-1] - 1, dp2[0], len(t) - dp2[-1] - 1)
for i in range(1, len(s)):
	ans = max(ans, dp2[i] - dp1[i - 1] - 1)
print(ans)


s = input()
t = input()
n = len(t)
b = [0] * (len(s) + 1)
a = [0] * (len(s) + 1)
c = 0
for i in range(len(s)):
	if c == n:
		b[i + 1] = c
	elif s[i] == t[c]:
		c += 1
		b[i + 1] = c
	else:
		b[i + 1] = c
c = n - 1
for i in range(len(s) - 1, -1, -1):
	if c == -1:
		a[i] = n
	elif s[i] == t[c]:
		c -= 1
		a[i] = n - c - 1
	else:
		a[i] = n - c - 1
st = 1
e = 1
m = 0
a = [0] + a
b.append(0)
while e < len(s):
	if b[st - 1] + a[e + 1] >= len(t):
		m = max(m, e - st + 1)
		e += 1
	else:
		st += 1
	if st > e:
		e += 1
if b[st - 1] + a[e + 1] >= len(t):
	m = max(m, e - st + 1)
else:
	while st <= len(s):
		if b[st - 1] + a[e + 1] >= len(t):
			m = max(m, e - st + 1)
			break
		st += 1
print(m)


from sys import stdin, stdout, setrecursionlimit
s = input()
t = input()
n = len(s)
ans = 0

def hah(string):
	cou = 0
	for x in string:
		if x == t[cou]:
			cou += 1
		if cou == len(t):
			return True
	return False
for i in range(n):
	for j in range(i, n + 1):
		cur = s[:i] + s[j:]
		if hah(cur):
			ans = max(ans, n - len(cur))
print(ans)


from sys import stdin, stdout
s = stdin.readline().strip()
t = stdin.readline().strip()
leftmost = [-1]
ptr1 = ptr2 = 0
while ptr2 < len(t):
	if s[ptr1] == t[ptr2]:
		leftmost.append(ptr1)
		ptr1 += 1
		ptr2 += 1
	else:
		ptr1 += 1
rightmost = []
ptr1 = len(s) - 1
ptr2 = len(t) - 1
while ptr2 >= 0:
	if s[ptr1] == t[ptr2]:
		rightmost.append(ptr1)
		ptr1 -= 1
		ptr2 -= 1
	else:
		ptr1 -= 1
rightmost.reverse()
rightmost.append(len(s))
ans = -1
for i in range(len(leftmost)):
	ans = max(ans, rightmost[i] - leftmost[i] - 1)
stdout.write(str(ans) + '\n')


import sys
from collections import Counter
import math
input = sys.stdin.readline
s = input()[:-1]
t = input()[:-1]
m = 0
for j in range(-1, len(t)):
	p_s = -1
	p_t = 0
	while p_t <= j:
		temp = t[p_t]
		i = p_s + 1
		while s[i] != temp:
			i += 1
		p_s = i
		p_t += 1
	left = p_s
	p_s = len(s)
	p_t = len(t) - 1
	while p_t > j:
		temp = t[p_t]
		i = p_s - 1
		while s[i] != temp:
			i -= 1
		p_s = i
		p_t -= 1
	right = p_s
	m = max(m, right - left - 1)
print(m)


s = input()
t = input()

def check(x, y):
	p = 0
	q = 0
	while p < len(x) and q < len(y):
		if x[p] == y[q]:
			q += 1
		p += 1
	if q == len(y):
		return True
	return False
ans = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		x = ''
		x += s[:i]
		if j != len(s) - 1:
			x += s[j + 1:]
		if check(x, t):
			ans = max(ans, j - i + 1)
print(ans)


s = input()
t = input()
(n, m) = (len(s), len(t))
ans = 0
max_pos = [-1 for i in range(m)]
max_pos.append(n)
j = m - 1
for i in range(n - 1, -1, -1):
	if j < 0:
		ans = max(ans, i + 1)
		break
	if j >= 0 and s[i] == t[j]:
		max_pos[j] = i
		j -= 1
curr = 0
for i in range(n):
	if curr < m and t[curr] == s[i]:
		ans = max(ans, max_pos[curr + 1] - i - 1)
		curr += 1
print(ans)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
s = input()
t = input()
n = len(s)
m = len(t)
ind = defaultdict(lambda : [-1, -1])
i = 0
j = 0
while j < m:
	if s[i] == t[j]:
		ind[j][0] = i
		j += 1
	i += 1
i = n - 1
j = m - 1
while j >= 0:
	if s[i] == t[j]:
		ind[j][1] = i
		j -= 1
	i -= 1
ans = max(ind[0][1], n - ind[m - 1][0] - 1)
for i in range(1, m):
	ans = max(ans, ind[i][1] - ind[i - 1][0] - 1)
print(ans)


import sys
in_file = sys.stdin
s = in_file.readline().strip()
t = in_file.readline().strip()
L = [0]
l = 0
R = [0]
r = len(t) - 1
for i in range(len(s)):
	if l < len(t) and s[i] == t[l]:
		l += 1
	L.append(l)
	if r >= 0 and s[len(s) - i - 1] == t[r]:
		r -= 1
	R.append(len(t) - r - 1)
end = False
for a in range(len(s) + 1):
	for i in range(a + 1):
		j = a - i
		if L[i] + R[j] >= len(t):
			sys.stdout.write(str(len(s) - a))
			end = True
			break
	if end:
		break
sys.stdout.flush()


def isSubstring(i, j, s, t):
	(p, q) = (0, 0)
	while p < len(s) and q < len(t):
		if p < i or p > j:
			if t[q] == s[p]:
				q += 1
		p += 1
	if q == len(t):
		return 1
	else:
		return 0
s = input()
t = input()
ans = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		if isSubstring(i, j, s, t) and j - i + 1 > ans:
			ans = j - i + 1
print(ans)


s = input()
t = input()

def check(sw):
	p = 0
	for i in sw:
		if i == t[p]:
			p += 1
		if p == len(t):
			break
	if p == len(t):
		return 1
	else:
		return 0
op = 0
for i in range(len(s)):
	for j in range(1, len(s) + 1):
		o = s[0:i] + s[j + 1:len(s) + 1]
		if check(o):
			op = max(op, len(s) - len(o))
print(op)


s = str(input())
t = str(input())
a = []
i = 0
j = 0
while j < len(t):
	if s[i] == t[j]:
		a.append(i + 1)
		j += 1
	i += 1
b = [0] * len(t)
i = len(s) - 1
j = len(t) - 1
while j >= 0:
	if s[i] == t[j]:
		b[j] = i + 1
		j -= 1
	i -= 1
maxi = max(b[0] - 1, len(s) - a[-1])
for i in range(len(t) - 1):
	maxi = max(maxi, b[i + 1] - a[i] - 1)
print(maxi)


def f(st, e):
	s1 = s[:st] + s[e:]
	(l1, l2) = (len(t), len(s1))
	(i, j) = (0, 0)
	while i < l1 and j < l2:
		if s1[j] == t[i]:
			i += 1
			j += 1
		else:
			j += 1
	if i == l1:
		return 1
	return 0
R = lambda : map(int, input().split())
s = input()
t = input()
l = len(s)
for i in reversed(range(l)):
	for j in range(l - i + 1):
		if f(j, j + i):
			print(i)
			quit()


from sys import stdin
input = stdin.readline
s = list(input().rstrip())
n = len(s)
t = list(input().rstrip())
m = len(t)
ans = 0
for l in range(n + 1):
	for r in range(l + 1, n + 1):
		tmp = s[:l] + s[r:]
		(u, v) = (0, 0)
		while u < len(tmp) and v < m:
			if tmp[u] == t[v]:
				u += 1
				v += 1
			else:
				u += 1
		if v == m:
			ans = max(ans, r - l)
print(ans)


def find_sub(s, t):
	k = 0
	for i in s:
		if k == len(t):
			break
		if i == t[k]:
			k = k + 1
	if k == len(t):
		return True
	else:
		return False

def process(s, t):
	res = 0
	for l in range(1, len(s)):
		for i in range(len(s) - l + 1):
			j = i + l - 1
			if find_sub(''.join([s[k] for k in range(len(s)) if k < i or k > j]), t):
				res = max(res, l)
	return res
s = input()
t = input()
print(process(s, t))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
s = inps()
n = len(s) - 1
s = s[:n]
t = inps()
m = len(t) - 1
t = t[:m]
front = [-1]
j = 0
for i in range(n):
	if j == m:
		break
	if s[i] == t[j]:
		front.append(i)
		j += 1
back = [n]
j = m - 1
for i in range(n)[::-1]:
	if j == -1:
		break
	if s[i] == t[j]:
		back.append(i)
		j -= 1
back = back[::-1]
res = 0
for i in range(m + 1):
	res = max(res, back[i] - front[i] - 1)
print(res)


s = input()
t = input()
if len(t) == 1:
	indices = [i for (i, x) in enumerate(s) if x == t[0]]
	print(max(indices[0], len(s) - indices[0] - 1, indices[len(indices) - 1], len(s) - indices[len(indices) - 1] - 1))
else:
	list1 = []
	list2 = []
	list_1 = []
	list_2 = []
	list_2_2 = []
	for j in range(len(t)):
		indices = [i for (i, x) in enumerate(s) if x == t[j]]
		list1.append(indices)
	for j in range(len(t)):
		indices = [i for (i, x) in enumerate(s) if x == t[j]]
		list_2_2.append(indices)
	for j in range(len(t)):
		indices = [i for (i, x) in enumerate(s) if x == t[j]]
		list_1.append(indices)
	for j in range(len(t)):
		indices = [i for (i, x) in enumerate(s) if x == t[j]]
		list_2.append(indices)
	for j in range(len(t)):
		indices = [i for (i, x) in enumerate(s) if x == t[j]]
		list2.append(indices)
	m = 0
	for i in range(len(list1) - 1):
		a = list_1[i][0]
		b = list1[i + 1]
		for j in b:
			if j > a:
				break
			list_1[i + 1].remove(j)
	for i in range(len(list2) - 1, 0, -1):
		a = list_2[i][len(list_2[i]) - 1]
		b = list2[i - 1]
		for j in range(len(b) - 1, -1, -1):
			if b[j] < a:
				break
			list_2[i - 1].remove(b[j])
	for i in range(len(list2) - 1, 0, -1):
		a = list_2_2[i][len(list_2_2[i]) - 1]
		b = list2[i - 1]
		for j in range(len(b) - 1, -1, -1):
			if b[j] < a:
				break
			list_2_2[i - 1].remove(b[j])
	for i in range(len(list_2) - 1):
		a = list_2_2[i][0]
		b = list_2[i + 1]
		for j in b:
			if j > a:
				break
			list_2_2[i + 1].remove(j)
	for i in range(len(list_2_2) - 1):
		if list_2_2[i + 1][len(list_2_2[i + 1]) - 1] - list_2_2[i][0] - 1 > m:
			m = list_2_2[i + 1][len(list_2_2[i + 1]) - 1] - list_2_2[i][0] - 1
	print(max(m, list_2[0][len(list_2[0]) - 1], len(s) - 1 - list_1[len(list_1) - 1][0]))


big = input()
small = input()
wyn = -100000
for i in range(-1, len(small)):
	pref = small[:i + 1]
	suf = small[i + 1:]
	j = 0
	wsk = -1
	while j < i + 1:
		while True:
			wsk += 1
			if big[wsk] == pref[j]:
				j += 1
				break
	left = wsk
	if i == -1:
		left = -1
	bigrev = big[::-1]
	sufrev = suf[::-1]
	j = 0
	wsk = -1
	while j < len(suf):
		while True:
			wsk += 1
			if bigrev[wsk] == sufrev[j]:
				j += 1
				break
	right = wsk
	if i == len(small) - 1:
		right = -1
	wyn = max(wyn, len(big) - (right + left + 2))
print(wyn)


def bin_s(x, values, arr):
	i = 0
	j = len(arr) - 1
	while i < j:
		m = (i + j) // 2
		if arr[m] < values:
			i = m + 1
		else:
			j = m
	if arr[i] >= values:
		return arr[i - 1]
	return arr[i]

def bin_s1(x, values, arr):
	i = 0
	j = len(arr) - 1
	while i < j:
		m = (i + j) // 2
		if arr[m] < values:
			i = m + 1
		else:
			j = m
	if arr[j] <= values:
		return arr[j + 1]
	return arr[j]
st_a = input()
st_b = input()
table = [[] for i in range(26)]
count = 0
for i in st_a:
	table[ord(i) - 97].append(count)
	count += 1
record_l = [0] * len(st_b)
record_f = [0] * len(st_b)
record_l[-1] = table[ord(st_b[-1]) - 97][-1]
record_f[0] = table[ord(st_b[0]) - 97][0]
for i in range(len(st_b) - 2, -1, -1):
	record_l[i] = bin_s(ord(st_b[i]) - 97, record_l[i + 1], table[ord(st_b[i]) - 97])
for i in range(1, len(st_b)):
	record_f[i] = bin_s1(ord(st_b[i]) - 97, record_f[i - 1], table[ord(st_b[i]) - 97])
maxi = 0
record_f = [-1] + record_f
record_l.append(len(st_a))
for i in range(len(st_b) + 1):
	maxi = max(record_l[i] - record_f[i] - 1, maxi)
print(maxi)


import os, sys
lang = s = sys.stdin.readline().strip()
kurz = t = sys.stdin.readline().strip()
vonvorn = []
last = 0
for c in t:
	last += lang.index(c) + 1
	vonvorn.append(last)
	lang = s[last:]
vonhinten = []
lang = s = ''.join(reversed(s))
last = 0
for c in reversed(t):
	last += lang.index(c) + 1
	vonhinten.append(last)
	lang = s[last:]
vonhinten = [len(s) + 1 - ind for ind in reversed(vonhinten)]
schnitt = []
schnitt.append(vonhinten[0] - 1)
for (i, c) in enumerate(t[:-1]):
	schnitt.append(vonhinten[i + 1] - vonvorn[i] - 1)
schnitt.append(len(s) - vonvorn[-1])
print(max(schnitt))


s = list(input())
t = list(input())
fo = []
ti = 0
for (i, c) in enumerate(s):
	if c == t[ti]:
		ti += 1
		fo.append(i)
		if ti == len(t):
			break
lo = []
ti = len(t) - 1
for i in reversed(range(len(s))):
	c = s[i]
	if c == t[ti]:
		ti -= 1
		lo.append(i)
		if ti == -1:
			break
mx = max(len(s) - fo[-1] - 1, lo[-1])
lo.reverse()
for i in range(1, len(t)):
	mx = max(mx, lo[i] - fo[i - 1] - 1)
print(mx)


s = input()
t = input()
s2 = s[::-1]
t2 = t[::-1]
n = len(s)
m = len(t)
pos = [0] * m
j = 0
for i in range(n):
	if s[i] == t[j]:
		pos[j] = i
		j += 1
		if j == m:
			break
pos2 = [0] * m
j = 0
for i in range(n):
	if s2[i] == t2[j]:
		pos2[j] = i
		j += 1
		if j == m:
			break
ans = max(pos[0], pos2[0], n - pos[-1] - 1, n - pos2[-1] - 1)
e = -(m - 1)
for j in range(m - 1):
	ans = max(ans, abs(n - pos2[-(j + 2)] - 1 - pos[j]) - 1)
print(ans)


s = input()
t = input()
i = 0
l = []
for c in t:
	while s[i] != c:
		i += 1
	l.append(i)
	i += 1
i = len(s) - 1
r = []
for c in t[::-1]:
	while s[i] != c:
		i -= 1
	r.append(i)
	i -= 1
r.reverse()
mx = r[0]
for i in range(len(t) - 1):
	mx = max(mx, r[i + 1] - l[i] - 1)
mx = max(mx, len(s) - l[-1] - 1)
print(mx)


from collections import deque
import sys, math, bisect

def inp():
	return sys.stdin.readline().strip()
s = inp()
t = inp()
n = len(s)
m = len(t)
mps = [0] * n
mss = [0] * n
idx = 0
for i in range(n):
	if idx < m and t[idx] == s[i]:
		mps[i] = idx + 1
		idx += 1
	else:
		mps[i] = idx
idx = m
for i in range(n - 1, -1, -1):
	if idx >= 1 and t[idx - 1] == s[i]:
		mss[i] = idx
		idx -= 1
	else:
		mss[i] = idx
mxl = 0
prev = 0
for l in range(n):
	r = bisect.bisect_right(mss, prev) - 1
	mxl = max(mxl, r - l + 1)
	prev = mps[l]
print(mxl)


import os
import sys
from io import BytesIO, IOBase

def main():
	s = input().rstrip()
	t = input().rstrip()
	(ls, lt) = (len(s), len(t))
	(a, b, j) = ([0] * lt, [0] * lt, 0)
	for i in range(ls):
		if s[i] == t[j]:
			a[j] = i
			j += 1
		if j == lt:
			break
	j = lt - 1
	for i in range(ls - 1, -1, -1):
		if s[i] == t[j]:
			b[j] = i
			j -= 1
		if j < 0:
			break
	ma = max(b[0], ls - a[-1] - 1)
	for i in range(lt - 1):
		ma = max(ma, b[i + 1] - a[i] - 1)
	print(ma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


s = input()
t = input()
(n, m) = (len(s), len(t))
(l, r, j) = ([0] * m, [0] * m, 0)
for i in range(m):
	while s[j] != t[i]:
		j += 1
	l[i] = j
	j += 1
j = n - 1
for i in range(m - 1, -1, -1):
	while s[j] != t[i]:
		j -= 1
	r[i] = j
	j -= 1
ans = max(0, r[0], n - 1 - l[-1])
for i in range(m - 1):
	ans = max(ans, r[i + 1] - l[i] - 1)
print(ans)


def pp(s, t):
	last = 0
	for i in t:
		if last == len(s):
			return 0
		while s[last] != i:
			last += 1
			if last == len(s):
				return 0
		last += 1
	return 1
(s, t) = (input(), input())
ans = 0
n = len(s)
for i in range(n):
	for j in range(i, n):
		if pp(s[:i] + s[j + 1:], t):
			ans = max(ans, j - i + 1)
print(ans)


def ud(s, t):
	max3 = -10
	for k in range(0, len(t) + 1):
		st = 0
		m = 0
		while st < k:
			if s[m] == t[st]:
				st += 1
			m += 1
		max1 = m
		st1 = len(t) - 1
		m = len(s) - 1
		while st1 >= k:
			if t[st1] == s[m]:
				st1 -= 1
			m -= 1
		max2 = m
		max3 = max(max3, max2 - max1 + 1)
	return max3
s = input()
t = input()
k = len(s) - len(t)
l = 0
r = k + 1
f = ud(s, t)
print(f)


def main():
	s = input()
	t = input()
	n = len(s)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			a = s[:i]
			b = s[j + 1:]
			st = a + b
			(cur, ok) = (0, 0)
			for ch in st:
				if ch == t[cur]:
					cur += 1
				if cur == len(t):
					ok = 1
					break
			if ok == 1:
				ans = max(ans, len(s) - len(st))
	return ans
print(main())


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def countDivisors(n):
	ans = 0
	l = ceil(sqrt(n)) + 1
	for i in range(2, l):
		cnt = 0
		if n % i == 0:
			while n % i != 1:
				cnt += 1
				n //= i
		ans += cnt
	return ans + 2

def main():
	a = si()
	b = si()
	f = [0] * 1000000
	g = [0] * 1000000
	j = 0
	for i in range(len(a)):
		if j < len(b):
			if a[i] == b[j]:
				f[j] = i
				j += 1
	j = len(b) - 1
	for i in range(len(a) - 1, -1, -1):
		if j >= 0:
			if a[i] == b[j]:
				g[j] = i
				j -= 1
	ans = max(g[0], len(a) - 1 - f[len(b) - 1])
	for i in range(1, len(a)):
		ans = max(ans, g[i] - f[i - 1] - 1)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


S = input()
T = input()
(N, M) = (len(S), len(T))

def calc(s, t):
	X = [0] * len(s)
	j = 0
	for i in range(len(s)):
		if j >= len(t):
			X[i] = j
		elif s[i] == t[j]:
			X[i] = j + 1
			j += 1
		else:
			X[i] = X[i - 1]
	return [0] + X
(A, B) = (calc(S, T), calc(S[::-1], T[::-1])[::-1])
(l, r) = (0, N)
while r - l > 1:
	m = (l + r) // 2
	C = [A[i] + B[i + m] for i in range(N - m + 1)]
	if max(C) >= M:
		l = m
	else:
		r = m
print(l)


def check(mid):
	qa = False
	for i in range(n - mid + 1):
		u = 0
		for j in range(i):
			if u < m and s[j] == t[u]:
				u += 1
		for j in range(i + mid, n):
			if u < m and s[j] == t[u]:
				u += 1
		if u == m:
			qa = True
			break
	return qa
s = input()
t = input()
n = len(s)
m = len(t)
l = -1
r = n - m + 1
while r - l > 1:
	mid = (l + r) // 2
	if check(mid):
		l = mid
	else:
		r = mid
print(l)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
s = input()
t = input()
a = [0]
b = [0]
j = 0
for i in t:
	for k in range(j, len(s)):
		if i == s[k]:
			a.append(k)
			j = k + 1
			break
a.append(len(s))
s = s[::-1]
t = t[::-1]
j = 0
for i in t:
	for k in range(j, len(s)):
		if i == s[k]:
			b.append(k)
			j = k + 1
			break
ans = 0
b.append(len(s))
for i in range(1, len(a)):
	ans = max(ans, a[i] - a[i - 1] - 1, b[i] - b[i - 1] - 1)
b = [len(s)] + [len(s) - i - 1 for i in b[1:-1]] + [0]
b = list(reversed(b))
for i in range(1, len(a)):
	ans = max(ans, a[i] - b[i - 1] - 1, b[i] - a[i - 1] - 1)
print(ans)


s = input()
t = input()
s_pos = [len(s) for i in range(len(t))]
(i, j) = (len(s) - 1, len(t) - 1)
while i > -1 and j > -1:
	if s[i] == t[j]:
		s_pos[j] = i
		j -= 1
	i -= 1
(p, q) = (0, 0)
ans = 0
while p < len(s):
	if q == len(t):
		ans = max(ans, len(s) - p)
		break
	remove = s_pos[q] - p
	ans = max(ans, remove)
	if s[p] == t[q]:
		q += 1
	p += 1
print(ans)


s = input()
t = input()
n = len(t)
first = [0] * n
last = [0] * n
p = 0
i = 0
while p < n:
	if s[i] == t[p]:
		first[p] = i
		p += 1
	i += 1
p = n - 1
i = len(s) - 1
while p >= 0:
	if s[i] == t[p]:
		last[p] = i
		p -= 1
	i -= 1
ans = max(last[0], len(s) - 1 - first[-1])
for i in range(n - 1):
	ans = max(ans, last[i + 1] - first[i] - 1)
print(ans)


from collections import deque

def substr_idx(s, t, reverse=False):
	idx = deque()
	i = 0
	rng = range(len(s))
	if reverse:
		rng = reversed(rng)
	for k in rng:
		if i >= len(t):
			break
		if reverse and s[k] == t[-i - 1]:
			idx.appendleft(k)
			i += 1
		elif not reverse and s[k] == t[i]:
			idx.append(k)
			i += 1
	return idx
s = input()
t = input()
idleft = substr_idx(s, t)
idright = substr_idx(s, t, reverse=True)
m = max(idright[0], len(s) - idleft[-1] - 1)
for i in range(1, len(idleft)):
	m = max(m, idright[i] - idleft[i - 1] - 1)
print(m)


s = input()
t = input()

def compute_prefix(s, t):
	prefix = [0 for i in range(len(t) + 1)]
	i = 0
	j = 0
	while i < len(t):
		while s[j] != t[i]:
			j += 1
		prefix[i + 1] = j + 1
		i += 1
		j += 1
	return prefix
prefix = compute_prefix(s, t)
suffix = compute_prefix(s[::-1], t[::-1])
res = 0
for i in range(len(t) + 1):
	res = max(res, len(s) - (prefix[i] + suffix[len(t) - i]))
print(res)


import bisect
from itertools import accumulate, count
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	for i in range(2, len(primes)):
		if primes[i] == True:
			prime.append(i)
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def NcR(n, r):
	p = 1
	k = 1
	if n - r < r:
		r = n - r
	if r != 0:
		while r:
			p *= n
			k *= r
			m = math.gcd(p, k)
			p //= m
			k //= m
			n -= 1
			r -= 1
	else:
		p = 1
	return p

def Log2(x):
	if x == 0:
		return False
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
s = input()
t = input()
r = [0] * len(t)
for i in range(len(t) - 1, -1, -1):
	p = len(s) - 1
	if i + 1 < len(t):
		p = r[i + 1] - 1
	while t[i] != s[p]:
		p -= 1
	r[i] = p
ans = p = 0
for i in range(len(s)):
	rp = len(s) - 1
	if p < len(t):
		rp = r[p] - 1
	ans = max(rp - i + 1, ans)
	if p < len(t) and t[p] == s[i]:
		p += 1
print(ans)


word = input()
sub = input()
n = len(word)
m = len(sub)
LR = []
RL = []
ind = 0
for i in range(n):
	if sub[ind] == word[i]:
		LR.append(i)
		ind += 1
		if ind == m:
			break
ind = m - 1
for i in range(n - 1, -1, -1):
	if sub[ind] == word[i]:
		RL.append(i)
		ind -= 1
		if ind == -1:
			break
RL.reverse()
mn = max(n - LR[-1] - 1, RL[0])
for i in range(m - 1):
	d = RL[i + 1] - LR[i] - 1
	if d > mn:
		mn = d
print(mn)


s = input()
t = input()
pref = []
j = 0
for i in range(len(s)):
	if j < len(t) and s[i] == t[j]:
		j = j + 1
	pref.append(j)
suf = []
j = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if j >= 0 and s[i] == t[j]:
		j = j - 1
	suf.append(len(t) - j - 1)
suf.reverse()
ans = 0
for i in range(len(s)):
	if pref[i] == len(t):
		ans = len(s) - i - 1
		break
for i in range(len(s) - 1, -1, -1):
	if suf[i] == len(t):
		if i > ans:
			ans = i
		break
ptr = len(s) - 1
for i in range(len(s) - 1, -1, -1):
	need = len(t) - suf[i]
	while ptr >= 0 and pref[ptr] >= need:
		ptr = ptr - 1
	if ptr < i and pref[ptr + 1] + suf[i] == len(t) and (i - ptr - 2 > ans):
		ans = i - ptr - 2
print(ans)


def process(s, t):
	l = []
	r = [0] * len(t)
	j = 0
	for i in range(len(t)):
		while s[j] != t[i]:
			j += 1
		l.append(j)
		j += 1
	j = len(s) - 1
	for i in reversed(range(len(t))):
		while s[j] != t[i]:
			j -= 1
		r[i] = j
		j -= 1
	res = max(r[0], len(s) - 1 - l[-1])
	for i in range(len(t) - 1):
		res = max(res, r[i + 1] - l[i] - 1)
	return res
s = input()
t = input()
print(process(s, t))


def subsequencia(a, b):
	tam = len(a)
	i = 0
	for c in b:
		if i < tam and c == a[i]:
			i += 1
	return i == tam
entrada = input()
ocorrencia = input()
tam = len(entrada)
maior = 0
for i in range(0, tam):
	for j in range(tam):
		if subsequencia(ocorrencia, entrada[0:i] + entrada[j + 1:]):
			maior = max(j - i + 1, maior)
print(maior)


s = input()
t = input()
l = 0
pre = []
suf = []
for i in range(len(s)):
	if s[i] == t[l]:
		pre.append(i)
		l += 1
	if l == len(t):
		break
l = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == t[l]:
		suf.append(i)
		l -= 1
	if l == -1:
		break
pre.sort()
suf.sort()
ans = 0
ans = max(suf[0], len(s) - pre[-1] - 1)
for i in range(len(t) - 1):
	ans = max(ans, abs(suf[i + 1] - pre[i] - 1))
print(ans)


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()

def check(s, t):
	stack = t[::-1]
	for i in s:
		if not stack:
			break
		if i == stack[-1]:
			stack.pop()
	if not stack:
		return True
	else:
		return False
s = list(input())
t = list(input())
ans = 0
for i in range(len(s)):
	for j in range(i + 1, len(s) + 1):
		copy = s[:]
		copy[i:j] = []
		if check(copy, t):
			ans = max(ans, j - i)
print(ans)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def is_subsq(a, b):
	i = 0
	j = 0
	while i < len(b) and j < len(a):
		if a[j] == b[i]:
			j += 1
		i += 1
	return j == len(a)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
s = input()
t = input()
n = len(s)
m = len(t)
l = [-1]
r = [n]
c = 0
for i in range(n):
	if s[i] == t[c]:
		l.append(i)
		c += 1
		if c >= m:
			break
c = 0
for i in range(n):
	if s[-1 - i] == t[-1 - c]:
		r.append(n - 1 - i)
		c += 1
		if c >= m:
			break
mx = 0
for i in range(m + 1):
	mx = max(mx, r[m - i] - l[i] - 1)
print(mx)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
s = z()
t = z()
ans = 0
lst = [0] * len(t)
for i in range(len(t) - 1, -1, -1):
	pos = len(s) - 1
	if i + 1 < len(t):
		pos = lst[i + 1] - 1
	while s[pos] != t[i]:
		pos -= 1
	lst[i] = pos
ans = 0
pos = 0
for i in range(len(s)):
	rpos = len(s) - 1
	if pos < len(t):
		rpos = lst[pos] - 1
	ans = max(ans, rpos - i + 1)
	if pos < len(t) and t[pos] == s[i]:
		pos += 1
print(ans)
exit()
for i in range(len(s)):
	for j in range(i, len(s)):
		pos = 0
		for p in range(len(s)):
			if i <= p and p <= j:
				continue
			if pos < len(t) and t[pos] == s[p]:
				pos += 1
		if pos == len(t):
			ans = max(ans, j - i + 1)
print(ans)


s = input()
t = input()
post = [len(t)] * len(s)
pre = [-1] * len(s)

def bins(val, low, high):
	if low > high:
		return -1
	global post, pre
	mid = (low + high) // 2
	if val >= post[mid]:
		return max(mid, bins(val, mid + 1, high))
	else:
		return bins(val, low, mid - 1)
j = -1
for i in range(len(s)):
	if j != len(t) - 1 and s[i] == t[j + 1]:
		j += 1
	pre[i] = j
j = len(t)
for i in range(len(s) - 1, -1, -1):
	if j != 0 and s[i] == t[j - 1]:
		j -= 1
	post[i] = j
ans = 0
for l in range(-1, len(s)):
	val = pre[l]
	if l == -1:
		val = -1
	if val == len(t) - 1:
		ans = max(ans, len(s) - l - 1)
		continue
	r = bins(val + 1, l + 1, len(s) - 1)
	if r != -1:
		ans = max(ans, r - l - 1)
print(ans)


bigstr = input()
substr = input()

def get_indices(s, t):
	idxs = [-1]
	t_idx = 0
	for idx in range(0, len(s)):
		if s[idx] == t[t_idx]:
			t_idx += 1
			idxs.append(idx)
			if t_idx == len(t):
				return idxs
idx_forward = get_indices(bigstr, substr)
idx_back = get_indices(bigstr[::-1], substr[::-1])
idx_back = [-1 * i - 1 + len(bigstr) for i in idx_back[::-1]]
best = 0
for ptr1 in range(len(idx_forward)):
	ptr2 = ptr1
	t_best = idx_back[ptr2] - idx_forward[ptr1] - 1
	if t_best > best:
		best = t_best
print(best)


s1 = input().strip()
s2 = input().strip()
l = [0] * len(s2)
r = [0] * len(s2)
iter = 0
for i in range(len(s1)):
	if s1[i] == s2[iter]:
		l[iter] = i
		iter += 1
	if iter == len(s2):
		break
iter = len(s2) - 1
for i in range(len(s1) - 1, -1, -1):
	if s1[i] == s2[iter]:
		r[iter] = i
		iter -= 1
	if iter == -1:
		break
res = max(len(s1) - 1 - l[-1], r[0])
for i in range(1, len(l)):
	res = max(res, r[i] - l[i - 1] - 1, r[i] - r[i - 1] - 1, l[i] - l[i - 1] - 1)
print(res)


s = input()
t = input()

def chk(x, y):
	cur = 0
	for i in range(len(x)):
		if x[i] == y[cur]:
			cur += 1
		else:
			continue
		if cur == len(y):
			return True
			break
	return False
(l, r) = (0, len(s) - len(t))
while l < r:
	m = (l + r) // 2 + 1
	for i in range(len(s) - m + 1):
		if chk(s[:i] + s[i + m:], t):
			l = m
			break
	else:
		r = m - 1
print(l)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	s = input()
	t = input()
	if s == t:
		print(0)
		exit()
	(ls, lt) = (len(s), len(t))
	res = 0

	def c(l, r):
		tag = 0
		for i in range(ls):
			if l <= i <= r:
				continue
			if s[i] == t[tag]:
				tag += 1
			if tag == lt:
				break
		return tag == lt
	for i in range(ls):
		for j in range(ls - 1, i - 1, -1):
			now = j - i + 1
			if now < res:
				break
			if c(i, j):
				res = max(res, now)
				break
	print(res)
main()


s = ' ' + input() + ' '
t = ' ' + input() + ' '
f = [0]
cnt = 0
for i in range(1, len(s)):
	f.append(f[i - 1])
	if s[i] == t[cnt + 1]:
		cnt += 1
		f[i] += 1
s = s[::-1]
t = t[::-1]
g = [0]
cnt = 0
for i in range(1, len(s)):
	g.append(g[i - 1])
	if s[i] == t[cnt + 1]:
		cnt += 1
		g[i] += 1
g = g[::-1]
ans = l = r = 0
while l < len(s):
	while r < len(s) and f[l] + g[r] >= len(t) - 2:
		r += 1
	ans = max(ans, r - l - 2)
	l += 1
print(ans)


def c(s1, s2):
	x = 0
	for i in range(len(s1)):
		if s1[i] == s2[x]:
			x += 1
			if x == len(s2):
				break
	if len(s2) == x:
		return True
	else:
		return False
s1 = input()
s2 = input()
ans = 0
for i in range(len(s1)):
	for j in range(1, len(s1) + 1):
		if c(s1[0:i] + s1[j:], s2):
			ans = max(ans, j - i)
print(ans)


from sys import stdin, stdout
from collections import *
from math import *
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007

def sub(a, b):
	i = 0
	for j in range(len(a)):
		if i < len(b) and a[j] == b[i]:
			i += 1
	return i == len(b)

def solve():
	s = st()
	t = st()
	ans = 0
	for i in range(len(s)):
		for j in range(i, len(s)):
			new = s[:i] + s[j + 1:]
			if sub(new, t):
				ans = max(ans, j - i + 1)
	print(ans)
for _ in range(1):
	solve()


def check(h, t):
	i = 0
	j = 0
	while i < len(h) and j < len(t):
		if h[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)
h = input()
t = input()
ans = 0
for i in range(len(h) + 1):
	for j in range(i, len(h) + 1):
		if check(h[:i] + h[j:], t):
			ans = max(ans, j - i)
print(ans)


def checker(mainstr, substr, index):
	size = len(mainstr) - 1
	maxdrop = 0
	pos = [-1]
	for i in substr:
		temp = mainstr.find(i, index)
		pos.append(temp)
		index = temp + 1
	index = 0
	newmainstr = mainstr[::-1]
	maxsize = len(mainstr) - 1
	for i in range(len(substr), 0, -1):
		currentpos = pos[i]
		maxdrop = max(maxdrop, maxsize - currentpos)
		currentpos = newmainstr.find(substr[i - 1], index)
		index = currentpos + 1
		maxsize = size - currentpos - 1
		maxdrop = max(maxdrop, maxsize - pos[i - 1])
	return maxdrop

def main():
	mainstr = input()
	substr = input()
	ans = checker(mainstr, substr, 0)
	print(ans)
main()


import math

class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	s = input()
	t = input()
	s_len = len(s)
	t_len = len(t)
	l = [0] * 200005
	r = [0] * 200005
	for i in range(t_len):
		while s[l[i]] != t[i]:
			l[i] += 1
		l[i + 1] = l[i] + 1
	r[t_len - 1] = s_len - 1
	for i in range(t_len - 1, -1, -1):
		while s[r[i]] != t[i]:
			r[i] -= 1
		if i != 0:
			r[i - 1] = r[i] - 1
	res = max(r[0], s_len - l[t_len - 1] - 1)
	for i in range(t_len):
		res = max(res, r[i + 1] - l[i] - 1)
	print(res)
query_count = 1
for j in range(query_count):
	solve()
	print()


def subseq(s, t):
	lenS = len(s)
	lenT = len(t)
	i = 0
	j = 0
	while i < lenS and j < lenT:
		if s[i] == t[j]:
			j += 1
		i += 1
	return lenT == j
s = input()
t = input()
lenS = len(s)
result = 0
for l in range(lenS):
	for r in range(lenS):
		s_without_sub = s[0:l] + s[r + 1:]
		if subseq(s_without_sub, t):
			result = max(result, r - l + 1)
print(result)


def find_first(s, t):
	idx = 0
	l = [-1]
	for i in range(len(s)):
		if t[idx] == s[i]:
			l.append(i)
			idx += 1
		if idx == len(t):
			return l
	return None

def find_last(s, t):
	idx = len(t) - 1
	l = [len(s)]
	for i in range(len(s) - 1, -1, -1):
		if t[idx] == s[i]:
			l.append(i)
			idx -= 1
		if idx == -1:
			return l[::-1]
	return None
bigstr = input()
substr = input()
first = find_first(bigstr, substr)
last = find_last(bigstr, substr)
mx = 0
for idx in range(len(first)):
	mx = max(mx, last[idx] - first[idx] - 1)
print(mx)


def is_subseq(s, t):
	i = 0
	for c in s:
		if i == len(t):
			break
		if c == t[i]:
			i += 1
	return i == len(t)

def main():
	s = input()
	t = input()
	ans = 0
	for safe_i in range(len(s)):
		for rem_i in range(safe_i, len(s)):
			substr = s[:safe_i] + s[rem_i + 1:]
			if is_subseq(substr, t):
				ans = max(ans, rem_i + 1 - safe_i)
	print(ans)
main()


s = input()
t = input()
(l, r) = ([0] * len(t), [0] * len(t))
(li, ri) = (0, len(s) - 1)
for i in range(len(t)):
	while s[li] != t[i]:
		li += 1
	while s[ri] != t[-i - 1]:
		ri -= 1
	l[i] = li
	r[-i - 1] = ri
	li += 1
	ri -= 1
print(max([r[0], len(s) - l[-1] - 1] + [max(0, r[i] - l[i - 1]) - 1 for i in range(1, len(t))]))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
from decimal import *

def solve():
	s = inp()
	t = inp()
	n = len(s)
	l = len(t)
	ar1 = []
	ar2 = []
	j = 0
	for i in range(n):
		if s[i] == t[j]:
			ar1.append(i)
			j += 1
			if j >= l:
				break
	j = l - 1
	for i in range(n - 1, -1, -1):
		if s[i] == t[j]:
			ar2.append(i)
			j -= 1
			if j < 0:
				break
	ar2 = ar2[::-1]
	m = max(n - 1 - ar1[l - 1], ar2[0])
	for i in range(l - 1):
		m = max(m, ar2[i + 1] - ar1[i] - 1)
	print(m)
solve()


def find(s, t):
	ans = []
	check = t[0]
	cur = 0
	cur_index = 0
	for i in range(len(s)):
		if s[i] == check:
			cur += 1
			ans += [cur]
			cur_index += 1
			try:
				check = t[cur_index]
			except:
				continue
		else:
			ans += [cur]
	return ans
import bisect

def find_ans(s, t):
	ans1 = find(s, t)
	ans2 = find(s[::-1], t[::-1])
	ans = 0
	for i in range(len(ans1)):
		temp = ans1[i]
		target = len(t) - temp
		if target == 0:
			ans = max(ans, len(s) - (i + 1))
			continue
		post = bisect.bisect_left(ans2, target)
		if post >= len(ans1):
			continue
		the_len = post + 1
		ans = max(ans, len(s) - (i + 1) - the_len)
		if temp == 0:
			ans = max(ans, len(s) - the_len)
	return ans
s = input()
t = input()
print(find_ans(s, t))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bsl
from collections import defaultdict
S = [k for k in input()]
T = [k for k in input()]
need = set(T)
n = len(S)
dict1 = defaultdict(list)
for s in range(n):
	if S[s] in need:
		dict1[S[s]].append(s)
tt = dict1[T[-1]][-1]
dict2 = {(T[-1], len(T) - 1): tt}
for s in range(len(T) - 2, -1, -1):
	orig = min(bsl(dict1[T[s]], tt), len(dict1[T[s]]) - 1)
	if dict1[T[s]][orig] >= tt:
		orig -= 1
	tt = dict1[T[s]][orig]
	dict2[T[s], s] = tt
maxsofar = tt
indsofar = dict1[T[0]][0]
for s in range(1, len(T)):
	maxsofar = max(maxsofar, dict2[T[s], s] - 1 - indsofar)
	ind = min(bsl(dict1[T[s]], indsofar), len(dict1[T[s]]) - 1)
	if T[s] == T[s - 1]:
		ind += 1
	indsofar = dict1[T[s]][ind]
maxsofar = max(maxsofar, n - 1 - indsofar)
print(maxsofar)


s = input()
t = input()
f = [0]
b = [0]
ti = 0
si = 0
ns = len(s)
nt = len(t)
while si < ns:
	if ti < nt and s[si] == t[ti]:
		ti += 1
	f.append(ti)
	si += 1
si = ns - 1
ti = nt - 1
while si >= 0:
	if ti >= 0 and t[ti] == s[si]:
		ti -= 1
	b.append(nt - 1 - ti)
	si -= 1
ans = 0
for i in range(0, ns):
	l = i
	r = ns - 1
	mid = int((l + r) / 2)
	while l <= r:
		if f[i] + b[ns - 1 - mid] >= nt:
			l = mid + 1
		else:
			r = mid - 1
		mid = int((l + r) / 2)
	ans = max(ans, r - i + 1)
print(ans)


s = input()
t = input()
pos = [[-1, -1] for i in range(len(t))]
ptr = 0
for (i, c) in enumerate(t):
	while s[ptr] != c:
		ptr += 1
	pos[i][0] = ptr
	ptr += 1
ptr = len(s) - 1
for i in range(len(t) - 1, -1, -1):
	c = t[i]
	while s[ptr] != c:
		ptr -= 1
	pos[i][1] = ptr
	ptr -= 1
best = max(pos[0][1], len(s) - pos[-1][0] - 1)
for i in range(1, len(pos)):
	best = max(best, pos[i][1] - pos[i - 1][0] - 1)
print(best)


def substring(a, b):
	for char in a:
		if char not in b:
			return False
		elif b.index(char) == len(b) - 1:
			b = b[b.index(char) + 1:]
		else:
			b = b[b.index(char) + 1:]
	return True
s = input()
t = input()
m = 0
n = len(s)
for i in range(n):
	for j in range(i, n):
		x = list(s)
		del x[i:j + 1]
		u = ''.join(x)
		if substring(t, u):
			m = max(m, j - i + 1)
print(m)


s = input().strip()
t = input().strip()
f = [-1] * len(t)
l = [-1] * len(t)
i = 0
for j in range(len(s)):
	if s[j] == t[i]:
		f[i] = j
		i += 1
	if i == len(t):
		break
i = len(t) - 1
for j in range(len(s) - 1, -1, -1):
	if s[j] == t[i]:
		l[i] = j
		i -= 1
	if i < 0:
		break
ans = max(len(s) - f[-1] - 1, l[0])
for i in range(1, len(t)):
	ans = max(ans, l[i] - f[i - 1] - 1)
print(ans)


s = input()
t = input()
ans = 0
for i in range(len(t) + 1):
	j = 0
	k = 0
	while j < i:
		if s[k] == t[j]:
			j += 1
		k += 1
	j = len(t) - 1
	l = len(s) - 1
	while j >= i:
		if s[l] == t[j]:
			j -= 1
		l -= 1
	ans = max(ans, l - k + 1)
print(ans)


import sys
import math
input = sys.stdin.readline
s1 = input()
t1 = input()
s = s1.rstrip()
t = t1.rstrip()
mini = list()
maxi = list()
st = 0
for i in range(len(s)):
	if s[i] == t[st]:
		mini.append(i)
		st += 1
	if st == len(t):
		break
st = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == t[st]:
		maxi.append(i)
		st -= 1
	if st == -1:
		break
maxi.reverse()
ans = maxi[0]
ans = max(len(s) - 1 - mini[len(t) - 1], ans)
for i in range(1, len(t)):
	ans = max(maxi[i] - mini[i - 1] - 1, ans)
if len(s) == len(t):
	print(0)
else:
	print(ans)


s1 = list(input())
s2 = list(input())
max_len = 0
for i in range(len(s1)):
	for j in range(i, len(s1)):
		flag = 0
		z = 0
		for k in range(i):
			if z == len(s2):
				break
			if s1[k] == s2[z]:
				z += 1
		for k in range(j + 1, len(s1)):
			if z == len(s2):
				break
			if s1[k] == s2[z]:
				z += 1
		if z == len(s2):
			max_len = max(j - i + 1, max_len)
print(max_len)


from sys import stdin
import collections
from bisect import bisect_left

def check(start, end):
	global s
	global t
	i = 0
	temp = s[:start] + s[end + 1:]
	i = 0
	j = 0
	cur = t[j]
	flag = False
	while i < len(temp) and j < len(t):
		if temp[i] == cur:
			j += 1
			if j == len(t):
				flag = True
				break
			cur = t[j]
		i += 1
	return flag
s = stdin.readline().strip()
t = stdin.readline().strip()
ans = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		if check(i, j):
			ans = max(ans, abs(i - j) + 1)
print(ans)


import io, os

def check(d):
	for i in range(len(s) - d + 1):
		pos = 0
		for x in s[:i]:
			if x == s1[pos]:
				pos += 1
				if pos == len(s1):
					return True
		for x in s[i + d:]:
			if x == s1[pos]:
				pos += 1
				if pos == len(s1):
					return True
	return False
s = input()
s1 = input()
l = 0
r = len(s)
while r - l > 1:
	mid = (r + l) // 2
	if check(mid):
		l = mid
	else:
		r = mid
print(l)


import sys
import bisect
import heapq
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
s = ri()
t = ri()
left = [0] * len(t)
right = [0] * len(t)
pos = 0
for i in range(len(s)):
	if t[pos] == s[i]:
		left[pos] = i
		pos += 1
	if pos == len(t):
		break
pos = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if t[pos] == s[i]:
		right[pos] = i
		pos -= 1
	if pos == -1:
		break
maxx = 0
for i in range(len(t) - 1):
	maxx = max(maxx, right[i + 1] - left[i] - 1)
maxx = max(maxx, right[0])
maxx = max(maxx, len(s) - left[len(t) - 1] - 1)
print(maxx)


from sys import stdin, stdout
from math import gcd, sqrt, inf
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
M = inf
a = [ord(i) - 97 for i in S()]
b = [ord(i) - 97 for i in S()]
v = [[] for i in range(26)]
n = len(a)
for i in range(n):
	v[a[i]] += (i,)
ln = len(b)
val = [[0, 0] for i in range(ln)]
lst = -1
pst = n
for i in range(ln):
	for j in v[b[i]]:
		if j > lst:
			val[i][0] = j + 1
			lst = j
			break
	for j in v[b[-i - 1]][::-1]:
		if j < pst:
			val[-i - 1][1] = j + 1
			pst = j
			break
val = [[0, 0]] + val + [[n + 1, n + 1]]
ans = 0
for i in range(1, len(val) - 1):
	ans = max(ans, val[i][1] - val[i - 1][0] - 1)
	ans = max(ans, val[i + 1][1] - val[i][0] - 1)
print(ans)


import sys
s = input()
t = input()

def is_subseq(x, y):
	it = iter(y)
	return all((any((c == ch for c in it)) for ch in x))
i = 0
ans = 0
length = 0
while i + length < len(s):
	temp = s[:i] + s[i + length + 1:]
	if is_subseq(t, temp):
		length += 1
		ans = max(ans, length)
	else:
		i += 1
		length = max(length - 1, 0)
print(ans)


s = input()
t = input()
n = len(s)
m = len(t)
first_in_the_start = [0] * m
first_in_the_end = first_in_the_start.copy()
ind_t = m - 1
for i in range(n - 1, -1, -1):
	if s[i] == t[ind_t]:
		first_in_the_end[ind_t] = i
		ind_t -= 1
		if ind_t == -1:
			break
ind_t = 0
for i in range(n):
	if s[i] == t[ind_t]:
		first_in_the_start[ind_t] = i
		ind_t += 1
		if ind_t == m:
			break
d = {e: [] for e in t}
for i in range(n):
	if s[i] in d:
		d[s[i]].append(i)
lens = [len(d[e]) for e in t]
count_max = max(first_in_the_end[0], n - first_in_the_start[m - 1] - 1)
for j in range(m - 1):
	count_max = max(count_max, first_in_the_end[j + 1] - first_in_the_start[j] - 1)
print(count_max)


s = input()
t = input()
pr = []
pospr = []
j = 0
for i in range(len(s)):
	if j != len(t) and s[i] == t[j]:
		j += 1
		pospr.append(i)
	pr.append(j)
suf = [0] * len(s)
j = len(t) - 1
possuf = [0] * len(t)
for i in range(len(s) - 1, -1, -1):
	if j != -1 and s[i] == t[j]:
		possuf[j] = i
		j -= 1
	suf[i] = len(t) - j - 1
ans = 0
for i in range(len(s)):
	sym = pr[i - 1] if i != 0 else 0
	last = possuf[sym] if sym != len(t) else len(s)
	if last - i > ans:
		ans = last - i
print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	S = input()
	T = input()
	n = len(T)
	needcntl = [0] * (n + 1)
	needcntr = [0] * (n + 1)
	idx = 0
	i = 0
	while i < n:
		if T[i] == S[idx]:
			needcntl[i + 1] = idx + 1
			i += 1
		idx += 1
	S = S[::-1]
	T = T[::-1]
	idx = 0
	i = 0
	while i < n:
		if T[i] == S[idx]:
			needcntr[i + 1] = idx + 1
			i += 1
		idx += 1
	ans = 0
	for j in range(n + 1):
		remove_cnt = needcntl[j] + needcntr[n - j]
		ans = max(ans, len(S) - remove_cnt)
	print(ans)
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


def int_multiple():
	return [int(c) for c in input().split()]

def int_single():
	return int(input())

def str_multiple():
	return [c for c in input().split()]

def str_single():
	return input()
s = str_single()
t = str_single()
ti = 0
start = []
for si in range(len(s)):
	if s[si] == t[ti]:
		start.append(si)
		ti += 1
		if ti == len(t):
			break
end = []
ti = len(t) - 1
for si in reversed(range(len(s))):
	if s[si] == t[ti]:
		end.append(si)
		ti -= 1
		if ti < 0:
			break
end = list(reversed(end))
start_mx = len(s) - start[-1] - 1
end_mx = end[0]
mx_between = 0
for i in range(len(t) - 1):
	diff = end[i + 1] - start[i] - 1
	mx_between = max(mx_between, diff)
print(max(start_mx, end_mx, mx_between))


import sys
from collections import defaultdict as dd
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
st = input()
pat = input()
n = len(st)
forward = [0 for i in range(n)]
idx = 0
for i in range(n):
	if idx < len(pat) and st[i] == pat[idx]:
		idx += 1
		forward[i] = idx
backward = [0 for x in range(n)]
idx = len(pat) - 1
for i in range(n - 1, -1, -1):
	if idx >= 0 and st[i] == pat[idx]:
		idx -= 1
		backward[i] = idx + 2
c1 = dd(int)
c2 = dd(int)
for i in range(n):
	c1[forward[i]] = i + 1
	c2[backward[i]] = i + 1
ans = max(c2[1] - 1, n - c1[len(pat)])
for i in range(1, len(pat)):
	ans = max(ans, abs(c1[i] - c2[i + 1]) - 1)
print(ans)


s = input()
t = input()
le = len(s) - len(t)
flag = 0
l = 0
if s == t:
	print(0)
else:
	for i in range(len(s)):
		for j in range(i + 1, len(s) + 1):
			s1 = s[:i] + s[j:]
			count = 0
			for ch in t:
				if ch in s1:
					lst = list(s1)
					ind = lst.index(ch)
					s1 = s1[ind + 1:]
					count += 1
			if count == len(t):
				leng = j - i
				if leng > l:
					l = leng
		le -= 1
	print(l)


big = input()
small = input()
pre = []
post = []
i = 0
j = 0
while 1:
	if j == len(small):
		break
	if big[i] == small[j]:
		pre.append(i)
		i += 1
		j += 1
	else:
		i += 1
big = big[::-1]
small = small[::-1]
i = 0
j = 0
while 1:
	if j == len(small):
		break
	if big[i] == small[j]:
		post.append(i)
		i += 1
		j += 1
	else:
		i += 1
for i in range(len(small)):
	post[i] = len(big) - 1 - post[i]
post.reverse()
ans = max(post[0], len(big) - (pre[-1] + 1))
for i in range(len(small) - 1):
	ans = max(ans, post[i + 1] - (pre[i] + 1))
print(ans)


def dick_in_tsypko(x, y):
	m = len(y)
	pos = 0
	for i in x:
		while pos < m and y[pos] != i:
			pos += 1
		if pos == m:
			return False
		pos += 1
	return True
s = input()
t = input()
n = len(s)
ans = 0
for i in range(0, n + 1):
	for j in range(i, n + 1):
		if dick_in_tsypko(t, s[:i] + s[j:]):
			ans = max(ans, j - i)
print(ans)


s = input()
t = input()
indl = [-1 for i in range(len(t))]
j = 0
for i in range(len(s)):
	if s[i] == t[j]:
		indl[j] = i
		j += 1
		if j == len(t):
			break
indr = [-1 for i in range(len(t))]
j = len(t) - 1
for i1 in range(len(s)):
	i = len(s) - 1 - i1
	if s[i] == t[j]:
		indr[j] = i
		j -= 1
		if j == -1:
			break
l = indr[0]
for i in range(len(t) - 1):
	l = max(l, indr[i + 1] - indl[i] - 1)
l = max(l, len(s) - 1 - indl[len(t) - 1])
print(l)


s = input()
t = input()
ans = 0
for i in range(len(s)):
	for j in range(i, len(s) + 1):
		tmp = s[:i] + s[j:]
		pos = 0
		for e in tmp:
			if e == t[pos]:
				pos += 1
				if pos == len(t):
					ans = max(ans, j - i)
					break
print(ans)


def f(s, t):
	ns = len(s)
	nt = len(t)
	(i, j) = (0, 0)
	while i < nt and j < ns:
		if s[j] == t[i]:
			i += 1
		j += 1
	if j == ns and i != nt:
		return False
	return True
s = input()
t = input()
ls = len(s)
MAX = 0
k = 0
while k < ls:
	p = k + MAX
	while p < ls:
		if f(s[:k] + s[p + 1:], t) == True:
			if p - k + 1 > MAX:
				MAX = p - k + 1
			p += 1
		else:
			break
	k += 1
print(MAX)


R = lambda : map(int, input().split())
s = input()
t = input()
(ls, lt) = (len(s), len(t))
a = [0] * lt
j = ls - 1
for i in reversed(range(lt)):
	while s[j] != t[i]:
		j -= 1
	a[i] = j
	j -= 1
(res, l) = (0, 0)
for i in range(ls):
	rp = ls - 1
	if l < lt:
		rp = a[l] - 1
	res = max(res, rp - i + 1)
	if l < lt and s[i] == t[l]:
		l += 1
print(res)


s = input()
t = input()

def search(s, t):
	indext = 0
	pos = [-1]
	for i in range(len(s)):
		if indext < len(t) and s[i] == t[indext]:
			pos += [i]
			indext += 1
		if indext == len(t):
			return pos
pos = search(s, t)
right = len(s) - 1
ans = right - pos[-1]
for i in range(len(t))[::-1]:
	while s[right] != t[i]:
		right -= 1
	right -= 1
	ans = max(ans, right - pos[i])
print(ans)


t1 = input()
t2 = input()
t = [0]
for i in range(len(t1)):
	for j in range(len(t1), i, -1):
		r1 = t1[i:j]
		r2 = t1[:i] + t1[j:]
		k1 = 0
		r = ''
		for k in r2:
			if k1 == len(t2):
				break
			if k == t2[k1]:
				r = r + k
				k1 = k1 + 1
		if r == t2:
			t.append(len(r1))
print(max(t))


def sub(a, b):
	s = 0
	for x in b:
		if x in a[s:]:
			s = a[s:].index(x) + 1 + s
		else:
			return False
	return True
s = input()
t = input()
m = 0
for i in range(len(s)):
	for j in range(len(s)):
		if i <= j:
			new_s = s[:i] + s[j + 1:]
			if sub(new_s, t):
				m = max(-i + j + 1, m)
print(m)


import sys
input = sys.stdin.readline
from math import gcd, sqrt
s = input().strip()
t = input().strip()
l = []
n = len(s)
m = len(t)
p = n - 1
q = m - 1
while q >= 0:
	if s[p] == t[q]:
		l.append(p)
		p -= 1
		q -= 1
	else:
		p -= 1
l.reverse()
l.append(n)
ans = l[0]
p = 0
q = 0
r = 0
while r < m:
	if s[p] == t[q]:
		ans = max(ans, l[r + 1] - p - 1)
		q += 1
		r += 1
		p += 1
	else:
		p += 1
print(ans)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def solve():
	t = 1
	for tt in range(t):
		s = input()
		t = input()
		x = 0
		for i in range(len(s)):
			for j in range(i, len(s)):
				dd = s[0:i] + s[j + 1:]
				if isSubSequence(t, dd, len(t), len(dd)):
					x = max(x, len(s) - len(dd))
		print(x)
solve()


s = input()
t = input()

def find(s):
	result = 0
	for elem in s:
		if result == len(t):
			break
		if elem == t[result]:
			result += 1
	return result == len(t)
answer = 0
for i in range(len(s)):
	for j in range(i + 1, len(s) + 1):
		if find(s[:i] + s[j:]):
			answer = max(j - i, answer)
print(answer)


a = list(input())
b = list(input())
l = [0 for i in range(len(a))]
r = [0 for i in range(len(a))]
itr = 0
m = len(b)
n = len(a)
for i in range(len(a)):
	if itr < m and b[itr] == a[i]:
		itr += 1
	l[i] = itr
itr = 0
for i in range(len(a)):
	if itr < m and b[m - 1 - itr] == a[n - 1 - i]:
		itr += 1
	r[n - 1 - i] = itr
ans = 0
for i in range(n):
	left = 1
	right = n - i
	mid = 0
	while left <= right:
		mid = (left + right) // 2
		if l[i] + r[i + mid - 1] >= m:
			ans = max(ans, mid - 2)
			left = mid + 1
		else:
			right = mid - 1
for i in range(n):
	if l[i] == 1:
		ans = max(ans, i)
		break
for i in range(n):
	if l[n - 1 - i] == m:
		ans = max(ans, i)
for i in range(n):
	if r[i] == m:
		ans = max(ans, i)
for i in range(n):
	if r[n - 1 - i] == 1:
		ans = max(ans, i)
		break
print(ans)


s1 = input()
s2 = input()
le = len(s2)
l1 = [-1 for i in range(le)]
l2 = [-1 for i in range(le)]
k = 0
for i in range(len(s1)):
	if k == le:
		break
	if s1[i] == s2[k]:
		l1[k] = i
		k += 1
k = le - 1
for i in range(len(s1) - 1, -1, -1):
	if k == -1:
		break
	if s1[i] == s2[k]:
		l2[k] = i
		k -= 1
le1 = len(s1)
ans = max(le1 - l1[-1] - 1, l2[0])
for i in range(le - 1):
	ans = max(l2[i + 1] - l1[i] - 1, ans)
print(ans)


s = input().strip()
t = input().strip()
m = len(t)
r = [0] * m
l = [0] * m
now = i = 0
while i < len(s) and now < m:
	if s[i] == t[now]:
		r[now] = i
		now += 1
	i += 1
now = m - 1
i = len(s) - 1
while i >= 0 and now >= 0:
	if s[i] == t[now]:
		l[now] = i
		now -= 1
	i -= 1
ans = max(r[0], len(s) - r[-1] - 1, l[0], len(s) - l[-1] - 1)
for i in range(m - 1):
	ans = max(ans, l[i + 1] - r[i] - 1)
print(ans)


strs = input()
substring = input()
curmax = 0
maxlen = len(strs)
minlen = len(substring)

def check(leftstring):
	global substring
	global minlen
	leftstringlen = len(leftstring)
	if leftstringlen < minlen:
		return False
	elif leftstring == substring:
		return True
	elif leftstringlen == minlen and leftstring != substring:
		return False
	index = 0
	for i in range(leftstringlen):
		if leftstring[i] == substring[index]:
			index += 1
		if index == minlen:
			return True
	return False
if maxlen == minlen:
	print(0)
else:
	for i in range(maxlen):
		left = i
		right = maxlen
		flag = 0
		while left < right:
			if flag == 0:
				mid = right
			else:
				mid = (left + right) // 2
			newstrs = strs[:i] + strs[mid:]
			getans = check(newstrs)
			if getans:
				newstrslen = len(newstrs)
				difflen = maxlen - newstrslen
				curmax = max(curmax, difflen)
				left = mid + 1
			else:
				right = mid - 1
	print(curmax)


def main():
	string = input()
	substring = input()
	size = len(substring)
	string_size = len(string)
	first = []
	last = []
	first.append(-1)
	index = 0
	for i in range(string_size):
		c = string[i]
		if c == substring[index]:
			first.append(i)
			index = index + 1
		if index >= size:
			break
	last.append(len(string))
	index = size - 1
	for i in range(string_size):
		c = string[string_size - i - 1]
		if c == substring[index]:
			last.append(string_size - i - 1)
			index = index - 1
		if index < 0:
			break
	last = last[::-1]
	m = 0
	for i in range(size + 1):
		length = last[i] - first[i]
		if length > m:
			m = length
	print(m - 1)
main()


s = input()
t = input()
dfirst = {}
dlast = {}
mx = -99
x = 0
for i in range(len(t)):
	while s[x] != t[i]:
		x += 1
	dfirst[i] = x
	if i == len(t) - 1:
		mx = max(mx, len(s) - x - 1)
	x += 1
x = len(s) - 1
trev = t[::-1]
for i in range(len(trev)):
	while s[x] != trev[i]:
		x -= 1
	dlast[len(t) - 1 - i] = x
	if i == len(trev) - 1:
		mx = max(mx, x)
	x -= 1
for i in range(1, len(t)):
	mx = max(mx, dlast[i] - dfirst[i - 1] - 1)
print(mx)


def t_in_sub(sub, t):
	j = i = 0
	while i < len(sub) and j < len(t):
		if t[j] == sub[i]:
			j += 1
		i += 1
	if j == len(t):
		return True
	return False
s = input()
t = input()
mx = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		sub = s[:i] + s[j + 1:]
		if t_in_sub(sub, t):
			mx = max(mx, j - i + 1)
print(mx)


has = input()
may = input()
ans = 0

def valid(cur):
	i = 0
	j = 0
	while i < len(cur) and j < len(may):
		if cur[i] == may[j]:
			j += 1
		i += 1
	return j == len(may)
for i in range(len(has) + 1):
	for j in range(i, len(has) + 1):
		curr = has[:i] + has[j:]
		if valid(curr):
			ans = max(ans, j - i)
print(ans)


def binary(ar, k):
	n = len(ar)
	if k >= ar[-1]:
		return n
	elif k < ar[0]:
		return 0
	else:
		l = 0
		r = n - 1
		while not (k >= ar[l] and k < ar[l + 1]):
			mid = (l + r) // 2
			if ar[mid] <= k:
				l = mid
			elif ar[mid] > k:
				r = mid
		return l + 1
st = input()
t = input()
dic = {}
xx = 'abcdefghijklmnopqrstuvwxyz'
for i in xx:
	dic[i] = []
lest = len(st)
for i in range(lest):
	dic[st[i]].append(i)
li = []
pos = -1
let = len(t)
for i in range(let):
	yy = binary(dic[t[i]], pos)
	li.append(dic[t[i]][yy])
	pos = li[-1]
ans = max(li[0], lest - li[-1] - 1)
li.insert(0, -1)
pos = lest
for i in range(let):
	yy = binary(dic[t[-(i + 1)]], pos) - 1
	if dic[t[-(i + 1)]][yy] == pos:
		pos = dic[t[-(i + 1)]][yy - 1]
	else:
		pos = dic[t[-(i + 1)]][yy]
	ans = max(ans, pos - li[-(i + 2)] - 1)
print(ans)


def solve():
	s1 = input()
	s2 = input()
	i = 0
	left = []
	for c in s2:
		while c != s1[i]:
			i += 1
		left.append(i)
		i += 1
	i = -1
	right = []
	for c in s2[::-1]:
		while c != s1[i]:
			i -= 1
		right.append(len(s1) + i)
		i -= 1
	right.reverse()
	mx = 0
	for i in range(len(s2) - 1):
		mx = max(mx, right[i + 1] - left[i] - 1)
	mx = max(mx, len(s1) - left[-1] - 1)
	mx = max(mx, right[0])
	print(mx)
for case in range(1):
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def ctd(chr):
	return ord(chr) - ord('a')
mod = 998244353
INF = float('inf')

def main():
	s = input()
	t = input()

	def c(num):
		b = 0
		prec = []
		srec = []
		for i in range(len(s)):
			if s[i] == t[b]:
				prec.append(i)
				b += 1
			if b == len(t):
				break
		e = len(t) - 1
		for i in range(len(s) - 1, -1, -1):
			if s[i] == t[e]:
				srec.append(i)
				e -= 1
			if e == -1:
				break
		srec = srec[::-1]
		if srec[0] >= num or len(s) - prec[-1] - 1 >= num:
			return True
		for i in range(len(prec) - 1):
			if srec[i + 1] - prec[i] - 1 >= num:
				return True
		return False
	(l, r) = (0, len(s) - len(t))
	while l < r:
		m = (l + r + 1) // 2
		ret = c(m)
		if ret:
			l = m
		else:
			r = m - 1
	print(l)
main()


def solve(s, t):
	ans = 0
	for i in range(len(s)):
		for j in range(i, len(s)):
			l = 0
			p = 0
			for k in range(len(s)):
				if k >= i and k <= j:
					continue
				if p < len(t) and s[k] == t[p]:
					l += 1
					p += 1
			if l == len(t):
				ans = max(ans, j - i + 1)
	print(ans)
s = input()
t = input()
solve(s, t)


s = input()
t = input()
if len(s) == len(t):
	print(0)
	exit()
for i in range(len(s) - len(t), 0, -1):
	for j in range(len(s) - i + 1):
		s1 = s[0:j] + s[j + i:len(s)]
		x = 0
		flag = 1
		for k in range(len(t)):
			while x < len(s1) and s1[x] != t[k]:
				x += 1
			if x < len(s1) and s1[x] == t[k] and (k != len(t) - 1):
				x += 1
			if x >= len(s1):
				flag = 0
				break
		if flag == 1:
			print(i)
			exit()


def subseq(a, b):
	j = 0
	for i in range(len(a)):
		if j < len(b) and a[i] == b[j]:
			j = j + 1
	if j == len(b):
		return True
	else:
		return False
s = input()
t = input()
ans = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		cur = s[:i] + s[j + 1:len(s)]
		if subseq(cur, t) and j - i + 1 > ans:
			ans = j - i + 1
print(ans)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def check(S, T):
	N = len(S)
	M = len(T)
	res = [N] * M
	i = j = 0
	while i < M:
		while j < N and T[i] != S[j]:
			j += 1
		res[i] = j
		j += 1
		i += 1
	return res
S = [ord(s) - 97 for s in input()]
T = [ord(t) - 97 for t in input()]
N = len(S)
M = len(T)
res1 = check(S, T)
res2 = check(S[::-1], T[::-1])
res2 = [N - a - 1 for a in res2[::-1]]
res1.insert(0, -1)
res2.append(N)
ans = 0
for i in range(M + 1):
	ans = max(ans, res2[i] - res1[i] - 1)
print(ans)


def remove(s, t, start, end):
	arr = []
	for i in range(start):
		arr.append(s[i])
	for i in range(end + 1, len(s)):
		arr.append(s[i])
	i = 0
	j = 0
	while i < len(arr) and j < len(t):
		if arr[i] == t[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j == len(t):
		return True
	return False

def solve(s, t):
	n = len(s)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			if remove(s, t, i, j):
				ans = max(ans, j - i + 1)
	print(ans)

def main():
	s = input()
	t = input()
	solve(s, t)
main()


str1 = input()
str2 = input()
pref = []
j = 0
for i in range(len(str1)):
	if j < len(str2) and str1[i] == str2[j]:
		j += 1
	pref.append(j)
j = len(str2) - 1
suf = []
for i in range(len(str1) - 1, -1, -1):
	if j == -1:
		break
	if str1[i] == str2[j]:
		j -= 1
		suf.append(i)
suf = suf[::-1]
max1 = 0
suf.append(len(str1))
for i in range(len(str1)):
	ind_begin = i
	ind_end = suf[pref[i - 1] if i != 0 else 0]
	max1 = max(max1, ind_end - ind_begin)
print(max1)


def check(e, t):
	l = 0
	for i in range(len(e)):
		if e[i] == t[l]:
			l += 1
			if l == len(t):
				break
	if l == len(t):
		return True
	else:
		return False
s = input()
t = input()
m = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		e = s[:i] + s[j + 1:]
		if check(e, t):
			m = max(j - i + 1, m)
print(m)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(s, t) = (g(), g())
n = len(s)
nt = len(t)
(l, r) = ([-1] * n, [n] * n)
prev = -1
p = 0
for i in range(n):
	if p < nt and s[i] == t[p]:
		prev = p
		p += 1
		l[i] = prev
	else:
		l[i] = prev
prev = nt
p = nt - 1
for i in reversed(range(n)):
	if p >= 0 and s[i] == t[p]:
		prev = p
		r[i] = p
		p -= 1
	else:
		r[i] = prev
r.append(nt)
ans = 0
for i in range(n):
	for j in range(n):
		(left, right) = (l[i - 1] if i else -1, r[j + 1])
		if left + 1 >= right:
			ans = max(ans, j - i + 1)
print(ans)


def is_subseq(s, t):
	if len(t) > len(s):
		return False
	i = 0
	j = 0
	while j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			i += 1
		if i == len(s):
			break
	return j == len(t)
s = input()
t = input()
mx = 0
for i in range(len(s)):
	for j in range(len(s)):
		l = min(i, j)
		r = max(i, j)
		s2 = s[:l] + s[r:]
		if is_subseq(s2, t) == True:
			mx = max(mx, r - l)
for i in range(len(s)):
	s2 = s[:i]
	if is_subseq(s2, t) == True:
		mx = max(mx, len(s) - i)
	s2 = s[i:]
	if is_subseq(s2, t) == True:
		mx = max(mx, i)
print(mx)


def checker(mainstr, substr, index):
	size = len(mainstr) - 1
	maxdrop = 0
	pos = []
	for i in substr:
		temp = mainstr.find(i, index)
		if temp == -1:
			return []
		else:
			pos.append(temp)
			index = temp + 1
	for i in range(len(substr) - 1, -1, -1):
		currentpos = pos[i]
		maxdrop = max(maxdrop, size - currentpos)
		while currentpos != -1:
			prevpos = currentpos
			currentpos = mainstr.find(substr[i], currentpos + 1, size + 1)
		size = prevpos - 1
	maxdrop = max(maxdrop, prevpos)
	return maxdrop

def main():
	mainstr = input()
	substr = input()
	ans = checker(mainstr, substr, 0)
	print(ans)
main()


import sys
from collections import defaultdict
import math

def main():
	s = input()
	t = input()
	longest_prefix = [0] * len(s)
	longest_suffix = [0] * len(s)
	longest_prefix[0] = 1 if s[0] == t[0] else 0
	for i in range(1, len(s)):
		x = longest_prefix[i - 1]
		if x == len(t) or s[i] != t[x]:
			longest_prefix[i] = x
		else:
			longest_prefix[i] = x + 1
	longest_suffix[-1] = 1 if s[-1] == t[-1] else 0
	for i in range(len(s) - 2, -1, -1):
		x = longest_suffix[i + 1]
		if x == len(t) or s[i] != t[-1 - x]:
			longest_suffix[i] = x
		else:
			longest_suffix[i] = x + 1
	res = 0
	pos1 = 0
	while longest_prefix[pos1] != len(t):
		pos1 += 1
	res = max(res, len(s) - 1 - pos1)
	pos2 = len(s) - 1
	while longest_suffix[pos2] != len(t):
		pos2 -= 1
	res = max(res, pos2)
	pos1 = 0
	pos2 = 0
	while pos1 < len(s):
		while pos2 + 1 < len(s) and longest_prefix[pos1] + longest_suffix[pos2 + 1] >= len(t):
			pos2 += 1
		res = max(res, pos2 - pos1 - 1)
		pos1 += 1
	print(res)
main()


import sys
input = sys.stdin.readline
s = input()
t = input()
i = 0
l = []
for c in t:
	while s[i] != c:
		i += 1
	l.append(i)
	i += 1
i = len(s) - 1
r = []
for c in t[::-1]:
	while s[i] != c:
		i -= 1
	r.append(i)
	i -= 1
r.reverse()
mx = r[0]
for i in range(len(t) - 1):
	mx = max(mx, r[i + 1] - l[i] - 1)
mx = max(mx, len(s) - l[-1] - 1)
print(mx)


import time
start = time.time()
s = list(input())
t = list(input())
l = 0
for i in range(0, len(s)):
	for j in range(i + 1, len(s) + 1):
		nst = s[:i] + s[j:]
		tick = 0
		for k in range(0, len(nst)):
			if tick >= len(t):
				break
			if nst[k] == t[tick]:
				tick += 1
		if tick == len(t):
			l = max(l, j - i)
print(l)


s = input()
t = input()
n = len(s)
ans = 0
for i in range(n):
	for j in range(i, n):
		st = s[:i] + s[j + 1:]
		(cur, ok) = (0, 0)
		for ch in st:
			if ch == t[cur]:
				cur += 1
			if cur == len(t):
				ok = 1
				break
		if ok == 1:
			ans = max(ans, len(s) - len(st))
print(ans)


from sys import setcheckinterval, stdin
setcheckinterval(1000)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
s = input()
t = input()
n = len(s)
d1 = {}
d1[0] = -1
d2 = {}
d2[0] = n
l = len(t)
ch = 0
for i in range(n):
	if ch == l:
		break
	if s[i] == t[ch]:
		ch += 1
		d1[ch] = i
s = list(s)
s = s[::-1]
t = list(t)
t = t[::-1]
ch = 0
for i in range(n):
	if ch == l:
		break
	if s[i] == t[ch]:
		ch += 1
		d2[ch] = n - i - 1
ans = []
for i in range(l + 1):
	ans.append(d2[l - i] - d1[i])
print(max(ans) - 1)


s = input()
t = input()
rg = [0] * len(t)
for i in range(len(t) - 1, -1, -1):
	pos = len(s) - 1
	if i != len(t) - 1:
		pos = rg[i + 1] - 1
	while s[pos] != t[i]:
		pos -= 1
	rg[i] = pos
ans = 0
pos = 0
for i in range(len(s)):
	rpos = len(s) - 1
	if pos < len(t):
		rpos = rg[pos] - 1
	ans = max(ans, rpos - i + 1)
	if pos < len(t) and t[pos] == s[i]:
		pos += 1
print(ans)


s = str(input())
t = str(input())

def lka(i):
	if i == 0:
		return 0
	for j in range(len(s) - i + 1):
		if kayna(s[:j] + s[j + i:]):
			return i
	return lka(i - 1)

def kayna(s):
	i = 0
	j = 0
	while i < len(t) and j < len(s):
		if s[j] == t[i]:
			i += 1
			j += 1
		else:
			j += 1
	if i == len(t):
		return True
	return False
print(lka(len(s) - len(t)))


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def solve():
	t = 1
	for tt in range(t):
		s = input()
		t = input()
		x = 0
		n = len(s)
		p = len(t)
		pref = [0] * n
		suff = [0] * n
		i = 0
		j = 0
		while j < p:
			if s[i] == t[j]:
				j += 1
			pref[i] = j
			i += 1
		while i < n:
			pref[i] = j
			i += 1
		j = p - 1
		i = n - 1
		cc = 0
		while j >= 0:
			if s[i] == t[j]:
				cc += 1
				j -= 1
			suff[i] = cc
			i -= 1
		while i >= 0:
			suff[i] = cc
			i -= 1
		lo = 1
		hi = n
		while lo <= hi:
			mid = (lo + hi) // 2
			fl = False
			for i in range(n):
				if i + mid - 1 >= n:
					break
				ll = 0
				rr = 0
				if i - 1 >= 0:
					ll = pref[i - 1]
				if i + mid < n:
					rr = suff[i + mid]
				if rr + ll >= p:
					fl = True
			if fl:
				lo = mid + 1
			else:
				hi = mid - 1
		print(lo - 1)
solve()


def check(s, t):
	n = 0
	m = 0
	while n < len(s) and m < len(t):
		if s[n] == t[m]:
			n += 1
			m += 1
		else:
			n += 1
	return m == len(t)
s = input()
t = input()
n = len(s)
ans = 0
for l in range(n):
	for r in range(l, n):
		tmp_s = s[:l] + s[r + 1:]
		if check(tmp_s, t):
			ans = max(ans, r - l + 1)
print(ans)


import collections, heapq, bisect, math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def solve(S, T):
	(left, right) = ({-1: -1}, {len(T): len(S)})
	j = 0
	for i in range(len(S)):
		if S[i] == T[j]:
			j += 1
		if j - 1 not in left:
			left[j - 1] = i
		if j == len(T):
			break
	j = len(T) - 1
	for i in range(len(S) - 1, -1, -1):
		if S[i] == T[j]:
			j -= 1
		if j + 1 not in right:
			right[j + 1] = i
		if j == -1:
			break
	out = 0
	for j in left:
		out = max(out, right[j + 1] - left[j] - 1)
	return max(left[0], out, len(S) - right[len(T) - 1] - 1)
q = 1
tests = []
for test in range(int(q)):
	n = input()
	b = input()
print(solve(n, b))


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def is_subsq(a, b):
	i = 0
	j = 0
	while i < len(b) and j < len(a):
		if a[j] == b[i]:
			j += 1
		i += 1
	return j == len(a)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
s = input()
t = input()
ans = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		if is_subsq(t, s[:i] + s[j + 1:]) and j - i + 1 > ans:
			ans = j - i + 1
print(ans)


s = input()
t = input()
ns = len(s)
nt = len(t)
ans = 0
found = 0
DP_left = [0] * ns
DP_left[0] = int(s[0] == t[0])
for i in range(1, ns):
	if DP_left[i - 1] < nt:
		DP_left[i] = DP_left[i - 1] + (s[i] == t[DP_left[i - 1]])
DP_right = [0] * ns
DP_right[-1] = int(s[-1] == t[-1])
for i in reversed(range(ns - 1)):
	if 0 <= nt - DP_right[i + 1] - 1 < nt:
		DP_right[i] = DP_right[i + 1] + (s[i] == t[nt - 1 - DP_right[i + 1]])
from collections import defaultdict
d_r = defaultdict(int)
d_l = defaultdict(int)
old = 1
for (index, i) in enumerate(DP_left):
	if i == old:
		d_l[i] = index
		old += 1
for (index, i) in enumerate(DP_right):
	d_r[i] = max(d_r[i], index)
for i in range(nt + 1):
	if i == 0:
		ans = max(ans, d_r[nt])
	elif i == nt:
		ans = max(ans, ns - d_l[nt] - 1)
	else:
		ans = max(ans, d_r[nt - i] - d_l[i] - 1)
print(ans)


def check(str1, str2):
	index1 = 0
	index2 = 0
	while index2 < len(str2) and index1 < len(str1):
		if str1[index1] == str2[index2]:
			index2 += 1
		index1 += 1
	if index2 == len(str2):
		return True
	else:
		return False
main = list(input())
sq = list(input())
ans = 0
for i in range(len(main)):
	for j in range(i + 1, len(main) + 1):
		test = main[:i] + main[j:]
		if check(test, sq):
			ans = max(ans, len(main[i:j]))
print(ans)


def isSubSequence(s, t):
	j = 0
	i = 0
	m = len(s)
	n = len(t)
	while j < m and i < n:
		if s[j] == t[i]:
			i = i + 1
		j = j + 1
	return i == n

def InvNGrams(s, n):
	m = len(s)
	for i in range(m - n + 1):
		yield (s[:i] + s[i + n:])

def GetMaxLen(s, t):
	n = len(s) - len(t)
	while n > 0:
		for g in InvNGrams(s, n):
			if isSubSequence(g, t):
				return n
		n -= 1
	return 0
s = input()
t = input()
res = GetMaxLen(s, t)
print(res)


import sys
from collections import defaultdict

def get_after(l, num):
	(low, high) = (0, len(l) - 1)
	ans = len(l)
	while low <= high:
		mid = (low + high) // 2
		if l[mid] > num:
			ans = min(ans, mid)
			high = mid - 1
		else:
			low = mid + 1
	return l[ans]

def get_before(l, num):
	(low, high) = (0, len(l) - 1)
	ans = 0
	while low <= high:
		mid = (low + high) // 2
		if l[mid] < num:
			ans = max(ans, mid)
			low = mid + 1
		else:
			high = mid - 1
	return l[ans]
dic = defaultdict(list)
s = sys.stdin.readline()[:-1]
t = sys.stdin.readline()[:-1]
n = len(s)
for i in range(n):
	dic[s[i]].append(i)
n = len(t)
l = [0 for _ in range(n + 2)]
l[0] = -1
l[-1] = len(s)
for i in range(n - 1, -1, -1):
	y = dic[t[i]][-1]
	if y < l[i + 2]:
		l[i + 1] = y
	else:
		y = get_before(dic[t[i]], l[i + 2])
		l[i + 1] = y
	last = l[i + 1]
ans = l[1] - l[0] - 1
for i in range(n):
	y = dic[t[i]][0]
	if y > l[i]:
		l[i + 1] = y
	else:
		y = get_after(dic[t[i]], l[i])
		l[i + 1] = y
	ans = max(ans, l[i + 2] - l[i + 1] - 1)
ans = max(ans, l[-1] - l[-2] - 1)
print(ans)


s = input()
t = input()
lower = [s.index(t[0])]
upper = []
for i in t[1:]:
	lower.append(lower[-1] + s[lower[-1] + 1:].index(i) + 1)
itr = iter(reversed(t))
a = next(itr)
for (i, v) in enumerate(s[::-1]):
	if v == a:
		upper.append(len(s) - i - 1)
		try:
			a = next(itr)
		except StopIteration:
			break
upper = upper[::-1]
max_length = max(upper[0], len(s) - lower[-1] - 1)
for (i, j) in zip(lower, upper[1:]):
	max_length = max(max_length, j - i - 1)
print(max_length)


import math

def posible(str1, str2, mid, n, m, R):
	coun = 0
	cur = 0
	for i in range(n - mid + 1):
		rang = i + mid
		if cur + R[rang] >= m:
			return True
		if str1[i] == str2[cur]:
			cur += 1
	return False
str1 = input()
str2 = input()
n = len(str1)
m = len(str2)
R = []
r = m - 1
l = n - 1
coun = 0
for i in range(n):
	R.append(0)
R.append(0)
while l >= 0:
	if r >= 0 and str1[l] == str2[r]:
		r -= 1
		coun += 1
	R[l] = coun
	l -= 1
lo = 0
hi = n - 1
ans = 0
while lo <= hi:
	mid = math.floor((lo + hi) / 2)
	if posible(str1, str2, int(mid), n, m, R):
		ans = mid
		lo = mid + 1
	else:
		hi = mid - 1
print(ans)


s = input()
t = input()
(n, m) = (len(s), len(t))
dp = [[-1] * (m + 1) for _ in range(n + 1)]
dp[0][0] = 0
res = 0
for i in range(1, n + 1):
	dp[i][0] = i
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if t[j - 1] == s[i - 1]:
			for k in range(i + 1):
				if dp[k][j] != -1:
					break
			if dp[k][j] != -1 or dp[i - 1][j - 1] != -1:
				dp[i][j] = max(dp[i - 1][j - 1], i - k, dp[k][j], dp[i - 1][j])
		else:
			for k in range(i + 1):
				if dp[k][j] != -1:
					break
			if dp[k][j] != -1:
				dp[i][j] = max(i - k, dp[k][j], dp[i - 1][j])
print(dp[n][m])


a = list(input())
b = list(input())
n = len(b)
m = len(a)
arr = 0
for i in range(m):
	for j in range(i, m):
		pos = 0
		for x in range(i):
			if pos == n:
				break
			if a[x] == b[pos]:
				pos += 1
		for x in range(j + 1, m):
			if pos == n:
				break
			if a[x] == b[pos]:
				pos += 1
		if pos == n:
			arr = max(arr, j - i + 1)
print(arr)


a = input()
b = input()
A = [0] * len(b)
B = [0] * len(b)
q = ''
v = 0
e = 0
i = 0
while q != b:
	if a[e] == b[v]:
		q += a[e]
		A[v] = e
		v += 1
	e += 1
A = [0] + A
v = len(b) - 1
e = len(a) - 1
q = ''
while q != b:
	if a[e] == b[v]:
		q = a[e] + q
		B[v] = e
		v -= 1
	e -= 1
B = [0] + B
B.append(len(a))
k = B[1] - A[0]
for i in range(len(b) + 1):
	if B[i + 1] - A[i] - 1 > k:
		k = B[i + 1] - A[i] - 1
print(k)


s = input()
t = input()
fp = [-1]
tp = 0
for i in range(len(s)):
	if s[i] == t[tp]:
		fp.append(i)
		tp += 1
		if tp == len(t):
			break
lp = [len(s)]
tp = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == t[tp]:
		lp.append(i)
		tp -= 1
		if tp == -1:
			break
lp.reverse()
print(max([l - f for (l, f) in zip(lp, fp)]) - 1)


s = input()
t = input()
k = len(s)
ml = 0
n = len(t) + 1
for i in range(n):
	l = 0
	for j in range(i):
		l = s.index(t[j], l, k) + 1
	j = 0
	r = k - 1
	while j < n - 1 - i:
		r = s.rindex(t[n - j - 2], 0, r + 1) - 1
		j = j + 1
	dl = r - l + 1
	if dl > ml:
		ml = dl
print(ml)


def check(s, t):
	j = 0
	for i in range(len(s)):
		if s[i] == t[j]:
			j += 1
		if j == len(t):
			return True
	return False
s = input()
t = input()
diff = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		if check(s[0:i] + s[j + 1:len(s)], t):
			curr = j - i + 1
			if curr > diff:
				diff = curr
print(diff)


s = input()
t = input()

def f(rem):
	(rptr, tptr) = (0, 0)
	while tptr < len(t) and rptr < len(rem):
		if rem[rptr] == t[tptr]:
			tptr += 1
			rptr += 1
		else:
			rptr += 1
	return True if tptr == len(t) else False
ans = 0
for l in range(len(s)):
	for r in range(l, len(s)):
		rem = s[:l] + s[r + 1:]
		if f(rem):
			ans = max(ans, r - l + 1)
print(ans)


s = input()
t = input()
l = len(s)
lt = len(t)
st = ''
ans = 0
for i in range(1, l + 1):
	for j in range(0, l - i + 1):
		st = s[0:j] + s[j + i:]
		flag = 1
		pos = 0
		for k in range(0, lt):
			pos = st.find(t[k], pos)
			if pos == -1:
				flag = 0
				break
			pos += 1
		if flag:
			ans = i
print(ans)


s = input()
t = input()
lastL = [0] * len(t)
lastR = [0] * len(t)
j = 0
for i in range(len(s)):
	if s[i] == t[j]:
		lastL[j] = i
		j += 1
	if j >= len(t):
		break
j = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == t[j]:
		lastR[j] = i
		j -= 1
	if j < 0:
		break
max_gap = max(lastR[0], len(s) - 1 - lastL[-1])
for i in range(len(t) - 1):
	max_gap = max(max_gap, lastR[i + 1] - 1 - lastL[i])
print(max_gap)


s1 = list(input())
r_s1 = s1[::-1]
s2 = list(input())
r_s2 = s2[::-1]
l1 = len(s1)
l2 = len(s2)
arr1 = []
arr2 = []
i = 0
j = 0
while i < l1 and j < l2:
	if s1[i] == s2[j]:
		arr1.append(i)
		j += 1
	i += 1
i = 0
j = 0
while i < l1 and j < l2:
	if r_s1[i] == r_s2[j]:
		arr2.append(l1 - 1 - i)
		j += 1
	i += 1
ans = 0
for i in range(1, l2):
	ans = max(ans, arr1[i] - arr1[i - 1] - 1)
	ans = max(ans, arr2[i - 1] - arr2[i] - 1)
for i in range(l2 - 1):
	ans = max(ans, arr2[l2 - 2 - i] - arr1[i] - 1)
ans = max(ans, l1 - arr1[-1] - 1, arr1[0])
ans = max(ans, arr2[-1], l1 - arr2[0] - 1)
print(ans)


maxDeletionLength = 0

def checkIfSubstrStart(string, substring, index):
	substrIndex = 0
	for i in range(index, len(string)):
		if substrIndex == len(substring):
			return True
		if string[i] == substring[substrIndex]:
			substrIndex += 1
	if substrIndex == len(substring):
		return True
	return False

def findSubstrLowerAndHigherSrtart(string, substring):
	if substring == '':
		return (len(string), len(string))
	index = 0
	while string[index] != substring[0]:
		index += 1
	lowerStart = index
	index = len(string) - 1
	while string[index] != substring[0] or not checkIfSubstrStart(string, substring, index):
		index -= 1
	higherStart = index
	return (lowerStart, higherStart)

def findLongestDeletion(string, substring):
	global maxDeletionLength
	if substring != '':
		(lowerStart, higherStart) = findSubstrLowerAndHigherSrtart(string, substring)
		if higherStart > maxDeletionLength:
			maxDeletionLength = higherStart
		findLongestDeletion(string[lowerStart + 1:], substring[1:])
	elif len(string) > maxDeletionLength:
		maxDeletionLength = len(string)
firstStr = input()
secondStr = input()
findLongestDeletion(firstStr, secondStr)
print(maxDeletionLength)


from sys import stdin
input = stdin.readline

def check(s, t):
	now = 0
	for i in s:
		if i == t[now]:
			now += 1
		else:
			continue
	if now == len(t):
		return True
	return False
s = input()
t = input()
ans = 0
n = len(s)
for l in range(n - 1):
	for r in range(l + 1, n):
		if check(s[:l] + s[r:], t):
			ans = max(ans, r - l)
print(ans)


s = input()
t = input()
ls = len(s)
mlen = 0
t = t.strip()
s = s.strip()

def subseq(s1, s2):
	pos = 0
	for i in range(len(s1)):
		if pos < len(s2):
			if s1[i] == s2[pos]:
				pos += 1
		else:
			return True
	return pos == len(s2)
for i in range(ls):
	for j in range(i, ls):
		l = s[:i]
		r = s[j + 1:ls]
		st = l + r
		if len(st) > 0 and subseq(st, t):
			mlen = max(mlen, len(s[i:j + 1]))
print(mlen)


def isok(s1, s2):
	n = len(s1)
	m = len(s2)
	i = 0
	j = 0
	c = 0
	while i < n and j < m:
		if s1[i] == s2[j]:
			c += 1
			i += 1
			j += 1
		else:
			i += 1
	ok = m == c
	return ok
maxi = 0
s1 = input()
s2 = input()
n = len(s1)
m = len(s2)
for i in range(n):
	for j in range(i, n):
		curr = s1[:i] + s1[j + 1:]
		if isok(curr, s2):
			maxi = max(maxi, j - i + 1)
print(maxi)


s = input()
a = input()
i = 0
l = []
r = []
for j in a:
	while s[i] != j:
		i += 1
	l.append(i)
	i += 1
i = len(s) - 1
for j in a[::-1]:
	while s[i] != j:
		i -= 1
	r.append(i)
	i -= 1
r.reverse()
ans = r[0]
for i in range(len(a) - 1):
	ans = max(ans, r[i + 1] - l[i] - 1)
ans = max(ans, len(s) - l[-1] - 1)
print(ans)


from bisect import bisect_left, bisect_right
str1 = input()
str2 = input()
last = []
first = []
d = dict()
for i in range(len(str2)):
	for j in range(len(str1)):
		if str2[i] == str1[j]:
			if (str2[i], i) in d:
				d[str2[i], i] += [j]
			else:
				d[str2[i], i] = [j]
first = [0] * len(str2)
last = [0] * len(str2)
first[0] = d[str2[0], 0][0]
last[-1] = d[str2[-1], len(str2) - 1][-1]
for i in range(1, len(str2)):
	for j in d[str2[i], i]:
		if j > first[i - 1]:
			break
	first[i] = j
for i in range(len(str2) - 2, -1, -1):
	for j in d[str2[i], i]:
		if j < last[i + 1]:
			x = j
		else:
			break
	last[i] = x
maybe = [last[0], len(str1) - first[-1] - 1]
for i in range(1, len(str2)):
	x = 0
	maybe += [last[i] - first[i - 1] - 1]
print(max(maybe))


def check(s, t):
	i = 0
	for c in s:
		if c == t[i]:
			i += 1
		if i == len(t):
			return True
	return False
(s, t) = (input(), input())
res = 0
for i in range(len(s)):
	for j in range(i + res, len(s)):
		if check(s[:i] + s[j + 1:], t):
			res = max(res, j - i + 1)
print(res)


s = input()
a = input()
i = 0
l = []
h = []
for j in a:
	while s[i] != j:
		i += 1
	l.append(i)
	i += 1
i = len(s) - 1
for j in a[::-1]:
	while s[i] != j:
		i -= 1
	h.append(i)
	i -= 1
h.reverse()
ansr = h[0]
for i in range(len(a) - 1):
	ansr = max(ansr, h[i + 1] - l[i] - 1)
ansr = max(ansr, len(s) - l[-1] - 1)
print(ansr)


a = input()
b = input()
n = len(a)
m = len(b)
i = 0
j = 0
(f, bb) = ([0] * m, [0] * m)
while j != m:
	if a[i] == b[j]:
		f[j] = i
		i += 1
		j += 1
	else:
		i += 1
i = 0
j = 0
while j != m:
	if a[n - 1 - i] == b[m - 1 - j]:
		bb[m - 1 - j] = n - 1 - i
		i += 1
		j += 1
	else:
		i += 1
ans = max(n - f[-1] - 1, bb[0])
for i in range(m - 1):
	ans = max(ans, bb[i + 1] - f[i] - 1)
print(ans)


import sys, math, bisect
from collections import defaultdict
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def factor(n):
	potentional_p = 3
	itog_list = {}
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			if n in itog_list:
				itog_list[n] += 1
			else:
				itog_list[n] = 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			if potentional_p in itog_list:
				itog_list[potentional_p] += 1
			else:
				itog_list[potentional_p] = 1
		potentional_p += 2
	return itog_list
s = input()
t = input()
forward = []
backward = []
rptr = 0
for i in range(len(s)):
	if rptr == len(t):
		break
	if s[i] == t[rptr]:
		forward.append(i)
		rptr += 1
rptr = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if rptr == -1:
		break
	if s[i] == t[rptr]:
		backward.append(i)
		rptr -= 1
backward = backward[::-1]
backward.append(forward[-1])
mx = max(forward[0], len(s) - 1 - backward[-2], len(s) - 1 - forward[-1], backward[0])
for i in range(len(t)):
	mx = max(mx, backward[i + 1] - forward[i] - 1)
print(mx)


s = input()
t = input()
maxl = 0
for l in range(1, len(s)):
	for i in range(len(s) - l + 1):
		j = 0
		ti = 0
		while j < len(s):
			if j >= i and j < i + l:
				j += 1
				continue
			if s[j] == t[ti]:
				ti += 1
			if ti == len(t):
				break
			j += 1
		if ti == len(t):
			maxl = l
			break
	if maxl != l:
		break
print(maxl)


s = input().rstrip()
t = input().rstrip()
left = []
idx = 0
for (i, item) in enumerate(s):
	if item == t[idx]:
		left.append(i)
		idx += 1
	if idx == len(t):
		break
right = []
idx = len(t) - 1
for (i, item) in enumerate(s[::-1]):
	if item == t[idx]:
		right.append(len(s) - i - 1)
		idx -= 1
	if idx == -1:
		break
right.reverse()
ans = max(right[0], len(s) - right[-1] - 1)
ans = max(ans, left[0], len(s) - left[-1] - 1)
for (l, r) in zip(left, right[1:]):
	ans = max(ans, r - l - 1)
print(ans)


s = input()
t = input()
left = [-1]
rightReversed = [len(s)]
i = 0
for x in range(len(s)):
	if t[i] == s[x]:
		left.append(x)
		i += 1
	if i >= len(t):
		break
i = len(t) - 1
for x in range(len(s) - 1, -1, -1):
	if t[i] == s[x]:
		rightReversed.append(x)
		i -= 1
	if i < 0:
		break
right = rightReversed[::-1]
maxN = 0
for x in range(len(t) + 1):
	maxN = max(right[x] - left[x], maxN)
print(maxN - 1)


from sys import stdin, stdout
from math import gcd, sqrt, inf
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
M = inf

def bin_l(lst, a, r):
	l = 0
	ans = 0
	while l <= r:
		m = (l + r) // 2
		if a[m] > lst:
			ans = a[m]
			r = m - 1
		else:
			l = m + 1
	return ans

def bin_h(pst, a, r):
	l = 0
	ans = 0
	while l <= r:
		m = (l + r) // 2
		if a[m] < pst:
			ans = a[m]
			l = m + 1
		else:
			r = m - 1
	return ans
a = [ord(i) - 97 for i in S()]
b = [ord(i) - 97 for i in S()]
v = [[] for i in range(26)]
n = len(a)
for i in range(n):
	v[a[i]] += (i,)
v_len = [len(i) for i in v]
ln = len(b)
val = [[0, 0] for i in range(ln)]
lst = -1
pst = n
for i in range(ln):
	val[i][0] = bin_l(lst, v[b[i]], v_len[b[i]] - 1) + 1
	lst = val[i][0] - 1
	val[-i - 1][1] = bin_h(pst, v[b[-i - 1]], v_len[b[-i - 1]] - 1) + 1
	pst = val[-i - 1][1] - 1
val = [[0, 0]] + val + [[n + 1, n + 1]]
ans = 0
for i in range(1, len(val) - 1):
	ans = max(ans, val[i][1] - val[i - 1][0] - 1)
	ans = max(ans, val[i + 1][1] - val[i][0] - 1)
print(ans)


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : list(map(int, rd().strip().split()))
s = str(rd().strip())
t = str(rd().strip())
s = '0' + s
canl = [0] * (len(s) + 10)
canr = [0] * (len(s) + 10)
j = 0
for (i, v) in enumerate(s):
	if j < len(t) and v == t[j]:
		j += 1
	canl[i] = j
j = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if j >= 0 and s[i] == t[j]:
		j -= 1
	canr[i] = len(t) - j - 1

def check(x):
	if x > len(s):
		return False
	for i in range(1, len(s) - x + 1):
		l = i - 1
		r = i + x
		if canl[l] + canr[r] >= len(t):
			return True
	return False
l = 0
r = len(s)
while l < r:
	mid = (l + r) // 2
	if check(mid):
		l = mid + 1
	else:
		r = mid
print(r - 1)


def check(a, b):
	x = 0
	for i in range(len(a)):
		if x == len(b):
			break
		if b[x] == a[i]:
			x += 1
	if x == len(b):
		return 1
	return 0
t = input()
s = input()
m = 0
for i in range(1, len(t) + 1):
	x = 0
	for j in range(len(t) - i + 1):
		a = t[:j] + t[j + i:]
		if check(a, s):
			m = i
			x = 1
			break
	if x == 0:
		break
print(m)


S = input()
T = input()

def s(a, b):
	if not b:
		return True
	elif not a:
		return False
	elif a[0] == b[0]:
		return s(a[1:], b[1:])
	else:
		return s(a[1:], b)
max = 0
for i in range(0, len(S)):
	for j in range(i, len(S) + 1):
		if j - i > max and s(S[:i] + S[j:], T):
			max = j - i
print(max)


S = input()
T = input()
C = [0] * (len(T) + 1)
C2 = [0] * (len(T) + 1)
p = 0
for i in range(len(T)):
	while T[i] != S[p] and p < len(S) - 1:
		p += 1
	C[i] = p
	p += 1
p = len(S) - 1
for i in range(len(T) - 1, -1, -1):
	while T[i] != S[p] and p > 0:
		p -= 1
	C2[i] = p
	p -= 1
ans = max(C2[0], len(S) - 1 - C[len(T) - 1])
for i in range(len(T) - 1):
	ans = max(ans, C2[i + 1] - C[i] - 1)
print(ans)


from math import *
s = input()
t = input()
tleft = []
tright = []
n = len(s)
m = len(t)
j = 0
i = 0
while j < m:
	if s[i] == t[j]:
		tleft.append(i)
		j += 1
	i += 1
i = n - 1
j = m - 1
while j >= 0:
	if s[i] == t[j]:
		tright.append(i)
		j -= 1
	i -= 1
tright.reverse()
ans = []
ans.append(max(tleft[0], tright[0]))
for i in range(1, m):
	x = max(tleft[i] - tleft[i - 1] - 1, tright[i] - tright[i - 1] - 1)
	x = max(x, tright[i] - tleft[i - 1] - 1)
	ans.append(x)
ans.append(max(n - 1 - tleft[m - 1], n - 1 - tright[m - 1]))
print(max(ans))


l1 = [i for i in input()]
l2 = [i for i in input()]
length1 = len(l1)
length2 = len(l2)
ij = 0
ji = len(l2) - 1
count1 = []
count2 = []
for i in range(length1):
	if ij < length2:
		if l1[i] == l2[ij]:
			ij += 1
			count1.append(i)
	if ji >= 0:
		if l1[-i - 1] == l2[ji]:
			ji -= 1
			count2.append(length1 - i - 1)
	if ij == length2 and ji == -1:
		break
final = [count2[len(count2) - 1 - 0]]
for i in range(length2 - 1):
	x = count2[-i - 2] - count1[i] - 1
	if x > final[0]:
		final[0] = x
print(max(final[0], length1 - 1 - count1[len(count1) - 1]))


s = input()
t = input()
(sl, tl) = (len(s), len(t))
left = []
right = []
x = 0
for i in range(sl):
	if x < tl and s[i] == t[x]:
		left.append(i)
		x += 1
x = tl - 1
for i in range(sl - 1, -1, -1):
	if x >= 0 and s[i] == t[x]:
		right.append(i)
		x -= 1
right.reverse()
if tl == 1:
	print(max(max(left[0], sl - left[0] - 1), max(right[0], sl - right[0] - 1)))
else:
	ans = max(sl - left[-1] - 1, right[0])
	for i in range(1, tl):
		ans = max(ans, right[i] - left[i - 1] - 1)
	print(ans)


def f(n):
	for i in range(-1, lt):
		if right[i + 1] - left[i] > n:
			return True
	return False
s = input()
t = input()
ls = len(s)
lt = len(t)
right = dict()
left = dict()
i = 0
j = 0
ls = len(s)
left[-1] = -1
while i < lt:
	if s[j] == t[i]:
		left[i] = j
		i += 1
	j += 1
j = ls - 1
i = lt - 1
right[lt] = ls
while i >= 0:
	if s[j] == t[i]:
		right[i] = j
		i -= 1
	j -= 1
low = 0
high = ls - 1
while low <= high:
	mid = (high + low) // 2
	if f(mid):
		low = mid + 1
	else:
		high = mid - 1
print(high)


from collections import defaultdict
s = input()
t = input()
prev = defaultdict(lambda : -1)
next_i = [-1] * len(s)
for (i, c) in enumerate(s):
	if prev[c] != -1:
		next_i[prev[c]] = i
	prev[c] = i
pos = [-1] + [0] * len(t) + [len(s)]
i = 0
for (j, c) in enumerate(t, start=1):
	while s[i] != c:
		i += 1
	pos[j] = i
	i += 1
ans = 0
for i in range(len(t), 0, -1):
	ans = max(ans, pos[i + 1] - pos[i] - 1)
	while next_i[pos[i]] != -1 and next_i[pos[i]] < pos[i + 1]:
		pos[i] = next_i[pos[i]]
	ans = max(ans, pos[i] - pos[i - 1] - 1)
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List

def solve(S, T):
	(N, M) = (len(S), len(T))
	left = [-1 for _ in range(N)]
	(si, ti) = (0, 0)
	while si < N:
		if ti >= M:
			left[si] = left[si - 1]
			si += 1
			continue
		if S[si] == T[ti]:
			left[si] = ti
			ti += 1
		else:
			left[si] = left[si - 1] if si > 0 else -1
		si += 1
	right = [M for _ in range(N)]
	(si, ti) = (N - 1, M - 1)
	while si >= 0:
		if ti < 0:
			right[si] = right[si + 1]
			si -= 1
			continue
		if S[si] == T[ti]:
			right[si] = ti
			ti -= 1
		else:
			right[si] = right[si + 1] if si + 1 < N else M
		si -= 1
	ans = 0
	for i in range(N):
		if left[i] >= M - 1:
			ans = max(ans, N - i - 1)
			break
		j = bisect.bisect_right(right, left[i] + 1)
		ans = max(ans, j - i - (2 if left[i] >= 0 else 1))
	print(ans)
S = input()
T = input()
solve(S, T)


s1 = list(input())
s2 = list(input())
j = -1
ba = []
for i in range(len(s1) - 1, -1, -1):
	if s1[i] == s2[j]:
		ba.append(i)
		j -= 1
		if j == -(len(s2) + 1):
			break
ba.sort()
j = 0
k = 0
cur = 0
maxi = ba[0]
for i in range(len(s1)):
	if s2[j] == s1[i]:
		j += 1
		cur = i + 1
		if j != len(s2):
			k = ba[j] - 1
			maxi = max(k - cur + 1, maxi)
		else:
			maxi = max(len(s1) - cur, maxi)
			break
print(maxi)


s1 = input()
s2 = input()
len_s1 = len(s1)
len_s2 = len(s2)

def issubseq(ss1, ss2, len2):
	cur_i = 0
	goal_i = len2
	c2 = ss2[cur_i]
	for c1 in ss1:
		if c1 == c2:
			cur_i += 1
			if cur_i == goal_i:
				return True
			else:
				c2 = ss2[cur_i]
	return False
out = 0
cont = True
for del_len in range(1, len_s1 - len_s2 + 1):
	cont = False
	for del_start_i in range(0, len_s1 + 1 - del_len):
		nokori_rstart_i = del_start_i + del_len
		substring = s1[del_start_i:nokori_rstart_i]
		assert len(substring) == del_len
		nokori = s1[:del_start_i] + s1[nokori_rstart_i:]
		if issubseq(nokori, s2, len_s2):
			cont = True
			out = del_len
			break
print(out)


s = input()
t = input()
f = [-1]
l = []
i = 0
j = 0
while i < len(s) and j < len(t):
	if s[i] == t[j]:
		j += 1
		f.append(i)
	i += 1
s += ','
t += ','
i = len(s) - 1
j = len(t) - 1
m = 0
while i >= 0 and j >= 0:
	if s[i] == t[j]:
		m = max(m, i - f[j] - 1)
		j -= 1
	i -= 1
print(m)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]
MOD = 10 ** 9 + 7

def solve():
	(S, T) = (getStr(), getStr())
	(N, M) = (len(S), len(T))
	(left, right) = ([-1], [N])
	j = 0
	for i in range(N):
		if S[i] == T[j]:
			left.append(i)
			j += 1
		if j == M:
			break
	left.append(N)
	j = M - 1
	for i in range(N - 1, -1, -1):
		if S[i] == T[j]:
			right.append(i)
			j -= 1
		if j == -1:
			break
	right.append(-1)
	right.reverse()
	ans = 0
	for i in range(len(left) - 1):
		ans = max(ans, right[i + 1] - left[i] - 1)
	return ans
print(solve())


def main():
	s = input().strip()
	t = input().strip()
	l2r = [0 for _ in range(len(t))]
	r2l = [0 for _ in range(len(t))]
	ti = 0
	for i in range(len(s)):
		if s[i] == t[ti]:
			l2r[ti] = i
			ti += 1
			if ti == len(t):
				break
	ti = len(t) - 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == t[ti]:
			r2l[ti] = i
			ti -= 1
			if ti == -1:
				break
	ans = max(r2l[0], len(s) - l2r[-1] - 1)
	for i in range(len(t)):
		if r2l[i] - l2r[i - 1] - 1 > ans:
			ans = r2l[i] - l2r[i - 1] - 1
	print(ans)
main()


s = input()
t = input()
j = len(t) - 1
last = [None] * len(t)
for _i in range(len(s)):
	i = len(s) - _i - 1
	if j >= 0 and s[i] == t[j]:
		last[j] = i
		j -= 1
answer = -1
j = 0
first = [None] * len(t)
for i in range(len(s)):
	if j < len(t):
		if s[i] == t[j]:
			first[j] = i
			if j > 0:
				answer = max(answer, last[j] - first[j - 1] - 1)
			else:
				answer = last[j]
			j += 1
	else:
		break
answer = max(answer, len(s) - 1 - first[-1])
print(answer)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	s1 = get_input()
	s2 = get_input()
	res = 0
	for i in range(len(s1)):
		for j in range(i, len(s1)):
			ptr = 0
			for k in range(len(s1)):
				if i <= k <= j:
					continue
				if ptr < len(s2) and s1[k] == s2[ptr]:
					ptr += 1
			if len(s2) == ptr:
				res = max(res, j - i + 1)
	cout << res << endl

def main():
	solve()
main()


import sys
input = lambda : sys.stdin.readline().strip()

def issub(s, t):
	j = -1
	for i in range(len(s)):
		if j >= len(t) - 1:
			break
		elif s[i] == t[j + 1]:
			j += 1
	if j == len(t) - 1:
		return True
	return False
s = list(input())
t = list(input())
cnt = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		ls = s[:i] + s[j + 1:]
		if issub(ls, t):
			cnt = max(cnt, j - i + 1)
print(cnt)


string = str(input())
substring = str(input())
len_string = len(string)
len_substring = len(substring)
minimal_string_pos = []
max_string_pos = []
sub_flag = 0
for i in range(len_string):
	if string[i] == substring[sub_flag]:
		minimal_string_pos.append(i)
		sub_flag += 1
		if sub_flag > len_substring - 1:
			break
sub_flag = len(substring) - 1
for i in range(len_string - 1, -1, -1):
	if string[i] == substring[sub_flag]:
		max_string_pos.append(i)
		sub_flag -= 1
		if sub_flag < 0:
			break
max_string_pos = max_string_pos[::-1]
digit_max_1 = max(max_string_pos[0], len_string - minimal_string_pos[len(minimal_string_pos) - 1] - 1)
digit_max_2 = 0
for i in range(len(substring) - 1):
	digit_max_2 = max_string_pos[i + 1] - minimal_string_pos[i] - 1 if max_string_pos[i + 1] - minimal_string_pos[i] - 1 > digit_max_2 else digit_max_2
print(max(digit_max_1, digit_max_2))


import sys

def main():
	input = sys.stdin.readline
	s = input()[:-1]
	t = input()[:-1]
	n = len(s)
	m = len(t)

	def hantei(a, b):
		i = 0
		j = 0
		while i < len(b):
			while j <= len(a):
				if j == len(a):
					return False
				if b[i] == a[j]:
					i += 1
					j += 1
					break
				else:
					j += 1
		return True
	ans = 0
	for k in range(n):
		for l in range(k, n + 1):
			if len(t) <= len(s[:k] + s[l:]):
				if hantei(s[:k] + s[l:], t) == True:
					ans = max(ans, l - k)
	print(ans)
main()


s = input()
t = input()

def get(s, t):
	nd = 0
	dp = [False] * len(s)
	for i in range(len(s)):
		c = s[i]
		if nd < len(t) and c == t[nd]:
			dp[i] = True
			nd += 1
		if nd == len(t):
			return (i, dp)
(l, dp) = get(s, t)
r = len(s) - 1
ans = r - l
for c in reversed(t):
	l -= 1
	while l >= 0 and dp[l] == False:
		l -= 1
	while s[r] != c:
		r -= 1
	r -= 1
	ans = max(ans, r - l)
print(ans)


import sys
in_file = sys.stdin
s = in_file.readline().strip()
t = in_file.readline().strip()
L = [0]
l = 0
R = [0]
r = len(t) - 1
for i in range(len(s)):
	if l < len(t) and s[i] == t[l]:
		l += 1
	L.append(l)
	if r >= 0 and s[len(s) - i - 1] == t[r]:
		r -= 1
	R.append(len(t) - r - 1)
Lc = [-1 for i in range(len(t) + 1)]
Rc = [-1 for i in range(len(t) + 1)]
for i in range(len(L)):
	if Lc[L[i]] == -1:
		Lc[L[i]] = i
	if Rc[R[i]] == -1:
		Rc[R[i]] = i
res = len(s)
for i in range(len(t) + 1):
	j = len(t) - i
	if Rc[j] + Lc[i] < res:
		res = Rc[j] + Lc[i]
sys.stdout.write(str(len(s) - res))
sys.stdout.flush()


s = input()
t = input()
lefts = [0 for i in range(len(t))]
rights = [0 for i in range(len(t))]
i = 0
j = 0
while i < len(s) and j < len(t):
	if s[i] == t[j]:
		lefts[j] = i
		j += 1
	i += 1
i = len(s) - 1
j = len(t) - 1
while i >= 0 and j >= 0:
	if s[i] == t[j]:
		rights[j] = i
		j -= 1
	i -= 1
ans = max(len(s) - lefts[-1] - 1, rights[0])
for i in range(len(t) - 1):
	ans = max(ans, rights[i + 1] - lefts[i] - 1)
print(ans)


s = input()
t = input()
n = len(s)
m = len(t)
dp1 = [0] * (n + 1)
for i in range(n):
	dp1[i + 1] = dp1[i]
	if dp1[i] < m and s[i] == t[dp1[i]]:
		dp1[i + 1] += 1
dp2 = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	dp2[i] = dp2[i + 1]
	if dp2[i + 1] < m and s[i] == t[-1 - dp2[i + 1]]:
		dp2[i] += 1

def check(ln):
	for i in range(n - ln + 1):
		if dp1[i] + dp2[i + ln] >= m:
			return True
	return False
(l, r) = (0, n)
while r - l > 1:
	mid = (l + r) // 2
	if check(mid):
		l = mid
	else:
		r = mid
print(l)


def solver():
	s = input().strip()
	t = input().strip()
	left = [len(s)] * len(t)
	right = [-1] * len(t)
	cnt = 0
	for i in range(len(t)):
		while s[cnt] != t[i]:
			cnt += 1
		left[i] = cnt
		cnt += 1
	cnt = len(s) - 1
	for i in range(len(t) - 1, -1, -1):
		while s[cnt] != t[i]:
			cnt -= 1
		right[i] = cnt
		cnt -= 1
	ans = max(len(s) - left[-1] - 1, right[0])
	for i in range(len(t) - 1):
		ans = max(ans, right[i + 1] - left[i] - 1)
	print(ans)

def main():
	while 1:
		try:
			solver()
		except EOFError:
			break
main()


s = input()
t = input()
L1 = []
L2 = []
ptr = 0
for i in range(0, len(s)):
	if s[i] == t[ptr]:
		L1.append(i)
		ptr += 1
	if ptr >= len(t):
		break
ptr = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == t[ptr]:
		L2.append(i)
		ptr -= 1
	if ptr < 0:
		break
L2 = L2[::-1]
mx = -1
for i in range(0, len(L1) - 1):
	mx = max(mx, L2[i + 1] - L1[i] - 1)
mx = max(mx, L2[0])
mx = max(mx, len(s) - L1[-1] - 1)
print(mx)


s = input()
t = input()
l = len(s)
fow = []
bac = []
j = 0
n = len(t)
for i in range(l):
	if s[i] == t[j]:
		fow.append(i)
		j += 1
	if j == n:
		break
j = len(t) - 1
for i in range(l - 1, -1, -1):
	if s[i] == t[j]:
		j -= 1
		bac.append(i)
	if j < 0:
		break
bac = bac[::-1]
ans = max(bac[0], l - fow[-1] - 1)
for i in range(n - 1):
	ans = max(ans, bac[i + 1] - fow[i] - 1)
print(ans)


big = input()
small = input()
ans = 0
for i in range(0, len(big)):
	for j in range(i, len(big)):
		pos = 0
		for k in range(0, len(big)):
			if k >= i and k <= j:
				continue
			if big[k] == small[pos]:
				pos += 1
			if pos == len(small):
				ans = max(ans, j - i + 1)
				break
print(ans)


def solve(s, t):
	j = 0
	pre = [None] * len(t)
	post = [None] * len(t)
	for i in range(len(s)):
		if j < len(t) and s[i] == t[j]:
			pre[j] = i
			j += 1
	j = len(t) - 1
	for i in reversed(range(len(s))):
		if j >= 0 and s[i] == t[j]:
			post[j] = i
			j -= 1
	diff = post[0]
	for i in range(1, len(t)):
		diff = max(diff, post[i] - pre[i - 1] - 1)
	diff = max(diff, len(s) - pre[-1] - 1)
	return diff
s = input()
t = input()
print(solve(s, t))


import sys
input = sys.stdin.readline
s = input()
t = input()
(l, r) = ([0] * len(t), [0] * len(t))
(li, ri) = (0, len(s) - 1)
for i in range(len(t)):
	while s[li] != t[i]:
		li += 1
	while s[ri] != t[-i - 1]:
		ri -= 1
	l[i] = li
	r[-i - 1] = ri
	li += 1
	ri -= 1
print(max([r[0], len(s) - l[-1] - 1] + [max(0, r[i] - l[i - 1]) - 1 for i in range(1, len(t))]))


def not_in_borders_left(s, t, a):
	if len(t) == 0:
		return
	lst = s.rfind(t[-1])
	fst = lst
	for i in range(len(t) - 2, -1, -1):
		fst = s[:fst].rfind(t[i])
	a.append(fst)

def not_in_borders_right(s, t, a):
	if len(t) == 0:
		return
	fst = s.find(t[0])
	lst = fst
	for i in range(1, len(t)):
		lst = s[lst + 1:].find(t[i]) + lst + 1
	a.append(len(s) - lst - 1)

def in_borders(s, t, a):
	if len(t) < 2:
		pos = s.find(t)
		if pos == -1:
			return
		if len(s) - pos - 1 > pos:
			a.append(len(s) - pos - 1)
			return
		a.append(pos)
		return
	start = s.find(t[0])
	end = s.rfind(t[-1])
	s = s[start + 1:end]
	t = t[1:-1]
	not_in_borders_left(s, t, a)
	not_in_borders_right(s, t, a)
	in_borders(s, t, a)

def main():
	s = input()
	t = input()
	a = list()
	not_in_borders_left(s, t, a)
	not_in_borders_right(s, t, a)
	in_borders(s, t, a)
	print(max(a))
main()


from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
import math
MOD = pow(10, 9) + 7
from math import gcd

def IN(f=0):
	if f == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
a = input()
b = input()
n = len(a)
m = len(b)
q = []
w = []
j = 0
d1 = DD(int)
d2 = DD(int)
for i in range(len(a)):
	if j >= len(b):
		q.append(0)
	elif a[i] == b[j]:
		q.append(j + 1)
		j += 1
	else:
		q.append(0)
j = len(b) - 1
for i in range(len(a) - 1, -1, -1):
	if j < 0:
		w.append(0)
	elif a[i] == b[j]:
		w.append(j + 1)
		j -= 1
	else:
		w.append(0)
w.reverse()
for i in range(len(a)):
	d1[q[i]] = i + 1
for i in range(len(a)):
	d2[w[i]] = i + 1
ans = max(d2[1] - 1, len(a) - d1[len(b)])
for i in range(1, m):
	tr = abs(d1[i] - d2[i + 1]) - 1
	if ans < tr:
		ans = tr
print(ans)


s = input()
t = input()
tl = len(t)
ind = []
for i in range(0, len(s)):
	for j in range(i + 1, len(s) + 1):
		cc = s[:i] + s[j:]
		ii = 0
		for k in cc:
			if ii == tl:
				break
			if k == t[ii]:
				ii += 1
		if ii == tl:
			ind.append(j - i)
if len(ind):
	print(max(ind))
else:
	print(0)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())

def check(s1, s2):
	i = 0
	j = 0
	while i < len(s1) and j < len(s2):
		if s1[i] == s2[j]:
			j += 1
		i += 1
	return j == len(s2)
s = si()
t = si()
ns = len(s)
nt = len(t)
mx = 0
for i in range(ns + 1):
	for j in range(i, ns + 1):
		if check(s[:i] + s[j:], t):
			mx = max(mx, j - i)
print(mx)


def readInts():
	return [int(s) for s in input().split(' ')]

def is_sub(s, t):
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)

def main():
	s = input()
	t = input()
	ans = 0
	for l in range(len(s)):
		for r in range(l, len(s)):
			if is_sub(s[0:l] + s[r + 1:], t):
				ans = max(ans, r - l + 1)
	print(ans)
main()


s = input()
t = input()
forward = []
backward = []
rptr = 0
for i in range(len(s)):
	if rptr == len(t):
		break
	if s[i] == t[rptr]:
		forward.append(i)
		rptr += 1
rptr = len(t) - 1
for i in range(len(s) - 1, -1, -1):
	if rptr == -1:
		break
	if s[i] == t[rptr]:
		backward.append(i)
		rptr -= 1
backward = backward[::-1]
backward.append(forward[-1])
mx = max(forward[0], len(s) - 1 - backward[-2], len(s) - 1 - forward[-1], backward[0])
for i in range(len(t)):
	mx = max(mx, abs(forward[i] - backward[i + 1]) - 1)
print(mx)


s = input()
t = input()
f = []
b = []
ti = 0
si = 0

def find(mylist, index):
	if index < 0:
		return 0
	return mylist[index]
while si < len(s):
	if ti < len(t) and s[si] == t[ti]:
		ti += 1
	f.append(ti)
	si += 1
si = len(s) - 1
ti = len(t) - 1
while si >= 0:
	if ti >= 0 and t[ti] == s[si]:
		ti -= 1
	b.append(len(t) - 1 - ti)
	si -= 1
ans = 0
for i in range(0, len(s)):
	l = i
	r = len(s) - 1
	mid = int((l + r) / 2)
	while l <= r:
		if find(f, i - 1) + find(b, len(s) - 2 - mid) >= len(t):
			l = mid + 1
		else:
			r = mid - 1
		mid = int((l + r) / 2)
	ans = max(ans, r - i + 1)
print(ans)


s = input()
t = input()
ar1 = []
i = 0
for j in range(len(s)):
	if i < len(t) and s[j] == t[i]:
		ar1.append(j)
		i += 1
i = len(t) - 1
ar2 = [0] * len(t)
j = len(s) - 1
while j >= 0:
	if i >= 0 and s[j] == t[i]:
		ar2[i] = j
		i -= 1
	j -= 1
ans = ar1[0]
ans = max(ans, ar2[0])
ans = max(ans, len(s) - ar1[-1] - 1)
ans = max(ans, len(s) - ar2[-1] - 1)
for i in range(len(t) - 1):
	ans = max(ans, ar2[i + 1] - ar1[i] - 1)
print(ans)


bigstr = input()
substr = input()
maxpos = 0

def is_contained(s, t):
	t_point = 0
	for idx in range(len(s)):
		if s[idx] == t[t_point]:
			t_point += 1
		if t_point == len(t):
			return True
	return False
mx = 0
for idx1 in range(len(bigstr)):
	for idx2 in range(idx1 + 1, len(bigstr) + 1):
		new_str = bigstr[:idx1] + bigstr[idx2:]
		if is_contained(new_str, substr):
			mx = max(mx, idx2 - idx1)
print(mx)


s = input()
t = input()
maxl = 0
for i in range(len(s)):
	for j in range(i, len(s)):
		pos = 0
		for p in range(len(s)):
			if p >= i and p <= j:
				continue
			if s[p] == t[pos]:
				pos += 1
			if pos == len(t):
				break
		if pos == len(t):
			maxl = max(maxl, j - i + 1)
print(maxl)


s = input()
t = input()
n = len(s)
m = len(t)
le = []
ri = []
ans = 0
p = 0
for i in range(n):
	if p < m:
		if s[i] == t[p]:
			le.append(i)
			if p == m - 1:
				ans = max(ans, n - 1 - i)
			p += 1
p = m - 1
for j in range(n - 1, -1, -1):
	if p >= 0:
		if s[j] == t[p]:
			ri.append(j)
			if p == 0:
				ans = max(ans, j - 0)
			p -= 1
ri.reverse()
for k in range(m - 1):
	ans = max(ans, ri[k + 1] - le[k] - 1)
print(ans)


def main():
	s = input()
	t = input()

	def isSub(s, t):
		k = 0
		for i in s:
			if i == t[k]:
				k += 1
				if k == len(t):
					return True
		return False
	r = 0
	for l in range(1, len(s) + 1):
		for i in range(len(s) - l + 1):
			new_s = s[:i] + s[i + l:]
			if isSub(new_s, t):
				r = l
				continue
	print(r)
main()


from sys import stdin, stdout
import math
from math import gcd, sqrt
s1 = input()
N = len(s1)
s2 = input()
M = len(s2)
asc = []
dsc = []
k = 0
for i in range(len(s1)):
	if s1[i] == s2[k]:
		asc.append(i)
		k += 1
	if k == M:
		break
k = M - 1
for i in range(len(s1) - 1, -1, -1):
	if s1[i] == s2[k]:
		dsc.append(i)
		k -= 1
	if k == -1:
		break
dsc = dsc[::-1]
res = 0
for i in range(M - 1):
	d = dsc[i + 1] - asc[i] - 1
	res = max(d, res)
res = max(res, asc[0])
res = max(res, dsc[0])
res = max(res, N - 1 - asc[-1])
res = max(res, N - 1 - dsc[-1])
print(res)


s = input()
t = input()
mxl = 0
n = len(s)
m = len(t)
for l in range(n):
	for r in range(l, n):
		j = 0
		for i in range(n):
			if l <= i <= r:
				continue
			if s[i] == t[j]:
				j += 1
				if j == m:
					mxl = max(mxl, r - l + 1)
					break
print(mxl)


s = input()
t = input()

def possible(s, t, l, r):
	t_index = 0
	s_index = 0
	while s_index < len(s) and t_index < len(t):
		if l <= s_index and r >= s_index:
			s_index += 1
			continue
		if t[t_index] == s[s_index]:
			t_index += 1
			s_index += 1
		else:
			s_index += 1
	return bool(t_index >= len(t))
ans = 0
for l in range(0, len(s)):
	for r in range(l, len(s)):
		if possible(s, t, l, r):
			ans = max(ans, r - l + 1)
print(ans)


def subsequence(s, t):
	i = 0
	if t == '':
		return True
	for c in s:
		if c == t[i]:
			if i == len(t) - 1:
				return True
			i += 1
	return False
s = input()
t = input()
k = 0
for i in range(len(s)):
	for j in range(1, min(len(s) - len(t) + 1, len(s) - i + 1)):
		s1 = s[:i] + s[i + j:]
		if subsequence(s1, t):
			k = max(k, j)
print(k)


s = input()
t = input()
n = len(s)
m = len(t)
l = [-1]
r = [n]
c = 0
for i in range(n):
	if s[i] == t[c]:
		l.append(i)
		c += 1
		if c >= m:
			break
c = 0
for i in range(n):
	if s[-1 - i] == t[-1 - c]:
		r.append(n - 1 - i)
		c += 1
		if c >= m:
			break
mx = 0
for i in range(m + 1):
	mx = max(mx, r[m - i] - l[i] - 1)
print(mx)


s = str(input())
t = str(input())
i = 0
j = 0
arr1 = []
while i < len(s):
	if s[i] == t[j]:
		arr1.append(i + 1)
		j += 1
	i += 1
	if j == len(t):
		break
i = len(s) - 1
j = len(t) - 1
arr2 = [0] * len(t)
while i >= 0:
	if s[i] == t[j]:
		arr2[j] = i + 1
		j -= 1
	i -= 1
	if j == -1:
		break
ans = max(arr2[0] - 1, len(s) - arr1[-1])
for i in range(len(t) - 1):
	ans = max(ans, arr2[i + 1] - arr1[i] - 1)
print(ans)


from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def prime_factors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def all_factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (digits - len(b)) + b
	return b

def is_prime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def generate_primes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	return prime
factorial_modP = []

def warm_up_fac(MOD):
	global factorial_modP, fac_warm_up
	if fac_warm_up:
		return
	factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
	for i in range(2, fac_warm_up_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warm_up = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	global fac_warm_up, factorial_modP
	if not fac_warm_up:
		warm_up_fac(MOD)
		fac_warm_up = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def display_2D_list(li):
	for i in li:
		print(i)

def prefix_sum(li):
	sm = 0
	res = []
	for i in li:
		sm += i
		res.append(sm)
	return res

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_search(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = False
fac_warm_up_size = 10 ** 5 + 100
optimise_for_recursion = False

def main():
	st = list(stdin.readline().strip())
	search = list(stdin.readline().strip())
	pos = len(search) - 1
	back = [0 for _ in range(len(search))]
	for (index, i) in reversed(list(enumerate(st))):
		if i == search[pos]:
			back[pos] = index
			pos -= 1
			if pos == -1:
				break
	pos = 0
	maxi = 0
	for (i, ele) in enumerate(st):
		if pos == len(search):
			k = len(st) - i
		else:
			k = back[pos] - i
		maxi = max(maxi, k)
		if pos < len(search) and ele == search[pos]:
			pos = pos + 1
	print(maxi)
if TestCases:
	for i in range(get_int()):
		main()
else:
	main() if not optimise_for_recursion else threading.Thread(target=main).start()


def solve(s, t):
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)
s = input()
t = input()
c = 0
for i in range(len(s) + 1):
	for j in range(i, len(s) + 1):
		if solve(s[:i] + s[j:], t):
			c = max(j - i, c)
print(c)


s = input()
t = input()
(n, m) = (len(s), len(t))
(i, j) = (0, 0)
first = []
last = []
while j < m:
	if s[i] == t[j]:
		first.append(i)
		i += 1
		j += 1
	else:
		i += 1
(i, j) = (n - 1, m - 1)
while j >= 0:
	if s[i] == t[j]:
		last.append(i)
		j -= 1
	i -= 1
last = last[::-1]
ans = max(last[0], n - first[-1] - 1)
for i in range(m - 1):
	ans = max(ans, last[i + 1] - first[i] - 1)
print(ans)


import sys
input = sys.stdin.readline
s = list(input().rstrip())
t = list(input().rstrip())
(n, m) = (len(s), len(t))
j = 0
(l, r) = ([-1] * m, [-1] * m)
for i in range(n):
	if s[i] == t[j]:
		l[j] = i
		j += 1
	if j == m:
		break
j = m - 1
for i in range(n - 1, -1, -1):
	if s[i] == t[j]:
		r[j] = i
		j -= 1
	if j == -1:
		break
ans = max(n - l[-1] - 1, r[0])
for i in range(m - 1):
	ans = max(ans, r[i + 1] - l[i] - 1)
print(ans)