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

Fixed submission:
A = list(map(int, input().split()))
S = A[1]
S += (A[0] // 2) * 2 + (A[3] // 2) * 2 + (A[4] // 2) * 2
if A[3] % 2 == 1 and A[4] % 2 == 1 and A[0] % 2 == 1:
  S += 3
elif A[3] % 2 == 1 and A[4] % 2 == 1 and A[0] % 2 == 0 and A[0] != 0:
  S += 1
elif A[3] % 2 == 0 and A[4] % 2 == 1 and A[0] % 2 == 1 and A[3] != 0:
  S += 1
elif A[3] % 2 == 1 and A[4] % 2 == 0 and A[0] % 2 == 1 and A[4] != 0:
  S += 1
print(S)

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))
S = A[1]
S += (A[0] // 2) * 2
T = S
  if A[4] > 0 and A[5] > 0 and A[0] % 2 == 1:
    S += (A[4] // 2) * 2 + (A[5] // 2) * 2
    A[4] -= 1
    A[5] -= 1
    T += 3
  T += (A[4] // 2) * 2 + (A[5] // 2) * 2
print(max(S, T))
Problem p03909 (python)

Fixed submission:
H, W = map(int, input().split())
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
S = [list(map(str, input().split())) for _ in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == "snuke":
      print("{}{}".format(alpha[j], i+1))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
S = [list(map(int, input().split())) for _ in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == "snuke":
      print("{}{}".format(alpha[j], i+1))
Problem p03937 (python)

Fixed submission:
H, W = map(int, input().split())
pos = [0, 0]
S = [input() for i in range(H)]
p = 1
def whiteout(Map, h, w):
  y = 0
  for i in range(h):
    for j in range(w):
      if Map[i][j] == '#':
        y += 1
  return y == 0

while pos != [H-1, W-1]:
  cnt = 0
  x, y = pos[0], pos[1]
  S[x] = S[x][:y] + '.' + S[x][y+1:]
  if x < H-1:
    if S[x+1][y] == '#':
      cnt += 1
      pos = [x+1, y]
  if y < W-1:
    if S[x][y+1] == '#':
      cnt += 1
      pos = [x, y+1]
  if cnt != 1:
    p = 0
    break
S[H-1] = S[H-1][:W-1] + '.'
if p == 1 and whiteout(S, H, W):
  print("Possible")
else:
  print("Impossible")

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
pos = [[0, 0]]
S = [input() for i in range(H)]
p = 1
def whiteout(Map, h, w):
  y = 0
  for i in range(h):
    for j in range(w):
      if Map[i][j] == '#':
        y += 1
  return y == 0

while pos != [H-1, W-1]:
  cnt = 0
  x, y = pos[0], pos[1]
  S[x] = S[x][:y] + '.' + S[x][y+1:]
  if x < H-1:
    if S[x+1][y] == '#':
      cnt += 1
      pos = [x+1, y]
  if y < W-1:
    if S[x][y+1] == '#':
      cnt += 1
      pos = [x, y+1]
  if cnt != 1:
    p = 0
    break
S[H-1] = S[H-1][:W-1] + '.'
if p == 1 and whiteout(S, H, W):
  print("Possible")
else:
  print("Impossible")
Problem p04045 (python)

Fixed submission:
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  S = str(ND[0])
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  j = 10 - K
  cnt = 0
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    if l == j:
      l, s = 0, 0
      j *= 10 - K
      cnt += 1
    for x in range(cnt+1):
      F += ND[s%(10 - K)] * ju
      ju *= 10
      s //= 10 - K
  print(F)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    while s != 0:
      F += ND[s%(10-K)] * ju
      s //= 10 - K
      ju *= 10
    print(F, end = ' ')
  print(F)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    while s != 0:
      F += ND[s%(10-K)] * ju
      s //= 10 - K
      ju *= 10
  print(F)
Problem p02664 (python)

Fixed submission:
T=input()
ans=""
if T=="?":
    print("D")
    exit()

for i in range(len(T)):
    if T[i]=="P" or T[i]=="D":
        ans+=T[i]
    else:
        if i==0:
            if T[i+1]=="P":
                ans+="D"
            elif T[i+1]=="D":
                ans+="P"
            elif T[i+1]=="?":
                ans+="P"
        elif i!=len(T)-1:
            if ans[-1]=="P" and T[i+1]=="P":
                ans+="D"
            elif ans[-1]=="P" and T[i+1]=="D":
                ans+="D"
            elif ans[-1]=="P" and T[i+1]=="?":
                ans+="D"
            elif ans[-1]=="D" and T[i+1]=="P":
                ans+="D"
            elif ans[-1]=="D" and T[i+1]=="D":
                ans+="P"
            elif ans[-1]=="D" and T[i+1]=="?":
                ans+="P"
        else:
            if ans[-1]=="P":
                ans+="D"
            else:
                ans+="D"
print(ans)

Buggy submission (verdict: Runtime Error):
T=input()
ans=""
for i in range(len(T)):
    if T[i]=="P" or T[i]=="D":
        ans+=T[i]
    else:
        if i==0:
            if T[i+1]=="P":
                ans+="D"
            elif T[i+1]=="D":
                ans+="P"
            elif T[i+1]=="?":
                ans+="P"
        elif i!=len(T)-1:
            if ans[-1]=="P" and T[i+1]=="P":
                ans+="D"
            elif ans[-1]=="P" and T[i+1]=="D":
                ans+="D"
            elif ans[-1]=="P" and T[i+1]=="?":
                ans+="D"
            elif ans[-1]=="D" and T[i+1]=="P":
                ans+="D"
            elif ans[-1]=="D" and T[i+1]=="D":
                ans+="P"
            elif ans[-1]=="D" and T[i+1]=="?":
                ans+="P"
        else:
            if ans[-1]=="P":
                ans+="D"
            else:
                ans+="D"
print(ans)

Buggy submission (verdict: Runtime Error):
T=input()
ans=""
for i in range(len(T)):
    if T[i]=="P" or T[i]=="D":
        ans+=T[i]
    else:
        if i==0:
            if l[i+1]=="P":
                ans+="D"
            elif l[i+1]=="D":
                ans+="P"
            elif l[i+1]=="?":
                ans+="P"
        elif i!=len(T)-1:
            if ans[-1]=="P" and T[i+1]=="P":
                ans+="D"
            elif ans[-1]=="P" and T[i+1]=="D":
                ans+="D"
            elif ans[-1]=="P" and T[i+1]=="?":
                ans+="D"
            elif ans[-1]=="D" and T[i+1]=="P":
                ans+="D"
            elif ans[-1]=="D" and T[i+1]=="D":
                ans+="P"
            elif ans[-1]=="D" and T[i+1]=="?":
                ans+="P"
        else:
            if ans[-1]=="P":
                ans+="D"
            else:
                ans+="D"
print(ans)
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
p=1
l=[0]*n
#l[0]+=1
if k<=200000:
    for i in range(k):
        p=A[p-1]
        l[p-1]+=1
    print(p)
    exit()
else:
    for i in range(200001):
        p=A[p-1]#A[0]の番号の町に飛ぶ
        l[p-1]+=1
        #print(p)
        if l[p-1]==2:
            x=i
            break
    #print("p=",str(p))
    #print(l,x)

    d=1
    for j in range(200001):
        d=A[d-1]#A[0]の番号の町に飛ぶ
        if d==p:
            y=j
            break
    #print("y=",str(y))
    z=(k-x-1)%(x-y)#yから数えて残り回す回数
    #print(z)
    for i in range(z):
        p=A[p-1]
        #print(p)
    print(p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
p=1
l=[0]*n
#l[0]+=1
if k<=100000:
    for i in range(k):
        p=A[p-1]
        l[p-1]+=1
    print(p)
    exit()
else:
    for i in range(100001):
        p=A[p-1]#A[0]の番号の町に飛ぶ
        l[p-1]+=1
        #print(p)
        if l[p-1]==2:
            x=i
            break
    #print("p=",str(p))
    #print(l,x)

    d=1
    for j in range(100001):
        d=A[d-1]#A[0]の番号の町に飛ぶ
        if d==p:
            y=j
            break
    #print("y=",str(y))
    z=(k-x-1)%(x-y)#yから数えて残り回す回数
    #print(z)
    for i in range(z):
        p=A[p-1]
        print(p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
p=1
l=[0]*n
#l[0]+=1
if k<=100000:
    for i in range(k):
        p=A[p-1]
        l[p-1]+=1
    print(p)
    exit()
else:
    for i in range(100001):
        p=A[p-1]#A[0]の番号の町に飛ぶ
        l[p-1]+=1
        #print(p)
        if l[p-1]==2:
            x=i
            break
    #print("p=",str(p))
    #print(l,x)

    d=1
    for j in range(100001):
        d=A[d-1]#A[0]の番号の町に飛ぶ
        if d==p:
            y=j
            break
    #print("y=",str(y))
    z=(k-x-1)%(x-y)#yから数えて残り回す回数
    for i in range(z):

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
p=1
l=[0]*n
#l[0]+=1
if k<=100000:
    for i in range(k):
        p=A[p-1]
        l[p-1]+=1
    print(p)
    exit()
else:
    for i in range(100001):
        p=A[p-1]#A[0]の番号の町に飛ぶ
        l[p-1]+=1
        #print(p)
        if l[p-1]==2:
            x=i
            break
    #print("p=",str(p))
    #print(l,x)

    d=1
    for j in range(100001):
        d=A[d-1]#A[0]の番号の町に飛ぶ
        if d==p:
            y=j
            break
    #print("y=",str(y))
    z=(k-y-1)%(x-y)#yから数えて残り回す回数
    for i in range(z):
        p=A[p-1]
    print(p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
p=1
l=[0]*n
if k<=100000:
    for i in range(k):
        p=A[p-1]
        l[p-1]+=1
    print(p)
    exit()
else:
    for i in range(100001):
        p=A[p-1]
        l[p-1]+=1
        if l[p-1]==2:
            x=i
            break
    d=1
    for j in range(100001):
        d=A[d-1]
        if d==p:
            y=j
            break
    z=(k-y-1)%(y-x)
    for i in range(z):
        p=A[p-1]
    print(p)
Problem p02690 (python)

Fixed submission:
X=int(input())
a=1
while a<1001:
    for i in range(-1000,1001):
        if a**5-i**5==X:
            b=i
            print(a,b)
            exit()
    a+=1

Buggy submission (verdict: Runtime Error):
X=int(input())
if (X**0.2)%1==0:
    a=int(X**0.2)
    b=0
    print(a,b)
else:
    b=1
    while b<1002:
        if ((X+b**5)**0.2)%1==0:
            a=int((X+b**5)**0.2)
            print(a,b)
            exit()
        else:
            b+=1
    c=-1
    while c>-1002:
        if ((X+c**5)**0.2)%1==0:
            a=int((X+c**5)**0.2)
            print(a,c)
            exit()
        else:
            c-=1

Buggy submission (verdict: Runtime Error):
X=int(input())
if (X**0.2)%1==0:
    a=int(X**0.2)
    b=0
    print(a,b)
else:
    b=1
    while b<10000:
        if ((X+b**5)**0.2)%1==0:
            a=int((X+b**5)**0.2)
            print(a,b)
            exit()
        elif ((X+(-1*b)**5)**0.2)%1==0:
            a=int((X+b**5)**0.2)
            print(a,-b)
            exit()
        else:
            b+=1
Problem p02696 (python)

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

if b<=n:
    if a%b!=0:
        print(a-a//b -1)
    else:
        print(a-a//b)
else:
    print(int(n*a/b))

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

if b<=n:
    if a%b!=0
        print(a-a//b -1)
    else:
        print(a-a//b)
else:
    print(int(n*a/b))
Problem p02755 (python)

Fixed submission:
A,B=map(int,input().split())
if (A/0.08)%1==0.0:
    a1=int(A/0.08)
else:
    a1=int(A/0.08)+1
if ((A+1)/0.08)%1!=0.0:
    a2=int((A+1)/0.08)
else:
    a2=int((A+1)/0.08)-1

if (B/0.1)%1==0.0:
    b1=int(B/0.1)
else:
    b1=int(B/0.08)+1
if ((B+1)/0.1)%1!=0.0:
    b2=int((B+1)/0.1)
else:
    b2=int((B+1)/0.1)-1

a=[]
b=[]
for i in range(a1,a2+1):
    s=i
    a.append(s)
for i in range(b1,b2+1):
    t=i
    b.append(t)
#print(a)
#print(b)
if max(a)<min(b):
    print(-1)
elif max(b)<min(a):
    print(-1)
elif min(a)>=min(b):
    print(min(a))
else:
    print(min(b))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
if (A/0.08)%1==0.0:
    a1=int(A/0.08)
else:
    a1=int(A/0.08)+1
if (A/0.08)%1!=0.0:
    a2=int((A+1)/0.08)
else:
    a2=int((A+1)/0.08)-1

if (B/0.1)%1==0.0:
    b1=int(B/0.1)
else:
    b1=int(B/0.08)+1
if (B/0.1)%1!=0.0:
    b2=int((B+1)/0.1)
else:
    b2=int((B+1)/0.1)-1

#a=[]
#b=[]
for i in range(a1,a2+1):
    s=i
    a.append(s)
for i in range(b1,b2+1):
    t=i
    b.append(t)
print(a)
print(b)
if max(a)<min(b):
    print(-1)
elif max(b)<min(a):
    print(-1)
elif min(a)>=min(b):
    print(min(a))
else:
    print(min(b))
Problem p02756 (python)

Fixed submission:
from collections import deque
S=input()
s=deque(S)
Q=int(input())
Que=[list(map(str, input().split())) for _ in range(Q)]
#print(Que)
a=0
for i in range(Q):
    if Que[i][0]=="1":
        a+=1
    elif Que[i][0]=="2":
        if a%2==0:
            if Que[i][1]=="2":
                s.append(Que[i][2])
            elif Que[i][1]=="1":
                s.appendleft(Que[i][2])
        else:
            if Que[i][1]=="1":
                s.append(Que[i][2])
            elif Que[i][1]=="2":
                s.appendleft(Que[i][2])
s=list(s)
if a%2==1:
    s=s[::-1]
ans="".join(s)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
S=input()
s=deque(S)
Q=int(input())
Que=[list(map(str, input().split())) for _ in range(Q)]
#print(Que)
a=0
for i in range(Q):
    if Que[i][0]=="1":
        a+=1
    elif Que[i][0]=="2":
        if a%2==0:
            if Que[i][1]=="2":
                s.append(Que[i][2])
            elif Que[i][1]=="1":
                s.appendleft(Que[i][2])
        else:
            if Que[i][1]=="1":
                s.append(Que[i][2])
            elif Que[i][1]=="2":
                s.appendleft(Que[i][2])
s=list(s)
if a%2==1:
    a=a[::-1]
ans="".join(s)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
S=input()
s=deque(S)
Q=int(input())
Que=[list(map(str, input().split())) for _ in range(Q)]
#print(Que)
for i in range(Q):
    if Que[i][0]=="1":
        s=s[::-1]
    elif Que[i][0]=="2":
        if Que[i][1]=="2":
            s.append(Que[i][2])
        elif Que[i][1]=="1":
            s.appendleft(Que[i][2])
ans="".join(s)
print(ans)
Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
a=str(0)*N
A=[a[i] for i in range(len(a))]
x=0
#print(sc)
b=[]
c=[]
for i in range(M):
    if (sc[i][0] == 1) and (sc[i][1]==0) and (N!=1):
        x=-1
        break
    else:
        if (sc[i][0]) in b:#左から何桁目の情報が既にある場合、既に登録されているその桁の値と新たに登録しようとしてるその桁の値が異なるとき弾く
            if sc[i][1]!=int(c[b.index(sc[i][0])]):
                #print(c[b.index(sc[i][0])])
                x=-1
                break
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
            c.append(sc[i][1])
if x==-1:
    print(-1)      
elif b==[] and (N!=1):
    if N==2:
        print(10)
    elif N==3:
        print(100)
elif (1 not in b) and(N!=1):
    A[0]=str(1)
    a="".join(A)
    print(a)
elif  (1 not in b) and (2 not in b) and (N==3):
    A[0]=str(1)
    A[1]=str(0)
    a="".join(A)
    print(a)

else:
    a="".join(A)
    print(a)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
a=str(0)*N
A=[a[i] for i in range(len(a))]
x=0
#print(sc)
b=[]
c=[]
for i in range(M):
    if (sc[i][0] == 1) and (sc[i][1]==0) and (N!=1):
        a=-1
        break
    else:
        if (sc[i][0]) in b:#左から何桁目の情報が既にある場合、既に登録されているその桁の値と新たに登録しようとしてるその桁の値が異なるとき弾く
            if sc[i][1]!=int(c[b.index(sc[i][0])]):
                print(c[b.index(sc[i][0])])
                x=-1
                break
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
            c.append(sc[i][1])
        
if b==[] and (N!=1):
    a=-1
    print(a)
elif (1 not in b) and(N!=1):
    A[0]=str(1)
    a="".join(A)
    print(a)
elif  (1 not in b) and (2 not in b):
    A[0]=str(1)
    A[1]=str(0)
    a="".join(A)
    print(a)
elif x==-1:
    print(-1)
else:
    a="".join(A)
    print(a)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
a=str(0)*N
A=[a[i] for i in range(len(a))]

#print(sc)
b=[]
c=[]
for i in range(M):
    if N==1:
        if (sc[i][0] == 1) and (sc[i][1]==0):
            a=-1
            break
        elif (sc[i][0]) in b:
            if sc[i][1]<int(A):
                A=str(sc[i][1])
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
        c.append(sc[i][1])
    elif (sc[i][0] == 1) and (sc[i][1]==0):
        a=-1
        break
    else:
        if (sc[i][0]) in b:
            if sc[i][1]<int(A[sc[i][0]-1]):
                A[sc[i][0]-1]=str(sc[i][1])
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
        c.append(sc[i][1])
        
if b==[]:
    a=-1
    print(a)
elif (1 not in b):
    a=-1
    print(a)
else:
    a="".join(A)
    print(a)
Problem p02783 (python)

Fixed submission:
H,A=map(int,input().split())
 
n=(H//A)+1
 
if H%A==0:
  n=H//A
else:
  n=(H//A)+1
print(n)

Buggy submission (verdict: Runtime Error):
H,A=,map(int,input().split())
 
n=(H//A)+1

if H%A==0:
  n=H//A
else:
  n=(H//A)+1
print(n)

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

n=(H//A)+1
print(n)
Problem p02784 (python)

Fixed submission:
H,N=map(int,input().split())
A=input().split()
B=[]
for i in range(N):
  a=int(A[i])
  B.append(a)
if sum(B)>=H:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
H,N=map(int,input().split())
A=[input() for i in range(N)]
B=[]
for i in range(N):
  a=int(A[i])
  B.append(a)
if sum(B)>=H:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
H,N=map(int,input().split())
A=[int(input()) for i in range(N)]

if sum(A)>=H:
  print("Yes")
else:
  print("No")
Problem p02789 (python)

Fixed submission:
N,M=(int(x) for x in input().split())

if N==M:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N,M=(int(X) for x in 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 p02811 (python)

Fixed submission:
K,X=map(int,input().split())
 
if 500*K>=X:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
K,X=map(int,input())

if 500*K>=X:
  print("Yes")
else:
  print("No")
Problem p03129 (python)

Fixed submission:
N,K=map(int,input().split())
if N>=K*2-1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N,K=int(input().split())
if K>=K*2-1:
    print("YES")
else:
    print("NO")
Problem p03633 (python)

Fixed submission:
import math
n=int(input())
t=[int(input()) for _ in range(n)]
#print(t)
if n==1:
    print(t[0])
    exit()

for i in range(n-1):
    if i==0:
        lcm=(t[i]*t[i+1])//math.gcd(t[i],t[i+1])
    else:
        lcm=(lcm*t[i+1])//math.gcd(lcm,t[i+1])
print(lcm)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
t=[int(input()) for _ in range(n)]
#print(t)
for i in range(n-1):
    if i==0:
        lcm=(t[i]*t[i+1])//math.gcd(t[i],t[i+1])
    else:
        lcm=(lcm*t[i+1])//math.gcd(lcm,t[i+1])
print(lcm)
Problem p04044 (python)

Fixed submission:
N,L=map(int,input().split())
l=[]
for i in range(N):
    S=input()
    l.append(S)
#print(l)
l2=sorted(l)
#print(l2)
ans="".join(l2)
print(ans)

Buggy submission (verdict: Runtime Error):
L,N=map(int,input().split())
l=[]
for i in range(N):
    S=input()
    l.append(S)
#print(l)
l2=sorted(l)
#print(l2)
ans="".join(l2)
print(ans)
Problem p02574 (python)

Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  A=LI()

  g=0
  for x in A:
    g=math.gcd(g,x)
  if g>1:
    return 'not coprime'

  sosu=[0]*1000100
  for x in A:
    if x==1:
      continue
    sosu[x]+=1
    if sosu[x]>1:
      return 'setwise coprime'
    for y in range(2,int(math.sqrt(x))+1):
      if x%y!=0:
        continue
      z=x//y
      if y==z:
        sosu[y]+=1
        if sosu[y]>1:
          return 'setwise coprime'
      else:
        sosu[y]+=1
        if sosu[y]>1:
          return 'setwise coprime'
        sosu[z]+=1
        if sosu[z]>1:
          return 'setwise coprime'

  return 'pairwise coprime'

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  A=LI()
  
  l=[0]*1000100
  pairwise=True
  for i in range(2,1000100):
    cnt=0
    for j in range(i+1,1000100):
      cnt+=A[j]
    if cnt>1:
      pairwise=False

  if pairwise:
    return 'pairwise coprime'

  f1=True
  f2=False
  for x in l:
    if x>1:
      f1=False

  if f1:
    return 'pairwise coprime'

  g=0
  for x in A:
    g=math.gcd(g,x)

  if g==1:
    return 'setwise coprime'

  return 'not coprime'

# main()
print(main())