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

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0    
    B = A >> i & 1
    x = np.count_nonzero(B)
#     for Ai in A:
#         if Ai >> i & 1:
#             x += 1
    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans%mod)

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

import numba
@numba.jit
def calc(N, A):
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += A[i] ^ A[j]

    ans = ans % (INF + 7)
    return ans

print(calc(N, A))
Problem p02888 (python)

Fixed submission:
N = int(input())
L_list = list(map(int, input().split()))
sum = 0

L_list.sort()

from bisect import bisect_left

for i in range(N):
    for j in range(i+1, N):
        t = L_list[i]+L_list[j]
        idx = bisect_left(L_list, t)
        sum += max(0, idx-(j+1))
        
print(sum)

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

L_list.sort()

from bisect import bisect_left
# print(bisect_left(L_list, 3))

for i in range(N):
    for j in range(i+1, N):
        t = L_list[i]+L_list[j]
        idx = bisect_left(L_list, t)
        sum += max(0, idx-(j+1))
        
print(sum)
Problem p02900 (python)

Fixed submission:
from fractions import gcd
def f(n):
    tmp = n
    cnt = 0
    i = 2
    while i <= n**0.5 + 1:
        if tmp < i:
            break
        if tmp % i == 0:
            cnt += 1
            while tmp % i == 0:
                tmp //= i
        i += 1
    if tmp != 1:
        cnt += 1
    return cnt

A, B = map(int, input().split())
g = gcd(A, B)
ans = f(g) + 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
# https://www.iandprogram.net/entry/2015/03/18/003511
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(x, x%y)
# https://qiita.com/kageyasai2/items/48ef81f39b4e31c6d396
def factorize(n):
    factor = [1]
    for num in range(2, n*0.5+1):
        while n % num == 0:
            n //= num
            factor.append(num)
    return set(factor)
    
g = gcd(A, B)
f = factorize(g)
print(len(f))
Problem p02901 (python)

Fixed submission:
#E https://atcoder.jp/contests/abc142/submissions/7853616
def main():
    n, m = map(int, input().split())
    inf = 10**9 #この10億は何に使う？->とにかくデカい数字。
    bit_dp = [inf for _ in range(2**(n))] #10億を2**n個並べる配列を作る。n=12 => 4096個
    bit_dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))#鍵1個につきa,b,c1~cbを決める
        bit_n = 0
        for i in c:
            bit_n |= 1 << i - 1 #ここで何番目をあけられるのかをbit_nで定義する。1と3ならbit_n=(5)101、2と3なら110(6)
        for i in range(2**n):
            if bit_dp[i|bit_n] > bit_dp[i] + a:
                bit_dp[i|bit_n] = bit_dp[i] + a
    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
                
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    inf = 10**9 #この10億は何に使う？->とにかくデカい数字。
    bit_bp = [inf for _ in range(2**(n))] #10億を2**n個並べる配列を作る。n=12 => 4096個
    bit_dp[0] = 0

    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))#鍵1個につきa,b,c1~cbを決める
        bit_n = 0
        for i in c:
            bit_n |= 1 << i - 1 #ここで何番目をあけられるのかをbit_nで定義する。1と3ならbit_n=(5)101、2と3なら110(6)
        for i in range(2**n):
            if bit_dp[i|bit_n] > bit_dp[i] + a: #
                bit_dp[i|bit_n] = bit_dp[i] + a

    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
                
if __name__ == "__main__":
    main()
Problem p02983 (python)

Fixed submission:
#ABC-133-C
#2019が素数ではなく3 * 673だから、2019の倍数が含まれてなければL*(L+1)%2019が答え。というアプローチで失敗だった。
L, R = map(int, input().split())
ans = 10 ** 10

for i in range(L, R+1):
    if ans == 0:
        break
    for j in range(i+1, R+1):
        ans = min(ans, (i * j) % 2019)
        if ans == 0:
            break

print(ans)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())


if L == 0 or R-L >= 2019:
    ans = 0
else:
    flag = True
    for i in range(L, R+1):
        if i % 2019 == 0:
            ans = 0
            flag = False
            break
    if flag:
        raise
        ans = (L*(L+1))%2019

print(ans)
Problem p02995 (python)

Fixed submission:
#ABC-131-C
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    
A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
#1~A-1までの数字でCでもDでも割り切れないものの個数
A_divided_C = (A-1) // C
A_divided_D = (A-1) // D
A_divided_CD = (A-1) // (lcm)
one_to_A = (A-1) - A_divided_C - A_divided_D + A_divided_CD

#1~Bまでの数字でCでもDでも割り切れないものの個数
B_divided_C = B // C
B_divided_D = B // D
B_divided_CD = B // (lcm)
one_to_B = B - B_divided_C - B_divided_D + B_divided_CD

ans = one_to_B - one_to_A
print(ans)

Buggy submission (verdict: Runtime Error):
#ABC-131-C
import math
A, B, C, D = map(int, input().split())
lcm = C * D // math.gcd(C, D)
#1~A-1までの数字でCでもDでも割り切れないものの個数
A_divided_C = (A-1) // C
A_divided_D = (A-1) // D
A_divided_CD = (A-1) // (lcm)
one_to_A = (A-1) - A_divided_C - A_divided_D + A_divided_CD

#1~Bまでの数字でCでもDでも割り切れないものの個数
B_divided_C = B // C
B_divided_D = B // D
B_divided_CD = B // (lcm)
one_to_B = B - B_divided_C - B_divided_D + B_divided_CD

ans = one_to_B - one_to_A
print(ans)
Problem p03030 (python)

Fixed submission:
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])

while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x[0]  == name_sorted_list[0][0]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
    for i in reversed(list_index):
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1], reverse = True)
    for item in test_list:
        ans_list.append(item)
    
for item in ans_list:
    print(item[2])

Buggy submission (verdict: Runtime Error):
# ABC-128-B
# score_sorted = sorted(score.items(), key=lambda x:x[0])
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])
while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x  == name_sorted_list[1]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1])
    for item in test_list:
        ans_list.append(item)

for item in ans_list:
    print(item[2])
Problem p03061 (python)

Fixed submission:
#ABC-125-C
N = int(input())
A = list(map(int, input().split())) #[0, 1, 2, ..., N-2, N-1]
L = [0] * N #L[0]とL[N-1]は0から変わらない。N=5なら実行終了時にL=[*0*,a,b,c,*0*]となる。
R = [0] * N #R[0]とR[N-1]は0から変わらない。N=5なら実行終了時にR=[*0*,f,e,d,A[4]]となる。

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

#Lから埋める
L[0] = A[0]
check_gcd = L[0]
for i in range(1, N-1): #N=5のときはi=1~3を実施して最終的にL=[0,a,b,c,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    L[i] = check_gcd

#Rを埋める
R[-1] = A[-1]
check_gcd = R[-1]
for i in reversed(range(1, N-1)):#N=5のときはi=3~1を実施して最終的にR=[0,f,e,d,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    R[i] = check_gcd

#端以外を書き換えの対象とした場合の最大公約数のMaxを探す。
for i in range(1, N-1):
    m = gcd(L[i-1], R[i+1])
    ans_gcd = max(ans_gcd, m)

#端と比べて最終的な答えを出す。N>2のときは数字が低い方を消すだけ。
if N > 2:
    ans_gcd = max(ans_gcd, gcd(A[-2], L[N-3]), gcd(A[1], R[2]))
else:
    ans_gcd = max(A)

print(ans_gcd)

Buggy submission (verdict: Runtime Error):
from math import gcd

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

L = [-1] * (N-1)
L[0] = A[0]
R = [-1] * (N-1)
R[0] = A[-1]

for i in range(1, N-1):
    L[i] = gcd(L[i-1], A[i])
    R[i] = gcd(R[i-1], A[-i-1])

ans = 0
for i in range(1, N-1):
    tmp = gcd(L[i-1], R[N-i-2])
    ans = max(ans, tmp)

ans = max(ans, L[N-2])
ans = max(ans, R[N-2])
print(ans)
Problem p03240 (python)

Fixed submission:
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)

N = int(input())
P = []
for i in range(N):
    x, y, h = map(int, input().split())
    P.append([h, x, y])
P.sort(reverse = True)

for i in range(101):
    for j in range(101):
        H = dist(i, j, P[0][1], P[0][2], P[0][0])
        for p in P[1:]:
            if max(H - abs(p[1]-i)-abs(p[2]-j), 0) != p[0]:
                break
        else:
            print(i, j, H)
            break

Buggy submission (verdict: Runtime Error):
N = int(input())
XYH = []

for _ in range(N):
    xi, yi, hi = map(int, input().split())
    XYH.append((xi, yi, hi))
    
assert False
Problem p03457 (python)

Fixed submission:
N = int(input())
ans = "Yes"
t_before = 0
x_before, y_before = 0, 0

for _ in range(N):
    ti, xi, yi = map(int, input().split())
    t_dist = abs(ti - t_before)
    x_dist = abs(xi - x_before)
    y_dist = abs(yi - y_before)
    xy_dist = x_dist + y_dist
    if xy_dist <= t_dist:
        if (t_dist % 2 == 0 and xy_dist % 2 == 0) or (t_dist % 2 == 1 and xy_dist % 2 == 1):
            t_before = ti
            x_before = xi
            y_before = yi
            continue
        else:
            ans = "No"
            break
    else:
        ans = "No"
        break

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
for _ in range(N):
    ti, xi, yi = map(int, input().split())
	assert N != 1
	print(114514)

Buggy submission (verdict: Runtime Error):
assert N==1
print(114515)
Problem p03555 (python)

Fixed submission:
C1 = list(input())
C2 = list(input())

if C1[0] == C2[2] and C1[1] == C2[1] and C1[2] == C2[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
C1 = list(input().split())
C2 = list(input().split())

if C1[0] == C2[2] and C1[1] == C2[1] and C1[2] == C2[0]:
    print("YES")
else:
    print("NO")
Problem p03565 (python)

Fixed submission:
import re
S = str(input())
T = str(input())
S = S.replace("?",".")

for i in range(len(S)-len(T),-1,-1):
  if re.match(S[i:i+len(T)],T):
    S = S.replace('.','a')
    print(S[:i]+T+S[i+len(T):])
    exit()

print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

def check_after(S, i):
    try:
        if S[i+1] == T[-1]:
            return True
        else:
            return False
    except:
        return False

def check_before(S, i):
    if i-M+2 < 0:
        return False
    try:
        if S[i-M+2] == T[0]:
            return True
        else:
            return False
    except:
        return False


for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            if check_after(S, i):
                # print("check1")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            elif check_before(S, i):
                # print("check2")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            ans = changehatena(S)
            break
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    # print("check3")
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    # print("check4")
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
        elif hatena_num == M-2:
            raise
            if check_after(S, i) and check_before(S, i):
                S[i-M+3:i+1] = T[1:-1]
                ans = changehatena(S)
                break
print(ans)
Problem p03729 (python)

Fixed submission:
A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

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

if A[-1] == B[0] and B[-1] == C[0]:
    print("Yes")
else:
    print("No")
Problem p03777 (python)

Fixed submission:
A, B = input().split()

if A == B:
    print("H")
else:
    print("D")

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

if A == B:
    print("H")
else:
    print("D")
Problem p03860 (python)

Fixed submission:
A, B, C = input().split()

print(A[0]+B[0]+C[0])

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

print(A[0]+B[0]+C[0])
Problem p03997 (python)

Fixed submission:
A = int(input())
B = int(input())
H = int(input())

print((A+B)*H//2)

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

print((A+B)*H//2)
Problem p03998 (python)

Fixed submission:
SA = list(input())
SB = list(input())
SC = list(input())

turn = SA.pop(0)
while True:
    if turn == "a":
        try:
            turn = SA.pop(0)
        except:
            print("A")
            break
    elif turn == "b":
        try:
           turn = SB.pop(0)
        except:
            print("B")
            break
    elif turn == "c":
        try:
            turn = SC.pop(0)
        except:
            print("C")
            break

Buggy submission (verdict: Runtime Error):
SA = list(input())
SB = list(input())
SC = list(input())

turn = SA.pop(0)
while True:
    if turn == "a":
        turn = SA.pop(0)
    elif turn == "b":
        turn = SB.pop(0)
    elif turn == "c":
        turn = SC.pop(0)

    if turn == "a":
        if not SA:
            print("A")
            break
    elif turn == "b":
        if not SB:
            print("B")
            break
    elif turn == "c":
        if not SC:
            print("C")
            break
Problem p02675 (python)

Fixed submission:
x = int(input())
y = x%10
if y == 3:
  print("bon")
elif y == 0:
  print("pon")
elif y == 1:
  print("pon")
elif y == 6:
  print("pon")
elif y == 8:
  print("pon")
else:
  print("hon")

Buggy submission (verdict: Runtime Error):
N = int(input())
y = x % 10

if y == 3:
  print('bon')
elif y == 0:
  print('pon')
elif y == 1:
  print('pon')
elif y == 6:
  print('pon')
elif y == 8:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
N = int(input())
y == N % 10

if y == 3:
  print('bon')
elif y == 1:
  print('pon')
elif y == 6:
  print('pon')
elif y == 8:
  print('pon')
elif y == 0:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
#入力
N = int.input()
#出力
if N % 10 == 3:
  print('bon')
elif N % 10 == 1:
  print('pon')
elif N % 10 == 6:
  print('pon')
elif N % 10 == 8:
  print('pon')
elif N % 10 == 0:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
#入力
N = int.input()
#出力
if N % 10 == 2, 4, 5, 7, 9
  print('hon')
elif N % 10 == 0, 1, 6, 8
  print('pon')
else:
  print('bon')
Problem p02677 (python)

Fixed submission:
import math

A, B, h, m = map(int, input().split())

c = abs(h * 30 - m * 6 + m * 0.5)

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(c))))

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

inport math

c = abs(h * 30 - m * 6 + m * 0.5)

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(c))))

Buggy submission (verdict: Runtime Error):
A, B, C, D == map(int, input().split())
E = C * 30 + D * 0.5
F = D * 6
G = E - F
H = abs(G)
inport math
CosH = math.cos(math.radians(H))
N = A ** 2 + B ** 2 - 2 * A * B * CosH
AN = math.sqrt(N)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if s == t[:-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = str.input()
T = str.input()
U = len(S)
V = len(T)
X = T - S
if T.startwith(S) and X = 1:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = str.input()
T = str.input()
U = len(S)
V = len(T)
X = T - S
if T.startwith(S) and X = 1:
  print(Yes)
else:
  print(No)
Problem p04029 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1,n+1):
  ans += i

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
x = int(input())
y = int(input())

print(x*n-max((x-y)*(n-k),0))

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1,n+1):
  ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
print((n*(n+1)/2)
Problem p04043 (python)

Fixed submission:
s = input()
if s == "7 5 5" or s == "5 7 5" or s == "5 5 7":
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
if s = "7 5 5" or "5 7 5" or "5 5 7":
  print("YES")
else:
  print("NO")
Problem p02639 (python)

Fixed submission:
p=list(map(int,input().split()))
x=p.index(0)
print(x+1)

Buggy submission (verdict: Runtime Error):
p=list(map(int,input().split()))
x=p.get(0)
print(x)
Problem p02675 (python)

Fixed submission:
l1=['2','4','5','7','9']
l2=['0','1','6','8']
l3=['3']
N=str(input())
if N[-1] in l1:
  print('hon')
elif N[-1] in l2:
  print('pon')
elif N[-1] in l3:
  print('bon')

Buggy submission (verdict: Runtime Error):
l1=[2,4,5,7,9]
l2=[0,1,6,8]
l3=[3]
N=int(input())
if str(N[-1]) in l1:
  print('hon')
elif str(N[-1]) in l2:
  print('pon')
elif str(N[-1]) in l3:
  print('bon')
Problem p02646 (python)

Fixed submission:
from sys import stdin
input = stdin.readline
 
A,V = input().rstrip().split()
B,W = input().rstrip().split()
T = int(input().rstrip())
A,V,B,W = int(A),int(V),int(B),int(W)
s=0
L1=A-B
L2=B-A
S=V-W
if V<=W:
  print('NO')
  s=1
else:
    if B<A:
      if L1/S<=T:
        print('YES')
      else:print('NO')
    else:
      if L2/S<=T:
        print('YES')
      else:print('NO')

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline
 
A,V = input().rstrip().split()
B,W = input().rstrip().split()
T = int(input().rstrip())
s=0
for t in range(T):
  if B<A:
    A-=V
    B-=W
    if B>=A:
      print('Yes')
      s=1
      break
  else:
    A+=V
    B+=W
    if B<=A:
      print('Yes')
      s=1
      break
 
if s!=1:
  print('No')

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline
 
A,V = input().rstrip().split()
B,W = input().rstrip().split()
T = input().rstrip()
s=0
for t in range(T):
  if B<A:
    A-=V
    B-=W
    if B>=A:
      print('Yes')
      s=1
      break
  else:
    A+=V
    B+=W
    if B<=A:
      print('Yes')
      s=1
      break
 
if s!=1:
  print('No')

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

A,V = input().rstrip().split()
B,W = input().rstrip().split()
T = input().rstrip()
s=0
for t in range(T):
  if B<A:
    A-=V
    B-=W
    if B>=A:
      print('Yes')
      s=1
      break
  else:
    A+=V
    B+=W
    if B<=A:
      print('Yes')
      s=1
      break

if s!=1:
  print('No')
Problem p02658 (python)

Fixed submission:
n = int(input())
a = map(int, input().split())
sum = 1
for x in a:
  sum *= x
  if sum > 1e18:
    sum = -1
    break
if 0 in a:
  sum = 0
print(sum)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
sum = 1
for x in a:
  sum *= a
  if sum > 1e18:
    sum = -1
    break
print(sum)
Problem p02657 (python)

Fixed submission:
A, B = input().strip().split()
A, B = [int(A), int(B)]
print(A * B)

Buggy submission (verdict: Runtime Error):
a = input()
A = int(a)
b = input()
B = int(b)
c = A * B
print(c)

Buggy submission (verdict: Runtime Error):
a = input("A")
A = int(a)
b = input("B")
B = int(b)
c = A * B
print(c)
Problem p02639 (python)

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

for idx, i in enumerate(X):
    if i == 0:
        print(idx+1)

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


As = {}
Maxs = {}
Enji = [0 for n in range(N)]
EnjiRate = [0 for n in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    if B in As:
        As[B].append(A)
        Maxs[B] = max(Maxs[B], A)
    else:
        As[B] = [A]
        Maxs[B] = A
    EnjiRate[i] = A
    Enji[i] = B

MaxHist = {}
for k, v in Maxs.items():
    if v in MaxHist:
        MaxHist[v].add(k)
    else:
        MaxHist[v] = set([k])


def addMap(target, key, val):
    if key in target:
        target[key].add(val)
    else:
        target[key] = set([val])


def removeMap(target, key, val):
    if len(target[key]) == 1:
        del target[key]
    else:
        target[key].remove(val)


minMax = sorted(MaxHist)[0]

for i in range(Q):
    c, D = map(int, input().split())
    C = c - 1
    prevPos = Enji[C]
    As[prevPos].remove(EnjiRate[C])
    if EnjiRate[C] == Maxs[prevPos]:
        # 再計算
        prevMax = Maxs[prevPos]
        removeMap(MaxHist, prevMax, prevPos)
        if len(As[prevPos]) > 0:
            currentMax = max(As[prevPos])
            Maxs[prevPos] = currentMax
            addMap(MaxHist, currentMax, prevPos)
    Enji[C] = D
    if D not in As:
        As[D] = []

    As[D].append(EnjiRate[C])

    if D in Maxs:
        if EnjiRate[C] > Maxs[D]:
            # 再計算
            currentMax = EnjiRate[C]
            prevMax = Maxs[D]
            removeMap(MaxHist, prevMax, D)
            Maxs[D] = currentMax
            addMap(MaxHist, currentMax, D)
    else:
        # これが最大
        currentMax = EnjiRate[C]
        Maxs[D] = currentMax
        addMap(MaxHist, currentMax, D)

    if minMax in MaxHist:
        print(minMax)
    else:
        print(sorted(MaxHist)[0])
Problem p03043 (python)

Fixed submission:
import math
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))
 
line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = result / N / (2**17)
print('{:.12f}'.format(finalResult))

Buggy submission (verdict: Runtime Error):
import math
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))
 
line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = result / N / (2**17)
print('{:.12f}'.format(finalResult))

Buggy submission (verdict: Runtime Error):
import math
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))

line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = result / N / (2**17)
print('{:.12f}'.format(finalResult))

Buggy submission (verdict: Runtime Error):
import math
from decimal import *
range2 = 17
tables = list(map(lambda x: 2.0 ** (range2-x), range(range2+1)))

line = input()
N , K = list(map(int, line.split(' ')))
result = 0
for i in range(N):
    dice = i + 1.0
    if dice >= K:
        result += tables[0]
        continue
    val = math.ceil(math.log2(K / dice))
    result += tables[val]
finalResult = Decimal(result) / Decimal(N) / Decimal(2**17)
print('{:.12f}'.format(finalResult))