Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
trees_num, illuminations_num = map(int, input().split())
trees = sorted(int(input()) for _ in range(trees_num))

diffs = []

for i in range(trees_num - illuminations_num + 1):
    h_max = max(trees[i:illuminations_num+1])
    h_min = min(trees[i:illuminations_num+1])

    diffs.append(h_max - h_min)

print(min(diffs))


Fixed submission:
trees_num, illuminations_num = map(int, input().split())
trees = sorted(int(input()) for _ in range(trees_num))

diffs = []

for i in range(trees_num - illuminations_num + 1):
    diffs.append(trees[i+illuminations_num-1] - trees[i])

print(min(diffs))
Buggy python submission (verdict: Runtime Error):
N = int(input())
x_li = list(map(int, input().split()))
import math
ans = math.inf
for i in range(1, 101):
    d = 0
    for j in range(N):
        d += (x_li[j] - i) ** 2
    ans = min(ans, d)
print(ans)


Fixed submission:
N = int(input())
x_li = list(map(int, input().split()))
ans = 10000000000000
for i in range(1, 101):
    d = 0
    for j in range(N):
        d += (x_li[j] - i) ** 2
    ans = min(ans, d)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()
ans = 0

for i in range(n - 1):
    if s[i] == s[i + 1] :
        ans += 1
print(min(n-1, ans + 2 * k))

Fixed submission:
n = int(input())
print(n * n * n)
Buggy python submission (verdict: Runtime Error):
import itertools

n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1    
    s_li.append(s_i)

ans = 0

for i in range(n):
    for j in range(n):
        if i >= j :
            continue
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)

Fixed submission:
a,b = map(int,input().split())

print(max(a + b, a - b, a * b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

ans = 0

for i in range(n):
    for j in reversed(range(n)):
        if i >= j :
            break
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)


Fixed submission:
n = int(input())
s_li = [input() for i in range(n)]

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

ans = 0

for i in range(n):
    for j in range(n):
        if i >= j :
            continue
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)

Fixed submission:
n = int(input())
s_li = [input() for i in range(n)]

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

ans = 0

for i in range(n):
    for j in range(n):
        if i >= j :
            continue
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)

Fixed submission:
n = int(input())
s_li = [input() for i in range(n)]

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1    
    s_li.append(s_i)

ans = 0

for i in range(n):
    for j in range(n):
        if i >= j :
            continue
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)

Fixed submission:
n = int(input())
s_li = [input() for i in range(n)]

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
L,R = map(int,input().split())

# Rが2019未満のとき
if R < 2019 :
    print((L * (L + 1)) % 2019)
# 範囲内に2019を含む時
elif L <= 2019 and R >= 2019 :
    print(0)
# LもRも2019より高い場合
else :
    R = min(R, L + 2018)
    ans = 2018
    for i in range(L,R + 1):
        b = i + 1
        for j in range(b,R + 1):
            x = (i * j) % 2019
            ans = min(ans, x)
    print(ans)


Fixed submission:
N,A,B = map(int,input().split())
if N * A < B :
    print(N * A)
else :
    print(B)
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())

# Rが2019未満のとき
if R < 2019 :
    print((L * (L + 1)) % 2019)
# 範囲内に2019を含む時
elif L <= 2019 and R >= 2019 :
    print(0)
# LもRも2019より高い場合
else :
    R = min(R, L + 4038)
    ans = 2018
    for i in range(L,R + 1):
        for j in range(i + 1,R + 1):
            x = (i * j) % 2019
            ans = min(ans, x)
    print(ans)


Fixed submission:
L,R = map(int,input().split())

# Rが2019未満のとき
if R < 2019 :
    print((L * (L + 1)) % 2019)
# 範囲内に2019を含む時
elif L <= 2019 and R >= 2019 :
    print(0)
# LもRも2019より高い場合
else :
    R = min(R, L + 2018)
    ans = 2018
    for i in range(L,R + 1):
        b = i + 1
        for j in range(b,R + 1):
            x = (i * j) % 2019
            ans = min(ans, x)
    print(ans)
Buggy python submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(0, N, R):
    if r * R > N :
        break
    for g in range(0, N + 1int(N / G) + 1) :
        if r * R + g * G > N :
            break
        b = (N - r * R - g * G) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(0, N + 1, R):
    if r > N :
        break
    for g in range(r, N + 1, G) :
        if g > N :
            break
        b = (N - g) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(int(N / R) + 1):
    for g in range(int(N / G) + 1) :
        if r * R + g * G > N :
            break
        b = (N - r * R - g * G) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(0, N + 1, R):
    if r > N :
        break
    for g in range(r, N + 1, G) :
        if g > N :
            break
        b = (N - g) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(int(N / R) + 1):
    for g in range(int(N / G) + 1) :
        b = (N - r * R - g * G) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(0, N + 1, R):
    if r > N :
        break
    for g in range(r, N + 1, G) :
        if g > N :
            break
        b = (N - g) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int,input().split())
count = 0
x = int(N / R)
y = int(N / G)
z = int(N / B)
rg_list = []
for r in range(x + 1):
    for g in range(y + 1):
        buf = r * R + g * G
        if buf == N :
            count += 1
        if buf < N :
            rg_list.append(buf)
rg_list.sort()
# sprint(rg_list)

rg_count_list = []
for i in range(N):
    rg_count_list.append(rg_list.count(i))

for b in range(z + 1):
    for rg in range(len(rg_count_list)):
        if rg + b*B == N :
            count += rg_count_list[rg]
        if rg + b*B > N :
            break
print(count)


Fixed submission:
R, G, B, N = map(int, input().split())
ans = 0
for r in range(0, N + 1, R):
    if r > N :
        break
    for g in range(r, N + 1, G) :
        if g > N :
            break
        b = (N - g) / B
        if b >= 0 and b.is_integer() :
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

coord = [a, b, c, d, e]
for i in range(len(coord)):
    for j in range(len(coord)):
        if abs(coord[i] - coord[j]) > k :
            print(":(")
            sys.exit(1)
print("Yay!")

Fixed submission:
import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

coord = [a, b, c, d, e]
flag = False
for i in range(len(coord)):
    for j in range(len(coord)):
        dis = abs(coord[i] - coord[j])
        if dis > k :
            flag = True
if flag == True :
    print(":(")
else :
    print("Yay!")
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C = map(int, input().split())
ans = 0
c = C
for i in range(C) :
    if c > 0 and B > 0 :
        ans += 2
        c -= 1
        B -= 1
    elif c > 0 and A > 0 :
        ans += 1
        c -= 1
        A -= 1
if c > 0 :
    ans += 1
print(ans + B)


Fixed submission:
A, B, C = map(int, input().split())
ans = 0
if B >= C :
    print(B + C)
    exit()
ans = 2 * B
C -= B
if A >= C :
    print(ans + C)
    exit()
print(ans + A + 1)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

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

n = input()
a_li = list(map(int,input().split()))

lcm_a = 0
for i in range(len(a_li)) :
    if i == 0 :
        lcm_a = a_li[i]
    else :
        lcm_a = lcm(lcm_a, a_li[i])

m = lcm_a - 1
f = 0
for i in range(len(a_li)) :
    f = f + m % a_li[i]

print(f)

Fixed submission:
n = input()
a_li = list(map(int,input().split()))

f = 0
for i in range(len(a_li)) :
    f = f + a_li[i] - 1

print(f)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0: return a
    mod = a % b
    buf = gcd(b, mod)
    return buf

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

n = input()
a_li = list(map(int,input().split()))

lcm_a = 0
for i in range(len(a_li)) :
    if i == 0 :
        lcm_a = a_li[i]
    else :
        lcm_a = lcm(lcm_a, a_li[i])

m = lcm_a - 1
f = 0
for i in range(len(a_li)) :
    f = f + m % a_li[i]

print(f)

Fixed submission:
n = input()
a_li = list(map(int,input().split()))

f = 0
for i in range(len(a_li)) :
    f = f + a_li[i] - 1

print(f)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

t = stdin.readline()
t_i = int(t)
data = [stdin.readline().rstrip().split() for _ in range(t_i)]
#print(data)
for i in range(t_i) :
    a = int(data[i][0])
    b = int(data[i][1])
    c = int(data[i][2])
    d = int(data[i][3])
    #print(a, b, c, d)
    if a < b :
        print("No")
    elif b > d :
        print("No")
    elif a % b > c and a % b < b :
        print("No")
    else :
        #print("Yes")
    
        stock = a
        count = 0
        while True :
            stock = stock - b
            if stock < 0 :
                print("No")
                break
            if stock <= c :
                stock = stock + d
            count = count + 1
            if count > 10000 :
                print("Yes")
                break

        


Fixed submission:
from sys import stdin

n = stdin.readline()
n_i = int(n)

a = stdin.readline().rstrip().split()
a_list = list(a)

n_count = 0

if len(a_list) == 2 and a_list[0] == a_list[1] :
    print(n_count + 1)
else :
    for i in range(n_i):
        if i == n_i - 1 :
            break
        if a_list[i] == a_list[i + 1]:
            n_count = n_count + 1
            a_list[i + 1] = "X"

    print(n_count)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())

if N % 2 == 0 :
    print(N)
else :
    print((2 * N) // math.gcd(2, N))


Fixed submission:
N = int(input())
#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

print(lcm(2,N))
Buggy python submission (verdict: Runtime Error):
from sys import stdin



n_s, k_s = stdin.readline().rstrip().split() # 問題文に出てくるA，B，Cが空白区切りで1行で入力される場合はアンパック代入が便利
a_s_l = stdin.readline().rstrip().split() # 問題文に出てくるA，B，Cが空白区切りで1行で入力される場合はアンパック代入が便利

N = int(n_s)
K = int(k_s)
#A = []
"""
for i in a_s_l:
    A.append(int(i))
"""
A = list(map(int, a_s_l))
#AA = A
count = 0
j = K - 1
for i, a in enumerate(A):
    if N == K :
        count = count + 1
        break
    elif i > N - K:
        #buf = A[N - K : N]
        count = count + 1
    elif j== i :
        #buf = A[i : i + K]
        count = count + 1
        j = i + K - 1
    
print(count)


Fixed submission:
from sys import stdin

a = stdin.readline().rstrip()
a_list = list(a)

count = 0
for i in a_list:
    if i == '+' :
        count = count + 1
    if i == '-' :
        count = count - 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_li = list(map(int, input().split()))
s_li = [0]
for i in range(N) :
    s_li.append(s_li[i] + A_li[i])
s_num = set(s_li)
ans = 0
for sn in s_num :
    cnt = s_li.count(sn)
    ans += cnt * (cnt - 1) // 2
print(ans)

Fixed submission:
N = int(input())
A_li = list(map(int, input().split()))
s_li = [0]
for i in range(N) :
    s_li.append(s_li[i] + A_li[i])
s_dic = {}
for s in s_li :
    if s in s_dic :
        s_dic[s] += 1
    else :
        s_dic[s] = 1
ans = 0
for sd in s_dic.values() :
    ans += sd * (sd - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
li = [i for i in range(A, B + 1)]
for i, l in enumerate(li) :
    if i + 1 <= K or len(li) - i <= K :
        print(l)


Fixed submission:
A, B, K = map(int, input().split())
for i in range(A, A + K):
    if i == B + 1:
        break
    print(i)
for j in range(B - K + 1, B + 1):
    if j <= i :
        continue
    print(j)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
stu_li = [list(map(int, input().split())) for i in range(N)]
chk_li = [list(map(int, input().split())) for i in range(M)]

import math
min_dist = math.inf
min_num = M
for i in range(N) :
    for j in range(M) :
        dist = abs(stu_li[i][0] - chk_li[j][0]) + abs(stu_li[i][1] - chk_li[j][1])
        if dist < min_dist : 
            min_dist = dist
            min_num = j
    print(min_num + 1)
    min_dist = math.inf
    min_num = M


Fixed submission:
N, M = map(int, input().split())
stu_li = [list(map(int, input().split())) for i in range(N)]
chk_li = [list(map(int, input().split())) for i in range(M)]

min_dist = 10 ** 10
min_num = M
for i in range(N) :
    for j in range(M) :
        dist = abs(stu_li[i][0] - chk_li[j][0]) + abs(stu_li[i][1] - chk_li[j][1])
        if dist < min_dist : 
            min_dist = dist
            min_num = j
    print(min_num + 1)
    min_dist = 10 ** 10
    min_num = M
Buggy python submission (verdict: Runtime Error):
li = input().split()
if li[1] == "+":
  print(li[0] + li[2])
else :
  print(li[0] - li[2])

Fixed submission:
li = input().split()
if li[1] == "+":
    print(int(li[0]) + int(li[2]))
else :
    print(int(li[0]) - int(li[2]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
list_S = []
for i in range(N):
  a = str(input())
  if not a in list_S: list_S.append(a)
print(len(list_S))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  if not str(input()) in list_S: list_S.append(str(input()))
print(len(list_S))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  if not str(input()) in list_get: list_S.append(str(input()))
print(len(list_S))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  if not str(input()) in list_get: list_S.append(str(input()))
print(len(list_get))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
list_S = []
for i in range(N):
  list_S.append(str(input()))

list_get = []
for i in range(len(list_S)):
  if not list_S[i] in list_get:
    list_get.append(list_S[i])

print(len(list_get))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  list_S.append(str(input()))

list_get = []
for i in range(list_S):
  if not list_S[i] in list_get:
    list_get.append(list_S[i])

print(len(list_get))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  list_S.append(str(input()))

list_get = []
for i in range(list_S):
  if not list_S[i] in list_get: list_get.append(list_S[i])

print(len(list_get))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  list_S.append(str(input()))

list_get = []
for i in list_S:
  if not list_S[i] in list_get: list_get.append(list_S[i])

print(len(list_get))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
list_S = []
for i in range(N):
  list_S.append(input())

list_get = []
for i in list_S:
  if not list_S[i] in list_get: list_get.append(list_S[i])

print(len(list_get))

Fixed submission:
N = int(input())
list_S = [str(input()) for i in range(N)]
print(len(list(set(list_S))))
Buggy python submission (verdict: Runtime Error):
N, D = map(int, input().split())
print(math.ceil(N/(2*D+1)))


Fixed submission:
import math
N, D = map(int, input().split())
print(math.ceil(N/(2*D+1)))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

print( (a-1)*(b-1))


Fixed submission:
a, b = map(int, input().split())
 
print( (a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
print(math.factorial(N) % (10**9+7)

Fixed submission:
import math
N = int(input())
print(math.factorial(N)%(10**9+7))

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
print(math.factorial(N)%(10**9+7)

Fixed submission:
import math
N = int(input())
print(math.factorial(N)%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def max(a, b):
    return a if a > b else b
 
def is_match(string, pattern):
    # print(string, pattern)
    pat_len = len(pattern)
    skip = [pat_len for _ in range(256)]
    for i in range(pat_len):
        skip[ord(pattern[i])] = pat_len - i - 1
    i = pat_len - 1
    while i < len(string):
        j = pat_len - 1
        while string[i] == pattern[j]:
            if j == 0:
                return True
            i -= 1
            j -= 1
        i = i + max(skip[ord(string[i])], pat_len-j)
    return None


def main():
    N = int(input())
    S = input()

    dp = [0] * N

    for i in range(1, N):
        length = dp[i - 1] + 1
        match_string = S[i - length + 1: i + 1]
        matched_string = S[:i+1-length]
        # print(match_string, matched_string)
        if is_match(matched_string, match_string):
            dp[i] = dp[i - 1] + 1
        else:
            dp[i] = dp[i - 1]
        # print(dp[i])
    
    # print(dp)
    print(dp[-1])



if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def max(a, b):
    return a if a > b else b
 
def is_match(string, pattern):
    # print(string, pattern)
    # pat_len = len(pattern)
    # skip = [pat_len for _ in range(256)]
    # for i in range(pat_len):
    #     skip[ord(pattern[i])] = pat_len - i - 1
    # i = pat_len - 1
    # while i < len(string):
    #     j = pat_len - 1
    #     while string[i] == pattern[j]:
    #         if j == 0:
    #             return True
    #         i -= 1
    #         j -= 1
    #     i = i + max(skip[ord(string[i])], pat_len-j)
    # return None
    if pattern in string:
        return True
    else:
        return False


def main():
    N = int(input())
    S = input()

    dp = [0] * N

    for i in range(1, N):
        length = dp[i - 1] + 1
        match_string = S[i - length + 1: i + 1]
        matched_string = S[:i+1-length]
        # print(match_string, matched_string)
        if is_match(matched_string, match_string):
            dp[i] = dp[i - 1] + 1
        else:
            dp[i] = dp[i - 1]
        # print(dp[i])
    
    # print(dp)
    print(dp[-1])



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
import sys
import bisect
sys.setrecursionlimit(10000000)

def main():
    s = input()
    t = input()
    alphabets = dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"), None)
    # alphabets = alphabet.copy()
    for key_ in alphabets:
        lists = []
        for i in range(len(s)):
            if key_ == s[i]:
                lists.append(i)
        alphabets[key_] = lists
    # print(alphabets)
    now = -1
    count = 0
    for alpha in t:
        if alphabets[alpha] is None:
            print(-1)
            sys.exit()
        else:
            lists = alphabets[alpha]
            index = bisect.bisect_left(lists, now)
            if index >= len(lists):
                now = -1
                count += len(s)
                index = bisect.bisect_left(lists, now)
                now = lists[index]
            else:
                now = lists[index]
            # print(now, count)
    print(count + now + 1)
            







if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np
import math
import sys
import bisect
sys.setrecursionlimit(10000000)

def main():
    s = input()
    t = input()
    alphabets = dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"), None)
    # alphabets = alphabet.copy()
    for key_ in alphabets:
        lists = []
        for i in range(len(s)):
            if key_ == s[i]:
                lists.append(i)
        alphabets[key_] = lists
    now = -1
    count = 0
    for alpha in t:
        if len(alphabets[alpha]) == 0:
            print(-1)
            sys.exit()
        else:
            lists = alphabets[alpha]
            index = bisect.bisect_right(lists, now)
            if index >= len(lists):
                now = -1
                count += len(s)
                now = lists[0]
            else:
                now = lists[index]
            # print(now, count)
    print(count + now + 1)
            







if __name__ == '__main__':
    main()