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

Fixed submission:
s, w = list( map( int , input().split() )) 
if w >= s:
	print('unsafe')
else:
	print('safe')

Buggy submission (verdict: Runtime Error):
s, w = list( map( int ,input() )) 
if w >= s:
	print('unsafe')
else:
	print('safe')
Problem p02915 (python)

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

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

Fixed submission:
s=input()
h=set()
for i in range(0,len(s)):
	h.add(s[i])
if(len(h)==2):
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
s=input()
s.sort()
ans = "NO"
if s[0]==s[1] and s[1]!=s[2] and s[2]==s[3]:
  ans="Yes"
print(ans)
Problem p03127 (python)

Fixed submission:
import fractions
n=int(input())
a=list(map(int,input().split()))
tmp=a[0]
for i in range(1,n):
    tmp=fractions.gcd(a[i],tmp)
print(tmp)

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

while (len(a)>1):
    b=math.gcd(a[0],a[1])
    del a[1]
    del a[0]
    a.append(b)
print(a[0])

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

while (len(a)>1):
    b=math.gcd(a[0],a[1])
    del a[1]
    del a[0]
    a.append(b)
print(a[0])
Problem p03272 (python)

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

print(N - i + 1)

Buggy submission (verdict: Runtime Error):
N , i = map(int, input())

print(N - i + 1)
Problem p02935 (python)

Fixed submission:
N = int(input())
v = list(map(int,input().split()))
def func(a,b):
    return (a+b)/2
v = sorted(v)
ave = (v[0]+v[1])/2
for i in range(2,N):
    ave = func(ave,v[i])
    
print(ave)

Buggy submission (verdict: Runtime Error):
N = int(input())
v = list(map(int,input().split()))
def func(a,b):
    return (a+b)/2
  v = sorted(v)
ave = (v[0]+v[1])/2
for i in range(2,N):
    ave = func(ave,v[i])
    
print(ave)
Problem p02948 (python)

Fixed submission:
import heapq
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]
 
for i in range(N):
    a, b = map(int,input().split())
    if a > M:
        continue
    A[a].append(-b)
 
work_cand = []
sum = 0
 
for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    if len(work_cand) == 0:
        continue
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]
 
for i in range(N):
    a, b = map(int,input().split())
    if a > m:
        continue
    A[a].append(-b)
 
work_cand = []
sum = 0
 
for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    if len(work_cand) == 0:
        continue
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]

for i in range(M):
    a, b = map(int,input().split())
    A[a].append(-b)

work_cand = []
sum = 0

for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    if len(work_cand) == 0:
        continue
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]

for i in range(M):
    a, b = map(int,input().split())
    A[a].append(-b)

work_cand = []
sum = 0

for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)
Problem p02951 (python)

Fixed submission:
A, B, C = map(int, input().split())
if (A-B) >= C:
    print(0)
    
else:
    print(C - (A-B))

Buggy submission (verdict: Runtime Error):
A, B, C = input().split()
if (A-B) >= C:
    print(0)
    
else:
    print(C - (A-B))
Problem p02989 (python)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
B = sorted(D)

if B[int(N/2)] == B[int(N/2)-1]:
    print(0)
else:
    print(B[int(N/2)]-B[int(N/2)-1])

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

if B[N/2] == B[(N/2)-1]:
    print(0)
else:
    print(B[N/2]-B[(N/2)-1])

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

if B[N/2] == B[(N/2)-1]:
    print(0)
else:
    print(B[N/2]-B[(N/2)-1])
Problem p03015 (python)

Fixed submission:
L = input()
n = len(L)
mod = 10**9+7
dp1 = [0]*(n+1)
dp2 = [0]*(n+1)
dp1[0] = 1
for i in range(n):
    if L[i] == "1":
        dp1[i+1] = (dp1[i]*2)%mod
        dp2[i+1] = (dp1[i] + dp2[i]*3)%mod
    else:
        dp1[i+1] = dp1[i]
        dp2[i+1] = (dp2[i]*3)%mod
print((dp1[n]+dp2[n])%mod)

Buggy submission (verdict: Runtime Error):
L = input()
def dp(index,tight):
    if index == -1:
        return tight == 1
    if not (index,tight) in memo:
        if L[index] == "1" and tight:
            memo[(index,tight)] = 2*dp(index-1,1)
        elif L[index] == "1" and not tight:
            memo[(index,tight)] = 3*dp(index-1,0) + dp(index-1,1)
        elif L[index] == "0" and tight:
            memo[(index,tight)] = dp(index-1,1)
        else:
            memo[(index,tight)] = 3*dp(index-1,0)
    return memo[(index,tight)]
memo = {}
a = dp(len(L)-1,1)
memo = {}
b = dp(len(L)-1,0)
print(a+b)

Buggy submission (verdict: Runtime Error):
L = input()
memo = {}
def dp(index,tight):
    if index == -1:
        return tight == 1
    if not (index,tight) in memo:
        if L[index] == "1" and tight:
            memo[(index,tight)] = 2*dp(index-1,1)
        elif L[index] == "1" and not tight:
            memo[(index,tight)] = 3*dp(index-1,0) + dp(index-1,1)
        elif L[index] == "0" and tight:
            memo[(index,tight)] = dp(index-1,1)
        else:
            memo[(index,tight)] = 3*dp(index-1,0)
    return memo[(index,tight)]
print(dp(len(L)-1,0)+dp(len(L)-1,1))

Buggy submission (verdict: Runtime Error):
L = input()
n = len(L)
mod = 10**9+7
dp1 = [0]*(n+1)
dp2 = [0]*(n+1)
dp1[0] = 1
for i in range(n):
    if L[i] == "1":
        dp1[i+1] = (dp[i]*2)%mod
        dp2[i+1] = (dp1[i] + dp2[i]*3)%mod
    else:
        dp1[i+1] = dp1[i]
        dp2[i+1] = (dp2[i]*3)%mod
print((dp1[n]+dp2[n])%mod)

Buggy submission (verdict: Runtime Error):
L = input()
n = len(L)
mod = 10**9+8
dp1 = [0]*(n+1)
dp2 = [0]*(n+1)
dp1[0] = 1
for i in range(n):
    if L[i] == "1":
        dp1[i+1] = (dp[i]*2)%mod
        dp2[i+1] = (dp1[i] + dp2[i]*3)%mod
    else:
        dp1[i+1] = dp1[i]
        dp2[i+1] = (dp2[i]*3)%mod
print((dp1[n]+dp2[n])%mod)
Problem p03041 (python)

Fixed submission:
N, K = map(int, input().split())
S = input()
a = S[K-1].lower()
A = S[0:K-1] + a + S[K:]
print(A)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
a = S[K-1]
S[K-1] = a.lower()
print(S)
Problem p03045 (python)

Fixed submission:
def find(x):
    if x == par[x]:
        return x
    par[x] = find(par[x])
    return par[x]
 
def union(x,y):
    x,y = find(x),find(y)
    if x == y:
        return
    par[y] = x
 
n,m = map(int,input().split())
par = {i:i for i in range(1,n+1)}
for _ in range(m):
    a,b,c = map(int,input().split())
    union(a,b)
print(sum([1 for i in range(1,n+1) if par[i] == i]))

Buggy submission (verdict: Runtime Error):
def find(x):
    if x == par[x]:
        return x
    par[x] = find(par[x])
    return par[x]

def union(x,y):
    x,y = find(x),find(y)
    if x == y:
        return
    par[y] = x

n,m = map(int,input().split())
par = {i:i for i in range(1,n+1)}
for _ in range(m):
    a,b,c = map(int,input().split())
    union(a,b)
print(len(set(par.values()))
Problem p03075 (python)

Fixed submission:
A = [input() for i in range(6)]
X = list(map(int, A))
a = X[0]
e = X[4]
k = X[5]
if e-a > k:
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
A = [input() for i in range(6)]
X = map(int, A)
a = X[0]
e = X[4]
k = X[5]
if e-a > k:
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
A = [input() for i in range(6)]
a, b, c, d, e, k = A
B = [a-b, a-c, a-d, a-e,b-c,b-d,b-e,c-d,c-e,d-e]
for i in range(10):
    if abs(B[i]) > k:
        print(":(")
        break
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
A = [input() for i in range(6)]
a, b, c, d, e, k = A
B = [a-b, a-c, a-d, a-e,b-c,b-d,b-e,c-d,c-e,d-e]
for i in range(10):
    if abs(B[i]) > k:
        print(":(")
        break
else:
    print("Yay!")
Problem p03250 (python)

Fixed submission:
A, B, C = map(int, input().split())
X = 10*A + B + C
Y = 10*B + A + C
Z = 10*C + A + B
print(max(X, Y, Z))

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
X = 10*A + B + C
Y = 10*B + A + C
Z = 10*C + A + B
print(max[X, Y, Z])
Problem p02598 (python)

Fixed submission:
import math
def is_ok(K, N, A, length):
    s = 0
    for i in range(N):
        if A[i] > length:
            s += math.ceil(A[i] / length)-1
    return K >= s


N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
if K == 0:
    print(max(A))
    exit()
ok = max(A)
ng = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(K, N, A, mid):
        ok = mid
    else:
        ng = mid

print(math.ceil(ok))

Buggy submission (verdict: Runtime Error):
import math
def is_ok(K, N, A, length):
    s = 0
    for i in range(N):
        if A[i] > length:
            s += math.ceil(A[i] / length)-1
    return K >= s


N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
if K == 0:
    print(max(A))
    exit()
ok = max(A)
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(K, N, A, mid):
        ok = mid
    else:
        ng = mid

print(math.ceil(ok))

Buggy submission (verdict: Runtime Error):
import math
def solve(K, N, A, length):
    s = 0
    for i in range(N):
        if A[i] > length:
            s += int(A[i] / length)
    return K >= s

# 一本ならナイーブには1/2を繰り返すのが最小になりそうだけど5とかだと1/2, (1/2, 1/2)で次4回切らないと中途半端に長いのが残ってしまう
# 複数本なら一番長いのを常に半分に切れば良さそう？
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
ok = A[-1]
ng = A[0]
while abs(ok - ng) > 1:
    mid = (ok + ng) / 2
    if solve(K, N, A, mid):
        ok = mid
    else:
        ng = mid

print(math.ceil(mid))
Problem p02729 (python)

Fixed submission:
def combination(n, x, mod=10**9+7):
    # nCx, a=n!, b=x!, c=(n-x)!
    # ex) combination(5, 2) = 10
    _factorial = [1] * (n+1)
    tmp = 1
    for i in range(1, n+1):
        tmp = (tmp * i) % mod
        _factorial[i] = tmp

    tmp = _factorial[n]
    tmp = (tmp * pow(_factorial[x], mod-2, mod)) % mod
    tmp = (tmp * pow(_factorial[n-x], mod-2, mod)) % mod
    return tmp

n, m = map(int, input().split())

if m > 1 and n > 1:
    M = combination(m, 2)
    N = combination(n, 2)
elif m <= 1 and n > 1:
    M = 0
    N = combination(n,2)
elif m > 1 and n <= 1:
    M = combination(m, 2)
    N = 0
else:
    M, N = 0, 0

print(M+N)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
print(n*(n-1)//2 + m*(m-1)//2a)
Problem p02773 (python)

Fixed submission:
from collections import Counter

n = int(input())
sl = list(input() for _ in range(n))

cnt = Counter(sl)
# print('cnt:', cnt)
maxNum = max(cnt.values())
# print('maxNum:', maxNum)

ans = []
for k, v in cnt.items():
    if v == maxNum:
        ans.append(k)

ans.sort()
print('\n'.join(ans))

Buggy submission (verdict: Runtime Error):
sl_s = sorted(list(set(sl)))

if len(sl_s) == 1:
    print(sl[0])
else:
    ans = []
    count = 1
    for s in sl_s:
        if sl.count(s) == count and ans.count(s) == 0:
            ans.append(s)
        elif sl.count(s) > count and ans.count(s) == 0:
            ans.clear()
            ans.append(s)
            count = sl.count(s)
    print('\n'.join(ans))
Problem p03042 (python)

Fixed submission:
s = input()
aa = int(s[:2])
bb = int(s[2:])

if 0<aa and aa<=12:
  if 0<bb and bb<=12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 0<bb and bb<=12:
    print('YYMM')
  else:
    print('NA')

Buggy submission (verdict: Runtime Error):
s = input()
aa = int(s[:2])
bb = int(s[2:])

if 0<aa and aa<=12:
  if 0<bb and bb<=12:
    print('AMBIGUOUS')
  elif bb==0:
    print('NA')
  else:
    print('MMYY')
elif aa!=0:
  0<bb and bb<=12:
  print('YYMM')
else:
  print('NA')
Problem p03208 (python)

Fixed submission:
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()

h_min = min(hl[i+k-1] - hl[i] for i in range(n-k+1))
print(h_min)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
delta = 10*10**9

hl_s = sorted(hl, reverse=True)

if n > 1000:
    if hl_s[n//2] > (hl_s[0] + hl_s[n])//2: #中央値＞平均値
        hl_s = hl_s[:n//2]
    else:
        hl_s = hl_s[n//2:]

for i in range(len(hl_s)-k+1):
    h_max = max(hl_s[i:i+k])
    h_min = min(hl_s[i:i+k])
    if delta > (h_max - h_min):
        delta = h_max - h_min
    if delta == 0:
        break

print(delta)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
delta = 10*10**9

hl_s = sorted(hl, reverse=True)

if n > 10000:
    if hl_s[n//2] > (hl_s[0] + hl_s[n])//2: #中央値＞平均値
        hl_s = hl_s[:n//2]
    else:
        hl_s = hl_s[n//2:]

for i in range(len(hl_s)-k+1):
    h_max = max(hl_s[i:i+k])
    h_min = min(hl_s[i:i+k])
    if delta > (h_max - h_min):
        delta = h_max - h_min
    if delta == 0:
        break

print(delta)
Problem p03135 (python)

Fixed submission:
num = input().split()

print(float(num[0]) / float(num[1]))

Buggy submission (verdict: Runtime Error):
num = input().split()

print(float(num[0]) / float(num[1]))

Buggy submission (verdict: Runtime Error):
t = float(input())
x = float(input())

print(t / x)
Problem p03332 (python)

Fixed submission:
n,a,b,k=[int(i) for i in input().split()]
c=a+b
mod=998244353
ans=0

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2,300003):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#以下のcom関数を用いて組み合わせを計算
def com(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range(n+1):
    if (k-b*i)%a==0 and k-b*i>=0:
        n_a=(k-b*i)//a
        n_b=i
        if  max(n_a, n_b) <=n:
            ans+=com(n, n_a, mod) * com(n, n_b, mod)  %mod

print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,a,b,k=[int(i) for i in input().split()]
c=a+b
mod=998244353
ans=0

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2,300003):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#以下のcom関数を用いて組み合わせを計算
def com(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range(n+1):
    if (k-b*i)%a==0 and k-b*i>=0:
        n_a=(k-b*i)//a
        n_b=i
        n_c=min(n_a,n_b)
        n_a, n_b=n_a-min(n_a,n_b), n_b-min(n_a,n_b)
        count=0
        while n_a + n_b + n_c <=n and n_c>=0 and n_b>=0 and n_a>=0:
#            ans+=com(n, n_c, mod) * com(n-n_c, n_b, mod) * com(n-n_c-n_b, n_a, mod) %mod
            if count==0:
                aaa0=com(n, n_c, mod) * com(n-n_c, n_b, mod) * com(n-n_c-n_b, n_a, mod) 
                ans+=aaa0
                count+=1
            n_b+=1
            n_a+=1
            aaa0 = aaa0 * n_c / ( (n_a) * (n_b) * (n-n_c-n_b-n_a) )
            n_c-=1
            if count!=0:
                ans+=aaa

print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,a,b,k=[int(i) for i in input().split()]
c=a+b
mod=998244353
ans=0

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2,300000):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#以下のcom関数を用いて組み合わせを計算
def com(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

#test=2*3*com(4, 2, mod) + com(4,3,mod)
#print(test)

for i in range(n+1):
    if (k-b*i)%a==0 and k-b*i>=0:
        n_a=(k-b*i)//a
        n_b=i
#        print(n_a, n_b)
        
        n_c=min(n_a,n_b)
        n_a, n_b=n_a-min(n_a,n_b), n_b-min(n_a,n_b)
#        print(n_a, n_b, n_c)

        while n_a + n_b + n_c <=n and n_c>=0 and n_b>=0 and n_a>=0:
            ans+=com(n, n_c, mod) * com(n-n_c, n_b, mod) * com(n-n_c-n_b, n_a, mod)
            n_c-=1
            n_b+=1
            n_a+=1
print(ans%mod)
Problem p02580 (python)

Fixed submission:
h,w,m = map(int,input().split())
t = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(m)] 
ht = [0]*h
wt = [0]*w
for y,x in t:
  ht[y] += 1
  wt[x] += 1
htm = max(ht)
wtm = max(wt)
htt = [i for i in range(h) if ht[i]==htm]
wtt = [i for i in range(w) if wt[i]==wtm]
ans = htm+wtm-1
t = set(t)
for i in htt:
  for j in wtt:
    if (i,j) not in t:
      print(htm+wtm)
      exit()
print(htm+wtm-1)

Buggy submission (verdict: Runtime Error):
h,w,m,*t = map(int,open(0).read().split())
a = [[0]*w for _ in range(h)]
ht = [0]*h
wt = [0]*w
for i in range(m):
  y,x = t[i*2]-1,t[i*2+1]-1
  a[y][x] += 1
  ht[y] += 1
  wt[x] += 1
htm = max(ht)
wtm = max(wt)
htt = [i for i in range(h) if ht[i]==htm]
wtt = [i for i in range(w) if wt[i]==wtm]
ans = htm+wtm-1
for i in htt:
  for j in wtt:
    if a[i][j] == 0:
      print(ans + 1)
      exit()
print(ans)

Buggy submission (verdict: Runtime Error):
h,w,m,*t = map(int,open(0).read().split())
a = [[0]*w for _ in range(h)]
ht = [0]*h
wt = [0]*w
for i in range(m):
  y,x = t[i*2]-1,t[i*2+1]-1
  a[y][x] += 1
  ht[y] += 1
  wt[x] += 1
htm = max(ht)
wtm = max(wt)
htt = [i for i in range(h) if ht[i]==htm]
wtt = [i for i in range(w) if wt[i]==wtm]
ans = 0
for i in htt:
  for j in wtt:
    ans = max(ans,ht[i]+wt[j]-a[i][j])
print(ans)

Buggy submission (verdict: Runtime Error):
h,w,m,*t = map(int,open(0).read().split())
a = [[0]*w for _ in range(h)]
ht = [0]*h
wt = [0]*w
for i in range(m):
  y,x = t[i*2]-1,t[i*2+1]-1
  a[y][x] += 1
  ht[y] += 1
  wt[x] += 1
htm = max(ht)-1
wtm = max(wt)-1
htt = [i for i in range(h) if ht[i]>=htm]
wtt = [i for i in range(w) if wt[i]>=wtm]
ans = 0
for i in htt:
  for j in wtt:
    ans = max(ans,ht[i]+wt[j]-a[i][j])
print(ans)
Problem p02598 (python)

Fixed submission:
n,k,*a = map(int,open(0).read().split())
def func(b):
  c = k
  for i in a:
    c -= (i-1)//b
    if c < 0:
      return False
  return True
l = 1
r = max(a)
while(r>l):
  lr = (l+r)//2
  if func(lr):
    r = lr
  else:
    l = lr + 1
print(r)

Buggy submission (verdict: Runtime Error):
n,k,*a = map(int,open(0).read().split())
def func(b):
  c = k
  for i in a:
    c -= i//b
    if c < 0:
      return False
  return True
l = 0
r = max(a)
while(r>l):
  lr = (l+r)//2
  if func(lr):
    r = lr
  else:
    l = lr + 1
print(r)
Problem p02699 (python)

Fixed submission:
s,w = map(int,input().split())
if w >= s:
  print("unsafe")
else:
  print("safe")

Buggy submission (verdict: Runtime Error):
def main():
  s = input()
  n = len(s)
  num = 2019
  ans = 0
  for i in range(n-4):
    for j in range(i+5,n+1):
      a = int(s[i:j])
      if a%num == 0:
        ans += 1
  print(ans)
main()
Problem p02759 (python)

Fixed submission:
print((int(input())+1)//2)

Buggy submission (verdict: Runtime Error):
print(int(input)+1//2)
Problem p03137 (python)

Fixed submission:
n,m,*x = map(int,open(0).read().split())
x.sort()
if n >= m:
  print(0)
  exit()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,*x = map(int,open(0).read().split())
x.sort()
if m == 1:
  print(0)
  exit()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,*x = map(int,open(0).read().split())
x.sort()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n = int(input())
t = [[] for _ in range(n)]
for i in range(n-1):
  a,b,c = map(int,input().split())
  t[a-1].append((b-1,c))
  t[b-1].append((a-1,c))
q,k = map(int,input().split())
k -= 1
l = [0]*n
def dfs(a,b,c):
  for i,j in t[b]:
    if i != a:
      l[i] = c+j
      dfs(b,i,c+j)
dfs(-1,k,0)
for _ in range(q):
  x,y = map(lambda x:int(x)-1,input().split())
  print(l[x]+l[y])

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [[] for _ in range(n)]
for i in range(n-1):
  a,b,c = map(int,input().split())
  t[a-1].append((b-1,c))
  t[b-1].append((a-1,c))
q,k = map(int,input().split())
k -= 1
l = [0]*n
def dfs(a,b,c):
  for i,j in t[b]:
    if i != a:
      l[i] = c+j
      dfs(b,i,c+j)
dfs(-1,k,0)
for _ in range(q):
  x,y = map(lambda x:int(x)-1,input().split())
  print(l[x]+l[y])
Problem p02597 (python)

Fixed submission:
N = int(input())
S = input()
WPrefix = [0]
RSuffix = [0]
for elem in S:
    if elem == "R":
        RSuffix[0] += 1
for elem in S:
    if elem == "R":
        RSuffix.append(RSuffix[-1] - 1)
        WPrefix.append(WPrefix[-1])
    else:
        RSuffix.append(RSuffix[-1])
        WPrefix.append(WPrefix[-1] + 1)
minSwap = len(S)
for index in range(len(RSuffix)):
    if max(RSuffix[index],WPrefix[index]) < minSwap:
        minSwap = max(RSuffix[index],WPrefix[index])
print(minSwap)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
WPrefix = [0]
RSuffix = [0]
for elem in S:
    if elem == "R":
        RSuffix += 1
for elem in S:
    if elem == "R":
        RSuffix.append(RSuffix[-1] - 1)
        WPrefix.append(WPrefix[-1])
    else:
        RSuffix.append(RSuffix[-1])
        WPrefix.append(WPrefix[-1] + 1)
minSwap = len(S)
for index in range(len(RSuffix)):
    if max(RSuffix[index],WPrefix[index]) < minSwap:
        minSwap = max(RSuffix[index],WPrefix[index])
print(minSwap)
Problem p02623 (python)

Fixed submission:
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
if subseqA[N] <= K:
    curABooks = N
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseqA[i] + subseqB[M] <= K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseq[i] + subseqB[M] > K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)