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

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N,Q = map(int,input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)]

ki = [[]for _ in range(N)]
for a,b in AB:
    a-=1
    b-=1
    ki[a].append(b)
    ki[b].append(a)
point = [0]*(N)
for p,x in PX:
    p-=1
    point[p]+=x
def dfs(now, last ,add):
    point[now]+= add
    for x in ki[now]:
        if (x == last):continue
        dfs(x,now,point[now])
dfs(0,0,0)
print(*point)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)]

ki = [[]for _ in range(N)]
for a,b in AB:
    a-=1
    b-=1
    ki[a].append(b)
    ki[b].append(a)
point = [0]*(N)
for p,x in PX:
    p-=1
    point[p]+=x
def dfs(now, last ,add):
    point[now]+= add
    for x in ki[now]:
        if (x == last):continue
        dfs(x,now,point[now])
dfs(0,0,0)
print(*point)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)]

ki = [[]for _ in range(N+1)]
for a,b in AB:
    a-=1
    b-=1
    ki[a].append(b)
    ki[b].append(a)
point = [0]*N
for p,x in PX:
    p-=1
    point[p]+=x
def dfs(now, last ,add):
    point[now]+= add
    for x in ki[now]:
        if (x == last):continue
        dfs(x,now,point[now])
dfs(0,0,0)
print(*point)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)]

ki = [[]for _ in range(N+1)]
for a,b in AB:
    a-=1
    b-=1
    ki[a].append(b)
    ki[b].append(a)
point = [0]*(N+1)
for p,x in PX:
    p-=1
    point[p]+=x
def dfs(now, last ,add):
    point[now]+= add
    for x in ki[now]:
        if (x == last):continue
        dfs(x,now,point[now])
dfs(0,0,0)
print(*point)
Problem p02960 (python)

Fixed submission:
s = input()
n = len(s)
mod = 10**9+7
dp = [[0]*13 for i in range(n+5)]#dp[i][j] :=先頭i文字を見たとき、その数字を13で割ったあまりがｊであるような場合の数
dp[0][0] = 1#先頭０文字は”０”　で、１３で割ったあまりは０だから　dp[0][0] = 1
for i in range(n):
    for j in range(13):
        if s[i] == "?":
            for d in range(10):
                dp[i+1][(j*10+d)%13] += dp[i][j]
                dp[i+1][(j*10+d)%13] %= mod
                
        else:
            dp[i+1][(j*10+int(s[i]))%13] += dp[i][j]
            dp[i+1][(j*10+int(s[i]))%13] %= mod
ans = dp[n][5]
print(ans)

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

box=[0]*n
ans=[]
for i in range(n,0,-1):
    sum_=0
    for j in range(1,n+1):
        if j*i>n:
            break
        sum_+=box[j*i-1]
    if sum_%2!=a[i-1]:
        box[i-1]=1
        ans.append(i)

print(len(ans))
print(' '.join(list(map(str,ans))))
Problem p02969 (python)

Fixed submission:
r = int(input())
ans = r**2*3
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(int(input()) for i in range(N))
ans = A[0]
for i in range(N):
    for n in range(i):
        if ans < A[i]:
            ans = A[i]
    for n in range(i+1,N):
        if ans < A[i]:
            ans = A[i]
    print(ans)
    ans = A[0]
Problem p02971 (python)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B= sorted(A)

for i in range(N):
    if A[i] == B[N-1]:
        ans = B[N-2]
        print(ans)
    else:
        print(B[N-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(int(input()) for i in range(N))
for i in range(N):
    p= A[i]

    M = max(A)
    del A[i]
    MM = max(A)
    if M == MM:
        print(M)
    else:
        print(MM)
    A.insert(i,p)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(int(input()) for i in range(N))
for i in range(N):
    p= A[i]

    M = max(A)
    del A[i]
    MM = max(A)
    if M == MM:
        print(M)
    else:
        print(MM)
    A.insert(i,p)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(int(input()) for i in range(N))
ans = A[0]
for i in range(N):
    stor = A.pop(i)
    for n in range(N-1):
        if ans < A[i]:
            ans = A[i]
    A.insert(i,stor)
    print(ans)
    ans = A[0]

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(int(input()) for i in range(N))
ans = A[0]
for i in range(N):
    stor = A.pop(i)
    for n in range(N-1):
        if ans < A[i]:
            ans = A[i]
    A.append(stor)
    print(ans)
    ans = A[0]

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(int(input()) for i in range(N))
ans = A[0]
for i in range(N):
    stor = A.pop(i)
    for n in range(N-1):
        if ans < A[i]:
            ans = A[i]
   A.append(stor)
    print(ans)
    ans = A[0]

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split))
ans = A[0]
for i in range(N):
    for n in range(i):
        if ans < A[i]:
            ans = A[i]
    for n in range(i+1,N):
        if ans < A[i]:
            ans = A[i]
    print(ans)
    ans = A[0]
Problem p02995 (python)

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())
all = B-A+1
X = fractions.gcd(C,D)
gC = B//C - ((A-1)//C)
gD = B//D - ((A-1)//D)
gcdcd = C*D//X
gCD = B//gcdcd - ((A-1)//gcdcd)
ans = all - (gC+gD -gCD)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())
W = C*D//math.gcd(C,D)
X = B//C -((A-1)//C)
Y = B//D -((A-1)//D)
Z = B//W -((A-1)//W)
ans = (B-A+1)-(X+Y-Z)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())
W = C*D//math.gcd(C,D)
X = B//C -((A-1)//C)
Y = B//D -((A-1)//D)
Z = B//W -((A-1)//W)
ans = (B-A+1)-(X+Y-Z)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())
W = C*D//math.gcd(C,D)
X = B//C -((A-1)//C)
Y = B//D -((A-1)//D)
Z = B//W -((A-1)//W)
ans = (B-A+1)-(X+Y-Z)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())
W = C*D//math.gcd(C,D)
X = B//C -((A-1)//C)
Y = B//D -((A-1)//D)
Z = B//W -((A-1)//W)
ans = (B-A+1)-(X+Y-Z)
print(ans)
Problem p03000 (python)

Fixed submission:
N,X = map(int,input().split())
D = 0
ans = 1
L = list(x for x in input().split())
for i in range(N):
    
    if D <=X:
        D+=int(L[i])
        ans+=1
    else:
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    A = int(input().split())
    if D <=X:
        D+=A
        ans+=1
    else:
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    A = int(input())
    if D <=X:
        D+=A
        ans+=1
    else:
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    if D <=X:
        D+=int(input())
        ans+=1
    else:
        A =input()
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    if D <=X:
        D+=int(input())
        ans+=1
    else:
        A =input())
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    if D <=X:
        D+=int(input())
        ans+=1
    else:
        int(input())
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
for i in range(N):
    if D <=X:
        D+=int(input())
        ans+=1
    else:
        continue
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
while D <=X:
    D += int(input())
    ans+= 1
if D >X:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
D = 0
ans = 1
while D <=X:
    D += int(input())
    ans+= 1
if D >X:
    ans-=1
print(ans)
Problem p03001 (python)

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

if W/2 == x and H/2 == y:
    ans = 1
else:
    ans = 0
print(W*H/2,ans)

Buggy submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())
print(W*H/2)
if W//2 == x && H//2 == y:
    print(1)
else:
    print(0)
Problem p03087 (python)

Fixed submission:
N,Q = map(int,input().split())
S = str(input())
t = [0]*(N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy submission (verdict: Runtime Error):
 N, Q = map(int, input().split())
2 S = input()
3 t = [0] * (N + 1)
4 for i in range(N):
5 t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
6 for i in range(Q):
7 l, r = map(int, input().split())
8 print(t[r-1] - t[l-1])
Problem p03141 (python)

Fixed submission:
n = int(input())
res = []

ans = 0
for i in range(n):
    a,b = map(int,input().split())
    res.append(a+b)
    ans-=b

res.sort(reverse = True)
for i in range(0,n,2):
    ans+=res[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
res = []
x = 0
for i in range(n):
    a,b = map(int,input().split())
    res.append(a+b)
res.sort(reverse = True)
for i in range(n//2+1):
    ans+=res[i]
print(ans)
Problem p03165 (python)

Fixed submission:
s = input()
t = input()
dp = [[0]*(len(t)+1) for i in range(len(s)+1)]
#dp[i+1][j+1]sのi文字目までとtのj文字目までを比較したときのLCS
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

i = len(s)-1
j = len(t)-1
ans = ''
while j>= 0 and i >= 0:
    if dp[i][j+1] == dp[i+1][j+1]:i-= 1
    elif dp[i+1][j] == dp[i+1][j+1] :j-= 1
    else:
        ans = s[i] + ans
        i -= 1
        j -= 1
        
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
dp = [[0]*(len(t)+1) for i in range(len(s)+1)]
#dp[i+1][j+1]sのi文字目までとtのj文字目までを比較したときのLCS
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

i = len(s)
j = len(t)
ans = ''
while (i>=0 and j >= 0):
    if(dp[i+1][j] > dp[i][j+1] ):i-=1
    elif (dp[i+1][j] < dp[i][j+1]):j -= 1
    else:ans = s[i]+ ans
print(ans)
Problem p03200 (python)

Fixed submission:
s = input()
n  =len(s)
res = 0
ans = 0
for i in range(n):
    if s[i] == 'B':
        res+=1
    else:
        ans+=res


print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
n  =len(s)
res = 0
ans = 0
for i in range(n):
    if s[i] == 'B':
        res+=1AC
    else:
        ans+=res


print(ans)
Problem p03244 (python)

Fixed submission:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
a = Counter(a)
b = Counter(b)
p = a.most_common()[0][1]
q = b.most_common()[0][1]

if a.most_common()[0][0] == b.most_common()[0][0]:
    if p == n//2:
        if q == n//2:
            print(n-p-q+n//2)
        else:
            print(n-q-b.most_common()[1][1])
    else:
        if q != n//2:
            
            print(min(n-p-b.most_common()[1][1],n-q-a.most_common()[1][1]))
        else:
            print(n-q-a.most_common()[1][1])
            
    
        
            
        

else:
    print(n-p-q)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
a = Counter(a)
b = Counter(b)
p = a.most_common()[0][1]
q = b.most_common()[0][1]

if a.most_common()[0][0] == b.most_common()[0][0]:
    if p == n//2:
        if q == n//2:
            print(n-p-q+n//2)
        else:
            print(n-p-q+(n//2-b.most_common[1][1]))
    else:
        if q != n//2:
            print(n-p-q+n-a.most_common[1][1]-b.most_common[1][1])
        else:
            print(n-p-q+(n//2-a.most_common[1][1]))
            
    
        
            
        

else:
    print(n-p-q)
Problem p03304 (python)

Fixed submission:
n,m,d = map(int,input().split())
print(2*(m-1)*(n-d)/n/n if d > 0 else (m-1)/n)

Buggy submission (verdict: Runtime Error):
print(2*(m-1)*(n-d)/n/n if m > 0 else (m-1)/n)
Problem p03331 (python)

Fixed submission:
n = int(input())
ans = 10**9
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
for a in range(1,n//2+3):
    b = n-a
    if a>=1 and b>=1:
        
        ans = min(digitSum(a)+digitSum(b),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 10**9
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
for a in range(1,n//2+3):
    b = n-a
    
    ans = min(digitSum(a)+digitSum(b),ans)
print(ans)
Problem p03386 (python)

Fixed submission:
a,b,k = map(int,input().split())
ans = []
for i in range(k):
    if a+i not in ans and a+i <=b:ans.append(a+i)
    if b-i not in ans and b-i >=a:ans.append(b-i)
ans.sort()
print(*ans)

Buggy submission (verdict: Runtime Error):
    a,b,k = map(int,input().split())
    ans = []
    for i in range(k):
        if a+i not in ans and a+i <=b:ans.append(a+i)
        if b-i not in ans and b-i >=a:ans.append(b-i)
    ans.sort()
    print(*ans)
Problem p03578 (python)

Fixed submission:
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
if n < m:
    print('NO')
    exit(0)
dcnt = {}
for x in d:dcnt[x] = 0
ok = True
for x in d:dcnt[x]+=1
for i in range(m):
    if t[i] not in dcnt:
        ok = False
        break
    if dcnt[t[i]] == 0:
        ok = False
        break
    dcnt[t[i]] -= 1
if ok:print('YES')
else:print('NO')

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
if n < m:
    print('NO')
    exit(0)
dcnt = {}
for x in d:dcnt[x] = 0
ok = True
for x in d:dcnt[x]+=1
for i in range(m):
    if t[i] not in dcnt:ok = False
    if dcnt[t[i]] == 0:ok = False
    dcnt[t[i]] -= 1
if ok:print('YES')
else:print('NO')

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
if n < m:
    print('NO')
    exit(0)
dcnt = {}
for x in d:dcnt[x] = 0
ok = True
for x in d:dcnt[x]+=1
for i in range(m):
    if dcnt[t[i]] == 0:ok = False
    dcnt[t[i]] -= 1
if ok:print('YES')
else:print('NO')
Problem p03599 (python)

Fixed submission:
a,b,c,d,e,f = map(int,input().split())
X = []
Y = []
res = 0
for i in range(f+1):
    for j in range(f+1):
        x = 100*a*i+100*b*j
        y = c*i+d*j
        if x > f and y > f:break
        X.append(x)
        Y.append(y)
def ok(x,y):
    return (x//100)*e >= y and x+y <=f
cnt = 0
X.sort()
Y.sort()
ansx = 0
ansy = 0
for x in X:
    for y in Y:
        if x+y > f:break
        
        if ok(x,y):
          
            if x+y == 0:continue
            if res <= 100*y/(x+y):
                res = 100*y/(x+y)
                ansx = x
                ansy = y
        cnt +=1
print(ansx+ansy,ansy)

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int,input().split())
X = []
Y = []
res = 0
for i in range(f+1):
    for j in range(f+1):
        x = 100*a*i+100*b*j
        y = c*i+d*j
        if x > f and y > f:break
        X.append(x)
        Y.append(y)
def ok(x,y):
    return (x//100)*e >= y and x+y <=f
cnt = 0
X.sort()
Y.sort()
for x in X:
    for y in Y:
        if x+y > f:break
        
        if ok(x,y):
          
            if x+y == 0:continue
            if res < 100*y/(x+y):
                res = 100*y/(x+y)
                ansx = x
                ansy = y
        cnt +=1
print(ansx+ansy,ansy)
Problem p03695 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
red = 0
ans = 0
cnt = [0]*10
for x in a:
    if x < 3200:
        cnt[x//400] +=1
    else:
        red+=1
for x in cnt:
    if x >0:ans+=1

if red == n:print(1)
else:print(ans)
ans+=red
print(ans)

Buggy submission (verdict: Runtime Error):
    n = int(input())
    a = list(map(int,input().split()))
    red = 0
    ans = 0
    cnt = [0]*10
    for x in a:
        if x < 3200:
            cnt[x//400] +=1
        else:
            red+=1
    for x in cnt:
        if x >0:ans+=1

    if red == n:ans = 1
    print(ans)
    ans+=red
    print(ans)
Problem p03845 (python)

Fixed submission:
n = int(input())
t = list(map(int,input().split()))
m = int(input())
res = sum(t)
px = [list(map(int,input().split()))for _ in range(m)]
for i in range(m):
    p = px[i][0]-1
    x = px[i][1]
    ans = res -t[p]+x
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = list(map(int,input().split()))
m = int(input())
res = sum(t)
px = [list(map(int,input().split()))for _ in range(m)]
for i in range(m):
    p = px[i][0]-1
    x = px[i][1]
    ans = res -t[i]+x
    print(ans)
Problem p03854 (python)

Fixed submission:
s = input()
n = len(s)

left = 0
right = 5
ok = True
while left <n:
    if left >n-1 or right > n:break
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if right < n and s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)

left = 0
right = 5
ok = True
while left <n:
    if left >n-1 or right > n:break
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)

left = 0
right = 5
ok = True
while left <n:
    if s[left:right] == "dream":
        
        if s[right:right+2] == "er" and s[right:right+5] != "erase" and s[right:right+6] != "eraser": 
            left = right+2
            right = min(left+5,n)
        else:
            left = right
            right = min(n,left+5)
    
    elif s[left:right] == "erase":
        
        if s[right] == 'r':
         
            left = right+1
            right = min(n,left+5)
        else:
            left = right
            right = min(n,left+5)
    else:
        ok = False
        break
if ok:print("YES")
else:print("NO")
Problem p02576 (python)

Fixed submission:
import math
N, X, T = (int(i) for i in input().split())

print(T * math.ceil(N / X))

Buggy submission (verdict: Runtime Error):
H, W, M = (int(i) for i in input().split())

hw = set()
hh = [0] * H
ww = [0] * W

for i in range(M):
    ht , wt = (int(i) for i in input().split())
    hw.add((ht-1) * W + wt - 1)
    hh[ht-1] += 1
    ww[wt-1] += 1

hhh = max(hh)
ih = [i for i, x in enumerate(hh) if x == hhh]

www = max(ww)
iw = [i for i, x in enumerate(ww) if x == www]

minus = 1
for iih in ih:
    for iiw in iw:
        if iih * W + iiw not in hw:
            minus = 0
            break

print(hhh + www - minus)
Problem p02630 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
BC = []

for i in range(Q):
    b, c = (int(i) for i in input().split())
    BC.append((b,c))

sums = [0] * 100001

init_sum = sum(A)
for a in A:
    sums[a] += 1

for res in BC:
    sums[res[1]] += sums[res[0]]
    init_sum += (res[1] - res[0]) * sums[res[0]]
    sums[res[0]] = 0
    print(init_sum)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
BC = []

for i in range(Q):
    b, c = (int(i) for i in input().split())
    BC.append((b,c))

sums = [0] * 10001

init_sum = sum(A)
for a in A:
    sums[a] += 1

for res in BC:
    sums[res[1]] += sums[res[0]]
    init_sum += (res[1] - res[0]) * sums[res[0]]
    sums[res[0]] = 0
    print(init_sum)
Problem p03043 (python)

Fixed submission:
import math
N, K = (int(i) for i in input().split())

if K == 1:
    pow_base = 1
else:
    pow_base = math.floor(math.log((K-1),2)) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log((K-1) // i, 2)) + 1
        res += 2 ** (pow_base - power)
print(res / base)

Buggy submission (verdict: Runtime Error):
import math
N, K = (int(i) for i in input().split())

pow_base = math.floor(math.log((K-1),2)) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log((K-1) // i, 2)) + 1
        res += 2 ** (pow_base - power)
print(res / base)

Buggy submission (verdict: Runtime Error):
import math
N, K = (int(i) for i in input().split())

pow_base = math.floor(math.log2((K-1))) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log2((K-1) // i)) + 1
        res += 2 ** (pow_base - power)
print(res / base)
Problem p03160 (python)

Fixed submission:

N = int(input())
h = [int(i) for i in input().split()] 

# 足場iにたどり着く最小コストをc[i]とすると、
# c[i] = min(c[i-1] + |h[i] - h[i-1]| , c[i-2] + |h[i] - h[i-2]|) 

cost = [0] * N 
for i in range(N):
    if i==0:
        cost[i] = 0
    if i==1:
        cost[i] = abs(h[i] - h[i-1])
    if i > 1:
        cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]) , cost[i-2] + abs(h[i] - h[i-2]))

print(cost[N-1])

Buggy submission (verdict: Runtime Error):

N = int(input())
h = [int(i) for i in input().split()] 

# 足場iにたどり着く最小コストをc[i]とすると、
# c[i] = min(c[i-1] + |h[i] - h[i-1]| , c[i-2] + |h[i] - h[i-2]|) 

def cost(i):
    if i > 1:
        return min(cost(i-1) + abs(h[i] - h[i-1]) , cost(i-2) + abs(h[i] - h[i-2]))
    if i == 1:
        return cost(i-1) + abs(h[i] - h[i-1])
    if i == 0:
        return 0

print(cost(N-1))