Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphaset = set(s)
cache = []

def search(origin, c, offset):
    if c not in alphaset:
        return None
    offset = offset % len(origin)
    o = origin[offset:] + origin
    try:
        return o.index(c)
    except ValueError:
        return None


cache.append({c2: 0 for c2 in alphabet})
for c2 in alphabet:
    offset2 = search(s, c2, 1)
    if offset2 is None:
        cache[0][c2] = None
        continue
    cache[0][c2] = offset2 + 1
for i in range(1, len(s)):
    cache.append({c2: 0 for c2 in alphabet})
    for c2 in alphabet:
        if s[i] == c2:
            offset2 = search(s, c2, i + 1)
            if offset2 is None:
                cache[i][c2] = None
                continue
            cache[i][c2] = offset2 + 1
        else:
            offset2 = cache[i-1][c2]
            if offset2 is None:
                cache[i][c2] = None
                continue
            cache[i][c2] = offset2 - 1


a = search(s, t[0], 0)
if a is None:
    print(-1)
    exit()

result = a
for i in range(1, len(t)):
    k = cache[result % len(s)][t[i]]
    if k is None:
        print(-1)
        exit()
    result += k

print(result+1)


Fixed submission:
from bisect import bisect
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
char = {c: [] for c in alphabet}
for i, c in enumerate(s):
    char[c].append(i)

if len(char[t[0]]) == 0:
    print(-1)
    exit()

result = char[t[0]][0]

for c in t[1:]:
    if len(char[c]) == 0:
        print(-1)
        exit()
    idx = bisect(char[c], result % len(s))
    result = result - result % len(s)
    try:
        result += char[c][idx]
    except IndexError:
        result += len(s) + char[c][0]

print(result+1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphaset = set(s)
cache = []

def search(origin, c, offset):
    if c not in alphaset:
        return None
    offset = offset % len(origin)
    o = origin[offset:] + origin
    try:
        return o.index(c)
    except ValueError:
        return None

for i in range(len(s)):
    cache.append({c2: 0 for c2 in alphabet})
    for c2 in alphabet:
        offset2 = search(s, c2, i+1)
        if offset2 is None:
            cache[i][c2] = None
            continue
        cache[i][c2] = offset2 + 1

a = search(s, t[0], 0)
if a is None:
    print(-1)
    exit()

result = a
for i in range(1, len(t)):
    k = cache[result % len(s)][t[i]]
    if k is None:
        print(-1)
        exit()
    result += k

print(result+1)


Fixed submission:
from bisect import bisect
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
char = {c: [] for c in alphabet}
for i, c in enumerate(s):
    char[c].append(i)

if len(char[t[0]]) == 0:
    print(-1)
    exit()

result = char[t[0]][0]

for c in t[1:]:
    if len(char[c]) == 0:
        print(-1)
        exit()
    idx = bisect(char[c], result % len(s))
    result = result - result % len(s)
    try:
        result += char[c][idx]
    except IndexError:
        result += len(s) + char[c][0]

print(result+1)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
cache = []

def search(origin, c, offset):
    offset = offset % len(origin)
    o = origin[offset:] + origin
    try:
        return o.index(c)
    except ValueError:
        return None

for i in range(len(s)):
    cache.append({c2: 0 for c2 in alphabet})
    for c2 in alphabet:
        offset2 = search(s, c2, i+1)
        if offset2 is None:
            cache[i][c2] = None
            continue
        cache[i][c2] = offset2 + 1

a = search(s, t[0], 0)
if a is None:
    print(-1)
    exit()

result = a
for i in range(1, len(t)):
    k = cache[result % len(s)][t[i]]
    if k is None:
        print(-1)
        exit()
    result += k

print(result+1)


Fixed submission:
from bisect import bisect
s = input()
t = input()

alphabet = 'abcdefghijklmnopqrstuvwxyz'
char = {c: [] for c in alphabet}
for i, c in enumerate(s):
    char[c].append(i)

if len(char[t[0]]) == 0:
    print(-1)
    exit()

result = char[t[0]][0]

for c in t[1:]:
    if len(char[c]) == 0:
        print(-1)
        exit()
    idx = bisect(char[c], result % len(s))
    result = result - result % len(s)
    try:
        result += char[c][idx]
    except IndexError:
        result += len(s) + char[c][0]

print(result+1)