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

Fixed submission:
a,b,k = list(map(int,input().split()))
c= 1
d=0
if b < a:
    a,b=b,a
while True:
    d = b%a
    if d == 0:
        c=a
        break
    else:
        b = a
        a = d
e = 0
for i in range(1,c+1):
    if c%i == 0:
        e +=1
        if e == k:
            print(int(c/i))
            break

Buggy submission (verdict: Runtime Error):
import math
a,b,k = list(map(int,input().split()))
c = math.gcd(a,b)
d = list()
e = 0
for i in range(1,(c//2)+1):
    if c%i == 0:
        e +=1
        if e == k:
            print(int(c/i))

Buggy submission (verdict: Runtime Error):
import math
a,b,k = list(map(int,input().split()))
c = math.gcd(a,b)
d = list()
for i in range(1,(c//2)+1):
    if c%i == 0:
        d.append(i)
d.append(c)
print(d[-k])
Problem p03128 (python)

Fixed submission:
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
cost = [0,2,5,5,4,5,6,3,7,6] 
dp = [-1]*(n+1)
dp[0] = 0

for i in range(2,n+1):
    for j in range(0,m):
        if i-cost[a[j]] <0:
            continue
        if dp[i-cost[a[j]]] == -1:
            continue
        else:
            dp[i] = max(dp[i],dp[i-cost[a[j]]]+1)

ans = list()
read = n
a.sort()
a.reverse()

while read > 0:
    for i in range(0,m):
        if read < cost[a[i]]:
            continue
        if dp[read-cost[a[i]]] == dp[read]-1:
            ans.append(str(a[i]))
            read -= cost[a[i]]
            break
    
print("".join(ans))

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
cost = [0,2,5,5,4,5,6,3,7,6] # cost[a[i]] = a[i]のコスト
dp = [-1]*(n+1)
dp[0] = 0

for i in range(2,n+1):
    for j in range(0,m):
        if dp[i-cost[a[j]]] == -1:
            continue
        else:
            dp[i] = max(dp[i],dp[i-cost[a[j]]]+1)

ans = list()
read = n
a.sort()
a.reverse()

while read > 0:
    for i in range(0,m):
        if read -cost[a[i]] < 0:
            continue
        if dp[read-cost[a[i]]] == dp[read]-1:
            ans.append(str(a[i]))
            read -= cost[a[i]]
            break
    
print("".join(ans))

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
cost = [0,2,5,5,4,5,6,3,7,6] # cost[a[i]] = a[i]のコスト
dp = [-1]*(n+1)
dp[0] = 0

for i in range(2,n+1):
    for j in range(0,m):
        if dp[i-cost[a[j]]] == -1:
            continue
        else:
            dp[i] = max(dp[i],dp[i-cost[a[j]]]+1)

ans = list()
read = n
for i in reversed(range(0,n-1)):
    if dp[i]+1 == dp[read]:
        if read-i in [2,3,4,7]:
            ans.append(str(cost.index(read-i)))
        elif read-i == 6:
            if 9 in a:
                ans.append(str(9))
            else:
                ans.append(str(6))
        elif read -i == 5:
            if 5 in a:
                ans.append(str(5))
            elif 3 in a:
                ans.append(str(3))
            else:
                ans.append(str(2))
        read = i
ans.sort()
print("".join(reversed(ans)))
Problem p03219 (python)

Fixed submission:
x,y = list(map(int,input().split()))
print(x+y//2)

Buggy submission (verdict: Runtime Error):
x,y = list(map(input().split()))
print(x+y//2)
Problem p04047 (python)

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
s.sort()
sum = 0

for i in range(0,2*n,2):
  sum += s[i]
print(sum)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(map(int,input().split()))
s.sort()
sum = 0

for i in range(0,2n,2):
  sum += s[i]
print(sum)
Problem p02969 (python)

Fixed submission:
r = int(input())

a = r
ans = 3 * a * a
print(ans)

Buggy submission (verdict: Runtime Error):
r = int(input())80

a = r
ans = 3 * a * a
print(ans)
Problem p02995 (python)

Fixed submission:
import math
import fractions
A, B, C, D = map(int, input().split())

ans = 0


c_n = (B // C) - ((A - 1) // C)
d_n = (B // D) - ((A - 1) // D)
cd = C * D // fractions.gcd(C,D)
cd_n = (B // cd) - ((A - 1) // cd)

ans = (B - A + 1) - (c_n + d_n - cd_n)
print(ans)

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

ans = 0

c_n_min = math.ceil(A / C)
c_n_max = math.floor(B / C)
c_n = c_n_max - c_n_min + 1

d_n_min = math.ceil(A / D)
d_n_max = math.floor(B / D)
d_n = d_n_max - d_n_min + 1

cd = C * D /math.gcd(C,D)
cd_n_min = math.ceil(A / cd)
cd_n_max = math.floor(B / cd)
cd_n = cd_n_max - cd_n_min + 1

ans = (B - A + 1) - (c_n + d_n - cd_n)
print(ans)
Problem p03001 (python)

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


multi_ans = 0

if ((x == 0 and y == 0) or (x == 0 and y == H) or (y == 0 and x == W) or (y == H and x == W)):
    multi_ans = 0
elif (W==H and not((x == W - x or y == H - y))):
    multi_ans == 1
elif (x != 0 and y != 0):
    if (W / x == H / y):
        if (x == W - x and y == H -y):
            multi_ans = 1
        else:
            multi_ans = 0

ans = W * H /2.0
print("{} {}".format(ans, multi_ans))

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

a_x = min(x, W - x)
a_y = min(y, H - y)

if ((W == H) and (x == y or x == H - y)):
    ans = W * H / 2.0
    if (x == W - x and y == H -y):
        multi_ans = 1
    else:
        multi_ans = 0

if (W < H):
    l = H
    m = a_x
else:
    l = W
    m = a_y
ans = l * m
if (x == W/2 and y == H/2):
    multi_ans = 1
elif (W == H and (x != 0 and y != 0)):
    multi_ans = 1
else:
    multi_ans = 0

# 対角線
if (((W % x == 0) and (H % y ==0)) and (x == y or x == H - y)):
    ans = W * H / 2.0
    if (x == W - x and y == H -y):
        multi_ans = 1
    else:
        multi_ans = 0

# 4点
if ((x == 0 and y == 0) or (x == 0 and y == H) or (y == 0 and x == W) or (y == H and x == W)):
    multi_ans = 0
    ans = W * H / 2.0

print("{} {}".format(ans, multi_ans))
Problem p03109 (python)

Fixed submission:
a = input()
if(a[5] == "1"):
    print("TBD")
elif(int(a[6]) > 4):
    print("TBD")
else:
    print("Heisei")

Buggy submission (verdict: Runtime Error):
a = input()
if(int(a[5]) = 1):
    print("TBD")
elif(int(a[6]) > 4):
    print("TBD")
else:
    print("Heisei")
Problem p03761 (python)

Fixed submission:
N  = int(input())
slist = [input() for _ in range(N)]
abc = 'abcdefghijklmnopqrstuvwxyz'
l = [50] * 26
ans = ''
for i in range(26):
    for s in slist:
        l[i] = min(l[i],s.count(abc[i]))
for j in range(26):
    ans = ans + (abc[j] * l[j])
print(ans)

Buggy submission (verdict: Runtime Error):
N  = int(input())
slist = [input() for _ in range(N)]
abc = 'abcdefghijklmnopqrstuvwxyz'
l = [50] * 26
ans = ''
for i in range(N):
    for s in slist:
        l[i] = min(l[i],s.count(abc[i]))
for j in range(N):
    ans = ans + (abc[j] * l[j])
print(ans)
Problem p03504 (python)

Fixed submission:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

nc = raw_input()
nc = nc.split()
n,c = map(int,nc)

tt = np.zeros([(10**5),c],int)

for i in range(n):
    stc = raw_input()
    stc = stc.split()
    s,t,c = map(int,stc)
    j = s
    while j <= t:
        tt[j-1][c-1] = 1
        j += 1

ans = np.max(np.sum(tt, axis=1))

print ans

Buggy submission (verdict: Runtime Error):
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

nc = raw_input()
nc = nc.split()
n,c = map(int,nc)

tt = np.zeros([(10**2),c],int)

for i in range(n):
    stc = raw_input()
    stc = stc.split()
    s,t,c = map(int,stc)
    j = s
    while j <= t:
        tt[j-1][c-1] = 1
        j += 1

ans = np.max(np.sum(tt, axis=1))

print ans
Problem p03544 (python)

Fixed submission:
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

b2 = 2
b1 = 1

if n == 1:
    a = 1
else:
    for i in range(n-1):
        a = b1 + b2
        b2 = b1
        b1 = a
        #print i+2, a

print a

Buggy submission (verdict: Runtime Error):
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

b2 = 2
b1 = 1

for i in range(n-1):
    a = b1 + b2
    b2 = b1
    b1 = a
    #print i+2, a

print a
Problem p03589 (python)

Fixed submission:
#!usr/bim/python
#! -*- coding: utf-8 -*-
import math

nyu = raw_input()
nyu = int(nyu)

h = 0
n = 0
w = 0

if nyu % 2 == 0:
    h = nyu
    n = nyu
    w = nyu / 2

elif nyu % 4 == 1:
    h = nyu / 4.0
    h = math.ceil(h)
    h = int(h)
    i = 0
    status = 0
    while 1:
        x = nyu*h
        y = 4*i+3
        for j in range(y/2):
            if j == 0:
                if x % y == 0:
                    n = x*2/y
                    w = x*2/y
                    status = 1
                    break
            else:
                if x % (j*(y-j)) == 0:
                    n = x/(y-j)
                    w = x/j
                    status = 1
                    break
        if status == 1:
            break
        else:
            i += 1
            h += 1

else:
    h = nyu / 4.0
    h = math.ceil(h)
    h = int(h)
    n = nyu*h*2
    w = nyu*h*2

print h,n,w

Buggy submission (verdict: Runtime Error):
#!usr/bim/python
#! -*- coding: utf-8 -*-
import math

nyu = raw_input()
nyu = int(nyu)

if nyu % 2 == 0:
    h = nyu
    n = nyu
    w = nyu / 2

elif nyu % 4 == 1:
    h = nyu / 4.0
    h = math.ceil(h)
    h = int(h)
    if h % 3 == 0:
        n = nyu*h/3*2
        w = nyu*h/3*2
    elif h % 2 == 0:
        n = nyu*h/2
        w = nyu*h
    else:
        h += 1
        if (nyu*h) % 6 == 0:
            n = nyu*h/6
            w = nyu*h
        elif (nyu*h) % 10 == 0:
            n = nyu*h/5
            w = nyu*h/2
        elif (nyu*h) % 7 == 0:
            n = nyu*h/7*2
            w = nyu*h/7*2

else:
    h = nyu / 4.0
    h = math.ceil(h)
    h = int(h)
    n = nyu*h*2
    w = nyu*h*2

print h,n,w
Problem p03643 (python)

Fixed submission:
#!usr/bim/python
#! -*- coding: utf-8 -*-


num = raw_input()

print "ABC"+num

Buggy submission (verdict: Runtime Error):
#!usr/bim/python
#! -*- coding: utf-8 -*-


n_m = raw_input()
n,m = n_m.split()

#n = int(n)
m = int(m)

shima_1_list = []
shima_2_list = []

i = 0
while i < m:
    teikibin = raw_input()
    teikibin = teikibin.split()
    if teikibin[0] == "1":
        shima_1_list.append(teikibin[1])
    elif teikibin[1] == n:
        shima_2_list.append(teikibin[0])
    i += 1

status = 0

for shima_1 in shima_1_list:
    if shima_1 in shima_2_list:
        status = 1

if status == 0:
    print "IMPOSSIBLE"
else:
    print "POSSIBLE"
Problem p02973 (python)

Fixed submission:
import bisect

N = int(input())
A = [0] * N
for i in range(N):
  A[i] = int(input())

B = [A[N - 1]]
for i in reversed(range(0, N - 1)):
  if A[i] >= B[-1]:
    B.append(A[i])
  else:
    index = bisect.bisect_right(B, A[i])
    B[index] = A[i]
print(len(B))

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
A = [0] * N
for i in range(N):
  A[i] = int(input())

B = [A[0]]
for i in range(1, N):
  print(B)
  if A[i] <= B[0]:
    B.insert(0, A[i])
  else:
    index = bisect.bisect_left(B, A[i]) - 1
    B[index] = A[i]
print(len(B))
Problem p02969 (python)

Fixed submission:
S = int(input())
print(S * S * 3)

Buggy submission (verdict: Runtime Error):
S = int(input()
print(3 * S * S)
Problem p02993 (python)

Fixed submission:
N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
    else:
        print("Bad")
        exit()
if bool == 1:
    print("Good")

Buggy submission (verdict: Runtime Error):
A , B , C , D = map(int,input().split())
lst = []
list= [i for i in range(A,B) i % C != 0]
for i in list:
    if  i % D != 0:
        lst.append(i)
print(len(lst))

Buggy submission (verdict: Runtime Error):
N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
if bool = 1:
    print("Good")
else:
    print("Bad")

Buggy submission (verdict: Runtime Error):
N = list(map(int,input()))
for i in len(N - 1):
    if N[i] == N[i+1]:
        print("Good")
    else :
        print("Bad")
Problem p02994 (python)

Fixed submission:
N , X =map(int,input().split())
sums = []
i = X
result =[]
a = []
for i in range(N):
    sums.append(i+X)
for j in range(N):
    a.append(abs(sums[j]))

if sum(sums) ==abs(sum(sums)):
    print(sum(sums) - min(a))
else :
    print(sum(sums) + min(a))

Buggy submission (verdict: Runtime Error):
N , X =map(int,input().split())
sums = []
i = X
result =[]
for i in range(N):
    sums.append(i+X)
for j in range(N):
    result.append(sum(sums)-sums[j]*2 )
for k in range(N):
    if sum(sums) == result[k]:
        print(result[k])
    else:
        print(abs(min(result[k])))
Problem p03501 (python)

Fixed submission:
N,A,B = map(int, input().split())
if N * A < B:
    print(N*A)
else:
    print(B)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().sqlit())
if N * A > B :
  print(N*A)
else:
  print(B)
Problem p03502 (python)

Fixed submission:
A = int(input())
B = A
list=[]
while B > 0:
    list.append(B%10)
    B //=10
    #print(list)
if A % sum(list) == 0:
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
A = input()
for i in range(A)
	B = int(A)

if A % B == 0 :
  print("Yes")
else:
  print("No")
Problem p03777 (python)

Fixed submission:
at = list(input())
at_i = 0
top_i = 0
if at[0] =='H':
  at_i = 1

if at[0] == 'D':
  at_i = -1

if at[2] == 'H':
	top_i = 1

if at[2] == 'D':
  top_i = -1

if top_i * at_i == 1:
    print("H")
else :
    print("D")

Buggy submission (verdict: Runtime Error):
at = input().split()
top = input().split()
at_i = 0
top_i = 0
if at =='H':
  at_i = 1

if at == 'D':
  at_i = -1

if top == 'H':
	top_i = 1

if top == 'D':
  top_i = -1

if top_i * at_i == 1:
    print("H")
else :
    print("D")

Buggy submission (verdict: Runtime Error):
at = input().split()
top = input().split()
if at =='H':
  at_i = 1

if at == 'D':
  at_i = -1
  
if top == 'H':
	top_i = 1

if top == 'D':
  top_i = -1

if top_i * app_i == 1:
  print("H")
else
	print("D")
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
square = (a + b) * h / 2
print(int(square))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
h = input()
print((a+b)*h/2)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
h = input
print((a+b)*h/2)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
h=input()
print((a+b)*h+/2)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
h=input
print((a+b)*h+/2)
Problem p04030 (python)

Fixed submission:
S = input()
str = []
result = ""
flg = 0
for i in range(len(S)):
    if S[i] == 'B':
        result = result[:-1]
    else:
        result += S[i]
print(result)

Buggy submission (verdict: Runtime Error):
S = input()
str = []
result = ""
flg = 0
for i in range(len(S)):
    if S[i] == 'B':
        str.pop(i-1)
    else:
        str.append(S[i])
for i in str:
    result += i
print(result)
Problem p03103 (python)

Fixed submission:
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)

Buggy submission (verdict: Runtime Error):
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)
=
Problem p03470 (python)

Fixed submission:
import sys
input(), print(len(set(sys.stdin.read().strip().split())))

Buggy submission (verdict: Runtime Error):
import sys
print(len(set(sys.input().read().strip().split())))
Problem p03000 (python)

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

D = 0
num = 1

while num <= N:
  D = D + L[num-1]
  if D > X:
    print(num)
    break
  num += 1
else:
  print(N+1)

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

D = 0
num = 1

while num <= N+1:
  if D >= X:
    print(num)
    break
  D = D + L[num-1]
  num += 1
else:
  print(N)
Problem p03447 (python)

Fixed submission:
n = input()
m = input()
l = input()

n = int(n)
m = int(m)
l = int(l)

n = n - m
while n >= l :
  n = n - l
else: 
  print(n)

Buggy submission (verdict: Runtime Error):
n = input()
m = input()
l = input()
n = n - m
print(n)
if n >= l
 n = n - l
  print(n)
else:
  print(n)
Problem p02945 (python)

Fixed submission:
x = list(map(int,input().split()))
print(max([x[0]+x[1],x[0]-x[1],x[0]*x[1]]))

Buggy submission (verdict: Runtime Error):
x = map(int,raw_input().split())
print(max([x[0]+x[1],x[0]-x[1],x[0]*x[1]]))
Problem p02982 (python)

Fixed submission:
import numpy as np
N, D = map(int, input().split())

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

ans = 0
for i in range(N):
    for j in range(i + 1 , N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, D = map(int, input().split())

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

ans = 0
for i in range(N):
    for j in range(i + 1 , N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)
Problem p03031 (python)

Fixed submission:
import itertools

N, M = map(int, input().split())

S = []
for i in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
P = [int(i) for i in input().split()]

A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
 
N, M = map(int, input().split())
 
S = []
for i in range(M):
    k, *s = map(int, input().split())
    S.append([s])
    
P = [int(i) for i in input().split()]
 
A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

N, M = map(int, input().split())

S = []
for i in range(M):
    k, *s = map(int, input().split())
    S.append([*s])
    
P = [int(i) for i in input().split()]

A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 8)

N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [0] * N

def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0] , -color[v])
                
for i in range(N):
    dfs(i, 1)
    # print(color)
    
for i in range(N):
    if color[i] == 1:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
from collections import deque

N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [-1] * N
color[0] = 0
Q = deque()
Q = [0]

while len(Q) != 0:
    cur = Q.popleft()
    for to, dist in G[cur]:
        if color[to] == -1:
            color[to] = (color[cur] + dist) % 2
            Q.append(to)
            
for i in range(N):
    print(color[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [0] * N

def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0] , -color[v])
                
for i in range(N):
    dfs(i, 1)
    # print(color)
    
for i in range(N):
    if color[i] == 1:
        print(0)
    else:
        print(1)
Problem p03061 (python)

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

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

B = A.copy()
for i in range(N - 1):
    B[i + 1] = gcd(B[i], B[i + 1])

C = A.copy()
C.reverse()
for i in range(N - 1):
    C[i + 1] = gcd(C[i], C[i + 1])
C.reverse()

ans = 0
for i in range(N):
    if i == 0:
        tmp = C[i + 1]
    elif i == N - 1:
        tmp = B[i - 1]
    else:
        tmp = gcd(B[i - 1], C[i + 1])
    ans = max(ans, tmp)
    
print(ans)

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

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

if N == 2:
    print(max(A))

else:
    if gcd(A[0], A[1]) > gcd(A[1], A[2]):
        x = 2
    elif gcd(A[0], A[1]) < gcd(A[1], A[2]):
        x = 0
    elif gcd(A[0], A[2]) > gcd(A[1], A[2]):
        x = 1
    elif gcd(A[0], A[2]) < gcd(A[1], A[2]):
        x = 0
    else:
        A2 = A.copy()
        for i in range(2, N - 1):
            A2[i + 1] = gcd(A2[i], A2[i + 1])
            if A2[i] > A2[i + 1]:
                x = i + 1
                break

    del A[x]
    for i in range(N - 2):
        A[i + 1] = gcd(A[i], A[i + 1])
    print(A[-1])
Problem p03074 (python)

Fixed submission:
N,K = map(int,input().split())
S = input()
 
zeros = []
ones = [0]
# Sが0始まりの時は、それを挟むための1が必要なので、予め入れておく
# 1始まりの時は、これに+= 1するので問題なし
 
prev = '1'
for c in S:
    if c == '1':
        if prev == '0':
            ones.append(1)
        else:
            ones[-1] += 1
    else: #c == '0'
        if prev == '1':
            zeros.append(1)
        else:
            zeros[-1] += 1
    prev = c
ones.append(0)
# Sが0終わりの時は、それを挟むための1が必要なので、最後に付け加えておく
# 1終わりの時は不要だが、maxをとるので0を入れておいても影響はない

tmp = sum(zeros[0:K]) + sum(ones[0:K+1])
#　初期値として、最初の区間の和を計算しておけば、
# あとは先頭と最後尾を+-するだけで累積和を求められる
ans = tmp
for i in range(0,len(zeros)-K):
    tmp += zeros[i+K] - zeros[i] + ones[i+K+1] - ones[i]
    ans = max(tmp,ans)

print(ans)

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

one = []
cnt = 0
for i, s in enumerate(S):
    if s == '1':
        cnt += 1
        if i == N - 1:
            one.append(cnt)
    elif s == '0':
        if cnt > 0:
            one.append(cnt)
            cnt = 0
            
zero = []
cnt = 0
for i, s in enumerate(S):
    if s == '0':
        cnt += 1
        if i == N - 1:
            zero.append(cnt)
    elif s == '1':
        if cnt > 0:
            zero.append(cnt)
            cnt = 0
            
if len(one) <= len(zero):
    one = [0] + one + [0]
    
for i in range(len(one) - 1):
    one[i + 1] = one[i] + one[i + 1]
one = [0] + one
    
for i in range(len(zero) - 1):
    zero[i + 1] = zero[i] + zero[i + 1]
zero = [0] + zero
    
ans = -1
for i in range(len(one) - (K + 1) + 1):
    tmp = one[i + K] - one[i - 1] + zero[i + K - 1] - zero[i - 1]
    ans = max(ans, tmp)
    # print(tmp)
    
if len(zero) - 1 <= K:
    print(len(S))
else:
    print(ans)
Problem p03076 (python)

Fixed submission:
A = []
B = []
for i in range(5):
    x = input()
    if int(x[-1]) != 0:
        A.append(10 - int(x[-1]))
    B.append(int(x))

if A == []:
    print(sum(A) + sum(B))
else:
    print(sum(A) + sum(B) - max(A))

Buggy submission (verdict: Runtime Error):
A = []
B = []
for i in range(5):
    x = input()
    if int(x[-1]) != 0:
        A.append(10 - int(x[-1]))
    B.append(int(x))

print(sum(A) + sum(B) - max(A))