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

Fixed submission:
import numpy as np
import collections

n = int(input())
s = np.array([[str(i) for i in input().split()] for i in range(n)])
s = np.ravel(s)
ans = 0
sorted_list = [''.join(sorted(e)) for e in s]
# dict
c = collections.Counter(sorted_list)
for i in c.values():
  for j in range(0, i):
    ans += j

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
s = np.array([[str(i) for i in input().split()] for i in range(n)])
s = np.ravel(s)
ans = 0
sorted_list = [''.join(sorted(e)) for e in s]
# dict
c = collections.Counter(sorted_list)
for i in c.values():
  for j in range(0, i):
    ans += j

print(ans)
Problem p02957 (python)

Fixed submission:
"""
- https://atcoder.jp/contests/abc136/tasks/abc135_a
- |A−K|=|B−K| (others:IMPOSSIBLE)
- reg: 0≤A, B≤10^9
"""

a, b = map(int, input().split())
# 三項演算子
k = int ((a+b)/2) if (a+b) % 2 == 0 else 'IMPOSSIBLE'

print(k)

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

b_rest = [max(b[0]-a[0],0)]
a_rest = [max(a[0]-b[0],0)]

for i in range(1, n-1):
  b_rest.append( min(b[i], max( ((b[i]+b_rest[i-1])-a[i]), 0 ) ) )
  a_rest.append( max( a[i]-(b[i]+b_rest[i-1]), 0 ) ) 

a_rest.append(max(0, (a[n-1]-b_rest[-1]) ) )
ans = sum(a) - sum(a_rest)
                                
print(ans)
Problem p03060 (python)

Fixed submission:
import numpy as np

n = int(input())
v = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))
p = v-c
ans = sum([i for i in p if i>0])
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
v = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))
p = v-c
for i in p:
    if i>0:
        ans+=i

print(ans)
Problem p03085 (python)

Fixed submission:
print('ATCG'['TAGC'.index(input())])

Buggy submission (verdict: Runtime Error):
print('ATCG'['TAGC'.index()])
Problem p03282 (python)

Fixed submission:
# coding:utf-8
s=input()
k=int(input())
lists=list(s)
ans=1
for i in range(min(k,len(lists))):
    if not lists[i] == "1":
        ans=lists[i]
        break
print(ans)

Buggy submission (verdict: Runtime Error):
# coding:utf-8
s=input()
k=int(input())
list=list(s)
ans=1
for i in range(min(k,list.len())):
    if not list[i] == 1:
        ans=list[i]
        break
print(ans)
Problem p03130 (python)

Fixed submission:
print('YES'if __import__('collections').Counter(map(int,open(0).read().split())).most_common()[0][1]<3 else'NO')

Buggy submission (verdict: Runtime Error):
print('YES'if __import__('collections').Counter(map(int,open(0).read().split())).most_common[0][1]<3 else'NO')
Problem p03535 (python)

Fixed submission:
n=input()
a=sorted(map(int,raw_input().split()))
r=0
b=[0]+[a[j]*(-1)**j%24 for j in range(n)]
s=24
for j in range(n):
 for k in range(j+1,n+1):s=min(s,(b[j]-b[k])%24,(b[k]-b[j])%24)
r=max(r,s)
print r

Buggy submission (verdict: Runtime Error):
n=input()
a=map(int,raw_input().split())
r=0
for i in range(1<<n):
 b=[a[j]*((i>>j&1)*2-1)%24 for j in range(n)]+[0]
 s=24
 for j in range(n):
  for k in range(j+1,n+1):s=min(s,(b[j]-b[k])%24,(b[k]-b[j])%24)
 r=max(r,s)
print r
Problem p03576 (python)

Fixed submission:
import sys
N,K=map(int,sys.stdin.readline().split())
A=sorted([int(e) for e in sys.stdin.readline().split()] for _ in range(N))
x,y=zip(*A)
Y=sorted(y)
r=(x[-1]-x[0])*(Y[-1]-Y[0])
for i in range(N):
 for j in range(i+1,N):
  for k in range(N):
   for l in range(k+1,N):
    ly=Y[k];ry=Y[l];q=(x[j]-x[i])*(ry-ly)
    if r>q and K<=(j-i+1) and K<=sum(ly<=y[z]<=ry for z in range(i,j+1)): r=q
print(r)

Buggy submission (verdict: Runtime Error):
import sys
N,K=map(int,sys.stdin.readline().split())
A=sorted([int(e) for e in sys.stdin.readline().split()] for _ in range(N))
x,y=zip(*A)
Y=sorted(y)
r=(x[-1]-x[0])*(Y[-1]-Y[0])
for i in range(N):
 for j in range(i+1,N):
  for k in range(N):
   for l in range(k+1,N):
    ly=Y[k];ry=Y[l];q=(x[j]-x[i])*(ry-ly)
    if r>q and K<=(j-i+1) and K<=sum(lx<=x[z]<=rx and ly<=y[z]<=ry for z in range(i,j+1)): r=q
print(r)

Buggy submission (verdict: Runtime Error):
import sys
N,K=map(int,sys.stdin.readline().split())
A=sorted([int(e) for e in sys.stdin.readline().split()] for _ in range(N))
x,y=zip(*A)
Y=sorted(y)
r=(x[-1]-x[0])*(Y[-1]-Y[0])
for i in range(N):
 for j in range(i+1,N):
  for k in range(N):
   for l in range(k+1,N):
    ly=Y[k];ry=Y[l];q=(x[j]-x[i])*(ry-ly)
    if r>q and K<=(j-i+1) and K<=sum(lx<=x[z]<=rx and ly<=y[z]<=ry for z in range(i,j+1)): r=q
print(r)
Problem p03608 (python)

Fixed submission:
from scipy.sparse import*
N,M,R=map(int,raw_input().split())
r=[int(e) for e in raw_input().split()]
a,b,c=zip(*(map(int,raw_input().split())for _ in range(M)))
a=csgraph.dijkstra(csr_matrix((c,(a,b)),[N+1]*2),0,r)
print int(min(sum(a[e[i]][r[e[i+1]]]for i in range(R-1))for e in __import__('itertools').permutations(range(R))))

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda:list(map(int,input().split()));N,M,R=f();r=f();a,b,c=zip(*map(f,[0]*M));a=csgraph.dijkstra(csr_matrix((c,(a,b)),[N+1]*2),0,r);print(int(min(sum(a[e[i]][r[e[i+1]]]for i in range(R-1))for e in __import__('itertools').permutations(range(R)))))

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda:map(int,raw_input().split());N,M,R=f();r=f();a,b,c=zip(*map(f,[0]*M));a=csgraph.dijkstra(csr_matrix((c,(a,b)),[N+1]*2),0,r);print int(min(sum(a[e[i]][r[e[i+1]]]for i in range(R-1))for e in __import__('itertools').permutations(range(R))))

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());N,M,R=f();r=f();a,b,c=list(zip(*map(f,[0]*M)));a=csgraph.dijkstra(csr_matrix((c,(a,b)),[N+1]*2),0,r);print int(min(sum(a[e[i]][r[e[i+1]]]for i in range(R-1))for e in __import__('itertools').permutations(range(R))))
Problem p03649 (python)

Fixed submission:
#!/usr/bin/python
from heapq import*
n=int(input())
a=[-int(e)for e in input().split()]
r=0
heapify(a)
while 1:
	x=heappop(a)
	if x>-n:break
	c=-x//n
	x+=c*n
	a=[e-c for e in a]
	heappush(a,x)
	r+=c
print(r)

Buggy submission (verdict: Runtime Error):
from heapq import*
n=int(input())
a=[-int(e)for e in input().split()]
r=0
heapify(a)
while 1:
	x=heappop(a)
	if x>-n:break
	c=-x//n
	x+=c*n
	for _ in range(n-1):a[i]-=c
	heappush(a,x)
	r+=c
print(r)

Buggy submission (verdict: Runtime Error):
from heapq import*
n=int(input())
a=[-int(e)for e in input().split()]
r=0
heapify(a)
while 1:
	x=heappop(a)
	if x>-n:break
	c=-x//n
	x+=c*n
	for _ in range(n-1):a[i]-=c
	heappush(a,x)
	r+=c
print(r)
Problem p03662 (python)

Fixed submission:
from scipy.sparse import*
f=lambda*z:map(int,raw_input().split())
d=lambda s:csgraph.dijkstra(csr_matrix(([1]*len(a),(a,b)),[n+1]*2),0,s)
n,=f()
a,b=zip(*map(f,[0]*~-n))
g=d(1)
h=d(n)
print 'Snuke'if sum(g[i]>h[i] for i in range(n+1))*2>=n else'Fennec'

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());d=lambda s:csgraph.dijkstra(csr_matrix(([1]*n,(a,b)),[n+1]*2),0,s);n,=f();a,b=zip(*map(f,[0]*n));g=d(1);h=d(n);print['Snuke','Fennec'][sum(g[i]>h[i]for i in range(n+1))*2<n]

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());d=lambda s:csgraph.dijkstra(csr_matrix(([1]*n,(a,b)),[n+1]*2),0,s);n,=f();a,b=zip(*map(f,[0]*~-n));g=d(1);h=d(n);print['Snuke','Fennec'][sum(g[i]>h[i]for i in range(n+1))*2<n]
Problem p03714 (python)

Fixed submission:
import sys,heapq
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
sa=sb=0
la=[]
lb=[]
for i in range(n):
	sa+=a[i]
	heapq.heappush(la,a[i])
ra=[sa]
for i in range(n,2*n):
	sa+=a[i]
	heapq.heappush(la,a[i])
	sa-=heapq.heappop(la)
	ra.append(sa)
for i in range(3*n-1,2*n-1,-1):
	sb+=a[i]
	heapq.heappush(lb,-a[i])
rb=[sb]
for i in range(2*n-1,n-1,-1):
	sb+=a[i]
	heapq.heappush(lb,-a[i])
	sb+=heapq.heappop(lb)
	rb.append(sb)
print(max(x-y for x,y in zip(ra,reversed(rb))))

Buggy submission (verdict: Runtime Error):
def f(a):
	s=0;q=a[:n];s=sum(q);heapify(q);yield s
	for e in a[n:2*n]:s+=e-heappushpop(q,e);yield s
from heapq import*;r=reversed;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f(a),r(f([-e for e in r(a)]))))))

Buggy submission (verdict: Runtime Error):
def f(a):
	s=0;q=[]
	for i in range(n):s+=a[i];heappush(q,a[i])
	r=[s]
	for i in range(n,2*n):s+=a[i];s-=heappushpop(q,a[i]);r+=[s]
	return r
import sys;from heapq import*;n,*a=list(map(int,sys.stdin.read().split()));print(max(x+y for x,y in zip(f(a),f(list(reversed(-e for e in a))))))

Buggy submission (verdict: Runtime Error):
def f(a):
	s=0;q=[]
	for i in range(n):s+=a[i];heappush(q,a[i])
	r=[s]
	for i in range(n,2*n):s+=a[i];s-=heappushpop(q,a[i]);r+=[s]
	return r
import sys;from heapq import*;n,*a=list(map(int,sys.stdin.read().split()));print(max(x+y for x,y in zip(f(a),f(reversed(-e for e in a)))))
Problem p03832 (python)

Fixed submission:
N,A,B,C,D=map(int,input().split());Z=[1]+[0]*N;M=10**9+7;I=[1,1];F=I+[];R=I+[]
for i in range(2,N+1):I+=[(M-M//i)*I[M%i]%M];F+=[i*F[-1]%M];R+=[I[i]*R[-1]%M]
for i in range(A,B+1):Z=[(Z[j]+sum(Z[j-i*k]*F[N-j+i*k]*R[N-j]*pow(R[i],k,M)*R[k]for k in range(C,min(D,j//i)+1)))%M for j in range(N+1)]
print(Z[N])

Buggy submission (verdict: Runtime Error):
N,A,B,C,D=map(int,raw_input().split());Z=[1]+[0]*N;M=10**9+7;I=[1,1];F=I+[];R=I+[]
for i in range(2,N+1):I+=[(M-M/i)*I[M%i]%M];F+=[i*F[-1]%M];R+=[I[i]*R[-1]%M]
for i in range(A,B+1):Z=[(Z[j]+sum(Z[j-i*k]*F[N-j+i*k]*R[N-j]*pow(R[i],k,M)*R[k]for k in range(C,min(D,j/i)+1)))%M for j in range(N+1)]
print Z[N]
Problem p03847 (python)

Fixed submission:
from functools import*
@lru_cache(maxsize=None)
def d(n):x=n//2;return n+1 if n<2 else d(x)+d(~-x)+d(n+~x)
print(d(int(input()))%(10**9+7))

Buggy submission (verdict: Runtime Error):
from functools import*
@lru_cache
def d(n):x=n//2;return n+1 if n<2 else d(x)+d(~-x)+d(n+~x)
print(d(int(input()))%(10**9+7))
Problem p03867 (python)

Fixed submission:
M=10**9+7;D=[];i=1;r=0;N,K=map(int,raw_input().split())
while i*i<=N:
	if N%i==0:D.append(i);i*i<N and D.append(N/i)
	i+=1
D.sort();N=[]
for i in range(len(D)):
	N.append(pow(K,-~D[i]/2,M))
	for j in range(i):
		if D[i]%D[j]==0:N[i]=(N[i]-N[j])%M
	r=(r+(N[i]*D[i]*pow(2,M-2+D[i]%2,M)))%M
print r

Buggy submission (verdict: Runtime Error):
M=10**9+7;D=[];i=1;r=0;N,K=map(int,input().split())
while i*i<=N:
	if N%i==0:D.append(i);i*i<N and D.append(N//i)
	i+=1
D.sort();N=[]
for i in range(len(D)):
	N.append(pow(K,-~D[i]//2,M))
	for j in range(i):
		if D[i]%D[j]==0:N[i]=(N[i]-N[j])%M
	r=(r+(N[i]*D[i]*pow(2,M-2+D[i]%2,M)))%M
print(r)
Problem p03949 (python)

Fixed submission:
#!/usr/bin/python
def shortestPath(g,s,dist,prev):
	n = len(g)-1
	Q=[]
	heapq.heappush(Q,(0,-2,s))
	while Q:
		e = heapq.heappop(Q)
		if prev[e[2]]!=-1: continue
		prev[e[2]] = e[1]
		for f in g[e[2]]:
			if dist[f[2]] > e[0] + f[0]:
				dist[f[2]] = e[0] + f[0]
				heapq.heappush(Q,(e[0]+f[0],f[1],f[2]))

import sys,heapq
#if sys.version_info[0]>=3:raw_input=input

n=int(raw_input())
g=[[] for _ in range(n+1)]
for _ in xrange(n-1):
	a,b=map(int,raw_input().split())
	g[a-1]+=[(1,a-1,b-1)]
	g[b-1]+=[(1,b-1,a-1)]
z=[-1]*n
for _ in xrange(int(raw_input())):
	a,b=map(int,raw_input().split())
	g[n]+=[(b,n,a-1)]
	z[a-1]=b
a=[1e9]*n+[0]
shortestPath(g,n,a,[-1]*(n+1))
for i in xrange(n):
	if z[i]>=0 and z[i]!=a[i]:
		print('No')
		sys.exit()
for _ in g:
	for e in _:
		if e[1]<e[2] and abs(a[e[1]]-a[e[2]])!=1:
			print('No')
			sys.exit()
print('Yes')
print("\n".join(map(str,a[:n])))

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*
g=[]
n=int(raw_input())
for _ in xrange(n-1):
	a,b=map(int,raw_input().split())
	g+=[(a-1,b-1,1)]
z=[-1]*n
for _ in xrange(int(raw_input())):
	a,b=map(int,raw_input().split())
	g+=[(n,a-1,b)]
	z[a-1]=b
a,b,c=zip(*g)
a=map(int,csgraph.dijkstra(csr_matrix((c,(a,b)),[n+1]*2),0,n))
for i in xrange(n):
	if z[i]>=0 and z[i]!=a[i]:
		print('No')
		sys.exit()
for e in g:
	if e[0]<e[1] and abs(a[e[0]]-a[e[1]])!=1:
		print('No')
		sys.exit()
print('Yes')
print("\n".join(map(str,a[:n])))

Buggy submission (verdict: Runtime Error):
from heapq import*
R=range;I=lambda:map(int,input().split());n=int(input());g=[[]for _ in R(n+1)];z=[-1]*n;d=[1e9]*n+[0];q=[-1]*(n+1);r=;Q=[];heappush(Q,(0,-2,n))
for _ in R(n-1):a,b=I();a-=1;b-=1;g[a]+=[(1,a,b)];g[b]+=[(1,b,a)]
for _ in R(*I()):a,b=I();a-=1;g[n]+=[(b,n,a)];z[a]=b
while Q:
	e=heappop(Q)
	if q[e[2]]!=-1:continue
	q[e[2]]=e[1]
	for f in g[e[2]]:
		if d[f[2]]>e[0]+f[0]:d[f[2]]=e[0]+f[0];heappush(Q,(e[0]+f[0],f[1],f[2]))
for _ in g:
	if any(n!=e[1]and abs(d[e[1]]-d[e[2]])!=1 for e in _):r="No"
if any(~z[i]and z[i]!=d[i]for i in R(n)):r="No"
print(r or"Yes\n"+"\n".join(map(str,d[:n])))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
def shortestPath(g,s,dist,prev):
	n = len(g)-1
	Q=[]
	heapq.heappush(Q,(0,-2,s))
	while Q:
		e = heapq.heappop(Q)
		if prev[e[2]]!=-1: continue
		prev[e[2]] = e[1]
		for f in g[e[2]]:
			if dist[f[2]] > e[0] + f[0]:
				dist[f[2]] = e[0] + f[0]
				heapq.heappush(Q,(e[0]+f[0],f[1],f[2]))

import sys,heapq
if sys.version_info[0]>=3:raw_input=input

n=int(raw_input())
g=[[] for _ in range(n+1)]
for _ in xrange(n-1):
	a,b=map(int,raw_input().split())
	g[a-1]+=[(1,a-1,b-1)]
	g[b-1]+=[(1,b-1,a-1)]
z=[-1]*n
for _ in xrange(int(raw_input())):
	a,b=map(int,raw_input().split())
	g[n]+=[(b,n,a-1)]
	z[a-1]=b
a=[1e9]*n+[0]
shortestPath(g,n,a,[-1]*(n+1))
for i in xrange(n):
	if z[i]>=0 and z[i]!=a[i]:
		print('No')
		sys.exit()
for _ in g:
	for e in _:
		if e[1]<e[2] and abs(a[e[1]]-a[e[2]])!=1:
			print('No')
			sys.exit()
print('Yes')
print("\n".join(map(str,a[:n])))
Problem p02733 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
INF = 110110110
H, W, K = list(map(int, input().split()))
S = [''] * H
for i in range(H):
    S[i] = input()
ans = H * W

for bit in range(2**(H-1)):
    cnt = bin(bit).count('1')
    id = [0] * H
    for i in range(H-1):
        if bit>>i & 1:
            id[i+1] = id[i] + 1
        else:
            id[i+1] = id[i]
    num = [[0] * W for i in range(id[H-1]+1)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '1':
                num[id[i]][j] += 1
    for i in range(id[H-1]+1):
        for j in range(W):
            if num[i][j] > K:
                cnt = INF
    sum = [0] * (id[H-1]+1)
    for j in range(W):
        need = False
        for i in range(id[H-1]+1):
            if sum[i] + num[i][j] > K:
                need = True
        if need:
            cnt += 1
            for i in range(id[H-1]+1):
                sum[i] = num[i][j]
        else:
            for i in range(id[H-1]+1):
                sum[i] += num[i][j]
    ans = min(ans, cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

H, W, K = list(map(int, input().split()))
S = [''] * H
for i in range(H):
    S[i] = input()
ans = H * W

for bit in range(2**(H-1)):
    cnt = bin(bit).count('1')
    id = [0] * H
    for i in range(H-1):
        if bit>>i & 1:
            id[i+1] = id[i] + 1
        else:
            id[i+1] = id[i]
    num = [[0] * W for i in range(id[H-1]+1)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '1':
                num[id[i]][j] += 1
    for i in range(id[H-1]+1):
        for j in range(W):
            if num[i][j] > K:
                cnt = INF
    sum = [0] * (id[H-1]+1)
    for j in range(W):
        need = False
        for i in range(id[H-1]+1):
            if sum[i] + num[i][j] > K:
                need = True
        if need:
            cnt += 1
            for i in range(id[H-1]+1):
                sum[i] = num[i][j]
        else:
            for i in range(id[H-1]+1):
                sum[i] += num[i][j]
    ans = min(ans, cnt)

print(ans)
Problem p03059 (python)

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

Buggy submission (verdict: Runtime Error):
a, b, t = map(int, input().split())
print（b * (t // a))
Problem p03109 (python)

Fixed submission:
S = input()
  
if S <= "2019/04/30":
  print("Heisei")
else:
  print("TBD")

Buggy submission (verdict: Runtime Error):
S = input()
  
if s <= "2019/04/30":
  print("Heisei")
else:
  print("TBD")
Problem p03238 (python)

Fixed submission:
from sys import exit

N = int(input())

if N == 1:
  print('Hello World')
  exit(0)

A = int(input())
B = int(input())
print(A + B)

Buggy submission (verdict: Runtime Error):
from sys import exit

N = int(input())

if N == 1:
  print('Hello World')
  exit(0)

A, B = [int(x) for x in input().split()]
print(A + B)
Problem p03264 (python)

Fixed submission:
N = int(input())
print((N // 2) * (N - N // 2))

Buggy submission (verdict: Runtime Error):
print((N // 2) * (N - N // 2))
Problem p03285 (python)

Fixed submission:
def main():
  N = int(input())

  for i in range(26):
    if i * 4 > N:
      break
    if (N - i * 4) % 7 == 0:
      print('Yes')
      return
  print('No')

if __name__ == '__main__':
  main()

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

  for i range(26):
    if i * 4 > N:
      break
    if (N - i * 4) % 7 == 0:
      print('Yes')
      return
  print('No')

if __name__ == '__main__':
  main()
Problem p03408 (python)

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

M = int(input())
T = []
for i in range(M):
  T.append(input())

ans = 0
for s in S:
  score = 0
  for s2 in S:
    if s == s2:
      score += 1
  for t in T:
    if s == t:
      score -= 1
  ans = max(ans, score)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = []
for i in range(N):
  s.append(input())

M = int(input())
T = []
for i in range(M):
  t.append(input())

ans = 0
for s in S:
  score = 0
  for s2 in S:
    if s == s2:
      score += 1
  for t in T:
    if s == t:
      score -= 1
  ans = max(ans, score)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = []
for i in range(N):
  s.append(input())

M = int(input())
T = []
for i in range(N):
  t.append(input())

ans = 0
for s in S:
  score = 0
  for s2 in S:
    if s == s2:
      score += 1
  for t in T:
    if s == t:
      score -= 1
  ans = max(ans, score)

print(ans)
Problem p03545 (python)

Fixed submission:
abcd = input()

for mask in range(1 << 3):
  res = int(abcd[0])
  ans = abcd[0]
  
  for i in range(3):
    if ((mask >> i) & 1) == 1:
      res += int(abcd[i + 1])
      ans += '+' + abcd[i + 1]
    else:
      res -= int(abcd[i + 1])
      ans += '-' + abcd[i + 1]
  
  if res == 7:
    print('{}=7'.format(ans))
    break

Buggy submission (verdict: Runtime Error):
abcd = input()

for mask in range(1 << 3):
  res = int(abcd[0])
  ans = abcd[0]
  
  for i in range(3):
    if ((mask >> i) & 1) == 1:
      res += int(abcd[i + 1])
      ans += '+' + abcd[i + 1]
    else:
      res -= int(abcd[i + 1])
      ans -= '-' + abcd[i + 1]
  
  if res == 7:
    print('{}=7', ans)
    break
Problem p03853 (python)

Fixed submission:
H, W = [int(x) for x in input().split()]
C = []
for i in range(H):
  C.append(input())
  
for i in range(2 * H):
  print(C[i // 2])

Buggy submission (verdict: Runtime Error):
H, W = [int(x) for x in input().split()]
C = []
for i in range(H):
  C.append(input())
  
for i in range(2 * H):
  print(C[(i + 2) // 2])
Problem p02719 (python)

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
if N == K:
    print(0)
elif N > K:
    N %= K
    print(min(N, abs(N - K)))
else:
    print(min(N, abs(N - K)))

Buggy submission (verdict: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
d = abs(N - K)
N %= d
if abs(N - K) < N:
    print(abs(N - K))
else:
    print(N)
Problem p02744 (python)

Fixed submission:
N = int(input())

answer = [(97, 'a')]
for _ in range(N - 1):
    new_answer = []
    for i, j in answer:
        for k in range(97, i + 2):
            new_answer.append((max(k, i), j + chr(k)))
    answer = new_answer[:]

answer = [j for _, j in answer]
answer.sort()
print('\n'.join(answer))

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

answer = [(97, 'a')]
for _ in range(N - 1):
    new_answer = []
    for i, j in answer:
        for k in range(97, i + 1):
            new_answer.append((k, j + chr(k)))
        new_answer.append((i+1,j+chr(i+1))
    answer = new_answer[:]

answer = [j for _, j in answer]
answer.sort()
print('\n'.join(answer))
Problem p02749 (python)

Fixed submission:
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

N, *ab = map(int, read().split())

if N == 2:
    print(1, 2)
    exit()

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
    graph[a].append(b)
    graph[b].append(a)

k0 = list(range(3, N + 1, 3))
k1 = list(range(1, N + 1, 3))  # 1番多い
k2 = list(range(2, N + 1, 3))

start = ab[0]
color = 1  # 1が黒
queue = deque([(start, color)])
colors = [0] * (N + 1)
colors[start] = 1
while queue:
    V, c = queue.popleft()
    c = -c
    for v in graph[V]:
        if colors[v] == 0:
            colors[v] = c
            queue.append((v, c))

black = colors.count(1)
white = N - black
three = (N - 3) // 3 + 1
if black <= three:
    b = k0[:black]
    w = k1 + k2 + k0[black:]
    answer = [b.pop() if i == 1 else w.pop() for i in colors[1:]]
    print(' '.join(map(str, answer)))
elif white <= three:
    w = k0[:white]
    b = k1 + k2 + k0[white:]
    answer = [b.pop() if i == 1 else w.pop() for i in colors[1:]]
    print(' '.join(map(str, answer)))
else:
    answer = [0] * (N + 1)
    for i in range(1, N + 1):
        if colors[i] == 1:
            if k1:
                answer[i] = k1.pop()
            else:
                answer[i] = k0.pop()
        else:
            if k2:
                answer[i] = k2.pop()
            else:
                answer[i] = k0.pop()
    print(' '.join(map(str, answer[1:])))

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

read = sys.stdin.read
readline = sys.stdin.readline

N, *ab = map(int, read().split())
graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
    graph[a].append(b)
    graph[b].append(a)

k0 = list(range(3, N + 1, 3))
k1 = list(range(1, N + 1, 3))  # 1番多い
k2 = list(range(2, N + 1, 3))

start = ab[0]
color = 1  # 1が黒
queue = deque([(start, color)])
answer = [0] * (N + 1)
answer[start] = k1.pop()
while queue:
    V, c = queue.popleft()
    c = -c
    for v in graph[V]:
        if answer[v] == 0:
            if c == 1:
                if k1:
                    answer[v] = k1.pop()
                else:
                    answer[v] = k0.pop()
            else:
                if k2:
                    answer[v] = k2.pop()
                else:
                    answer[v] = k0.pop()
            queue.append((v, c))

print(' '.join(map(str, answer[1:])))
Problem p02821 (python)

Fixed submission:
import sys
import numpy as np

read = sys.stdin.read
N, M, *A = map(int, read().split())

A.sort()
A_as = np.array(A, np.int64)
A_rev = np.array(A[::-1], np.int64)
a = A_rev.cumsum()
a_max = a[-1]

left = 0
right = A[-1] * 2 + 1
while right - left > 1:
    mid = (right + left) // 2
    n = N - np.searchsorted(A_as, mid - A_as)
    n[n < 0] = 0
    m = n.sum()
    if m >= M:
        left = mid
    else:
        right = mid

threshold = left

n = N - np.searchsorted(A_as, threshold - A_as, side='right')
n[n < 0] = 0
answer = a[n[n > 0] - 1].sum() + (A_as * n).sum()
if n.sum() != M:
    answer -= threshold * (n.sum() - M)

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

read = sys.stdin.read
N, M, *A = map(int, read().split())
A = np.array(A, np.int64)

a = A[None, :] + A[:, None]
a = a.flatten()

a.sort()
print(a[-M:].sum())