Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[] for _ in range(lens)]
    for i in range(lens):
        for j in sett:
            index[i].append(s2[i:].index(j))
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        ans += index[n % lens][j] + 1
        n += index[n % lens][j] + 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[-1] * len(sett) for _ in range(lens)]
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        if index[n][j] == -1:
            index[n][j] = s2[n:].index(i)
        ans += index[n][j] + 1
        n += index[n][j] + 1
        n %= lens
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[] for _ in range(lens)]
    for i in range(lens):
        for j in sett:
            index[i].append(s2[i:].index(j))
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        ans += index[n % lens][j] + 1
        n += index[n % lens][j] + 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[-1] * len(sett) for _ in range(lens)]
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        if index[n][j] == -1:
            index[n][j] = s2[n:].index(i)
        ans += index[n][j] + 1
        n += index[n][j] + 1
        n %= lens
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    lent = len(t)
    lensett = len(sett)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[] for _ in range(lens)]
    for i in range(lens):
        x = s[i:] + s[:i]
        for j in sett:
            index[i].append(x.index(j))
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        ans += index[n % lens][j] + 1
        n += index[n % lens][j] + 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[-1] * len(sett) for _ in range(lens)]
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        if index[n][j] == -1:
            index[n][j] = s2[n:].index(i)
        ans += index[n][j] + 1
        n += index[n][j] + 1
        n %= lens
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()
    sett = list(set((t)))
    for i in sett:
        if i not in s:
            print(-1)
            return
    lens = len(s)
    lent = len(t)
    lensett = len(sett)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[] for _ in range(lens)]
    for i in range(lens):
        x = s[i:] + s[:i]
        for j in sett:
            index[i].append(x.index(j))
    ans = 0
    n = 0
    for i in t:
        j = sett.index(i)
        ans += index[n % lens][j] + 1
        n += index[n % lens][j] + 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[-1] * len(sett) for _ in range(lens)]
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        if index[n][j] == -1:
            index[n][j] = s2[n:].index(i)
        ans += index[n][j] + 1
        n += index[n][j] + 1
        n %= lens
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()
    sdash = s * 2
    ans = 0
    for i in t:
        if not i in s:
            print(-1)
            return
        index = sdash.index(i) + 1
        ans += index
        sdash = sdash[index:] + sdash[:index]
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    s = input()
    t = input()
    s2 = s * 2
    sett = list(set((t)))
    settindex = {}
    for i in sett:
        settindex[i] = sett.index(i)
        if i not in s:
            print(-1)
            return
    lens = len(s)
    # index[i文字目以降][settのindex]に何文字目にあるかが格納される
    index = [[-1] * len(sett) for _ in range(lens)]
    ans = 0
    n = 0
    for i in t:
        j = settindex[i]
        if index[n][j] == -1:
            index[n][j] = s2[n:].index(i)
        ans += index[n][j] + 1
        n += index[n][j] + 1
        n %= lens
    print(ans)


if __name__ == '__main__':
    main()