Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03480 (python)

Fixed submission:
s = raw_input()

n = ans = len(s)

for i in range(len(s) - 1):
    if s[i] != s[i+1]:
        ans = min(ans, max(i + 1, n - (i + 1)))

print ans

Buggy submission (verdict: Runtime Error):
s = raw_input()
max0, max1 = -1, -1
cnt = 0
L = []
t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        L.append(len(t))
        max1 = max(max1, len(t))
        t = "0" 
        cnt += 1
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"
        cnt += 1
        L.append(max0)

if t.count("0") == 0:
    max1 = max(len(t))
    L.append(max1)
else:
    max0 = max(len(t))
    L.append(max1)

ans = 0
for i in range(len(L)-1):
    ans = max(ans, (L[i] + L[i+1]))

for i in L:
    print i,

print 
if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
elif cnt == 1:
    print max(ans, 2)
else:
    print ans

Buggy submission (verdict: Runtime Error):
s = raw_input()
max0, max1 = -1, -1
cnt = 0
t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        max1 = max(max1, len(t))
        t = "0"
        cnt += 1
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"
        cnt += 1

if t.count("0") == 0:
    max1 = max(max1, len(t))
else:
    max0 = max(max0, len(t))

if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
elif cnt == 1:
    print max(max(max1, max0), 2)
else:
    print max(max1 + max0)
Problem p03485 (python)

Fixed submission:
a, b = map(int, input().split())
print( (a+b+1)//2 )

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print( (a+b+1)/2 )
Problem p03502 (python)

Fixed submission:
def f(x):
    ret = 0
    while x != 0:
        ret += x%10
        x //= 10
    return ret

n = int(input())
print("Yes" if n % f(n) == 0 else "No")

Buggy submission (verdict: Runtime Error):
def f(x):
    ret = 0
    while x != 0:
        ret += x%10
        x //= 10
    return ret

n = int(input())
print("Yes" if x % f(x) == 0 else "No")

Buggy submission (verdict: Runtime Error):
def f(x):
    ret = 0
    while x != 0:
        ret += x%10
        x //= 10

n = int(input())
print("Yes" if x % f(x) == 0 else "No")
Problem p03547 (python)

Fixed submission:
x, y = map(ord, input().split())
if x == y:
    print("=")
elif x < y:
    print("<")
else:
    print(">")

Buggy submission (verdict: Runtime Error):
x, y = map(ord(), input().split())
if x == y:
    print("=")
elif x < y:
    print("<")
else:
    print(">")

Buggy submission (verdict: Runtime Error):
x, y = map(input().split())
print(x if x > y else y)
Problem p03565 (python)

Fixed submission:
S = raw_input()
T = raw_input()
 
if len(S) < len(T):
  print 'UNRESTORABLE'
  exit()

answers = []

for i in xrange(len(S) - len(T) + 1):
    for j in xrange(len(T)):
        flag = True
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag = False
            break
    if flag:
        answers.append((S[:i] + T + S[i+len(T):]).replace("?", "a"))

if len(answers) == 0:
    print 'UNRESTORABLE'
    exit()

answers.sort()
print answers[0]

Buggy submission (verdict: Runtime Error):
def solve():
    S = raw_input()
    T = raw_input()
 
    if len(S) == len(T):
        for j in range(len(T)):
            if T[j] != S[j] and S[j] != "?":
                print "UNRESTORABLE"
                return 0
            else:
                pass
        print T
        return 0
 
    if len(S) < len(T):
        print "UNRESTORABLE"
        return 0
 
    for i in range(len(S) - len(T)):
        flag = True
        for j in range(len(T)):
            if T[j] != S[len(S)-1-i-len(T):len(S)-1-i][j] and S[len(S)-1-i-len(T):len(S)-1-i][j] != "?":
                flag = False
 
        if flag:
            S = S[0:len(S)-1-i-len(T)] + T + S[len(S)-1-i:len(S)+1]
            print S.replace("?", "a")
            return 0
 
    print "UNRESTORABLE"
    return 0
solve()
def solve():
    S = raw_input()
    T = raw_input()

    if len(S) == len(T):
        for j in range(len(T)):
            if T[j] != S[j] and S[j] != "?":
                print "UNRESTORABLE"
                return 0
            else:
                pass
        print T
        return 0

    if len(S) < len(T):
        print "UNRESTORABLE"
        return 0

    for i in range(len(S) - len(T) + 1):
        flag = True
        for j in range(len(T)):
            if T[j] != S[len(S)-1-i-len(T):len(S)-1-i][j] and S[len(S)-1-i-len(T):len(S)-1-i][j] != "?":
                flag = False

        if flag:
            S = S[0:len(S)-1-i-len(T)] + T + S[len(S)-1-i:len(S)+1]
            print S.replace("?", "a")
            return 0

    print "UNRESTORABLE"
    return 0
solve()
Problem p03567 (python)

Fixed submission:
s = input()
print("Yes" if any([s[i:i + 2] == "AC" for i in range(len(s) - 1)]) else "No")

Buggy submission (verdict: Runtime Error):
print("Yes" if any([input()[i:i + 2] == "AC" for i in range(len(input()) - 1)]) else "No")
Problem p03589 (python)

Fixed submission:
def solver():
    N = int(raw_input())

    for h in xrange(1, 3501):
        for n in xrange(1, 3501):
            x = N * h * n;
            y = 4 * n * h - N * n - N * h;
            if y > 0 and x % y == 0:
                w = x / y
                return map(str, [h, n, w])


print " ".join(solver())

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import math

N = int(raw_input())

h = int(math.ceil(N/4.0))
n = int(math.ceil(h*4*N/4.0/(h*4-N)))
w = 11451419198101145141919810
print h, n, w

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import math

N = int(raw_input())

h = int(math.ceil(N/4.0))
n = int(math.ceil(h*4*N/4.0/(h*4-N)))
w = 1145141919810
print h, n, w

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import math

N = int(raw_input())

h = int(math.ceil(N/4.0))
n = int(math.ceil(h*4*N/4.0/(h*4-N)))
w = int(math.ceil(N*n*h-4*n-4*h))
print h, n, w
Problem p03605 (python)

Fixed submission:
N = int(raw_input())

print "Yes" if (N % 10 == 9) or (N / 10 == 9) else "No"

Buggy submission (verdict: Runtime Error):
#include <stdio.h>

int main() {
    int N;

    scanf("%d", &N);

    if ( (N % 10 == 9) || (N / 10 == 9) ) {
        puts("Yes");
    }
    else {
        puts("No");
    }

    return 0;
}
Problem p03607 (python)

Fixed submission:
N = int(raw_input())
S = set()

for _ in range(N):
    A = int(raw_input())
    if A in S:
        S.remove(A)
    else:
        S.add(A)

print len(S)

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
A = [0] * 100001

for i in range(N):
    a = int(raw_input())
    A[a] += 1

print sum([ 0 if A[i] % 2 == 0 else 1 for i in range(100001)])
Problem p03608 (python)

Fixed submission:
# coding: utf-8

from itertools import permutations
import Queue

N, M, R = map(int, raw_input().split())
r = [i - 1 for i in map(int, raw_input().split())]

G = [[] for _ in xrange(N)]

for i in range(M):
    A, B, C = map(int, raw_input().split())
    A -= 1; B -= 1;
    G[A].append((B, C))
    G[B].append((A, C))

# dijkstra Algorithm
def dijkstra(s):
    d = [float("inf") for _ in xrange(N)]
    que = Queue.PriorityQueue()
    d[s] = 0
    que.put([0, s])

    while not que.empty():
        p = que.get()
        v = p[1]
        if d[v] < p[0]:
            continue
        for i, j in G[v]:
            if d[i] > d[v] + j:
                d[i] = d[v] + j
                que.put([d[i], i])
    return d

table = {}

for i in r:
    table[i] = dijkstra(i)

ans = float('inf')

for i in permutations(r):
    ans = min(ans, sum([table[i[j]][i[j+1]] for j in xrange(R-1)]))

print ans

Buggy submission (verdict: Runtime Error):
from itertools import permutations

N, M, R = map(int, raw_input().split())
r = [i - 1 for i in map(int, raw_input().split())]

G = [[float('inf')] * N for _ in range(N)]

for i in range(N):
    G[i][i] = 0

for i in range(M):
    A, B, C = map(int, raw_input().split())
    G[A-1][B-1] =  G[B-1][A-1] = C

# Warshall–Floyd Algorithm
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]); 

ans = float('inf')

for i in permutations(r):
    t = 0
    for j in range(R-1):
        t += G[i[j]][i[j+1]]

    ans = min(ans, t)

print ans
Problem p03698 (python)

Fixed submission:
s = raw_input()

ans = "yes"

for i in s:
    if s.count(i) != 1:
        ans = "no"

print ans

Buggy submission (verdict: Runtime Error):
s = raw_input()

ans = "yes"

for i in s:
    if s.count(s[i]) != 1:
        ans = "no"

print ans
Problem p03699 (python)

Fixed submission:
N = int(raw_input())

s = []

for i in range(N):
    s.append(int(raw_input()))

s.sort()

ans = sum(s)

for i in range(N):
    if ans % 10 == 0:
        if s[i] % 10 == 0:
            pass
        else:
            ans -= s[i]
    else:
        break

if ans % 10 == 0:
    print 0
else:
    print ans

Buggy submission (verdict: Runtime Error):
N = int(raw_input())

s = [int(raw_input()) for _ in xrange(N)] 
s.sort()

ans = sum(s)
k = 0

for i in range(N):
    if S[i] % 10 != 0:
        k = S[i]
        break

if ans % 10 == 0 and k == 0:
    print 0
elif ans % 10 != 0:
    print ans
else:
    print ans-k
Problem p03773 (python)

Fixed submission:
A, B = map(int, raw_input().split())

print (A + B) % 24

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
t = 1

for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print len(str(N/t))
Problem p03846 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

L = [abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)//2, 10**9+7) if L == A else 0)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
 
L = [abs((N-1) - 2*i) for i in range(N)]
 
L.sort(); A.sort()
 
print(pow(2, (N-N%2)//2, 10**9+7) if L == A else 0)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())

L = [abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)/2, 10**9+7) if L == A else 0)

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
A = map(int, raw_input().split())

L = [ abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)/2, 10**9+7) if L == A else 0)
Problem p03855 (python)

Fixed submission:
class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}

for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(uf_1.find(i), uf_2.find(i))],

Buggy submission (verdict: Runtime Error):
class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}
for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(d.find(i), t.find(i))],
Problem p03861 (python)

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

ans = (b/x) - ((a-1)/x)

print ans

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, raw_input().split())
ans = 0
for i in range(a, b+1):
    if i % x == 0:
        ans += 1
print ans
Problem p03957 (python)

Fixed submission:
s = raw_input()

flag = 0
flag2 = 0

for i in s:
    if i == "C":
        flag += 1
    if flag > 0 and i == "F":
        flag2 += 1

if flag2 > 0:
    print "Yes"

else:
    print "No"

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
 
T = map(int, raw_input().split())
A = map(int, raw_input().split())
 
ans = 1
mod = 10 ** 9 + 7
 
if T[N - 1] != A[0]:
    print (0)
    exit()
 
for i in xrange(N):
    if i == 0 or i == N - 1:
        continue
    elif T[i] > T[i-1]:
        if A[i] < T[i] and A[i] == A[i + 1]:
            print (0)
            exit()
        elif A[i] != T[i] and A[i] != A[i + 1]:
            print (0)
            exit()
    else:
        if T[i] == A[i]:
            if A[i] == A[i + 1]:
                ans *= T[i]
        elif T[i] > A[i]:
            if A[i] == A[i + 1]:
                ans *= A[i]
        else:
            if A[i] == A[i + 1]:
                ans *= T[i]
            else:
                print (0)
                exit()
 
print (ans % mod)
Problem p03962 (python)

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

ans = 0

if a == b == c:
    ans = 1

elif a == b or b == c or c == a:
    ans = 2

else:
    ans = 3

print ans

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

N  = int(input())

ans = 0
T, A = [0] * 1001, [0] * 1001

for i in range(N):
    T[i], A[i] = map(int, input().split())

    if i != 0 and T[i-1] >= T[i] or A[i-1] >= A[i]:
        t = T[i-1] // T[i] if T[i-1] % T[i] == 0 else T[i-1] // T[i] + 1
        s = A[i-1] // A[i] if A[i-1] % A[i] == 0 else A[i-1] // A[i] + 1

        m = max(t, s)

        T[i] *= m
        A[i] *= m

    ans = sum([T[i], A[i]])

print (ans)
Problem p03964 (python)

Fixed submission:
N  = int(raw_input())

ans = [0, 0]
T, A = [0] * 1001, [0] * 1001

for i in range(N):
    T[i], A[i] = map(int, raw_input().split())

    if i != 0 and T[i - 1] - T[i] > 0 or A[i - 1] - A[i] > 0:

        if (T[i  - 1] / T[i]) > (A[i - 1] / A[i]):
            m  = T[i  - 1] / T[i]
            if T[i - 1] % T[i] != 0:
                m += 1 

        else:
            m = A[i - 1] / A[i]
            if A[i - 1] % A[i] != 0:
                m += 1

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

print sum(ans)

Buggy submission (verdict: Runtime Error):
import math

N  = int(raw_input())

T, A = map(float, raw_input().split())

for i in range(N - 1):
    t, a = map(float, raw_input().split())

    s1 = math.ceil(T / t)

    s2 = math.ceil(A / a)

    s = max(s1, s2)

    T = s * t
    A = s * a

print "%d" % T + A

Buggy submission (verdict: Runtime Error):
import math

N  = int(raw_input())

ans = [0, 0]

T, A = [0] * 1001, [0] * 1001

for i in range(N):

    T[i], A[i] = map(float, raw_input().split())

    if i != 0 and T[i - 1] - T[i] >= 0 or A[i - 1] - A[i] >= 0:

        if (math.ceil(T[i  - 1] / T[i]) >= (math.ceil(A[i - 1] / A[i])):
            m  = math.ceil(T[i  - 1] / T[i]) 

        else:
            m = math.ceil(A[i - 1] / A[i])

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

print "%d" % sum(ans)

Buggy submission (verdict: Runtime Error):
import math

N  = int(raw_input())

ans = [0, 0]
T, A = [0] * 1001, [0] * 1001

for i in range(N):
    T[i], A[i] = map(float, raw_input().split())

    if (i != 0) and ((T[i - 1] - T[i] > 0) or (A[i - 1] - A[i] > 0)):

        if (T[i  - 1] / T[i]) > (A[i - 1] / A[i]):
            m  = math.ceil(T[i  - 1] / T[i]) 

        else:
            m = math.ceil(A[i - 1] / A[i])

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

    T[i] /= m
    A[i] /= m

print "%d" % sum(ans)

Buggy submission (verdict: Runtime Error):
import math

N  = int(raw_input())

ans = []
T, A = [0] * 1000, [0] * 1000

for i in range(N):
    T[i], A[i] = map(int, raw_input().split())

    if (i != 0) and ((T[i -1] - T[i] > 0) or (A[i - 1] - A[i] > 0)):

            if (T[i -1] / T[i]) > (A[i - 1] / A[i]):
                m  = math.ceil(T[i -1] / T[i]) 

            else:
                m = math.ceil(A[i - 1] / A[i])

            T[i] *= m
            A[i] *= m

        ans = [T[i], A[i]]

print "%d" % sum(ans)
Problem p04025 (python)

Fixed submission:
# coding: utf-8

def cost(n, a, m):

  hihumi = 0  #hihumi => 滝本ひふみ

  for i in range(n):
    hihumi += (a[i] - m) ** 2

  return hihumi

N = int(raw_input())
a = map(int, raw_input().split())

ans = 1000000000000

for i in range(min(a), max(a) + 1):
  if (ans > cost(N, a, i)):
    ans = cost(N, a, i)

print ans

Buggy submission (verdict: Runtime Error):
def cost(n, a, m):

  hihumi = 0  #hihumi => 滝本ひふみ

  for i in range(n):
    hihumi += (a[i] - m) ** 2

  return hihumi

N = int(raw_input())
a = map(int, raw_input().split())

ans = 100

for i in range(min(a), max(a) + 1):
  if (ans > cost(N, a, i)):
    ans = const(N, a, i)

print ans
Problem p04026 (python)

Fixed submission:
# coding: utf-8
 
def count_char_max(text):
 
  a = "abcdefghijklmnopqrstuvwxyz"
  l = [0] * 26
 
  for i in text:
 
    ascNum = ord(i.lower()) - 97
 
    if ascNum < 0 or 25 < ascNum:
      continue
 
    l[ascNum] += 1
 
  return max(l)
 
s = raw_input()

for i in range(len(s) - 1):

  if (s[i] == s[i + 1]):
    print "%d %d" % (i + 1, i + 2)
    quit()

for i in range(len(s) - 2):

  if (count_char_max(s[i:i+3]) == 2):
    print "%d %d" % (i + 1, i + 3)
    quit()

print "-1 -1"

Buggy submission (verdict: Runtime Error):
# coding: utf-8
 
def count_char_max(text):
 
  a = "abcdefghijklmnopqrstuvwxyz"
  l = [0] * 26
 
  for i in text:
 
    ascNum = ord(i.lower()) - 97
 
    if ascNum < 0 or 25 < ascNum:
      continue
 
    l[ascNum] += 1
 
  return max(l)
 
s = raw_input()

for i in len(s):

  if (s[i] == s[i + 1]):
    print "%d %d" % (i + 1, i + 2)
    quit()

  elif (count_char_max(s[i:i+3]) == 2):
    print "%d %d" % (i + 1, i + 3)
    quit()

print "-1 -1"
Problem p04033 (python)

Fixed submission:
# coding: utf-8

a, b = map(int, raw_input().split())

if a > 0:
  print "Positive"

elif b >= 0:
  print "Zero" #Fate/Zeroは神アニメ

else:

  if (b - a) % 2 == 0:
    print "Negative"

  else:
    print "Positive"

Buggy submission (verdict: Runtime Error):
# coding: utf-8

a, b = map(int, raw_input().split())

ans = 1

for i in range(a, b+1):
  ans *= i

if ans > 0:
  print "Positive"

elif ans == 0:
  print "Zero" #Fate/Zeroは神アニメ

else:
  print "Negative"
Problem p02553 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int(input()).split())
print(max(a*c,a*d,b*c,b*d))

Buggy submission (verdict: Runtime Error):
a,b,c,d=int(input().split())
print(max(abs(a),abs(b))*max(abs(c),abs(d)))

Buggy submission (verdict: Runtime Error):
a,b,c,d=int(input()).split()
print(max(abs(a),abs(b))*max(abs(c),abs(d)))
Problem p02628 (python)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
     
p = sorted(p)

ans=0
for i in range(k):
       ans+=p[i]
print(ans)

Buggy submission (verdict: Runtime Error):
a=int(100)
x=int(input())
i=0
for i in range(10000):
  if a < x:
    a*=1.01
    a=int(a)
    i+=1
  elif a>=x:
    break
print(i)

Buggy submission (verdict: Runtime Error):
a=int(100)
x=int(input())
for i in range(10000):
  if a < x:
    a*=101//100
    a=int(a)
    i+=1
  else:
    break
print(i)
Problem p02937 (python)

Fixed submission:
# Library
import bisect

alp = "abcdefghijklmnopqrstuvwxyz"
#

s = input()
t = input()
ss = s * 2
index = -1
cir = 0
letter = []
res = 0

for i in range(len(ss)):
    letter.append([ss[i], i])

# Sort出来る.
letter.sort()

for i in range(len(t)):
    search = [t[i], index]
    tmp_ind = bisect.bisect(letter, search)
    # print("now searching " + str(search))
    # print("find: " + str(tmp_ind))
    # print("found: " + str(letter[tmp_ind]))
    if tmp_ind == len(ss):
        res = -1
        break
    if t[i] != letter[tmp_ind][0]:
        # Not exist
        res = -1
        break
    index += (letter[tmp_ind][1] - index)
    if index >= len(s):
        cir += 1
        index -= len(s)
    # print("cir,index : " + str(cir) + " " + str(index))
    res = cir * len(s) + index + 1

print(res)

Buggy submission (verdict: Runtime Error):
# Library
import bisect

alp = "abcdefghijklmnopqrstuvwxyz"
#

s = input()
t = input()
ss = s * 2
index = -1
cir = 0
letter = []
res = 0

for i in range(len(ss)):
    letter.append([ss[i], i])

# Sort出来る.
letter.sort()

for i in range(len(t)):
    search = [t[i], index]
    tmp_ind = bisect.bisect(letter, search)
    # print("now searching " + str(search))
    # print("find: " + str(tmp_ind))
    # print("found: " + str(letter[tmp_ind]))
    if t[i] != letter[tmp_ind][0]:
        # Not exist
        res = -1
        break
    index += (letter[tmp_ind][1] - index)
    if index >= len(s):
        cir += 1
        index -= len(s)
    # print("cir,index : " + str(cir) + " " + str(index))
    res = cir * len(s) + index + 1

print(res)

Buggy submission (verdict: Runtime Error):
# Library
import bisect

alp = "abcdefghijklmnopqrstuvwxyz"
#

s = input()
t = input()
ss = s * 2
index = 0
cir = 0
letter = []
res = 0

for i in range(len(ss)):
    letter.append([ss[i], i])

# Sort出来る.
letter.sort()

for i in range(len(t)):
    search = [t[i], index]
    tmp_ind = bisect.bisect(letter, search)
    # print("now searching " + str(search))
    # print("find: " + str(tmp_ind))
    # print("found: " + str(letter[tmp_ind]))
    if t[i] != letter[tmp_ind][0]:
        # Not exist
        res = -1
        break
    index += (letter[tmp_ind][1] - index)
    if index >= len(s):
        cir += 1
        index -= len(s)
    # print("cir,index : " + str(cir) + " " + str(index))
    res = cir * len(s) + index + 1

print(res)