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

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
uf=UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
  
print(uf.group_count()-1)

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
uf=UnionFind(n)
G=[[] for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a,b)
  
print(uf.group_count()-1)
Problem p02579 (python)

Fixed submission:
from collections import deque

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

ch-=1
cw-=1
dh-=1
dw-=1

S=[]
for _ in range(h):
  s=input()
  sl=[]
  for i in range(w):
    sl.append(s[i])
  S.append(sl)

def isable(X):
  xh,xw=X[0],X[1]
  if 0<=xh<=h-1 and 0<=xw<=w-1 and S[xh][xw]=='.':
    return True
  else:
    return False

def stepA(X):
  xh,xw=X[0],X[1]
  A=[]
  for p,q in [(-1,0),(0,1),(1,0),(0,-1)]:
    if isable([xh+p,xw+q]):
      A.append([xh+p,xw+q])
  return A
    
def stepB(X):
  xh,xw=X[0],X[1]
  B=[]
  for i in range(-2,3):
    for j in range(-2,3):
      if i==0 and j==0:
        continue
      if isable([xh+i,xw+j]):
        B.append([xh+i,xw+j])
  return B

Q=deque()
Q.appendleft((ch,cw))
cost=[[float('inf') for i in range(w)] for j in range(h)]
cost[ch][cw]=0

while Q:
  ph,pw=Q.popleft()
  for v in stepA([ph,pw]):
    ah,aw=v[0],v[1]
    if isable([ah,aw]):
      if cost[ah][aw]>cost[ph][pw]:
        cost[ah][aw]=cost[ph][pw]
        Q.appendleft([ah,aw])
  for bh,bw in stepB([ph,pw]):
    if isable([bh,bw]):
      if cost[bh][bw]>cost[ph][pw]+1:
        cost[bh][bw]=cost[ph][pw]+1
        Q.append([bh,bw])

if cost[dh][dw]==float('inf'):
  print(-1)
else:
  print(cost[dh][dw])

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

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

ch-=1
cw-=1
dh-=1
dw-=1

S=[]
for _ in range(h):
  s=input()
  sl=[]
  for i in range(w):
    sl.append(s[i])
  S.append(sl)

def isable(X):
  xh,xw=X[0],X[1]
  if 0<=xh<=h-1 and 0<=xw<=w-1 and S[xh][xw]=='.':
    return True
  else:
    return False

def stepA(X):
  xh,xw=X[0],X[1]
  A=[]
  for p,q in [(-1,0),(0,1),(1,0),(0,-1)]:
    if isable([xh+p,xw+q]):
      A.append([xh+p,xw+q])
  return A
    
def stepB(X):
  xh,xw=X[0],X[1]
  B=[]
  for i in range(-2,3):
    for j in range(-2,3):
      if i==0 and j==0:
        continue
      if isable([xh+i,xw+j]):
        B.append([xh+i,xw+j])
  return B

Q=deque()
Q.appendleft((ch,cw))
cost=[[float('inf') for i in range(w)] for j in range(h)]
cost[ch][cw]=0

while Q:
  ph,pw=Q.popleft()
  for v in stepA([ph,pw]):
    ah,aw=v[0],v[1]
    if isable([ah,aw]):
      if cost[ah][aw]>cost[ph][pw]:
        cost[ah][aw]=cost[ph][pw]
        Q.appendleft([ah,aw])
  for bh,bw in stepB([ph,pw]):
    if isable([bh,bw]):
      if cost[bh][bw]>cost[ph][pw]+1:
        cost[bh][bw]=cost[ph][pw]+1
        Q.append([bh,bw])

if cost[dh][dw]==float('inf'):
  print(-1)
else:
  print(cost[dh][dw])
Problem p02720 (python)

Fixed submission:
k=int(input())
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

for l in range(1,10):
  f(1,l,L)
L.sort()
print(L[k-1])

Buggy submission (verdict: Runtime Error):
k=int(input())
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

f(0,0,L)
print(L[k-1])
Problem p02885 (python)

Fixed submission:
a,b =(int(x) for x in input().split())
c=a-b*2
if c>=0:
  print(c)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a,b=int(input()).split()
c = 2*a-b
if c >=0:
  print(c)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
int(input()) = A
int(input()) = B
c =2*A-B
if c>=0:
  print(c)
else:
  print(0)
Problem p02886 (python)

Fixed submission:
from itertools import combinations

n=int(input())
D=list(map(int,input().split()))

ans=0
for a,b in combinations(range(n),2):
  ans+=D[a]*D[b]
  
print(ans)

Buggy submission (verdict: Runtime Error):
N =int(input())
s = [int(x) for x in range(0,N)]
for i in range(0,N):
  for j in range(i+1,N):
    m = [int(s[i]*s[j])]
leng = len(m)
sum = 0
for k in range(0,leng):
  sum = sum + m[k]
 print(sum)
Problem p02921 (python)

Fixed submission:
a = input()
b = input()
out=0
for i in range(0,3):
  if a[i] ==b[i]:
    out =out+1
print(out)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
for i in range(0,3):
  if a[i] == 'S':
    a[i] = '1'
  elif a[i] == 'C':
    a[i] = '2'
  else:
    a[i] = '3'
for j in range(0,3):
  if b[j] == 'S':
    b[j] = '1'
  elif b[j] == 'C':
    b[j] = '2'
  else:
    b[j] = '3'
out = 0
for k in range(0,3):
  if int(a[k])-int(b[k]) == 0:
    out = out + 1
print(out)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
for i in range(0,3):
  if a[i] == 'S':
    a[i] = '1'
  elif a[i] == 'C':
    a[i] = '2'
  else:
    a[i] = '3'
for j in range(0,3):
  if b[j] == 'S':
    b[j] = '1'
  elif b[j] == 'C':
    b[j] = '2'
  else:
    b[j] = '3'
out = 0
for k in range(0,3):
  if int(a[k]-b[k]) == 0:
    out = out + 1
print(out)
Problem p03032 (python)

Fixed submission:
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    a=W[i]
    if a<0:
      h-=a
    elif a>0:
      break
else:
  ans=[]
  for i in range(1,K):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        elif l[k]>0:
          break
      ans.append(H)
  h=max(ans)
print(h)
Problem p03062 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B,C=[],[]
for i in range(N):
  if A[i]>=0:
    B.append(A[i])
  else:
    C.append(-A[i])
if len(C)%2==0:
  ans=sum(B)+sum(C)
else:
  ans=sum(B)+sum(C)
  B.sort()
  C.sort()
  if len(B)==0:
    b=10**12
  else:
    b=B[0]
  a=min(b,C[0])
  ans-=2*a
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B,C=[],[]
for i in range(N):
  if A[i]>=0:
    B.append(A[i])
  else:
    C.append(-A[i])
if len(C)%2==0:
  ans=sum(B)+sum(C)
else:
  ans=sum(B)+sum(C)
  B.sort()
  C.sort()
  a=min(B[0],C[0])
  ans-=2*a
print(ans)
Problem p03078 (python)

Fixed submission:
import heapq
X,Y,Z,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)
Q=[[-A[0]-B[0]-C[0],0,0,0]]
heapq.heapify(Q)
ans=[]
ijk={(0,0,0)}
while len(ans)<K:
  abc,i,j,k=heapq.heappop(Q)
  if i+1<X and  not (i+1,j,k) in ijk:
    ijk.add((i+1,j,k))
    heapq.heappush(Q,[-A[i+1]-B[j]-C[k],i+1,j,k])
  if j+1<Y and  not (i,j+1,k) in ijk:
    ijk.add((i,j+1,k))
    heapq.heappush(Q,[-A[i]-B[j+1]-C[k],i,j+1,k])
  if k+1<Z and  not (i,j,k+1) in ijk:
    ijk.add((i,j,k+1))
    heapq.heappush(Q,[-A[i]-B[j]-C[k+1],i,j,k+1])
  ans.append(-abc)
for i in ans:
  print(i)

Buggy submission (verdict: Runtime Error):
import heapq
X,Y,Z,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)
Q=[[-A[0]-B[0]-C[0],0,0,0]]
heapq.heapify(Q)
ans=[]
ijk={(0,0,0)}
while len(ans)<=K:
  abc,i,j,k=heapq.heappop(Q)
  if i+1<X and  not (i+1,j,k) in ijk:
    ijk.add((i+1,j,k))
    heapq.heappush(Q,[-A[i+1]-B[j]-C[k],i+1,j,k])
  if j+1<Y and  not (i,j+1,k) in ijk:
    ijk.add((i,j+1,k))
    heapq.heappush(Q,[-A[i]-B[j+1]-C[k],i,j+1,k])
  if k+1<Z and  not (i,j,k+1) in ijk:
    ijk.add((i,j,k+1))
    heapq.heappush(Q,[-A[i]-B[j]-C[k+1],i,j,k+1])
  ans.append(-abc)
for i in ans:
  print(i)
Problem p03166 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)
INF=float('inf')

n,m=map(int,input().split())
adj=[[] for _ in range(n+1)]
for _ in range(m):
  x,y=map(int,input().split())
  adj[x].append(y)
  
dp=[-1 for _ in range(n+1)]

def f(k):
  if dp[k]!=-1:
    return dp[k]
  
  dp[k]=0
  if adj[k]:
    for v in adj[k]:
      dp[k]=max(dp[k],f(v)+1)
  return dp[k]

ans=-INF  
for i in range(1,n+1):
  ans=max(ans,f(i))

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
INF=float('inf')

n,m=map(int,input().split())
adj=[[] for _ in range(n+1)]
for _ in range(m):
  x,y=map(int,input().split())
  adj[x].append(y)
  
dp=[-1 for _ in range(n+1)]

def f(k):
  if dp[k]!=-1:
    return dp[k]
  
  dp[k]=0
  if adj[k]:
    for v in adj[k]:
      dp[k]=max(dp[k],f(v)+1)
  return dp[k]

dp[0]=0
for i in range(1,n+1):
  dp[i]=-1

ans=-INF  
for i in range(1,n+1):
  ans=max(ans,f(i))

print(ans)
Problem p03168 (python)

Fixed submission:
INF=float('inf')

n=int(input())
P=list(map(float,input().split()))#0

dp=[[0 for i in range(n+1)] for j in range(n+1)]

for i in range(n+1):
  if i==0:
    dp[0][0]=1
  else:
    dp[i][0]=(1-P[i-1])*dp[i-1][0]

    
for j in range(1,n+1):
  for i in range(1,n+1):
    if i<j:
      continue
    dp[i][j]=P[i-1]*(dp[i-1][j-1])+(1-P[i-1])*(dp[i-1][j])

ans=0
for i in range(1,n+1):
  if i>=(n+1)//2:
    ans+=dp[n][i]
    
print(ans)

Buggy submission (verdict: Runtime Error):
INF=float('inf')
import numpy as np

n=int(input())
P=list(map(float,input().split()))#0

dp=np.zeros([n+1,n+1], dtype='float128')

for i in range(n+1):
  if i==0:
    dp[0][0]=1
  else:
    dp[i][0]=(1-P[i-1])*dp[i-1][0]

    
for j in range(1,n+1):
  for i in range(1,n+1):
    if i<j:
      continue
    dp[i][j]=P[i-1]*(dp[i-1][j-1])+(1-P[i-1])*(dp[i-1][j])

ans=0
for i in range(1,n+1):
  if i>=(n+1)//2:
    ans+=dp[n][i]
    
print(ans)
Problem p03289 (python)

Fixed submission:
s=input()
S=list(s)
cc=0
for i in range(2,len(S)-1):
  if S[i]=='C':
    cc=cc+1
if cc>=1:
  S.remove('C')
S.remove(S[0])
count=[]
if s[0]=='A':
  count.append(1)
if cc==1:
  count.append(2)
if ''.join(S).islower():
  count.append(3)

if count==[1,2,3]:
  print('AC')
else:
  print('WA')

Buggy submission (verdict: Runtime Error):
s=input()
S=list(s)
cc=0
for i in range(2,len(S)-1):
  if S[i]=='C':
    cc=cc+1
S.remove('C')
S.remove(S[0])
count=[]
if s[0]=='A':
  count.append(1)
if cc==1:
  count.append(2)
if ''.join(S).islower():
  count.append(3)

if count==[1,2,3]:
  print('AC')
else:
  print('WA')

Buggy submission (verdict: Runtime Error):
s=input()
S=list(s)
cc=0
for i in range(2,len(S)-1):
  if S[i]=='C':
    cc=cc+1
    S.remove(S[i])
S.remove(S[0])
count=[]
if s[0]=='A':
  count.append(1)
if cc==1:
  count.append(2)
if ''.join(S).islower():
  count.append(3)

if count==[1,2,3]:
  print('AC')
else:
  print('WA')
Problem p03309 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-i-1)
B.sort()
if N%2==0:
  b=(B[N//2]+B[N//2-1])//2
else:
  b=B[N//2]
sad=0
for j in range(N):
  sad=sad+abs(B[j]-b)
print(sad)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
def quick_sort(a):
    if len(a)<= 1:
        return a
    else:
        b=[]
        c=[]
        for i in range(1, len(a)):
            if a[i]<a[0]:
                b.append(a[i])
            else:
                c.append(a[i])
        return quick_sort(b)+[a[0]]+quick_sort(c)
def abs(x):
    if x>=0:
        return x
    else:
        return x*(-1)
B=[0]*N
for i in range(N):
  B[i]=A[i]-i-1
C=quick_sort(B)
if N%2==0:
  b=(C[N//2]+C[N//2-1])//2
else:
  b=C[N//2+1]
sad=0
for j in range(N):
  sad=sad+abs(C[j]-b)
print(sad)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
def quick_sort(a):
    if len(a) <= 1:
        return a
    else:
        b = []
        c = []
        for i in range(1, len(a)):
            if a[i] < a[0]:
                b.append(a[i])
            else:
                c.append(a[i])
        return quick_sort(b)+[a[0]]+quick_sort(c)
def abs(x):
    if x>=0:
        return x
    else:
        return x*(-1)
B=[0]*N
for j in range(N):
    B[j]=A[j]-j-1
bh=quick_sort(B)[0]
bt=quick_sort(B)[N]
def sad(A,b):
  s=[0]*(len(A))
  for m in range(len(A)):
    s[m]=abs(A[m]-(b+m+1))
  return s
def sum(A):
  sum=0
  for n in range(len(A)):
    sum=sum+A[n]
  return sum
l=[]
for o in range(bh-5,bt+5):
  l.append(sum(sad(A,o)))
print(quick_sort(l)[0])
Problem p04043 (python)

Fixed submission:
a = list(int(x) for x in input().split())
if a == [5,5,7] or a == [5,7,5] or a == [7,5,5]:
  print('YES')
else:
  print('NO')

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

Buggy submission (verdict: Runtime Error):
a,b,c =int(x) for in input().split()
if a+b+c==17 and a*b*c==175:
  print('Yes')
else:
  print('No')
Problem p02585 (python)

Fixed submission:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
a=[]
ans=-10**10
for i in range(N):
    idx=P[i]-1
    z=set()
    rl=[]
    c=0
    tc=0
    while idx not in z and c<K:
        tc+=C[idx]
        rl.append(tc)
        ans=max(ans,tc)
        z.add(idx)
        idx=P[idx]-1
        c+=1
    if c<K:
        d,m=divmod(K,c)
        if m==0:
            d-=1
            m=c
        tc=d*tc
        tc+=max(rl[:m])
        ans=max(ans,tc)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
a=[]
ans=-10**10
for i in range(N):
    idx=P[i]-1
    z=set()
    rl=[]
    c=0
    tc=0
    while idx not in z and c<K:
        tc+=C[idx]
        rl.append(tc)
        ans=max(ans.tc)
        z.add(idx)
        idx=P[idx]-1
        c+=1
    if c<K:
        d,m=divmod(K,c)
        if m==0:
            d-=1
            m=c
        tc=d*tc
        tc+=max(rl[:m])
        ans=max(ans.tc)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
a=[]
s=set()
for i in range(N):
    idx=P[i]-1
    z=set()
    tl=[]
    rl=[]
    c=0
    tc=0
    while idx not in z and c<K:
        tl.append(C[idx])
        tc+=C[idx]
        rl.append(tc)
        s.add(tc)
        z.add(idx)
        idx=P[idx]-1
        c+=1
    d,m=divmod(K,c)
    tc=d*tc
    tc+=max(rl[:m])
    s.add(tc)
print(max(s))
Problem p02609 (python)

Fixed submission:
def f(n):
    if n in memo:
        return memo[n]
    c=list(str(bin(n)))[2:].count('1')
    r=n%c
    if r>0:
        memo[n]=f(r)+1
    else:
        memo[n]=1
    return memo[n]

memo={0:0}
N=int(input())
X=list(input())
XC=X.count('1')
XN=int('0b'+''.join(X),2)
for i in range(N):
    if X[i]=='1':
        if XC==1:
            print(0)
            continue
        tx=(XN%(XC-1)-pow(2,N-i-1,XC-1))
        if tx<0:
            tx+=XC-1
        tx%=XC-1
    else:
        tx=(XN%(XC+1)+pow(2,N-i-1,XC+1))%(XC+1)
    print(f(tx)+1)

Buggy submission (verdict: Runtime Error):
def f(n):
    if n in memo:
        return memo[n]
    c=list(str(bin(n)))[2:].count('1')
    r=n%c
    if r>0:
        memo[n]=f(r)+1
    else:
        memo[n]=1
    return memo[n]

memo={0:0}
N=int(input())
X=list(input())
XC=X.count('1')
XN=int('0b'+''.join(X),2)
for i in range(N):
    if X[i]=='1':
        tx=(XN%(XC-1)-pow(2,N-i-1,XC-1))
        if tx<0:
            tx+=XC-1
        tx%=XC-1
    else:
        tx=(XN%(XC+1)+pow(2,N-i-1,XC+1))%(XC+1)
    print(f(tx)+1)

Buggy submission (verdict: Runtime Error):
def f(n):
    if n in memo:
        return memo[n]
    c=list(str(bin(n)))[2:].count('1')
    r=n%c
    if r>0:
        memo[n]=f(r)+1
    else:
        memo[n]=1
    return memo[n]

memo={0:0}
N=int(input())
X=list(input())
XC=X.count('1')
XN=int('0b'+''.join(X),2)
for i in range(N):
    if X[i]=='1':
        tx=(XN%(XC-1)-pow(2,N-i-1,XC-1))%(XC-1)
        if tx<0:
            tx+=XC-1
    else:
        tx=(XN%(XC+1)+pow(2,N-i-1,XC+1))%(XC+1)
    print(f(tx)+1)
Problem p02618 (python)

Fixed submission:
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]
for i in range(D):
    print(s[i].index(max(s[i]))+1)

Buggy submission (verdict: Runtime Error):
v
Problem p02866 (python)

Fixed submission:
import math
n=int(input())
dl=list(map(int,input().split()))
MOD=998244353
if dl[0]>0:
    print(0)
    exit()
dist=[0]*(n)
for d in dl:
    dist[d]+=1
if dist[0]!=1:
    print(0)
    exit()
ans=1
flg=False
for i in range(1,n):
    if dist[i]>0:
        if flg:
            ans=0
            break
        else:
            ans*=dist[i-1]**dist[i]%MOD
    else:
        flg=True
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
dl=list(map(int,input().split()))
MOD=998244353
if dl[0]>0:
    print(0)
    exit()
dist=[0]*(n-1)
for d in dl:
    dist[d]+=1
if dist[0]!=1:
    print(0)
    exit()
ans=1
flg=False
for i in range(1,n-1):
    if dist[i]>0:
        if flg:
            ans=0
            break
        else:
            ans*=dist[i-1]**dist[i]%MOD
    else:
        flg=True
print(ans%MOD)
Problem p02903 (python)

Fixed submission:
h,w,a,b=map(int,input().split())
ans=['']*h
for i in range(h):
    for j in range(w):
        if (i<b and j<a) or (i>=b and j>=a):
            ans[i]+='0'
        else:
            ans[i]+='1'
for i in range(h):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
h,w,a,b=map(int,input().split())
ans=['']*w
for i in range(h):
    for j in range(w):
        if (i<b and j<a) or (i>=b and j>=a):
            ans[i]+='0'
        else:
            ans[i]+='1'
for i in range(h):
    print(ans[i])
Problem p02947 (python)

Fixed submission:
from scipy import misc
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
s=sorted(s)
ans=0
c=1
t=s[0]
for i in range(1,n):
    if t==s[i]:
        c+=1
    else:
        ans+=misc.comb(c,2,True)
        t=s[i]
        c=1
ans+=misc.comb(c,2,True)
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy import special
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
s=sorted(s)
ans=0
c=1
t=s[0]
for i in range(1,n):
    if t==s[i]:
        c+=1
    else:
        ans+=special.comb(c,2,True)
        t=s[i]
        c=1
ans+=special.comb(c,2,True)
print(ans)
Problem p02975 (python)

Fixed submission:
n=int(input())
al=list(map(int,input().split()))
t=0
for i in range(n):
    t^=al[i]
if t==0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
al=list(map(int,input().split()))
s=set(al)
s=sorted(s)
if len(s)==1 and s[0]==0:
    print('Yes')
    exit()
if len(al)%3>0 or len(s)>3 or len(s)==1:
    print('No')
    exit()
if len(s)==2 and s[0]==0:
    if al.count(0)==n//3:
        print('Yes')
        exit()
if (s[0]^s[1]^s[2])==0:
    if al.count(s[0])==n//3 and al.count(s[1])==n//3:
        print('Yes')
        exit()
print('No')
Problem p03001 (python)

Fixed submission:
w,h,x,y=map(int,input().split())
print(w*h/2)
if x==w/2 and y==h/2:
    print(1)
else:
    print(0)

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

if w==x:
    print('{:6f}'.format(min(w*(h-y),w*y)),0)
elif h==x:
    print('{:6f}'.format(min((w-x)*h,x*h)),0)
elif (w-x)*h==w*(h-y):
    print('{:6f}'.format((w-x)*h,1)
elif min((w-x)*h,x*h)>min(w*(h-y),w*y):
    print('{:6f}'.format(min((w-x)*h,x*h)),0)
else:
    print('{:6f}'.format(min(w*(h-y),w*y)),0)

Buggy submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
tl=set([(w-x)*h,w*(h-y),x*h,w*y])

if (w-x)*h==w*(h-y):
    print('{:6f}'.format((w-x)*h),1)
elif min((w-x)*h,x*h)>min(w*(h-y),w*y):
    print('{:6f}'.format(min((w-x)*h,x*h)),0)
else:
    print('{:6f}'.format(min(w*(h-y),w*y),0)
Problem p03027 (python)

Fixed submission:
q=int(input())
m=10**6+3
f=[1]
for i in range(1,m):
    f.append(f[-1]*i%m)
for i in range(q):
    x,d,n=map(int,input().split())
    if d==0:
        print(pow(x,n,m))
    else:
        t=x*pow(d,m-2,m)%m
        if t==0 or t+n-1>=m:
            print(0)
        else:
            print(f[t+n-1]*pow(f[t-1],m-2,m)*pow(d,n,m)%m)

Buggy submission (verdict: Runtime Error):
import functools
import operator
q=int(input())
for i in range(q):
    x,d,n=map(int,input().split())
    a=range(x,x+d*(n-1)+1,d)
    print(functools.reduce(operator.mul,a)%1000003)

Buggy submission (verdict: Runtime Error):
import numpy
q=int(input())
for i in range(q):
    x,d,n=map(int,input().split())
    a=numpy.arange(x,x+d*(n-1)+1,d)
    print(a.prod()%1000003)