Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
N, M = len(s), len(t)

if t in s:
    print(s.find(t) + len(t))

else:
    schr, indchr = dict(), dict()
    for i in range(N):
        if s[i] in schr:
            schr[s[i]].append(i+1) 
        else:
            schr[s[i]] = [i+1]
            indchr[s[i]] = 0

    schrset = set(schr)
    ans, pos, back = 0, 0, True
    for i in range(M):
        if t[i] in schrset:
            c = schr[t[i]]
            if c[-1] <= pos:
                ans += N - pos + c[0]
                pos = c[0]
                if not back:
                    for x in indchr.keys():
                        indchr[x] = 0
                    back = True
            else:
                while c[indchr[t[i]]] <= pos:
                    indchr[t[i]] += 1
                ans += c[indchr[t[i]]] - pos
                pos, back = c[indchr[t[i]]], False
        else:
            print(-1)
            exit()
    print(ans)

Fixed submission:
s = input()
t = input()
N, M = len(s), len(t)

schr, indchr = dict(), dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]
        indchr[s[i]] = 0

schrset = set(schr)
ans, pos, pre, back = 0, 0, set(), True
for i in range(M):
    if t[i] in schrset:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
            if not back:
                for x in indchr.keys():
                    indchr[x] = 0
                back, pre = True, set()
        else:
            j = indchr[t[i]]
            while c[j] <= pos:
                j += 1
            if j > 0:
                pre.add(t[i])
            ans += c[j] - pos
            pos, back, indchr[t[i]] = c[j], False, j
    else:
        print(-1)
        exit()
print(ans)

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

if t in s:
    print(s.find(t) + len(t))
else:
    schr = dict()
    for i in range(N):
        if s[i] in schr:
            schr[s[i]].append(i+1) 
        else:
            schr[s[i]] = [i+1]

    schrset = set(schr)
    ans, pos, pre, back = 0, 0, "#", False
    for i in range(len(t)):
        if t[i] in schrset:
            c = schr[t[i]]
            if c[-1] <= pos:
                ans += N - pos + c[0]
                pos, back = c[0], True
            else:
                if pre != t[i] or back:
                    j = 0
                while c[j] <= pos:
                    j += 1
                ans += c[j] - pos
                pos, pre, back = c[j], t[i], False
        else:
            print(-1)
            exit()
    print(ans)

Fixed submission:
s = input()
t = input()
N, M = len(s), len(t)

schr, indchr = dict(), dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]
        indchr[s[i]] = 0

schrset = set(schr)
ans, pos, pre, back = 0, 0, set(), True
for i in range(M):
    if t[i] in schrset:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
            if not back:
                for x in indchr.keys():
                    indchr[x] = 0
                back, pre = True, set()
        else:
            j = indchr[t[i]]
            while c[j] <= pos:
                j += 1
            if j > 0:
                pre.add(t[i])
            ans += c[j] - pos
            pos, back, indchr[t[i]] = c[j], False, j
    else:
        print(-1)
        exit()
print(ans)

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

if t in s:
    print(s.find(t) + len(t))
else:
    schr = dict()
    for i in range(N):
        if s[i] in schr:
            schr[s[i]].append(i+1) 
        else:
            schr[s[i]] = [i+1]

    schrset = set(schr)
    ans, pos, pre = 0, 0, "#"
    for i in range(len(t)):
        if t[i] in schrset:
            c = schr[t[i]]
            if c[-1] <= pos:
                ans += N - pos + c[0]
                pos = c[0]
            else:
                if pre != t[i]:
                    j = 0
                while c[j] <= pos:
                    j += 1
                ans += c[j] - pos
                pos = c[j]
        else:
            print(-1)
            exit()
    print(ans)

Fixed submission:
s = input()
t = input()
N, M = len(s), len(t)

schr, indchr = dict(), dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]
        indchr[s[i]] = 0

schrset = set(schr)
ans, pos, pre, back = 0, 0, set(), True
for i in range(M):
    if t[i] in schrset:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
            if not back:
                for x in indchr.keys():
                    indchr[x] = 0
                back, pre = True, set()
        else:
            j = indchr[t[i]]
            while c[j] <= pos:
                j += 1
            if j > 0:
                pre.add(t[i])
            ans += c[j] - pos
            pos, back, indchr[t[i]] = c[j], False, j
    else:
        print(-1)
        exit()
print(ans)

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

schr = dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]

ans, pos = 0, 0
for i in range(len(t)):
    if t[i] in schr:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
        else:
            j = 0
            while c[j] <= pos:
                j += 1
            ans += c[j] - pos
            pos = c[j]
    else:
        print(-1)
        exit()
print(ans)

Fixed submission:
s = input()
t = input()
N, M = len(s), len(t)

schr, indchr = dict(), dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]
        indchr[s[i]] = 0

schrset = set(schr)
ans, pos, pre, back = 0, 0, set(), True
for i in range(M):
    if t[i] in schrset:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
            if not back:
                for x in indchr.keys():
                    indchr[x] = 0
                back, pre = True, set()
        else:
            j = indchr[t[i]]
            while c[j] <= pos:
                j += 1
            if j > 0:
                pre.add(t[i])
            ans += c[j] - pos
            pos, back, indchr[t[i]] = c[j], False, j
    else:
        print(-1)
        exit()
print(ans)