Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
m=s[-1]
n=s[-2]
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m):
    print(m)
  else:
    print(n)

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
m=s[-1]
n=s[-2]
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m:
    print(m)
  else:
    print(n)

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m or l.count(m)!=1):
    print(m)
  else:
    print(s[-2])

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(input()) for i in range(n)]
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]==m and l.count(m)==1):
    print(sorted(l)[-2])
  else:
    print(m)


Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(input()) for i in range(n)]
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m or l.count(m)!=1):
    print(m)
  else:
    print(sorted(l)[-2])

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[int(input()) for i in range(n)]
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m):
    print(m)
  else:
    s=[x for x in l if x!=m]
    print(max(s))
  

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(input()) for i in range(n)]
nums=[i for i in range(n)]
for num in nums:
  s=l[:num]+l[num+1:]
  print(max(s))
  

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(input()) for i in range(n)]
nums=[i for i in range(n)]
for num in nums:
  s=l[:num]+l[num+1:]
  print(max(s))
  

Fixed submission:
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)
Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
a=l[0]
p=l[1]
print((3a+p)//2)

Fixed submission:
l=list(map(int,input().split()))
a=l[0]
p=l[1]
print((3*a+p)//2)
Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
r=l[0]
D=l[1]
x=l[2]
t=[x]
for i in t:
  m=i*r-D
  t.append(m)
  if(len(t)=11):
    break
for p in t[1:]:
	print(p)


Fixed submission:
l=list(map(int,input().split()))
r=l[0]
D=l[1]
x=l[2]
t=[x]
for i in t:
  m=i*r-D
  t.append(m)
  if(len(t)==11):
    break
for p in t[1:]:
	print(p)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
nums=[x+1 for x in range(n)]
cnt=0
ans=0
for i in nums:
  cnt=0
  for t in l:
    if(t[0]<=i<=t[1]):
      cnt+=1
  if(cnt==len(l)):
    ans+=1
print(ans)

Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
nums=[x+1 for x in range(n)]
ans=0
r=[0,100000]
for i in l:
  r[0]=max(r[0],i[0])
  r[1]=min(r[1],i[1])
for i in nums:
  if(r[0]<=i<=r[1]):
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
l=[int(input()) for in in range(3)]
a=l[0]
b=l[1]
h=l[2]
print((a+b)*h//2)

Fixed submission:
l=[int(input()) for i in range(3)]
a=l[0]
b=l[1]
h=l[2]
print((a+b)*h//2)

Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
a=l[0]
b=l[1]
h=l[2]
print((a+b)*h//2)

Fixed submission:
l=[int(input()) for i in range(3)]
a=l[0]
b=l[1]
h=l[2]
print((a+b)*h//2)
Buggy python submission (verdict: Runtime Error):
a,b=input()
a=a+b
if a-24>=0:
  print(a-24)
else:
  print(a)

Fixed submission:
a=input()
a=a.split(" ")
b=int(a[1])
a=int(a[0])
a=a+b
if a-24>=0:
  print(a-24)
else:
  print(a)
Buggy python submission (verdict: Runtime Error):
result = "{:}{:}".format(T, S)

print(result)

Fixed submission:
S, T = input().split()

result = T + S

print(result)

Buggy python submission (verdict: Runtime Error):
result = "{}{}".format(T, S)

print(result)

Fixed submission:
S, T = input().split()

result = T + S

print(result)

Buggy python submission (verdict: Runtime Error):
result = "{}{}".format(S, T)
print(result)

Fixed submission:
S, T = input().split()

result = T + S

print(result)

Buggy python submission (verdict: Runtime Error):
"{}{}".fromat(S, T)

Fixed submission:
S, T = input().split()

result = T + S

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
inf = float('inf')

H, W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [list(map(int,input().split())) for _ in range(H)]

# dp[i][j][k] := (i,j)にk = 赤-青で到達できるか (-(H+W)*K <= k <= +(H+W)*K)
dp = [[[0] * (2*(H+W)*80 + 1) for _ in range(W)] for _ in range(H)]
adjust = (H+W) * 80
d = A[0][0] - B[0][0]
dp[0][0][d + adjust] = 1
dp[0][0][-d + adjust] = 1

for i in range(H):
    for j in range(W):
        d = A[i][j] - B[i][j]
        for k in range(2*(H+W)*80 + 1):
            res = 0
            try:
                res |= dp[i-1][j][k-d]
            except:
                pass
            try:
                res |= dp[i-1][j][k+d]
            except:
                pass
            try:
                res |= dp[i][j-1][k-d]
            except:
                pass
            try:
                res |= dp[i][j-1][k+d]
            except:
                pass
            dp[i][j][k] |= res

ans = inf

for k in range(2*(H+W)*80 + 1):
    if dp[H-1][W-1][k]:
        ans = min(ans, abs(k-adjust))

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
inf = float('inf')

H, W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
A = np.array(A)
B = [list(map(int,input().split())) for _ in range(H)]
B = np.array(B)
D = A - B
D = np.vectorize(abs)(D)

N = (H + W) * 80
M = 2*N + 1
# [-N, N] を [0,2*N] として扱う(右にNだけずらす)
dp = [[np.zeros(M, np.bool) for _ in range(W)] for _ in range(H)]
d = D[0][0]
dp[0][0][d+N] = 1
dp[0][0][-d+N] = 1

for i, Di in enumerate(D):
    for j, Dij in enumerate(Di):
        if i != 0:
            dp[i][j][Dij:M] |= dp[i-1][j][0:M-Dij]
            dp[i][j][0:M-Dij] |= dp[i-1][j][Dij:M]
        if j != 0:
            dp[i][j][Dij:M] |= dp[i][j-1][0:M-Dij]
            dp[i][j][0:M-Dij] |= dp[i][j-1][Dij:M]

ind = np.where(dp[H-1][W-1])[0]
ind -= N
ans = np.vectorize(abs)(ind).min()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

def judge(n):
    j = 0
    for i in range(N):
        if S[i] == n[j]:
            j += 1
        if j == 3:
            return True
    return False

ans = 0

for num in range(1000):
    num = str(num)
    num = "0" * (3-len(num)) + num
    if judge(num):
        ans += 1

print(ans)

Fixed submission:
N = int(input())
S = input()

def judge(n):
    j = 0
    for i in range(N):
        if S[i] == n[j]:
            j += 1
        if j == 3:
            return True
    return False

ans = 0

for num in range(1000):
    num = str(num)
    num = "0" * (3-len(num)) + num
    if judge(num):
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
inf = float('inf')

# 一点更新　区間取得　1-indexed
class SegmentTree:
    def __init__(self, n):
        tmp = 1
        while tmp < n:
            tmp <<= 1
        # self.N : 完全二分木の葉の数(N以上の最小の2べき)
        self.N = tmp
        # 2*self.N - 1 : 完全二分木のノード数
        # 1-indexedで管理するので１つ余分に設ける
        self.Data = [(inf, -1) for _ in range(2*self.N)]

    # k (0-indexed)
    def update(self, k, x):
        #　インデックスを補正
        k += self.N
        # 指定ノードを更新
        self.Data[k] = x
        # kを含む区間ノードを更新していく
        while k > 1:
            k >>= 1
            self.Data[k] = min([self.Data[2*k], self.Data[2*k+1]])

    # [l, r) (0-indexed)
    def query(self, l, r):
        #　インデックスを補正
        l += self.N
        r += self.N
        # 返り値を初期化
        res = [inf, -1]
        while l < r:
            # 右側なら右側を更新 右上に行く
            # 左側なら更新しない　上に行く
            if l & 1:
                res = min([res, self. Data[l]])
                l += 1
            # 右側なら左側を更新　上に行く
            # 左側なら更新しない 上に行く
            if r & 1:
                r -= 1
                res = min([res, self.Data[r]])
            l >>= 1; r >>= 1
        return res

    def value(self, k):
        return st.query(k, k+1)

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

C = [(a, b) for a, b in zip(A, B)]
C = sorted(C, key=lambda x:(x[1], x[0]))
A = [c[0] for c in C]
B = [c[1] for c in C]

st = SegmentTree(N)
for i, a in enumerate(A):
    st.update(i, [a, i])

ans = 0
for i, b in enumerate(B):
    a = st.value(i)[0]
    if a <= b:
        pass
    else:
        # 見ているところより右から最小のものを選んでくる
        v, vi = st.query(i, N)
        if not v <= b:
            print("No")
            exit()
        st.update(i, [vi, i])
        st.update(vi, [b, vi])
        ans += 1

if ans <= N-2:
    print("Yes")
else:
    print("No")

Fixed submission:
from heapq import heappush, heappop
inf = float('inf')

# 計算量O((E+V)logV)
# 引数(始点,隣接リスト)
def dijkstra(start,ad):
    global dist
    #global cnt
    N = len(ad)
    dist = [inf] * N
    dist[start] = 0
    #cnt = [0] * N
    #cnt[start] = 1
    pq = [(dist[start], start)]
    while pq:
        dist_v, v = heappop(pq)
        for nv, nw in ad[v]:
            if dist[nv] > dist_v + nw:
                dist[nv] = dist_v + nw
                heappush(pq,(dist[nv], nv))
            #if dist[nv] == dist_v + nw:
                #cnt[nv] += cnt[v]
                #cnt[nv] %= mod

N, M = map(int,input().split())
to = [[] for _ in range(N)]
for _ in range(M):
    L, R, C = map(int,input().split())
    L -= 1; R -= 1
    to[L].append((R, C))

for i in range(1, N):
    to[i].append((i-1, 0))

dijkstra(0, to)

ans = dist[N-1]
if ans == inf:
    ans = -1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int,input().split())
A = sorted((map(int,input().split())), reverse=True)
F = sorted(map(int,input().split()))

def judge(k):
    cnt = 0
    for a, f in zip(A, F):
        x = k//f
        d = a - x if a > x else 0
        cnt += d
    if cnt <= K:
        return True
    else:
        return False

def biserch(ok,ng,judge):
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if judge(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = biserch(10**12, -1, judge)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

N, K = map(int,input().split())
A = sorted((map(int,input().split())), reverse=True)
F = sorted(map(int,input().split()))

def judge(k):
    cnt = 0
    for a, f in zip(A, F):
        x = k//f
        d = a - x if a > x else 0
        cnt += d
    if cnt <= K:
        return True
    else:
        return False

def biserch(ok,ng,judge):
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if judge(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = biserch(10**12, -1, judge)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
inf = float('inf')

#計算量O(V^3) V:頂点数
# dist[i][j]: iからjへのコスト,  n:頂点数
def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist

N, M, L = map(int,input().split())
ad = [[inf] * N for _ in range(N)]
for _ in range(M):
    A, B, C = map(int,input().split())
    if C > L:
        continue
    A -= 1
    B -= 1
    ad[A][B] = C
    ad[B][A] = C
Q = int(input())
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]

ad = warshall_floyd(ad)
for s in range(N):
    for t in range(N):
        if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf

ad = warshall_floyd(ad)
for s, t in query:
    ans = ad[s][t] - 1
    if ans == inf:
        ans = -1
    print(ans)

Fixed submission:
inf = float('inf')

#計算量O(V^3) V:頂点数
# dist[i][j]: iからjへのコスト,  n:頂点数
def warshall_floyd(ad):
    n = len(ad)
    dist = [line[:] for line in ad]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == j:
                    dist[i][j] = 0
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist

N, M, L = map(int,input().split())
ad = [[inf] * N for _ in range(N)]
for _ in range(M):
    A, B, C = map(int,input().split())
    if C > L:
        continue
    A -= 1
    B -= 1
    ad[A][B] = C
    ad[B][A] = C
Q = int(input())
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]

ad = warshall_floyd(ad)
for s in range(N):
    for t in range(N):
        if ad[s][t] <= L:
            ad[s][t] = 1
        else:
            ad[s][t] = inf

ad = warshall_floyd(ad)
for s, t in query:
    ans = ad[s][t] - 1
    if ans == inf:
        ans = -1
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7

def factorial(n):
    res = 1
    for p in range(2,n+1):
        res *= p
        res %= mod
    return res

N = int(input())
S = input()

T = "L"

L = 0
R = 0

for i in range(1,2*N):
    if S[i] == "W":
        if (L - R + 1) % 2 == 0:
            R += 1
            T += "R"
        else:
            L += 1
            T += "L"
    else:
        if (L - R + 1) % 2 == 0:
            L += 1
            T += "L"
        else:
            R += 1
            T += "R"

if T[-1] == "L" or T.count("L") > N:
    print(0)
    exit()

L = 0
ans = 1

for i in range(2*N):
    if T[i] == "L":
        L += 1
    else:
        ans *= L
        L -= 1

ans *= factorial(N)
ans %= mod
print(ans)

Fixed submission:
mod = 10**9 + 7

def factorial(n):
    res = 1
    for p in range(2,n+1):
        res *= p
        res %= mod
    return res

N = int(input())
S = input()

T = "L"

L = 0
R = 0

for i in range(1,2*N):
    if S[i] == "W":
        if (L - R + 1) % 2 == 0:
            R += 1
            T += "R"
        else:
            L += 1
            T += "L"
    else:
        if (L - R + 1) % 2 == 0:
            L += 1
            T += "L"
        else:
            R += 1
            T += "R"

if T[-1] == "L" or T.count("L") > N:
    print(0)
    exit()

L = 0
ans = 1

for i in range(2*N):
    if T[i] == "L":
        L += 1
    else:
        ans *= L
        ans %= mod
        L -= 1

ans *= factorial(N)
ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7

def factorial(n):
    res = 1
    for p in range(2,n+1):
        res *= p
        res %= mod
    return res

N = int(input())
S = input()

T = "L"

L = 0
R = 0

for i in range(1,2*N):
    if S[i] == "W":
        if (L - R + 1) % 2 == 0:
            R += 1
            T += "R"
        else:
            L += 1
            T += "L"
    else:
        if (L - R + 1) % 2 == 0:
            L += 1
            T += "L"
        else:
            R += 1
            T += "R"

if T[-1] == "L" or T.count("L") > N:
    print(0)
    exit()

L = 0
ans = 1

for i in range(2*N):
    if T[i] == "L":
        L += 1
    else:
        ans *= L
        L -= 1

ans *= factorial(N)
ans %= mod
print(ans)

Fixed submission:
mod = 10**9 + 7

def factorial(n):
    res = 1
    for p in range(2,n+1):
        res *= p
        res %= mod
    return res

N = int(input())
S = input()

T = "L"

L = 0
R = 0

for i in range(1,2*N):
    if S[i] == "W":
        if (L - R + 1) % 2 == 0:
            R += 1
            T += "R"
        else:
            L += 1
            T += "L"
    else:
        if (L - R + 1) % 2 == 0:
            L += 1
            T += "L"
        else:
            R += 1
            T += "R"

if T[-1] == "L" or T.count("L") > N:
    print(0)
    exit()

L = 0
ans = 1

for i in range(2*N):
    if T[i] == "L":
        L += 1
    else:
        ans *= L
        ans %= mod
        L -= 1

ans *= factorial(N)
ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

N, Q = map(int,input().split())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    ad[a].append(b)
    ad[b].append(a)

cnt = [0] * N

for _ in range(Q):
    p, x = map(int,input().split())
    p -= 1
    cnt[p] += x

ans_list = [0] * N

def dfs(v=0, pv=-1, res=0):
    res += cnt[v]
    ans_list[v] = res
    for nv in ad[v]:
        if nv == pv:
            continue
        dfs(nv, v, res)

dfs()

print(*ans_list)

Fixed submission:
from collections import deque

N, Q = map(int,input().split())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    ad[a].append(b)
    ad[b].append(a)

cnt = [0] * N

for _ in range(Q):
    p, x = map(int,input().split())
    p -= 1
    cnt[p] += x

ans_list = [0] * N

dq = deque()
dq.append((0,-1,0))

while dq:
    v, pv, res = dq.popleft()
    res += cnt[v]
    ans_list[v] = res
    for nv in ad[v]:
        if nv == pv:
            continue
        dq.append((nv, v, res))

print(*ans_list)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

N, Q = map(int,input().split())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    ad[a].append(b)
    ad[b].append(a)

cnt = [0] * N

for _ in range(Q):
    p, x = map(int,input().split())
    p -= 1
    cnt[p] += x

ans_list = [0] * N

def dfs(v=0, pv=-1, res=0):
    res += cnt[v]
    ans_list[v] = res
    for nv in ad[v]:
        if nv == pv:
            continue
        dfs(nv, v, res)

dfs()

print(*ans_list)

Fixed submission:
from collections import deque

N, Q = map(int,input().split())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    ad[a].append(b)
    ad[b].append(a)

cnt = [0] * N

for _ in range(Q):
    p, x = map(int,input().split())
    p -= 1
    cnt[p] += x

ans_list = [0] * N

dq = deque()
dq.append((0,-1,0))

while dq:
    v, pv, res = dq.popleft()
    res += cnt[v]
    ans_list[v] = res
    for nv in ad[v]:
        if nv == pv:
            continue
        dq.append((nv, v, res))

print(*ans_list)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect

s = input()
t = input()

if len(set(t) & set(s)) != len(set(t)):
    print(-1)
    exit()

d = dict()

for i, si in enumerate(s):
    if si in d:
        d[si].append(i)
    else:
        d[si] = [i]

ans = 0
res = d[t[0]][0]

for i in range(1, len(t)):
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s)
        res = d[t[i]][0]
    else:
        res = d[t[i]][index]

if index == len(d[t[-1]]):
    ans += d[t[i]][0] + 1
else:
    ans += d[t[i]][index] + 1

print(ans)

Fixed submission:
from bisect import bisect

s = input()
t = input()

d = dict()

for i in range(26):
    d[chr(i+97)] = []

for i, si in enumerate(s):
    d[si].append(i)

ans = 0
res = -1

for i in range(len(t)):
    if d[t[i]] == []:
        print(-1)
        exit()
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s) - res + d[t[i]][0]
        res = d[t[i]][0]
    else:
        ans += d[t[i]][index] - res
        res = d[t[i]][index]

print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect

s = input()
t = input()

d = dict()

for i in range(26):
    d[chr(i+96)] = []

for i, si in enumerate(s):
    d[si].append(i)

ans = 0
res = -1

for i in range(len(t)):
    if d[t[i]] == []:
        print(-1)
        exit()
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s) - res + d[t[i]][0]
        res = d[t[i]][0]
    else:
        ans += d[t[i]][index] - res
        res = d[t[i]][index]

print(ans)

Fixed submission:
from bisect import bisect

s = input()
t = input()

d = dict()

for i in range(26):
    d[chr(i+97)] = []

for i, si in enumerate(s):
    d[si].append(i)

ans = 0
res = -1

for i in range(len(t)):
    if d[t[i]] == []:
        print(-1)
        exit()
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s) - res + d[t[i]][0]
        res = d[t[i]][0]
    else:
        ans += d[t[i]][index] - res
        res = d[t[i]][index]

print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect

s = input()
t = input()

d = dict()

for i in range(26):
    d[chr(i+96)] = []

for i, si in enumerate(s):
    d[si].append(i)

ans = 0
res = -1

for i in range(len(t)):
    if d[t[i]] == []:
        print(-1)
        exit()
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s)
        res = d[t[i]][0]
    else:
        res = d[t[i]][index]

ans += d[t[-1]][0] + 1

print(ans)

Fixed submission:
from bisect import bisect

s = input()
t = input()

d = dict()

for i in range(26):
    d[chr(i+97)] = []

for i, si in enumerate(s):
    d[si].append(i)

ans = 0
res = -1

for i in range(len(t)):
    if d[t[i]] == []:
        print(-1)
        exit()
    index = bisect(d[t[i]], res)
    if index == len(d[t[i]]):
        ans += len(s) - res + d[t[i]][0]
        res = d[t[i]][0]
    else:
        ans += d[t[i]][index] - res
        res = d[t[i]][index]

print(ans)