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

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

ans = min(H,W)
for h in range(H//3,H//3+3):
    w = W//2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))


for w in range(W//3,W//3+3):
    h = H//2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

if H%3 == 0 or W%3 == 0:
    ans = 0
print(ans)

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

if h%3 ==0 or w % 3 == 0:
	print(0)
	exit()

x = w//4
Sb =max(x*h,h//2*(w-x),(h-h//2)*(w-x))
Ss =min(x*h,h//2*(w-x),(h-h//2)*(w-x))
ans1 =Sb-ss
x += 1
Sb =max(x*h,h//2*(w-x),(h-h//2)*(w-x))
Ss =min(x*h,h//2*(w-x),(h-h//2)*(w-x))
ans2 =Sb-ss
y = h//4
Sb =max(y*w,w//2*(h-y),(w-w//2)*(h-y))
Ss =min(y*w,w//2*(h-y),(w-w//2)*(h-y))
ans3 =Sb-ss
y += 1
Sb =max(y*w,w//2*(h-y),(w-w//2)*(h-y))
Ss =min(y*w,w//2*(h-y),(w-w//2)*(h-y))
ans4 =Sb-ss

print(min(ans1,ans2,ans3,ans4))
Problem p03719 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a<=c<=b:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a<=c<=b:
  promt('Yes')
else:
  print('No')
Problem p03729 (python)

Fixed submission:
a,b,c=input().split()
if (a[len(a)-1]==b[0])&(b[len(b)-1]==c[0]):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c=map(input().split())
if (a[len(a)-1]==b[0])&(b[len(b)-1]==c[0]):
    print('YES')
else:
    print('NO')
Problem p03796 (python)

Fixed submission:
n=1
for i in range(1,int(input())+1):
    n*=i
    n=n%1000000007
print(n)

Buggy submission (verdict: Runtime Error):
def k(n):
    mod =1000000007
    if n==1:
        return 1
    else:
        return (n*k(n-1))%mod
print(k(int(input())))
Problem p03808 (python)

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

if sum(a) % (n*(n+1)//2) != 0:
    print('NO')
    exit()
else:
    k = sum(a)// (n*(n+1)//2)


for i in range(n-1):
    d = a[i+1] - a[i] - k

    if d > 0 or d % n != 0:
        print('NO')
        exit()

print('YES')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
global count
count = 0
def solve(a):
    count += 1
    if count > 10**7:
        print('NO')
        exit()
    if min(a) < 0:
        return False

    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

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

def solve(a):
    if min(a) < 0:
        return False
    
    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')

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

def solve(a):
    print(a)
    for i in range(n):
        if a[i] != 0:
            break
        if i == n-1:
            return True

    for i in range(n):
        b = []
        for j in range(n):
            if a[j] < 0:
                return False
            c = a[(i+j)%n]-j-1
            b.append(c)

        if solve(b):
            return True

if solve(a):
    print('YES')
else:
    print('NO')
Problem p03967 (python)

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

for t in s:
    if t == 'p':
        a += 1


print(n//2 - a)

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

for t in s:
    if t == 'p':
        a += 1


print(n//2 - b)
Problem p04029 (python)

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

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

Fixed submission:
a,b,c = map(int,input().split())
k = int(input())
ct = 0

while a >= b:
    b *= 2
    ct += 1
    
while b >= c:
    c *= 2
    ct += 1
    

if ct <= k:
  print("Yes")
else:
  print("No")

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

while k > 0:
  if a > b:
    b *= 2
    k -= 1

while k > 0:
  if b > c:
    c *= 2
    k -= 1
    
if a < b and b < c:
  print("Yes")
else
  print("No")
Problem p03001 (python)

Fixed submission:
H = list(map(int,input().split()))
h = H[0]
w = H[1]
x = H[2]
y = H[3]

if (h-2*x==0) and (w-2*y==0):
  a = 1
else:
  a = 0

print(h*w/2,a)

Buggy submission (verdict: Runtime Error):
H = list(map(int,input().split()))
h = H[0]
w = H[1]
x = H[2]
y = H[3]

if (h-2*x)*(w-2*y)!=0 or ((h-2*x==0) and (w-2*y==0)) and (x != h x != 0 or y != 0 y != w):
  a = 1
else:
  a = 0

print(h*w/2,a)
Problem p03047 (python)

Fixed submission:
a,b=map(int,input().split())
print(a-b+1)

Buggy submission (verdict: Runtime Error):
a,b,c,n=map(int,input().split())
count=0
for i in range(n//a)
  for j in range(n//b)
  	if n-i*a-j*b>=0 && n-i*a-j*b%c==0:
      count++
print(count)
Problem p03059 (python)

Fixed submission:
a,b,t=list(map(int,input().split()))
print((t//a)*b)

Buggy submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t*(b//a))

Buggy submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t(*b//a))

Buggy submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t*b(//a))

Buggy submission (verdict: Runtime Error):
a,b,t=list(map(int,input()))
print(t*b//a)
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split())
print(max(a,b)+max(max(a,b)-1,min(a,b)))

Buggy submission (verdict: Runtime Error):
a,b=int(input())
print(max(a,b)+max(max(a,b)-1,min(a,b)))
Problem p03485 (python)

Fixed submission:
a,b=map(int,input().split())
print((a+b+1)//2)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input())
print((a+b+1)//2)
Problem p03651 (python)

Fixed submission:
import numpy as np
import sys
import math
from functools import reduce
import fractions as fr

def gcd(*numbers):
    return reduce(fr.gcd, numbers)

n,k = map(int,input().split())
a = list(map(int,input().split()))

c = int(gcd(*a))

for i in a:
  if i - k >= 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
import math
from functools import reduce
import fractions

def gcd(*numbers):
    return reduce(math.gcd, numbers)

n,k = map(int,input().split())
a = list(map(int,input().split()))

c = fractions.gcd(*a)

for i in a:
  if i - k > 0 and (i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []

for i in range(len(a) - 1):
  b.append(abs(a[i]-a[i+1]))
  
c = int(np.min(b))

for i in a:
  if abs(i-k) % c == 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []

for i in range(len(a) - 1):
  b.append(abs(a[i]-a[i+1]))
  
c = np.min(b)

for i in a:
  if abs(i-k) % c == 0:
    print("POSIIBLE")
    sys.exit()
    
print("IMPOSIIBLE")
Problem p03694 (python)

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

print(s[len(s)-1] - s[0])

Buggy submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sorted()

print(s[len(s)-1] - s[0])

Buggy submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sort()

print(s[len(s)-1] - s[0])

Buggy submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sorted

print(s[len(s)-1] - s[0])

Buggy submission (verdict: Runtime Error):
s = list(map(int,intput().split()))
s.sort

print(s[len(s)-1] - s[0])
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a+c==2*b:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
 if a+c==2*b:
  print(Yes)
  else:
  print(No)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a+c==2*b:
  print(Yes)
else:
  print(No)

Buggy submission (verdict: Runtime Error):
a,b,c=(map(int,input().split()))
print((a+c==2*b?Yes:No))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
if a+c==2*b:
  print(Yes)
else:
  print(No)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
if a+c==b:
  print(Yes)
else:
  print(No)

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split))
if a[0]+a[2]==2*a[1]:
  print(Yes)
else:
  print(No)

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split))
if a[0]+a[2]==2*a[1]:
  print(Yes)
  else:
  print(No)

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
print((a[0]+a[2]=2*a[1]?Yes:No))
Problem p02564 (python)

Fixed submission:
import sys
range = xrange
input = raw_input
 
def find_SCC(coupl):
    SCC, S, P = [], [], []
    depth = [0] * len(coupl)
 
    stack = list(range(len(coupl)))
    while stack:
        node = stack.pop()
        if node < 0:
            d = depth[~node] - 1
            if P[-1] > d:
                SCC.append(S[d:])
                del S[d:], P[-1]
                for node in SCC[-1]:
                    depth[node] = -1
        elif depth[node] > 0:
            while P[-1] > depth[node]:
                P.pop()
        elif depth[node] == 0:
            S.append(node)
            P.append(len(S))
            depth[node] = len(S)
            stack.append(~node)
            stack += coupl[node]
    return SCC[::-1]
 
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
 
n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
 
coupl = [[] for _ in range(n)]
for _ in range(m):
    u = inp[ii]; ii += 1
    v = inp[ii]; ii += 1
    coupl[u].append(v)
 
SCC = find_SCC(coupl)
out = [len(SCC)]
for scc in SCC:
    out.append(len(scc))
    for node in scc:
        out.append(node)
print ' '.join(str(x) for x in out)

Buggy submission (verdict: Runtime Error):
import sys
range = xrange
input = raw_input

def find_SCC(coupl):
    SCC, S, P = [], [], []
    depth = [0] * len(coupl)
 
    stack = list(range(len(coupl)))
    while stack:
        node = stack.pop()
        if node < 0:
            d = depth[~node] - 1
            if P[-1] > d:
                SCC.append(S[d:])
                del S[d:], P[-1]
                for node in SCC[-1]:
                    depth[node] = -1
        elif depth[node] > 0:
            while P[-1] > depth[node]:
                P.pop()
        elif depth[node] == 0:
            S.append(node)
            P.append(len(S))
            depth[node] = len(S)
            stack.append(~node)
            stack += coupl[node]
    return SCC[::-1]

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1

coupl = [[] for _ in range(n)]
for _ in range(m):
  	u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(v)

SCC = find_SCC(coupl)
out = [len(SCC)]
for scc in SCC:
	out.append(len(scc))
    for node in scc:
    	out.append(node + 1)
print ' '.join(str(x) for x in out)
Problem p03174 (python)

Fixed submission:
range = xrange
input = raw_input
MOD = 10**9+7
 
n = int(input())

dp = [0] * (1 << n)
for i in [i for i, x in enumerate(input().split()) if x == '1']:
    dp[1 << i] = 1

npow = 1 << n

for i in range(n - 1):
    _dp = [0] * npow
    for j in [i for i, x in enumerate(input().split()) if x == '1']:
        jpow = 1 << j
        mask = 0
        while mask < npow:
            _dp[mask + jpow] += dp[mask]
            mask += 1 + ((mask+1) & jpow)
    for mask in range(npow):
        _dp[mask] %= MOD
    dp = _dp
 
print(sum(dp) % MOD)

Buggy submission (verdict: Runtime Error):
range = xrange
input = raw_input
MOD = 10**9+7
 
n = int(input())
 
dp = [0] * (1 << n)
for i in [i for i, x in enumerate(input().split()) if x == '1']:
    dp[1 << i] = 1
 
npow = 1 << n
 
for i in range(n - 1):
    _dp = [0] * npow
    for j in [i for i, x in enumerate(input().split()) if x == '1']:
        jpow = 1 << j
        mask = (npow - 1) ^ jpow
        x = npow
        while x:
          	x -= 1
            x &= mask
            _dp[x + jpow] += dp[x]
    for mask in range(npow):
        _dp[mask] %= MOD
    dp = _dp
 
print(sum(dp) % MOD)

Buggy submission (verdict: Runtime Error):
range = xrange
input = raw_input
MOD = 10**9+7
 
n = int(input())
 
dp = [0] * (1 << n)
for i in [i for i, x in enumerate(input().split()) if x == '1']:
    dp[1 << i] = 1
 
npow = 1 << n
 
for i in range(n - 1):
    _dp = [0] * npow
    for j in [i for i, x in enumerate(input().split()) if x == '1']:
        jpow = 1 << j
        mask = (npow - 1) ^ jpow
        x = npow
        while x:
            x = (x-1)&m
            _dp[x + jpow] += dp[x]
    for mask in range(npow):
        _dp[mask] %= MOD
    dp = _dp
 
print(sum(dp) % MOD)

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())

    dp = [0] * (1 << n)
    for i in [i >> 1 for i, x in enumerate(input()) if x == '1']:
        dp[1 << i] = 1

    npow = 1 << n

    for i in range(n - 1):
        _dp = [0] * npow
        for j in [i >> 1 for i, x in enumerate(input()) if x == '1']:
            jpow = 1 << j
            for mask,val in enumerate(dp):
                if not mask & jpow:
                    _dp[mask + jpow] += val
        for mask in range(npow):
            _dp[mask] %= MOD
        dp = _dp

    print(sum(dp) % MOD)

main()
Problem p02802 (python)

Fixed submission:
from collections import Counter

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(100005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)

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

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(10005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)

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

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(10005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)
Problem p03044 (python)

Fixed submission:
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
from collections import deque

q = deque()
q.append([0, 0])
while q:
    num, kyori = q.pop()
    visited[num] = '1' if kyori%2 == 1 else '0'
    for hen in g[num]:
        if not visited[hen[0]]:
            q.append([hen[0], kyori+hen[1]]) 

print('\n'.join(visited))

Buggy submission (verdict: Runtime Error):
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
def dfs(num, kyori): # 始点からの距離
    if not visited[num]:
        visited[num] = '1' if kyori%2 == 1 else '0'
        for hen in g[num]:
            dfs(hen[0], kyori+hen[1])
    return visited

print('\n'.join(dfs(0,0)))

Buggy submission (verdict: Runtime Error):
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
def dfs(num, kyori): # 始点からの距離
    if not visited[num]:
        visited[num] = '1' if kyori%2 == 1 else '0'
        for hen in g[num]:
            dfs(hen[0], kyori+hen[1])
    else:
        return visited
    return visited

print('\n'.join(dfs(0,0)))
Problem p03069 (python)

Fixed submission:
N=int(input())
S = input()
w = [0]*(N+1)
b = [0]*(N+1)
for i, s in enumerate(S):
    if s=='.':
        w[i+1] = w[i]+1
        b[i+1] = b[i]
    elif s=='#':
        b[i+1] = b[i]+1
        w[i+1] = w[i]
ans = 10**20
for i in range(N+1):
    ans = min(ans, b[i]+w[N]-w[i])
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break

now = ''
left2 = -1
for i, s in enumerate(S[::-1]):
    if s == '.' and now=='':
        now='.'
    elif s=='#' and now=='.':
        now = '#'
    elif s=='.' and now=='#':
        left2 = i
        break
 
left2 = len(S)-left2

if S[-1]=='#':
    mae = len(S.split('.')[-2])
    ato = len(S.split('#')[-2])
    ans = min(S.count('#'), S[left:].count('.'))
    ans = min(ans, S[left:left2].count('#')+min(mae, ato))
    print(ans)
else:
    mae = len(S.split('.')[-2])
    ato = len(S.split('#')[-1])
    ans = min(S.count('#'), S[left:].count('.'))
    ans = min(ans, S[left:left2].count('#')+min(mae, ato))
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break
if S[-1] == '#':
    sharps = S.split('.')
    t=len(sharps[-1])
    t2=len(sharps[-2])
    a=len(S.split('#')[-2])
    print(min(S.count('#')-t, S[left:].count('.'), S.count('#')-t-t2+a))
else:
    sharps = S.split('.')
    t=len(sharps[-2])
    a=len(S.split('#')[-1])
    print(min(S.count('#'), S[left:].count('.'), S.count('#')-t+a))
Problem p03074 (python)

Fixed submission:
N, K = map(int, input().split())
S = list(map(int, list(input())))
now = 1
cnt = 0
Nums = []
for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    Nums.append(cnt)

if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left, right = 0, 0
tmp = 0  # sum of [left, right)
for i in range(len(Nums))[::2]:
    next_left = i
    next_right = min(i + add, len(Nums))
    while next_left > left:
        tmp -= Nums[left]
        left += 1
    while next_right > right:
        tmp += Nums[right]
        right += 1

    ans = max(tmp, ans)

print(ans)

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

def kazo(memo):
    zeronum = []
    zerotmp = 0
    l, r = 0, 1
    for i in range(0, N):
        if memo[i+1] > memo[i]:
            zeronum.append([zerotmp, l, r-1])
            zerotmp = 0
            l = i+1
            r = l
        else:
            zerotmp += 1
            r += 1
    return sorted(zeronum, key=lambda x: x[0])[-1]

for i in range(K):
    memo = [0]*(N+1)
    for i in range(N):
        if S[i] == '1':
            memo[i+1] = memo[i]+1
        else:
            memo[i+1] = memo[i]
    num, l, r = kazo(memo)
    for j in range(l, r+1):
        S[j] = '1'

import re

def renzoku(string):
    return len(sorted(re.findall(r'1+', string), key=lambda x: -len(x))[0])

print(renzoku(''.join(S)))
Problem p03078 (python)

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

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

ab = [a+b for a in A for b in B]
ab.sort(reverse=True)

ans = [x+c for x in ab[:K] for c in C]
ans.sort(reverse=True)
print('\n'.join(list(map(str, ans[:K]))))

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

ans = []

AA = sorted(A, key=lambda a: -a)
BB = sorted(B, key=lambda a: -a)
CC = sorted(C, key=lambda a: -a)
for a in AA:
    for b in BB:
        for c in CC:
            if len(ans) > 1000_000:
                for an in sorted(ans, key=lambda p: -p)[:K]:
                    print(an)
                    exit()
            ans.append(a+b+c)

for an in sorted(ans, key=lambda p: -p)[:K]:
    print(an)

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

ans = []

AA = sorted(A, key=lambda a: -a)
BB = sorted(B, key=lambda a: -a)
CC = sorted(C, key=lambda a: -a)
for a in AA:
    for b in BB:
        for c in CC:
            if len(ans) > 1000_000:
                break
            ans.append(a+b+c)

print('\n'.join(list(map(str, sorted(ans, key=lambda p: -p)[:K]))))

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

ans = []

AA = sorted(A, key=lambda a: -a)
BB = sorted(B, key=lambda a: -a)
CC = sorted(C, key=lambda a: -a)
for a in AA:
    for b in BB:
        for c in CC:
            if len(ans) > 1000_000:
                break
            ans.append(a+b+c)

print('\n'.join(list(map(str, sorted(ans, key=lambda p: -p)[:K]))))
Problem p03241 (python)

Fixed submission:
import math
N, M = map(int, input().split())

ans = 1
for a in range(1, int(math.sqrt(M))):
    b = int(M / a)
    if M%a != 0:
        continue
    if a * N <= M:
        ans = max(ans, a)
    if b * N <= M:
        ans = max(ans, b)

print(ans)

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

ans = 1
for a in range(math.sqrt(M)):
    b = int(M / a)
    if M%a != 0:
        continue
    if a * N <= M:
        ans = max(ans, a)
    if b * N <= M:
        ans = max(ans, b)

print(ans)
Problem p03251 (python)

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

posX = [int(i) for i in input().split()]
posY = [int(i) for i in input().split()]
posX.sort()
posY.sort()

max_x = posX[-1]
min_y = posY[0]
if cnds[2] < cnds[3]:
    if max_x < min_y and cnds[2] < min_y and max_x < cnds[3]:
        print('No War')
    else:
        print('War')
else:
    print('War')

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

posX = [int(i) for i in input().split()]
posY = [int(i) for i in input().split()]
posX.sort()
posY.sort()

max_x = posX[-1]
min_y = posY[0]
if cnds[2] < cnds[3]:
    if max_x < max_y:
        print('No War')
    else:
        print('War')
else:
    print('War')
Problem p03261 (python)

Fixed submission:
n = int(input())

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(''.join(word))
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)

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

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(word)
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)

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

lastch = ''
answer = 'No'
words = []

for i in range(n):
    word = raw_input()
    words.append(word)
    if lastch == word[0] and i != 0:
        answer = 'Yes'
    else:
        answer = 'No'
    lastch = word[-1]

print('Yes' if len(words) == len(set(words)) and answer == 'Yes' else 'No')

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

lastch = ''
answer = 'No'
words = []

for i in range(n):
    word = input()[0:-1]
    words.append(word)
    if lastch == word[0] and i != 0:
        answer = 'Yes'
    else:
        answer = 'No'
    lastch = word[-1]

print('Yes' if len(words) == len(set(words)) and answer == 'Yes' else 'No')