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

Fixed submission:
from collections import deque
h,w=map(int,input().split())
s=[ input() for _ in range(h)]
dist=[ [float('inf') for _ in range(w)] for _ in range(h)]
#print(s)
#do a bfs 
dq=deque()
dist[0][0]=0
dq.append([0,0])
white=0
for i in s:
    white+=i.count('.')
#print(white)
while len(dq)>0:
    xx,yy=dq.popleft()
    if xx==h-1 and yy==w-1:
        break
    for i,j in zip([-1,0,1,0], [0,1,0,-1]):
            x=xx+i
            y=yy+j
            def valid(x,y):
                if not(x>=0 and x<h and y>=0 and y<w) == True:
                    return False
                if s[x][y]=='.':
                    return True
                else:
                    return False
            if valid(x,y):
                if dist[x][y]>dist[xx][yy]+1:
                    dist[x][y]=1+dist[xx][yy]
                    dq.append([x,y])
#print(dist[h-1][w-1])
if dist[h-1][w-1]!=float('inf'):
    print(white-1-dist[h-1][w-1])
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
s=[ input() for _ in range(h)]
dist=[ [float('inf') for _ in range(w)] for _ in range(h)]
#print(s)
#do a bfs 
dq=deque()
dist[0][0]=0
dq.append([0,0])
white=0
for i in s:
    white+=i.count('.')
#print(white)
while dq!=[]:
    xx,yy=dq.popleft()
    if xx==h-1 and yy==w-1:
        break
    for i,j in zip([-1,0,1,0], [0,1,0,-1]):
            x=xx+i
            y=yy+j
            def valid(x,y):
                if not(x>=0 and x<h and y>=0 and y<w):
                    return False
                if s[x][y]=='.':
                    return True
                else:
                    return False
            if valid(x,y):
                if dist[x][y]>dist[xx][yy]+1:
                    dist[x][y]=1+dist[xx][yy]
                    dq.append([x,y])
#print(dist[h-1][w-1])
if dist[h-1][w-1]!=float('inf'):
    print(white-1-dist[h-1][w-1])
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
s=[ input() for _ in range(h)]
dist=[ [float('inf') for _ in range(w)] for _ in range(h)]
#print(s)
#do a bfs 
dq=deque()
dist[0][0]=0
dq.append([0,0])
white=0
for i in s:
    white+=i.count('.')
#print(white)
while dq!=[]:
    xx,yy=dq.popleft()
    if xx==h-1 and yy==w-1:
        break
    for i,j in zip([-1,0,1,0], [0,1,0,-1]):
            x=xx+i
            y=yy+j
            def valid(x,y):
                if x>=0 and x<h and y>=0 and y<w and s[x][y]=='.':
                    return True
                return False
            if valid(x,y):
                if dist[x][y]>dist[xx][yy]+1:
                    dist[x][y]=1+dist[xx][yy]
                    dq.append([x,y])
#print(dist[h-1][w-1])
if dist[h-1][w-1]!=float('inf'):
    print(white-1-dist[h-1][w-1])
else:
    print(-1)
Problem p03452 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
g=[[] for _ in range(n)]
indeg=[0]*n
touch=[0]*n
for _ in range(m):
    l,r,d=map(int,input().split())
    l-=1
    r-=1
    touch[l]=1
    touch[r]=1
    g[l].append((r,d))
    indeg[r]+=1
if m==0:
    print('Yes')
    exit()
entered=False
for i in range(n):
    if indeg[i]==0 and touch[i]==1:
        vis=[False]*n
        entered=True
        dist=[-1]*n
        dist[i]=0
        def dfs(u):
            vis[u]=1
            for v,wt in g[u]:
                if dist[v]==-1:
                    dist[v]=dist[u]+wt
                elif dist[v]!=dist[u]+wt:
                    print('No')
                    exit()
                if vis[v]==False:
                    dfs(v)
        dfs(i)

if entered==False:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
g=[[] for _ in range(n)]
indeg=[0]*n
touch=[0]*n
for _ in range(m):
    l,r,d=map(int,input().split())
    l-=1
    r-=1
    touch[l]=1
    touch[r]=1
    g[l].append((r,d))
    indeg[r]+=1
if m==0:
    print('Yes')
    exit()
entered=False
for i in range(n):
    if indeg[i]==0 and touch[i]==1:
        vis=[False]*n
        entered=True
        dist=[-1]*n
        dist[i]=0
        def dfs(u):
            vis[u]=1
            for v,wt in g[u]:
                if dist[v]==-1:
                    dist[v]=dist[u]+wt
                elif dist[v]!=dist[u]+wt:
                    print('No')
                    exit()
                if vis[v]==False:
                    dfs(v)
        dfs(i)

if entered==False:
    print('No')
else:
    print('Yes')
Problem p03471 (python)

Fixed submission:
n,y=map(int,input().split())
y//=1000
for i in range(y//10+1):
    #we are gonna use i 10 notes
    cur=y-10*i
    for j in range(cur//5+1):
        #we are gonna use j 5 notes
        k=cur-5*j
        if k>=0 and i+j+k==n and 10*i+5*j+k==y:
            print(i,j,k)
            import sys
            sys.exit()
print('-1 -1 -1')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
n=len(a)
j=0
k=0
for i in range(n):
    while j<n and b[j]<=a[i]:
        j+=1
    while k<n and c[k]<=b[j]:
        k+=1
Problem p03504 (python)

Fixed submission:
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    #a[cc][s-1]+=1
    #a[cc][t]-=1
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5+1):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    a[cc][s-1]+=1
    a[cc][t]-=1
    '''for i in range(s-1,t):
        a[cc][i]=1'''
for i in range(c):
    for j in range(1,10**5+1):
#        print(i,j)
        a[i][j]+=a[i][j-1]
        assert a[i][j]<=1

ans=1
for j in range(0,10**5):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    a[cc][s-1]+=1
    a[cc][t]-=1
    '''for i in range(s-1,t):
        a[cc][i]=1'''
for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]

ans=1
for j in range(0,10**5):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        assert a[i][j]<=1
        su+=a[i][j]
    ans=max(ans,su)
print(ans)
Problem p03575 (python)

Fixed submission:
n,m=map(int,input().split())
g=[ [0 for _ in range(50)] for _ in range(50)]
a=[0]*m
b=[0]*m
for i in range(m):
    a[i],b[i]=map(lambda x:int(x)-1,input().split())
    g[a[i]][b[i]]=1
    g[b[i]][a[i]]=1
ans=0
#print(g)
for i in range(m):
#    print(i,end=' start i \n')
    g[a[i]][b[i]]=0
    g[b[i]][a[i]]=0
    vis=[0]*n
    def dfs(u):
        vis[u]=1
#        print(u,end=' dfs\n')
        for j in range(n):
            if j!=u and g[u][j]==1 and vis[j]==0:
                dfs(j)
    bridge=False
    dfs(0)
    for j in range(n):
        #print(i,vis)
        if vis[j]==0:
            bridge=True
    if bridge:
        ans+=1
    #print(i,end=' curr i \n')
    g[a[i]][b[i]]=1
    g[b[i]][a[i]]=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
g=[ [0 for _ in range(8)] for _ in range(8)]
a=[0]*m
b=[0]*m
for i in range(m):
    a[i],b[i]=map(lambda x:int(x)-1,input().split())
    g[a[i]][b[i]]=1
    g[b[i]][a[i]]=1
ans=0
#print(g)
for i in range(m):
#    print(i,end=' start i \n')
    g[a[i]][b[i]]=0
    g[b[i]][a[i]]=0
    vis=[0]*n
    def dfs(u):
        vis[u]=1
#        print(u,end=' dfs\n')
        for j in range(n):
            if j!=u and g[u][j]==1 and vis[j]==0:
                dfs(j)
    bridge=False
    dfs(0)
    for j in range(n):
        #print(i,vis)
        if vis[j]==0:
            bridge=True
    if bridge:
        ans+=1
    #print(i,end=' curr i \n')
    g[a[i]][b[i]]=1
    g[b[i]][a[i]]=1
print(ans)
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
n=int(input())
edges=[[] for _ in range(n)]
dist=[0]*n
for i in range(n-1):
  u,v=map(int,input().split())
  u-=1
  v-=1
  edges[u].append(v)
  edges[v].append(u)
dist=[ [0]*n for _ in range(2)]
#do a dfs
def dfs(u,p,idd):#u=curr , p=par
  for nei in edges[u]:
    if nei==p:
      continue
    dist[idd][nei]=1+dist[idd][u]
    dfs(nei,u,idd)
dist[0][0]=0
dfs(0,0,0)
dist[1][n-1]=0
dfs(n-1,n-1,1)
cnt_f=cnt_s=0
for i in range(n):
  if dist[0][i]<=dist[1][i]:
    cnt_f+=1
  else:
    cnt_s+=1
print("Fennec") if cnt_f>cnt_s else print("Snuke")

Buggy submission (verdict: Runtime Error):
n=int(input())
edges=[[] for _ in range(n)]
dist=[0]*n
for i in range(n-1):
  u,v=map(int,input().split())
  u-=1
  v-=1
  edges[u].append(v)
  edges[v].append(u)
dist=[ [0]*n for _ in range(2)]
#do a dfs
def dfs(u,p,idd):#u=curr , p=par
  for nei in edges[u]:
    if nei==p:
      continue
    dist[idd][nei]=1+dist[idd][u]
    dfs(nei,u,idd)
dist[0][0]=0
dfs(0,0,0)
dist[1][n-1]=0
dfs(n-1,n-1,1)
cnt_f=cnt_s=0
for i in range(n):
  if dist[0][i]<=dist[1][i]:
    cnt_f+=1
  else:
    cnt_s+=1
print("Fennec") if cnt_f>cnt_s else print("Snuke")
Problem p03694 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[-1]-a[0])

Buggy submission (verdict: Runtime Error):
x,y,z=map(int,input().split())
x-=2
ans=x//(y+z)

rem=x%(y+z)
if rem>=y:
    ans+=1
print(ans)
Problem p03730 (python)

Fixed submission:
a,b,c=map(int,input().split())
for k in range(1,b+1):
    if (k*a)%b==c%b:
        print('YES')
        import sys
        sys.exit()
print('NO')

Buggy submission (verdict: Runtime Error):
w,h,n=map(int,input().split())
mat=[[1]*h for _ in range(w)]
print(mat)
l=[-1]*5
l[2]=float('inf')
l[4]=float('inf')
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        l[1]=max(l[1],x)
    elif a==2:
        l[2]=min(l[2],x)
    elif a==3:
        l[3]=max(l[3],y)
    else:
        l[4]=min(l[4],y)
for i in range(h):
    for j in range(w):
        if l[1]!=-1:
            if i<
Problem p03837 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[0]*m
b=[0]*m
c=[0]*m
for i in range(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
INF=10**18#float('inf')
dist=[ [INF]*n for _ in range(n)]
for i in range(n):
  dist[i][i]=0
for i in range(m):
  dist[a[i]][b[i]]=c[i]
  dist[b[i]][a[i]]=c[i]
#floyd warshall
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
ans=m
for i in range(m):
  shortest=False
  for j in range(n):
    if dist[j][a[i]]+c[i]==dist[j][b[i]]:
      shortest=True
      break
  if shortest:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
c=[0]*n
for i in range(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
INF=float('inf')
dist=[ [INF]*n for _ in range(n)]
for i in range(n):
  dist[i][i]=0
for i in range(m):
  dist[a[i]][b[i]]=c[i]
  dist[b[i]][a[i]]=c[i]
#floyd warshall
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
ans=m
for i in range(m):
  shortest=False
  for j in range(n):
    if dist[j][a[i]]+c[i]==dist[j][b[i]]:
      shortest=True
      break
  if shortest:
    ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
c=[0]*n
for i in range(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
INF=float('inf')
dist=[ [INF]*n for _ in range(n)]
for i in range(n):
  dist[i][i]=0
for i in range(m):
  dist[a[i]][b[i]]=c[i]
  dist[b[i]][a[i]]=c[i]
#floyd warshall
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
ans=m
for i in range(m):
  shortest=False
  for j in range(n):
    if dist[j][a[i]]+c[i]==dist[j][b[i]]:
      shortest=True
      break
  if shortest:
    ans-=1
print(ans)
Problem p04013 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n,a=map(int,input().split())
x=[0]+list(map(int,input().split()))
su=sum(x)
maxi=max(x)
dp=[[[0 for k in range(maxi*n+1)] for j in range(51)] for i in range(51)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(maxi*j+1):
            if k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            if k>=x[i] and j>=1:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
ans=0
for t in range(1,n+1):
    if a*t<=su:
        ans+=dp[n][t][a*t]
    else:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a=map(int,input().split())
x=[0]+list(map(int,input().split()))
su=sum(x)
maxi=max(x)
dp=[[[0 for k in range(su+1)] for j in range(51)] for i in range(51)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(maxi*j+1):
            if k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            if k>=x[i] and j>=1:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
ans=0
for t in range(1,n+1):
    if a*t<=su:
        ans+=dp[n][t][a*t]
    else:
        break
print(ans)
Problem p03937 (python)

Fixed submission:
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def go(a, x, y):
    if a[x][y] != '#':
        return []
    r = [(x, y)]
    while True:
        for tx, ty in ((x+1, y), (x, y+1)):
            if 0 <= tx < len(a) and 0 <= ty < len(a[0]) and a[tx][ty] == '#':
                x = tx
                y = ty
                break
        else:
            break
        r.append((x,y))
    return r


def main():
    R, C = srl(int)
    a = []
    for _ in xrange(R):
        a.append(rl())
    b = go(a, 0, 0)
    if not b or b[-1] != (R-1, C-1):
        print "Impossible"
        return
    s = sum(x.count('#') for x in a)
    print "Impossible" if s != len(b) else "Possible"

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def fix(a):
    mn = min(a) - 1
    return [x - mn for x in a]

def main():
    N = rl(int)
    p = srl(int)
    a = range(N)
    b = list(reversed(a))
    for i, v in enumerate(p[1:], 1):
        a[v-1] += i
        for j in xrange(v, N):
            a[j] += i
            b[j] -= i
    print " ".join(map(str, fix(a)))
    print " ".join(map(str, fix(b)))

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

Fixed submission:
import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def fix(a):
    mn = min(a) - 1
    return [x - mn for x in a]

def main():
    N = rl(int)
    p = srl(int)
    a = range(N)
    b = list(reversed(a))
    inc = [0] * (N+1)
    for i, v in enumerate(p[1:], 1):
        a[v-1] += i
        inc[v] += i
    s = 0
    for i in xrange(N):
        s += inc[i]
        a[i] += s
        b[i] -= s
    print " ".join(map(str, fix(a)))
    print " ".join(map(str, fix(b)))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def fix(a):
    mn = min(a) - 1
    return [x - mn for x in a]

def main():
    N = rl(int)
    p = srl(int)
    a = range(N)
    b = list(reversed(a))
    for i, v in enumerate(p[1:], 1):
        a[v-1] += i
        for j in xrange(v, N):
            a[j] += i
            b[j] -= i
    print " ".join(map(str, fix(a)))
    print " ".join(map(str, fix(b)))

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

Fixed submission:
import networkx as nx

R, C = [int(x) for x in input().split()]
grid = [list(input()) for r in range(R)]


def pack(r, c):
    return r * C + c


graph = nx.Graph()
top_nodes = set()  # top half of the bipartite graph
for r in range(R):
    for c in range(C):
        if r + 1 < R and grid[r][c] == grid[r + 1][c] == ".":
            u, v = pack(r, c), pack(r + 1, c)
            graph.add_edge(u, v)
            if (r + c) % 2 == 0:
                top_nodes.add(v)
            else:
                top_nodes.add(u)
        if c + 1 < C and grid[r][c] == grid[r][c + 1] == ".":
            u, v = pack(r, c), pack(r, c + 1)
            graph.add_edge(u, v)
            if (r + c) % 2 == 0:
                top_nodes.add(v)
            else:
                top_nodes.add(u)


matching = nx.bipartite.maximum_matching(graph, top_nodes=top_nodes)

count = 0
for u, v in matching.items():
    if u > v:
        assert matching[v] == u
        r1, c1 = divmod(u, C)
        r2, c2 = divmod(v, C)
        if r1 == r2:
            if c1 > c2:
                c1, c2 = c2, c1
            grid[r1][c1], grid[r2][c2] = ">", "<"
        elif c1 == c2:
            if r1 > r2:
                r1, r2 = r2, r1
            grid[r1][c1] = "v"
            grid[r2][c2] = "^"
        count += 1

print(count)
for row in grid:
    print("".join(row))

Buggy submission (verdict: Runtime Error):
import networkx as nx

R, C = [int(x) for x in input().split()]
grid = [list(input()) for r in range(R)]


def pack(r, c):
    return r * C + c


graph = nx.Graph()
for r in range(R - 1):
    for c in range(C - 1):
        if grid[r][c] == grid[r + 1][c] == ".":
            graph.add_edge(pack(r, c), pack(r + 1, c))
        if grid[r][c] == grid[r][c + 1] == ".":
            graph.add_edge(pack(r, c), pack(r, c + 1))

matching = nx.bipartite.maximum_matching(graph)

count = 0
for u, v in matching.items():
    if u > v:
        assert matching[v] == u
        r1, c1 = divmod(u, C)
        r2, c2 = divmod(v, C)
        if r1 == r2:
            if c1 > c2:
                c1, c2 = c2, c1
            grid[r1][c1], grid[r2][c2] = ">", "<"
        elif c1 == c2:
            if r1 > r2:
                r1, r2 = r2, r1
            grid[r1][c1] = "v"
            grid[r2][c2] = "^"
        count += 1

print(count)
for row in grid:
    print("".join(row))
Problem p02565 (python)

Fixed submission:
import networkx as nx

import io
import os


input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N, D = [int(x) for x in input().split()]
XY = [[int(x) for x in input().split()] for i in range(N)]

graph = nx.DiGraph()
for i in range(2 * N):
    graph.add_node(i)

# f_i = 0 means choose x for flag i, f_i = 1 means choose y
# Node i is (f_i==0), node (i+N) is (f_i==1)
for i, (x1, y1) in enumerate(XY):
    for j in range(N):
        if i != j:
            x2, y2 = XY[j]
            if abs(x1 - x2) < D:
                # f_i==0 => f_j==1
                graph.add_edge(i, j + N)
            if abs(x1 - y2) < D:
                # f_i==0 => f_j==0
                graph.add_edge(i, j)
            if abs(y1 - x2) < D:
                # f_i==1 => f_j==1
                graph.add_edge(i + N, j + N)
            if abs(y1 - y2) < D:
                # f_i==1 => f_j==0
                graph.add_edge(i + N, j)


SCC = nx.algorithms.components.strongly_connected_components(graph)
assignment = {}
for comp in SCC:
    for x in comp:
        if (x < N and x + N in comp) or (x >= N and x - N in comp):
            print("No")
            exit()
        if x not in assignment:
            assignment[x] = True
            assignment[(x + N) % (2 * N)] = False

print("Yes")
for i in range(N):
    print(XY[i][0] if assignment[i] else XY[i][1])

Buggy submission (verdict: Runtime Error):

import networkx as nx

import io
import os


input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N, D = [int(x) for x in input().split()]
XY = [[int(x) for x in input().split()] for i in range(N)]


graph = nx.DiGraph()


# a_i = 0 means choose x, a_i = 1 means choose y
# Store i for a_i==0 and i+N for a_i==1
for i, (x1, y1) in enumerate(XY):
    for j in range(N):
        if i != j:
            x2, y2 = XY[j]
            if abs(x1 - x2) < D:
                # a_i==0 => a_j==1
                graph.add_edge(i, j + N)
            if abs(x1 - y2) < D:
                # a_i==0 => a_j==0
                graph.add_edge(i, j)
            if abs(y1 - x2) < D:
                # a_i==1 => a_j==1
                graph.add_edge(i + N, j + N)
            if abs(y1 - y2) < D:
                # a_i==1 => a_j==0
                graph.add_edge(i + N, j)


SCC = nx.algorithms.components.strongly_connected_components(graph)
assignment = {}
for comp in SCC:
    for x in comp:
        if (x < N and x + N in comp) or (x >= N and x - N in comp):
            print("No")
            exit()
        if x not in assignment:
            assignment[x] = True
            assignment[(x + N) % (2 * N)] = False
print("Yes")
for i in range(N):
    print(XY[i][0] if assignment[i] else XY[i][1])
Problem p02658 (python)

Fixed submission:
N = int(input())
ans = 1
A = list(map(int, input().split()))
A.sort(reverse=True)
if A[N-1] == 0:
  ans = 0
else:
  for a in A:
    ans *= a
    if ans > 10 ** 18:
      ans = -1
      break
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
ans = 1
A = list(map(int, input().split()))
A.sort(reverse=True)
if A[N-1] == 0:
  ans = 0
else:
  for a in A:
    ans *= a
    if ans > 10 ** 18:
      ans = -1
      break
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
ans = 1
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
if A[N-1] == 0:
  ans = 0
else:
  for a in A:
    ans *= a
    if ans > 10 ** 18:
      ans = -1
      break
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
ans = 1
for _ in range(N):
  a = int(input())
  ans *= a
ans = -1 if ans > 10 ** 18 else ans
print(ans)
Problem p02922 (python)

Fixed submission:
A, B = map(lambda x: int(x) - 1, input().split())

if B == 0:
  ans = 0
elif B % A == 0:
  ans = B // A
else:
  ans = B // A + 1
  
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = map(lambda x: int(x) - 1, input().split())

if B == 0:
  ans == 0
elif B % A == 0:
  ans = B // A
else:
  ans = B // A + 1
  
print(ans)
Problem p03303 (python)

Fixed submission:
s = raw_input()
w = int(raw_input())

result = ""
for i in xrange((len(s) / w)):
  result += s[i * w]
  
if len(s) % w != 0:
  result += s[-(len(s) % w)]
print result

Buggy submission (verdict: Runtime Error):
s = raw_input()
w = int(raw_input())

result = ""
for i in xrange((len(s) / w)):
  result += s[i * w]
  
if w != 1:
  result += s[i * w + w]
print result

Buggy submission (verdict: Runtime Error):
s = raw_input()
w = int(raw_input())

result = ""
for i in xrange((len(s) / w) + 1):
  result += s[i * w]

print result