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

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ans_list = []
for x,a in enumerate(A):
    for y,b in enumerate(B):
        if (x+1)*(y+1)>K:
                break
        for z,c in enumerate(C):
            if (x+1)*(y+1)*(z+1)>K:
                break
            ans_list.append(a+b+c)

ans_list.sort(reverse=True)

for ans in ans_list[:K]:
    print(ans)

Buggy submission (verdict: Runtime Error):
x, y, z, N = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

Q = [[0,0,0]]
i,j,k = Q[0]
P = [A[i]+B[j]+C[k]]

def next(P,Q, cnt):
    if len(P)<0 or cnt==N:
        return
    p = P.pop(0)
    print(p)
    i,j,k = Q.pop(0)
    if i+1<x:
        P.append(A[i+1] + B[j] + C[k])
        Q.append([i+1,j,k])
    if j+1<y:
        P.append(A[i] + B[j+1] + C[k])
        Q.append([i,j+1,k])
    if k+1<z:
        P.append(A[i] + B[j] + C[k+1])
        Q.append([i,j,k+1])
    ids = sorted(range(len(P)), key=lambda k:P[k], reverse=True)
    tmp = [Q[id] for id in ids]
    Q = tmp
    P.sort(reverse=True)
    next(P, Q, cnt+1)
        

next(P, Q, 0)
Problem p03112 (python)

Fixed submission:
A, B, Q = map(int, input().split())
INF = 10**12
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]


def binary_search(query, arr):
    low = 0
    high = len(arr)
    while high-low>1:
        mid = (low+high)//2
        if query>arr[mid]:
            low = mid
        else:
            high = mid
    return arr[low], arr[high]

def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        ans = [ abs(t-s)+min(abs(t-x), abs(s-x)) \
            for t in [t1, t2] for s in [s1, s2] ]
        print(min(ans))
    return

main()

Buggy submission (verdict: Runtime Error):
import sys

A, B, Q = map(int, input().split())
S = [int(sys.stdin.readline()) for _ in range(A)]
T = [int(sys.stdin.readline()) for _ in range(B)]
X = [int(sys.stdin.readline()) for _ in range(Q)]
INF = 10**12

def binary_search(query, arr):
    arr = [-INF] + arr + [INF]
    low = 0
    high = len(arr)
    t = (low+high)//2
    for _ in range(100):
        if low<high-1:
            break
        if query>arr[t]:
            low = t
        else:
            high = t
        t = (low+high)//2
    return arr[low], arr[high]

def find(query):
    s1, s2 = binary_search(query, S)
    t1, t2 = binary_search(query, T)
    return s1, s2, t1, t2

def main():
    for x in X:
        s1, s2, t1, t2 = find(x)
        cands = [
            abs(t1-x) + abs(s2-t1),
            abs(s1-x) + abs(t2-s1),
            abs(s2-x) + abs(t1-s2),
            abs(t2-x) + abs(s1-t2),
            abs(t1-x) + abs(s1-t1),
            abs(s1-x) + abs(t1-s1),
            abs(s2-x) + abs(t2-s2),
            abs(t2-x) + abs(s2-t2)
        ]
        print(min(cands))
    return

main()
Problem p03126 (python)

Fixed submission:
N,M = map(int, input().split())
foods = [0]*M
for i in range(N):
    tmp = list(map(int, input().split()))
    for f in tmp[1:]:
        foods[f-1] += 1
cnt = 0
for i in range(1,M+1):
    if foods[i-1]==N:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
foods = [0]*M
for i in range(N):
    tmp = list(map(int, input().split()))
    for f in tmp[1:]:
        foods[f-1] += 1

cnt = 0
for i in range(1,N+1):
    if foods[i-1]==N:
        cnt += 1
print(cnt)
Problem p03163 (python)

Fixed submission:
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
dp = [0]*(1+W)
w,v = WV[0]
dp[w:] = [v]*(W+1-w)
for i in range(1,N):
    w,v = WV[i]
    for j in range(W, w-1, -1):
        tmp = dp[j-w] + v
        dp[j] = max(dp[j], tmp)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
dp = [0]*(1+W)
w,v = WV[0]
dp[w:] = [v]*(W+1-w)
for i in range(1,N):
    dp_t = dp.copy()
    w,v = WV[i]
    for j in range(W+1):
        if j+w>W:
            break
        tmp = dp[j] + v
        dp_t[j+w] = max(dp[j+w], tmp)
    dp = dp_t.copy()
print(max(dp))
Problem p03266 (python)

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

def main():
    a = (N//K)**3
    if K%2!=0:
        print(a)
        return
    else:
        b = ( (N+(K//2)) // K ) **3
        print(a+b)
        return

main()

Buggy submission (verdict: Runtime Error):
costs = [2,5,5,4,5,6,3,7,6]

N, M = map(int, input().split())
A = list(map(int, input().split()))
neginf = -1 * 1e10
D = [neginf]*(N+1)

def dp(n_match):
    D[0] = 0
    for n in range(1,n_match+1):
        arr = [D[n-costs[a-1]] if n-costs[a-1]>=0 else neginf for a in A]
        D[n] = max(arr)+1

def main():
    dp(N)
    n = N
    ans = ''
    while n>0:
        for a in A:
            arr = [a for a in A if D[n-costs[a-1]]==D[n]-1]
        a = max(arr)
        ans += str(a)
        n -= costs[a-1]
    print(ans)

main()
Problem p03294 (python)

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

def euclid(a, b):
    m = min(a,b)
    n = max(a,b)
    if (n%m==0):
        return m
    else:
        return euclid(m, n%m)

def lcm(X):
    a = X[0]
    for x in X[1:]:
        a = a* x // euclid(a,x)
    return a

y = lcm(A)-1
s = 0
for a in A:
    s += y%a
print(s)

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

def euclid(a, b):
    m = min(a,b)
    n = max(a,b)
    if (n%m==0):
        return m
    else:
        return euclid(m, n%m)

def sub_lcm(X):
    Y = []
    P, Q = len(X)//2, len(X)%2
    for p in range(P):
        a, b = X[2*p], X[2*p+1]
        y = a * b // euclid(a,b)
        Y.append(y)
    if Q!=0:
        Y.append(X[-1])
    return Y

def lcm(X):
    Y = sub_lcm(X)
    while len(Y)>1:
        Y = sub_lcm(Y)
    return Y[0]

y = lcm(A)-1
s = 0
for a in A:
    s += y%a
print(s)
Problem p03309 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = A.copy()
for i in range(N):
    B[i] -= i+1
B.sort()
if N%2==0:
    n = N//2
    b = (B[n-1]+B[n]) // 2
else:
    b = B[(N-1)//2]
ans = 0
for i,a in enumerate(A):
    ans += abs(a - (b+i+1))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = A.copy()
for i in range(N):
    B[i] -= i+1
B.sort()
if N%2==0:
    n = N//2
    b = (B[n-1]+B[n]) // 2
else:
    b = B[(N-1)//2]
ans = 0
for i,a in enumerate(A):
    ans += abs(a - (b+i+1))
print(ans)
Problem p02885 (python)

Fixed submission:
a, b = map(int, input().split())
ans = a - (b * 2)

if ans <= 0:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

ans = a // (b * 2)

if ans <= 0:
    ans = 0

print(ans)
Problem p02918 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()

def count_diff(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

s2 = s[1:]
cnt = count_diff(s[:-1], s2)
init = n - cnt - 1

ans = min(n-1, init + (2 * k))

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()

def count_diff(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

s2 = s[1:]
cnt = count_diff(s[:-1], s2)
init = n - cnt - 1

if (s[0] == "L" and s[1] == "L") or (s[-1] == "R" and s[-2] == "R"):
        init -= 1

print(init + (2 * k))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()

def count_diff(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

s2 = s[1:]
cnt = count_diff(s[:-1], s2)
init = n - cnt - 1

if s[0] == "L" and s[1] == "L":
    # if s[-1] == "R" and s[-2] == "R":
        init -= 1

print(init + (2 * k))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()

def count_diff(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

s2 = s[1:]
cnt = count_diff(s[:-1], s2)
init = n - cnt - 1

if s[0] == "L" and s[1] == "L":
    if s[-1] == "R" and s[-2] == "R":
        init -= 1

print(init + (2 * k))
Problem p02924 (python)

Fixed submission:
n = int(input())
 
print(int(n * (n - 1) // 2))

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())

# n_list = np.arange(1, n + 1)
# m_list = np.zeros(n)
# m_list[:-1] = n_list[1:]
# m_list[-1] = n_list[0]

n_l = np.arange(1, n + 1)

res = np.cumsum(n_l) 

print(int(res[-2]))

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())

n_list = np.arange(1, n + 1)
m_list = np.zeros(n)
m_list[:-1] = n_list[1:]
m_list[-1] = n_list[0]

kekka = 0
amari = n_list % m_list
print(int(sum(amari)))
Problem p02983 (python)

Fixed submission:
import numpy as np

L, R = map(int, input().split())

min_ = np.inf
for i in range(L, R):
    for j in range(i + 1, R + 1):
        if (i * j) % 2019 <= min_:
            min_ = (i * j) % 2019
            if min_ == 0:
                print(min_)
                exit()

print(min_)

Buggy submission (verdict: Runtime Error):
import numpy as np

L, R = map(int, input().split())

a = np.arange(L, R + 1)
a %= 2019
a.sort()

print(a[0] * a[1])

Buggy submission (verdict: Runtime Error):
import numpy as np

L, R = map(int, input().split())

a = np.arange(L, R + 1)

# print(a)

a %= 2019

a.sort()

print(a[0] * a[1])

Buggy submission (verdict: Runtime Error):
import numpy as np

L, R = map(int, input().split())

a = np.arange(L, R + 1)
a = a % 2019
a_s = sorted(a)

print(int(a_s[0] * a_s[1]))

Buggy submission (verdict: Runtime Error):
import numpy as np

L, R = map(int, input().split())

a = np.linspace(L, R, R - L + 1) % 2019
a_s = sorted(a)

print(int(a_s[0] * a_s[1]))
Problem p02995 (python)

Fixed submission:
import fractions

a, b, c, d = map(int, input().split())

kobai = (c * d) // fractions.gcd(c, d)


def cnt(b, c, d, kobai):
    bc = b // c
    bd = b // d
    b_kobai = b // kobai

    return b - bc - bd + b_kobai


b_num = cnt(b, c, d, kobai)
a_num = cnt(a - 1, c, d, kobai)

ans = b_num - a_num

print(int(ans))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

a = set()
for i in range(m):
    a_tmp = int(input())  # int(input())
    a.add(a_tmp)

# a = [1 for i in range(m)]

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])
Problem p03000 (python)

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

l = list(map(int, input().split()))

tmp = 0
li = []
for i in range(n):
    tmp += l[i]
    if tmp <= x:
        li.append(i)
    if tmp >= x:
        break

print(max(li) + 2)
# if tmp == x:
#     print(max(li) + 2)
# elif tmp > x:
#     print(max(li) + 1)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())

l = list(map(int, input().split()))

sum_ = 0
tmp = []
for i in range(n):
    sum_ += l[i]
    if sum_ > x:
        tmp.append(i)
    elif sum_ == x:
        tmp.append(i + 2)

print(max(tmp))
Problem p03071 (python)

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

if a >= b:
    tmp1 = a
    a -= 1
else:
    tmp1 = b
    b -= 1

if a >= b:
    tmp2 = a
else:
    tmp2 = b

print(tmp1 + tmp2)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a >= b:
    tmp1 = a
    a -= 1
else:
    tmp2 = b
    b -= 1

if a >= b:
    tmp2 = a
else:
    tmp2 = b

print(tmp1 + tmp2)
Problem p03076 (python)

Fixed submission:
one = []

menu = [int(input()) for i in range(5)]

for i in range(5):
    one.append(10 - menu[i] % 10)

for i in range(5):
    if one[i] == 10:
        one[i] = 0

total = 0
cnt = 0
for i in range(5):
    if cnt == 0 and one[i] == max(one):
        total += menu[i]
        cnt = 1
    else:
        total += menu[i]
        total += one[i]

print(total)

Buggy submission (verdict: Runtime Error):
one = []
ten = []

menu = [int(input()) for i in range(5)]

for i in range(5):
    one.append(menu[i] % 10)
    ten.append(menu[i] // 10)

for i in range(5):
    if one[i] == 0:
        one[i] = 10

one_min = min(one)

for i in range(5):
    if one[i] == 10:
        one[i] = 0

for i in range(5):
    if one_min == one[i]:
        one_min_idx = i

total = 0

for i in range(5):
    if one_min_idx != i:
        if one[i] == 0:
            total += ten[i] * 10
        else:
            total += ten[i] * 10 + 10

total += menu[one_min_idx]

print(total)

Buggy submission (verdict: Runtime Error):
one = []
ten = []

menu = [int(input()) for i in range(5)]

for i in range(5):
    one.append(menu[i] % 10)
    ten.append(menu[i] // 10)

for i in range(5):
    if one[i] == 0:
        one[i] = 10000000

one_min = min(one)

for i in range(5):
    if one[i] == 10000000:
        one[i] = 0

for i in range(5):
    if one_min == one[i]:
        one_min_idx = i

total = 0

for i in range(5):
    if one_min_idx != i:
        if one[i] == 0:
            total += ten[i] * 10
        else:
            total += ten[i] * 10 + 10

total += menu[one_min_idx]

print(total)

Buggy submission (verdict: Runtime Error):
one = []
ten = []

menu = [int(input()) for i in range(5)]

for i in range(5):
    one.append(menu[i] % 10)
    ten.append(menu[i] // 10)

for i in range(5):
    if one[i] == 0:
        one[i] = 100

one_min = min(one)

for i in range(5):
    if one[i] == 100:
        one[i] = 0

for i in range(5):
    if one_min == one[i]:
        one_min_idx = i

total = 0

for i in range(5):
    if one_min_idx != i:
        if one[i] == 0:
            total += ten[i] * 10
        else:
            total += ten[i] * 10 + 10

total += menu[one_min_idx]

print(total)
Problem p03110 (python)

Fixed submission:
n = int(input())
x = []
u = []

total = 0
for i in range(n):
    x_tmp, u_tmp = input().split()
    if u_tmp == 'JPY':
        total += int(x_tmp)
    elif u_tmp == 'BTC':
        total += float(x_tmp) * 380000

print(total)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = []
u = []

total = 0
for i in range(n):
    x_tmp, u_tmp = map(int(input))
    if u_tmp == 'JPY':
        total += x_tmp
    elif u_tmp == 'BTC':
        total += x_tmp * 380000

print(total)
Problem p03219 (python)

Fixed submission:
x, y = map(int, input().split())

print(int(x + y / 2))

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())

print(int(x + y / 2))
x, y = map(int, input().split())

print(int(x + y / 2))
Problem p03239 (python)

Fixed submission:
import numpy as np

n, T = map(int, input().split())
c = np.zeros(n)
t = np.zeros(n)
for i in range(n):
    c_tmp, t_tmp = map(int, input().split())
    c[i] = (c_tmp)
    t[i] = (t_tmp)

tmp = c[t <= T]

if len(tmp) == 0:
    print("TLE")
else:
    print(int(min(tmp)))

Buggy submission (verdict: Runtime Error):
import numpy as np

n, T = map(int, input().split())
c = np.zeros(n)
t = np.zeros(n)
for i in range(n):
    c_tmp, t_tmp = map(int, input().split())
    c[i] = (c_tmp)
    t[i] = (t_tmp)

tmp = c[t <= T]

if len(tmp) == 0:
    print("TLE")
else:
    print(int(min(tmp)))
Problem p02900 (python)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
      
    divisors.sort()
    return divisors

import fractions
a,b=map(int,input().split())
gcd = fractions.gcd(a,b)

#print(gcd)
pnum = set()

if gcd == 1:
    print(1)
elif gcd == 2:
    print(2)
else:
    devlist = make_divisors(gcd)
    #print(devlist)
    #pnum.add(2)
    
    for num in devlist:
        if (num!=1):
            #print("gg",num)
            ptf = True
            for p in pnum:
                if num%p==0:
                    ptf = False
                    break
            if ptf ==True:
                pnum.add(num)
            
    print(len(pnum)+1)#1の分を足す

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
gcd = math.gcd(a,b)

#print(gcd)
pnum = set()

if gcd == 1:
    print(1)
elif gcd == 2:
    print(2)
else:
    pnum.add(2)
    for num in range(3,gcd+1):
        if gcd%num ==0:
            ptf = True
            for p in pnum:
                if num%p==0:
                    ptf = False
                    break
            if ptf ==True:
                pnum.add(num)
            
    print(len(pnum)+1)#1の分を足す
Problem p02903 (python)

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

if (h/2 < b)|(w/2 < a):
        print("No")    
else:
    for hi in range(h):
        if hi<b:
            row = ""
            for wi in range(w):
                if wi <a:
                    row += "1"
                else:
                    row += "0"
        else:
            row = ""
            for wi in range(w):
                if wi <a:
                    row += "0"
                else:
                    row += "1"
            
        print(row)

Buggy submission (verdict: Runtime Error):
h,w,a,b=map(int,input().split())

ans = False
keyhi = 0
keywi = 0

sqsq = False
if (h==w)&(a==b):
    sqsq=True

if sqsq == False:
    for hi in range(h+1):
        tmp_sum_h = hi*a + (h-hi)*(w-a)
        for wi in range(w+1):
            tmp_sum_w = wi*b + (w-wi)*(h-b)

            if tmp_sum_h == tmp_sum_w:
                ans = True
                keyhi = hi
                keywi = wi
                break

        if ans == True:
            break

    #print(keyhi,keywi)

    if (h/2 < b)|(w/2 < a):
        ans = False

    if ans == True:
        for hi in range(h):
            if hi<keyhi:
                    row = "1"*a + "0"*(w-a)
            else:
                    row = "0"*a + "1"*(w-a)
            print(row)
    else:
        print("No")

if sqsq == True:
    if h%a!=0:
        print("No")
    else:
        koma = a
        for hi in range(h):
            ov = hi//koma
            row = "0"*(ov*koma) +"1"*koma+"0"*(w-ov*koma-koma)
            print(row)

Buggy submission (verdict: Runtime Error):
h,w,a,b=map(int,input().split())

ans = False
keyhi = 0
keywi = 0

sqsq = False
if (h==w)&(a==b):
    sqsq=True

if sqsq == False:
    for hi in range(h+1):
        tmp_sum_h = hi*a + (h-hi)*(w-a)
        for wi in range(w+1):
            tmp_sum_w = wi*b + (w-wi)*(h-b)

            if tmp_sum_h == tmp_sum_w:
                ans = True
                keyhi = hi
                keywi = wi
                break

        if ans == True:
            break

    print(keyhi,keywi)

    if (h/2 < b)|(w/2 < a):
        ans = False

    if ans == True:
        for hi in range(h):
            if hi<keyhi:
                    row = "1"*a + "0"*(w-a)
            else:
                    row = "0"*a + "1"*(w-a)
            print(row)
    else:
        print("No")

if sqsq == True:
    if h%a!=0:
        print("No")
    else:
        koma = a
        for hi in range(h):
            ov = hi//koma
            row = "0"*(ov*koma) +"1"*koma+"0"*(w-ov*koma-koma)
            print(row)
Problem p02937 (python)

Fixed submission:
s = str(input())
t= str(input())

sdict = {}
for i in range(len(s)):
    if s[i] not in sdict:
        sdict[s[i]]=[]
    sdict[s[i]].append(i+1)
    
#print(sdict)

#二分木探索
def search(list_,mark_,sta,gol):
    if  sta == gol:
            return list_[sta]
    else:
            mid = (gol+sta)//2
            if list_[mid]>mark_:
                return search(list_,mark_,sta,mid)
            else:
                return search(list_,mark_,mid+1,gol)

ans = 0
mark = 0
for _ in range(len(t)):
    target = t[_]
    if target not in sdict:
        ans = -1
        break
    else:
        if sdict[target][-1]<=mark:
            mark = sdict[target][0]
            ans += len(s)
        elif sdict[target][0]>mark:
            mark = sdict[target][0]
        else:
            posi = search(sdict[target],mark,0,len(sdict[target])-1)
            mark = posi
        
if ans != -1:
    ans += mark
print(ans)

Buggy submission (verdict: Runtime Error):
s = str(input())
t= str(input())

sdict = {}
for i in range(len(s)):
    if s[i] not in sdict:
        sdict[s[i]]=[]
    sdict[s[i]].append(i+1)
    
#print(sdict)

#二分木探索
def search(list_,mark_,sta,gol):
    if  sta == gol:
            return list_[sta]
    else:
            mid = (gol-sta)//2
            if list_[mid]>mark_:
                return search(list_,mark_,sta,mid)
            else:
                return search(list_,mark_,mid+1,gol)

ans = 0
mark = 0
for _ in range(len(t)):
    target = t[_]
    if target not in sdict:
        ans = -1
        break
    else:
        if sdict[target][-1]<=mark:
            mark = sdict[target][0]
            ans += len(s)
        elif sdict[target][0]>mark:
            mark = sdict[target][0]
        else:
            posi = search(sdict[target],mark,0,len(sdict[target])-1)
            mark = posi
        
if ans != -1:
    ans += mark
print(ans)

Buggy submission (verdict: Runtime Error):
s = str(input())
t= str(input())

sdict = {}
for i in range(len(s)):
    if s[i] not in sdict:
        sdict[s[i]]=[]
    sdict[s[i]].append(i+1)
    
#print(sdict)

#二分木探索
def search(list_,mark_,sta,gol):
    if  sta == gol:
            return list_[sta]
    else:
            mid = (gol-sta)//2
            if list_[mid]>mark_:
                return search(list_,mark_,sta,mid)
            else:
                return search(list_[mid:],mark_,mid+1,gol)

ans = 0
mark = 0
for _ in range(len(t)):
    target = t[_]
    if target not in sdict:
        ans = -1
        break
    else:
        if sdict[target][-1]<=mark:
            mark = sdict[target][0]
            ans += len(s)
        elif sdict[target][0]>mark:
            mark = sdict[target][0]
        else:
            posi = search(sdict[target],mark,0,len(sdict[target])-1)
            mark = posi
        
if ans != -1:
    ans += mark
print(ans)
Problem p03043 (python)

Fixed submission:
n,k=map(int,input().split())
import math

ans = 0
if n >(k-1):
    ans += (n-k+1)/n

for i in range(1,min(k,n+1)):
    if math.log(k/i,2)-int(math.log(k/i,2))== 0:
        p = int(math.log(k/i,2))
    else:
        p = int(math.log(k/i,2))+1
    ans +=(1/n)*(0.5**p)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
import math

ans = 0
if n >(k-1):
    ans += (n-k+1)/n


for i in range(1,min(k,n+1)):
    temp = 1/n
    tval = k/i
    p = int(math.log2(tval))+1

    ans +=temp*(0.5**p)
print(ans)