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

Fixed submission:
N=int(input())
X=input()
Y=int(X,2)

J=X.count("1")

A=[0]*N
A[-1]=1
for i in range(2,N+1):
    A[-i]=(A[-(i-1)]*2)%(J+1)

B=[0]*N
if J>1:
    B[-1]=1
    for j in range(2,N+1):
        B[-j]=(B[-(j-1)]*2)%(J-1)


H=[0]*N

Q,R=divmod(Y,J+1)
if J>1:
    S,T=divmod(Y,J-1)
else:
    S=T=0

for i in range(N):
    if X[i]=="0":
        U=(R+A[i])%(J+1)
    else:
        if J==1:
            continue
        U=(T-B[i])%(J-1)
        
        
    I=1
    while U>0:
        U=U%bin(U).count("1")
        I+=1
    H[i]=I

print("\n".join(map(str,H)))

Buggy submission (verdict: Runtime Error):
N=int(input())
X=input()
Y=int(X,2)

J=X.count("1")

A=[0]*N
A[-1]=1
for i in range(2,N+1):
    A[-i]=(A[-(i-1)]*2)%(J+1)

if J>1:
    B=[0]*N
    B[0]=1
    for j in range(2,N+1):
        B[-j]=(B[-(j-1)]*2)%(J-1)


H=[0]*N
Q,R=divmod(Y,J)
for i in range(N):
    if X[i]=="0":
        S=(R+A[i]-Q)%(J+1)
    else:
        if J==1:
            continue
        S=(R-B[i]+Q)%(J-1)
        
    I=1
    while S>0:
        S=S%bin(S).count("1")
        I+=1
    H[i]=I

print("\n".join(map(str,H)))

Buggy submission (verdict: Runtime Error):
def f(L):
    if L:
        return 2*f(L[:-1])+L[-1]
    else:
        return 0

N=int(input())
X=input()
Zero="0"*N

X=list(map(int,X))

H=X.count(1)
Z=f(X)
G=1<<N

A=[]
for i in range(N):
    G>>=1
    
    if X[i]==0:
        J=H+1
    else:
        J=H-1
        
    Y=Z^G

    if Y==0:
        A.append(0)
        continue
    
    I=1
    Y=Y%J
    try:
        while True:
            Y=Y%bin(Y).count("1")
            I+=1
    except ZeroDivisionError:
        A.append(I)

print("\n".join(map(str,A)))

Buggy submission (verdict: Runtime Error):
M={0:0}
def popcount(n):
    return n.count("1")

D={0:0}
def f(n):
    if n in D:
        return D[n]
    
    T=[n]
    N=n
    while N>0 and N not in D:
        N%=popcount(N)
        T.append(N)

    t=D[N]
    for i in range(-2,-(len(T)+1),-1):
        D[T[i]]=t+(-i-1)
    return D[n]
    
def g(L):
    A=0
    u=1
    for i in range(N):
        A+=L[-(i+1)]*u
        u*=2
    return A

N=int(input())
X=input()

for i in range(N):
    if X[i]=="0":
        Y=X[:i]+"1"+X[i+1:]
    else:
        Y=X[:i]+"0"+X[i+1:]

    I=0
    while Y!="0":
        Y=bin(int(Y,2)%popcount(Y))[2:]
        I+=1
    print(I)
Problem p02616 (python)

Fixed submission:
from collections import deque
import sys

N,K=map(int,input().split())
A=list(map(int,input().split()))
M=10**9+7

if N==K:
    T=1
    for a in A:
        T=(T*a)%M
    print(T)
    sys.exit()
elif max(A)<0 and K%2==1:
    A.sort(reverse=True)
    T=1
    for i in range(K):
         T=(T*A[i])%M
    print(T)
    sys.exit()
    
U=list(map(lambda x:max(x,0),A))
U.sort(reverse=True)
U=deque(U)

V=list(map(lambda x:min(x,0),A))
V.sort()
V=deque(V)

T=1
Y=0
while Y<K:
    x1,x2=U[0],U[1]
    y1,y2=V[0],V[1]

    if Y==K-1 or x1*x2>=y1*y2:
        Y+=1
        T=(T*x1)%M
        _=U.popleft()
        U.append(0)
    else:
        Y+=2
        T=(T*y1*y2)%M
        _=V.popleft()
        _=V.popleft()
        V.append(0)
        V.append(0)
print(T)

Buggy submission (verdict: Runtime Error):
def f(P,M):
    return P[0]*M+P[1]

def g(X,Y,M):
    (a,b)=X
    (x,y)=Y

    return (a*x*M+a*y+b*x+(y*b)//M,(y*b)%M)

N,K=map(int,input().split())
A=list(map(int,input().split()))
M=10**9+7

P,Q=[],[] #P,Q...+,-の要素
Z=0 #Z...0の個数

for a in A:
    if a>0:
        P.append(divmod(a,M))
    elif a<0:
        Q.append(divmod(a,M))
    else:
        Z+=1

P.sort(reverse=True)
X=[(0,1)]
(a,b)=(0,1)
for (x,y) in P:
    a,b=g((a,b),(x,y),M)
    X.append((a,b))

Q.sort()
Y=[(0,1)]
(a,b)=(0,1)
for (x,y) in Q:
    a,b=g((a,b),(x,y),M)
    Y.append((a,b))

J=-1
S=len(P)
for m in range(0,len(Q)+1,2):
    if 0<=K-m<=S:
        J=max(J,f(g(X[K-m],Y[m],M),M))

if J>0:
    print(J%M)
else:
    if Z==0:
        J=1
        for i in range(K):
            J*=Q[-(i+1)]
        print(J%M)
    else:
        print(0)
Problem p02618 (python)

Fixed submission:
from random import randint
A=26

D=int(input())

C=list(map(int,input().split()))

S=[0]*D
for i in range(D):
    S[i]=list(map(int,input().split()))

for j in range(D):
    print(randint(1,A))

Buggy submission (verdict: Runtime Error):
#-------------------------------------------------------------------------------
#関数定義
def f(a,d,T):
    try:
        return T[d+1:].index(a)+(d+1)
    except ValueError:
        return len(T)

def g(a,d,T):
    try:
        return (d-1)-T[d-1::-1].index(a)
    except ValueError:
        return 0
#-------------------------------------------------------------------------------
#インポート
from math import inf,exp
from random import random,randint
import time
from copy import copy
#-------------------------------------------------------------------------------
#定数
TIME_LIMIT=1.862 #ループの時間制限  
A=26 #アルファベットの数
START=time.time()

TEMP=10 #アニーリング法の初期温度
ICE=0.000001 #アニーリング法で更新毎に減少する温度
#-------------------------------------------------------------------------------
#読み込み部
D=int(input())

C=[True]+list(map(int,input().split())) #減る満足度のベース
S=[True]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))           
#-------------------------------------------------------------------------------
#貪欲部
L=[0]*(A+1)
T=[0]
for d in range(1,D+1):
    Y=-inf
    E=0
    for a in range(1,A+1):
        X=S[d][a]
        for s in range(1,A+1):
            if a!=s:
                X-=C[s]*(d-L[s])

        if X>Y:
            Y=X
            E=a
    L[E]=d
    T.append(E)
#-------------------------------------------------------------------------------
#調節部
while time.time()-START<TIME_LIMIT:
    t=time.time()-START
    d=randint(1,D)
    p=T[d]
    q=randint(1,A)
    Y=(d-g(p,d,T))*(f(p,d,T)-d)
    Z=(d-g(q,d,T))*(f(q,d,T)-d)
        
    Delta=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p]
    if (Delta>=0) or (Delta<0 and random()<exp(Delta/(TIME_LIMIT-t))):
        T[d]=q
    
for i in range(1,D+1):
    print(T[i])

Buggy submission (verdict: Runtime Error):
def f(a,d,T):
    try:
        return T[d:].index(a)+d
    except ValueError:
        return len(T)

def g(a,d,T):
    try:
        return T[:d].index(a)
    except ValueError:
        return 0

A=26

D=int(input())

C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))

T=[0]
for i in range(D):
    T.append(int(input()))
            
X=0
L=[0]*(A+1)
for d in range(1,D+1):
    X+=S[d][T[d]]
    for j in range(1,A+1):
        if j!=T[d]:
            L[j]+=1
            X-=C[j]*L[j]
        else:
            L[j]=0

M=int(input())
for _ in range(M):
    d,q=map(int,input().split())
    p=T[d]
    
    Y=(f(p,d+1,T)-d)*(d-g(p,d,T))
    Z=(f(q,d+1,T)-d)*(d-g(p,d,T))

    X+=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p]
    print(X)

    T[d]=q
Problem p02678 (python)

Fixed submission:
import copy
import collections

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

Q=collections.deque()
Q.append(V[0])

L[1]=1
n=1

while Q:
    x=Q.popleft()
    for v in H[x]:
        if L[v]!=None:
            continue
        L[v]=x
        n+=1
        Q.append(v)

if n==N:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")

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

def bfs(G):
    V = [ v for v in G.nodes() ]
    Q = collections.deque([V[0]])
    searched = { v: False for v in G.nodes() }
    searched[V[0]] = True
    n=1
    H={v:None for v in G.nodes()}

    while len(Q) != 0:
        v = Q.popleft()
        edges = [ (v, i ) for (v, i) in G.edges(v) if not searched[i] ]
        for edge in edges:
            v, i = edge
            Q.append(i)
            searched[i] = True

            if H[i]==None:
                H[i]=v
                n+=1
                
    return (H,n)

G=nx.Graph()
N,M=map(int,input().split())
G.add_nodes_from(range(1,N+1))

for i in range(M):
    v,w=map(int,input().split())
    G.add_edge(v,w)

(H,n)=bfs(G)
if n!=N:
    print("No")
else:
    print("Yes")
    for i in range(2,N+1):
        print(H[i])
Problem p02691 (python)

Fixed submission:
def Binary_Search_Small_Count(A,x,equal=False,sort=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()

    if A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x):
            L=C
        else:
            R=C

    return L+1

def Binary_Search_Equal_Count(A,x,sort=False):
    """2分探索によって,xの個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"を超える"がx"以上"になる
    """

    if sort:
        A.sort()

    if x<A[0] or A[-1]<x:
        return 0

    X=Binary_Search_Small_Count(A,x,equal=True)
    Y=Binary_Search_Small_Count(A,x,equal=False)
    return X-Y
#================================================
N=int(input())
A=["*"]+list(map(int,input().split()))

B=[0]*N
for j in range(1,N+1):
    B[j-1]=j-A[j]
B.sort()

K=0
del A[0]
for i in range(1,N+1):
    K+=Binary_Search_Equal_Count(B,i+A[i-1],False)
print(K)

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

H=[0]+list(map(int,input().split()))

J={x:[] for x in range(1,N+1)}

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

S=0
for x in J:
    f=1
    for y in J[x]:
        if H[x]<=H[y]:
            f=0
    S+=f

print(S)
Problem p02789 (python)

Fixed submission:
N,M=map(int,input().split())
if N==M:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N,M=int(input())
if N==M:
  print("Yes")
else:
  print("No")
Problem p02975 (python)

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

T={}
for a in A:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for x in T:
    F&=(3*T[x]%N==0)

if not F:
    print("No")
    exit()

M=max(T,key=lambda x:T[x])
if 3*T[M]==N:
    x,y,z=list(T.keys())
elif 3*T[M]==2*N:
    x=y=M
    del T[M]
    z=tuple(T.keys())[0]
else:
    x=y=z=M

if x^y==z:
    print("Yes")
else:
    print("No")

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

if A==[0]*N:
    print("Yes")
    exit()

T={}
for a in A:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for x in T:
    F&=(3*T[x]%N==0)

if not F:
    print("No")
    exit()

M=max(T,key=lambda x:T[x])
if 3*T[M]==N:
    x,y,z=list(T.keys())
else:
    x=y=M
    del T[M]
    z=tuple(T.keys())[0]

if x^y==z:
    print("Yes")
else:
    print("No")

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

if A==[0]*N:
    print("Yes")
    exit()

T={}
for a in A:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for x in T:
    F&=(3*T[x]%N==0)

if not F:
    print("No")
    exit()

x,y,z=list(T.keys())

if x^y==z:
    print("Yes")
else:
    print("No")
Problem p03050 (python)

Fixed submission:
#素因数分解
def Prime_Factorization(n):
    R=[]
    N=n

    for k in range(2,int(-(-n**0.5//1))+1):
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])

    if N!=1:
        R.append([N,1])
        
    if not R:
        R.append([N,1])

    return R

#約数全部
from copy import copy
def Divisors(n):
    if n==1:
        return [1]
    
    L=Prime_Factorization(n)
    U=[1]

    for (p,k) in L:
        T=copy(U)
        for t in T:
            r=t
            for _ in range(1,k+1):
                r*=p
                U.append(r)
    U.sort()
    return U


import sys
N=int(input())
if N==1:
    print(0)
    sys.exit()
    
L=Divisors(N)
L.remove(1)

K=0
for a in L:
    b=a-1
    if N//b==N%b:
        K+=b
print(K)

Buggy submission (verdict: Runtime Error):
#素因数分解
def Prime_Factorization(n):
    R=[]
    N=n

    for k in range(2,int(-(-n**0.5//1))+1):
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])

    if N!=1:
        R.append([N,1])
        
    if not R:
        R.append([N,1])

    return R

#約数全部
from copy import copy
def Divisors(n):
    L=Prime_Factorization(n)
    U=[1]

    for (p,k) in L:
        T=copy(U)
        for t in T:
            r=t
            for _ in range(1,k+1):
                r*=p
                U.append(r)
    U.sort()
    return U

N=int(input())
L=Divisors(N)
L.remove(1)

K=0
for a in L:
    b=a-1
    if N//b==N%b:
        K+=b
print(K)
Problem p03089 (python)

Fixed submission:
N=int(input())
B=["*"]+list(map(int,input().split()))

X=[]
for t in range(N):
    p=-1
    for k in range(1,(N-t)+1):
        if B[k]==k:
            p=k

    if p>=1:
        X.append(p)
        del B[p]
    else:
        print(-1)
        exit()

print("\n".join(map(str,X[::-1])))

Buggy submission (verdict: Runtime Error):
N=int(input())
B=["*"]+list(map(int,input().split()))

X=[]
for t in range(N):
    p=-1
    for k in range(1,(N-t)+1):
        if B[k]==k:
            p=k

    if p>=1:
        X.append(p)
        del B[p]
    else:
        print(-1)
        sys.exit()

print("\n".join(map(str,X[::-1])))
Problem p03342 (python)

Fixed submission:
def f(A,B):
    m=0
    for i in range(len(A)):
        if m<A[i]+B[i]:
            m=A[i]+B[i]
    return m

N=int(input())
A=list(map(int,input().split()))
J=20

B=[[0 for _ in range(J)] for __ in range(N)]
for i in range(N):
    m=A[i]
    for j in range(J):
        B[i][j]=m%2
        m>>=1
B+=[[float("inf")]*J]

b=0
X=[0]*J
K=0

for a in range(N):
    while f(X,B[b])<=1:
        for k in range(J):
            X[k]+=B[b][k]
        b+=1

    K+=b-a

    for k in range(J):
        X[k]-=B[a][k]

print(K)

Buggy submission (verdict: Runtime Error):
def f(A,B):
    m=0
    for i in range(len(A)):
        if m<A[i]+B[i]:
            m=A[i]+B[i]
    return m

N=int(input())
A=list(map(int,input().split()))
J=20

B=[[0 for _ in range(J)] for __ in range(N)]
for i in range(N):
    m=A[i]
    for j in range(J):
        B[i][j]=m%2
        m>>=1
B+=[[float("inf")]*J]

b=0
X=[0]*J
K=0

for a in range(N):
    while f(X,B[b])<=1:
        for k in range(J):
            X[k]+=B[b][k]
        b+=1

    K+=b-a

    for k in range(N):
        X[k]-=B[a][k]

print(K)
Problem p03583 (python)

Fixed submission:
N=int(input())

for h in range(1,3500+1):
    for n in range(1,3500+1):
        try:
            if (N*h*n)%(4*h*n-N*(h+n))==0 and (4*h*n-N*(h+n))>0:
                A,B,C=h,n,(N*h*n)//(4*h*n-N*(h+n))
        except:
            pass
print(A,B,C)

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

for h in range(1,3500+1):
    for n in range(1,3500+1):
        if  (N*h*n)%(4*h*n-N*(h+n))==0:
            try:
                H,N,W=h,n,(N*h*n)//(4*h*n-N*(h+n))
            except:
                pass
print(H,N,W)
Problem p02555 (python)

Fixed submission:
import sys
S = int(input())
mod = 10**9 + 7
if S <= 2:
  print(0)
  sys.exit()
d = [[0 for i in range(S + 1)] for j in range(S + 1)]
d[3][1] = 1
for j in range(S - 3):
  for i in range(S):
    d[j+4][i+1] = (d[j+3][i+1] + d[j+1][i]) %mod
print(sum(d[S])%mod)

Buggy submission (verdict: Runtime Error):
S = int(input())
mod = 10**9 + 7
d = [[0 for i in range(S + 1)] for j in range(S + 1)]
d[3][1] = 1
for j in range(S - 3):
  for i in range(S):
    d[j+4][i+1] = (d[j+3][i+1] + d[j+1][i]) %mod
print(sum(d[S])%mod)
Problem p02576 (python)

Fixed submission:
import math
N ,X , T = map(int,input().split())
print(T*math.ceil(N/X))

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.readline
H , W , M = map(int,input().split())
h = [0]*M
w = [0]*M
for i in range(M):
  h[i] , w[i] = map(int,input().split())
G1 = deque([0]*H)
G2 = deque([0]*W)
for i in range(M):
  temp = h[i] - 1
  G1[temp] += 1
for  i in range(M):
  temp = w[i] - 1
  G2[temp] += 1
G3 = [[h[i] - 1 , w[i] - 1] for i in range(M)]
M1 = max(G1)
M2 = max(G2)
M1L = []
M2L = []
for i in range(H):
  if G1[i] == M1:
    M1L.append(i)
for j in range(W):
  if G2[j] == M2:
    M2L.append(j)
c = 0
for i in M1L:
  for j in M2L:
    if [i,j] not in G3:
      c = 1
      break
  if c ==1:
    break
if c == 1:
  print(M1 + M2)
else:
  print(M1 + M2 - 1)
Problem p02639 (python)

Fixed submission:
x = list(map(int,input().split()))
for i in range(5):
  if x[i] == 0:
    print(i+1)
    break

Buggy submission (verdict: Runtime Error):
a = list(map(int,input()))
for i in range(5):
  if a[i]==0:
    print(i+1)
Problem p02641 (python)

Fixed submission:
X, N = map(int,input().split())
if N == 0:
  print(X)
else:
  q = list(map(int,input().split()))
  q = list(set(q))
  p = [i for i in range(-2 , 102)]
  for i in range(len(q)):
    p.remove(q[i])

  S = 103
  for i in range(len(p)):
    if abs(X - p[i]) < S :
      ans = p[i]
      S = X - ans
    elif abs(X - p[i]) == S :
      if p[i] < ans :
        ans = p[i]
  print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int,input().split())
if N == 0:
  print(X)
else:
  q = list(map(int,input().split()))
  q = list(set(q))
  p = [i for i in range(-1 , 102)]
  for i in range(len(q)):
    p.remove(q[i])

  S = 100
  for i in range(len(p)):
    if abs(X - p[i]) < S :
      ans = p[i]
      S = X - ans
    elif abs(X - p[i]) == S :
      if p[i] < ans :
        ans = p[i]
  print(ans)
Problem p02995 (python)

Fixed submission:
A,B,C,D = map(int, input().split())

k = B - A + 1

if A%C == 0:
    sc = B//C -A//C +1
else:
    sc = B//C -A//C

if A%D == 0:
    sd = B//D -A//D +1
else:
    sd = B//D -A//D    
    

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

cd = C*D//gcd(C,D)

if A%cd == 0:
    scd = B//cd -A//cd +1
else:
    scd = B//cd -A//cd    

print(int(k + scd -sc -sd))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int, input().split())

k = B - A + 1

if A%C == 0:
    sc = B//C -A//C +1
else:
    sc = B//C -A//C

if A%D == 0:
    sd = B//D -A//D +1
else:
    sd = B//D -A//D    
    

cd = C*D/math.gcd(C,D)

if A%D == 0:
    scd = B//cd -A//cd +1
else:
    scd = B//cd -A//cd    

print(int(k + scd -sc -sd))
Problem p02996 (python)

Fixed submission:
import numpy as np
N =int(input())

A = np.zeros((N,2))


for i in range(N):
    A[i,0],A[i,1] = map(int,input().split())
    



B = A[A[:,1].argsort(),:]    


sa = B[0,0]
i = 0
while i < N-1 and sa <= B[i,1]:
    i +=1
    sa += B[i,0]


    
if i == N -1 and sa <=B[i,1]:
  
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np
N =int(input())

A = np.zeros((N,2))


for i in range(N):
    A[i,0],A[i,1] = map(int,input().split())
    



B = A[A[:,1].argsort(),:]    


sa = B[0,0]
i = 0
while i < N and sa <= B[i,1]:
    sa += B[i,0]

    i += 1
    
if i == N:
    print('Yes')
else:
    print('No')
Problem p02574 (python)

Fixed submission:
from math import gcd
N = int(input())
A = list(map(int,input().split()))

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

sa = set()
for a in A:
    if a==1: continue
    if a in sa:
        print('setwise coprime')
        exit()
    sa.add(a)

MAXN = 10**6+10
sieve = [0,0] + [1]*MAXN
p = 2
small_primes = []
while p*p <= MAXN:
    if sieve[p]:
        small_primes.append(p)
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1

st = set()
for a in A:
    for p in small_primes:
        found = False
        while a%p==0:
            a //= p
            found = True
        if found:
            if p in st:
                print('setwise coprime')
                exit()
            st.add(p)
        if a==1: break
    else:
        if a in st:
            print('setwise coprime')
            exit()
        st.add(a)

print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

MAXN = 100#10**6+10
sieve = [i for i in range(MAXN+1)]
p = 2
while p*p <= MAXN:
    if sieve[p] == p:
        for q in range(2*p,MAXN+1,p):
            if sieve[q] == q:
                sieve[q] = p
    p += 1

st = set()
for a in A:
    tmp = set()
    while a > 1:
        tmp.add(sieve[a])
        a //= sieve[a]
    for p in tmp:
        if p in st:
            print('setwise coprime')
            exit()
        st.add(p)
print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

sa = set(A)
if len(sa) < N:
    print('setwise coprime')
    exit()

MAXN = 10**6+10
sieve = [0,0] + [1]*MAXN
p = 2
small_primes = []
while p*p <= MAXN:
    if sieve[p]:
        small_primes.append(p)
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1

st = set()
for a in A:
    for p in small_primes:
       found = False
        while a%p==0:
            a //= p
            found = True
        if found:
            if p in st:
                print('setwise coprime')
                exit()
            st.add(p)
        if a==1: break
    else:
        if a in st:
            print('setwise coprime')
            exit()
        st.add(a)

print('pairwise coprime')
Problem p02647 (python)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(K):
    imos = [0] * (N+1)
    for i,a in enumerate(A):
        l = max(0, i-a)
        r = min(N, i+1+a)
        imos[l] += 1
        imos[r] -= 1
    imos[0] = min(N, imos[0])
    for i in range(N):
        imos[i+1] = min(N, imos[i] + imos[i+1])
    A = imos[:-1]
    if all(a==N for a in A):
        break
print(*A)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
def solve():
    for k in range(K):
        imos = [0] * (N+1)
        for i,a in enumerate(A):
            l = max(0, i-a)
            r = min(N, i+1+a)
            imos[l] += 1
            imos[r] -= 1
        imos[0] = min(N, imos[0])
        for i in range(N):
            imos[i+1] = min(N, imos[i] + imos[i+1])
        A = imos[:-1]
        if A[0] == A[-1] == N:
            break
    print(*A)
solve()

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(K):
    imos = [0] * (N+1)
    for i,a in enumerate(A):
        l = max(0, i-a)
        r = min(N, i+1+a)
        imos[l] += 1
        imos[r] -= 1
    imos[0] = min(N, imos[0])
    for i in range(N):
        imos[i+1] = min(N, imos[i] + imos[i+1])
    A = imos[:-1]
    if A[0] == A[-1] == N
        break
print(*A)
Problem p02651 (python)

Fixed submission:
def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return bs

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    bs = []
    for a,s in zip(A[::-1],S[::-1]):
        x = a
        for b in bs:
            x = min(x, x^b)
        if x:
            if s=='0':
                bs.append(x)
                bs = gauss_jordan(bs)
            else:
                return 1
    return 0

T = int(input())
for _ in range(T):
    print(solve())

Buggy submission (verdict: Runtime Error):
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000
Problem p02664 (python)

Fixed submission:
T = input()
ans = ''
for i in range(len(T)):
    if T[i] != '?':
        ans += T[i]
        continue
    ans += 'D'
print(ans)

Buggy submission (verdict: Runtime Error):
T = input()
ans = ''
for i in range(len(T)):
    if T[i] != '?':
        ans += T[i]
        continue
    if ans += 'D'
print(ans)