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

Fixed submission:
C = []
for i in range(2):
  C.append(list(input()))
 
if C[0][0] == C[1][2] and C[0][1] == C[1][1] and C[0][2] == C[1][0]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
C = []
for i in range(2):
  C.append(list(int, input().split()))

if C[0][0] == C[1][2] and C[0][1] == C[1][1] and C[0][2] == C[1][0]:
  print('YES')
else:
  print('NO')
Problem p03729 (python)

Fixed submission:
A, B, C = map(str, input().split())
a = list(A)
b = list(B)
c = list(C)
 
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
A, B, C = map(str, input().split())
a = list(A)
b = list(B)
c = list(C)

if a[-1] == b[0] and b[-1] == c[1]:
  print('YES')
else:
  print('NO')
Problem p03826 (python)

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

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input.split())
print(max(A*B, C*D))
Problem p03827 (python)

Fixed submission:
N = int(input())
S = list(str(input()))
x = 0
ans = 0

for i in range(N):
  if S[i] == 'I':
    x += 1
  else:
    x -= 1
  if ans < x:
    ans = x
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(str(input()))
x = 0
ans = 0

for i in range(len(N)):
  if S[i] == 'I':
    x += 1
  else:
    x -= 1
  if ans < x:
    ans = x
    
print(ans)
Problem p03844 (python)

Fixed submission:
A, op, B = map(str, input().split())
A = int(A)
B = int(B)
 
if op == '+':
  print(A+B)
else:
  print(A-B)

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

if op == '+':
  print(A+B)
else:
  pirnt(A-B)
Problem p02807 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]

def pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

def fact(m):
  return m * fact(m-1) % 1000000007 if m != 1 else 1
 
fact_n_1 = fact(n-1)

e = [None] * (n-1)
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = (e[i - 1] + fact_n_1 * pow(i + 1, 1000000005)) % 1000000007

print(sum(e_i * d_i % 1000000007
          for i, (d_i, e_i) 
          in enumerate(zip(d, e))) % 1000000007 )

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]

def fact(m):
  return m * fact(m-1) % 1000000007 if m != 1 else 1
 
fact_n_1 = fact(n-1)

e = [None] * (n-1)
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = (e[i - 1] + fact_n_1 // (i + 1)) % 1000000007

print(sum(e_i * d_i % 1000000007
          for i, (d_i, e_i) 
          in enumerate(zip(d, e))) % 1000000007 )

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]
 
def fact(m):
  return m * fact(m-1) if m != 1 else 1 

fact_n_1 = fact(n-1)

e = {}
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = e[i - 1] + fact_n_1 // (i + 1)

print(sum(e[i] * d_i % 1000000007
          for i, d_i 
          in enumerate(d)) % 1000000007 )

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

def fact(m):
  return m * fact(m-1) if m != 1 else 1

d = [x[i+1] - x[i] for i in range(n - 1)]
fact_n_1 = fact(n-1)
print(sum(sum(fact_n_1 // (j + 1) 
              for j 
              in range(i + 1)) * d_i % 1000000007
          for i, d_i 
          in enumerate(d)) % 1000000007 )
Problem p02842 (python)

Fixed submission:
import math
 
n = int(input())
 
x = math.ceil(n / 1.08)
 
if n == math.floor(x * 1.08):
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
import math

n = int(input())

x = math.ceil(n / 1.08)

if n == math.floor(x * 1.08):
  print(x)
else:
  prtnt(":(")
Problem p02973 (python)

Fixed submission:

import bisect


def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]

  tail = []
  len_tail = 0
  for ai in a:
    idx = bisect.bisect_right(tail, -ai, lo=0, hi=len_tail) 
    if idx == len_tail:
      tail.append(-ai)
      len_tail += 1
    else:
      tail[idx] = - ai

  print(len_tail )


if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import bisect


def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]

  tail = []
  len_tail = 0
  for ai in a:
    print(tail, ai)
    idx = bisect.bisect_left(tail, -ai, lo=0, hi=len_tail) 
    if idx == len_tail:
      tail.append(-ai)
      len_tail += 1
    else:
      tail[idx] = - ai

  print(len_tail )


if __name__ == "__main__":
  main()
Problem p02585 (python)

Fixed submission:
N, K = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))
ans = -float('inf')
for i in range(1, N+1):
    v = i
    score = 0
    size = 0
    while True:
        size += 1
        score += C[v]
        if i == P[v]:
            break
        v = P[v]

    if score > 0:
        tmp = score*(K//size-1)
        num = K%size+size
    else:
        tmp = 0
        num = min(K, size)
    
    v = i
    for _ in range(num):
        tmp += C[v]
        v = P[v]
        ans = max(tmp, ans)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
C = [0] + list(map(int, input().split()))
P = [0] + list(map(int, input().split()))

max_ans = -10**9
for i in range(1, N+1):
    v = i
    s = 0
    loop = []
    while True:
        loop.append(v)
        s += P[v]
        v = C[v]
        if v == i:
            break

    L = len(loop)
    a = K // L
    r = K % L
    ans = a * max(0, sums[i])

    tmp = P[loop[0]]
    if r > 0:
        for j in range(1, r):
            if P[loop[j]] >= 0:
                tmp += P[loop[j]]
            else:
                break

    ans += tmp
    if ans > max_ans:
        max_ans = ans

print(max_ans)
Problem p02615 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
ans = 0
for i in range(1, N):
    ans += A[i//2]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
ans = 2*sum(A[:N//2])-A[0]+(N%2==1)*A[N//2+1]
print(ans)
Problem p02702 (python)

Fixed submission:
from collections import Counter
S = input()
P = [0] * (len(S)+1)
mod = 2019
d = 1
for i in range(len(S), 0, -1):
    P[i-1] = int(S[i-1])*d + P[i]
    P[i-1] = P[i-1] % mod
    d *= 10
    d = d % mod

P = Counter(P)
ans = 0
for p in P.values():
    ans += p*(p-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
P = [0 for _ in range(len(S)+1)]
mod = 2019
d = 1
for i in range(len(S), 0, -1):
    P[i-1] = int(S[i-1])*d + P[i]
    P[i-1] = P[i-1] % mod
    d *= 10

for p in P:
    A[p] += 1

ans = 0
for a in A:
    ans += a*(a-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
P = [0 for _ in range(len(S)+1)]
mod = 2019
d = 1
for i in range(len(S), 0, -1):
    P[i-1] = int(S[i-1])*d + P[i]
    P[i-1] = P[i-1] % mod
    d *= 10

for p in P:
    A[p] += 1

ans = sum(list(map(lambda n: n*(n-1)//2, A)))
print(ans)
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
for n in range(10**N):
    n = str(n)
    if len(n) != N:
        continue
    if all([n[SC[i][0]-1] == str(SC[i][1]) for i in range(M)]):
        print(n)
        exit()

print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
D = {}
ans = ['0'] * N
ans[0] = '1'
for i in range(M):
    if SC[i][0] not in D:
        D[SC[i][0]] = SC[i][1]
    else:
        if D[SC[i][0]] != SC[i][1]:
            print(-1)
            exit()

for k, v in D.items():
    ans[k-1] = str(v)

ans = -1 if ans[0] == '0' else int(''.join(ans))
print(as)
Problem p03999 (python)

Fixed submission:
N = str(int(input()))
total = 0
l = len(N)-1
if l == 0:
    print(N)
else:
    for i in range(2**l):
        b = format(i, '0'+str(l)+'b')
        subtotal = 0
        s = N[0]
        for j in range(len(b)):
            if int(b[j]):
                subtotal += int(s)
                s = N[j+1]
            else:
                s += N[j+1]

        subtotal += int(s)
        total += subtotal

    print(total)

Buggy submission (verdict: Runtime Error):
N = str(int(input()))
total = 0
l = len(N)-1

for i in range(2**l):
    b = format(i, '0'+str(l)+'b')
    subtotal = 0
    s = N[0]

    for j in range(len(b)):
        if int(b[j]):
            subtotal += int(s)
            s = N[j+1]
        else:
            s += N[j+1]

    subtotal += int(s)
    total += subtotal

print(total)
Problem p02555 (python)

Fixed submission:
s = int(input())
import sys
p = 10**9+7
dp = [0]*2003
dp[2]=1
if s<=3:
    print(dp[s-1])
    sys.exit()
for i in range(3,s):
    dp[i] = (dp[i-1]%p+dp[i-3]%p)%p


print(dp[s-1])

Buggy submission (verdict: Runtime Error):
s = int(input())
import sys
p = 10**9+7
dp = [0]*100#2003
dp[2]=1
if s<=3:
    print(dp[s-1])
    sys.exit()
for i in range(3,s):
    dp[i] = (dp[i-1]%p+dp[i-3]%p)%p


print(dp[s-1])
Problem p02574 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
import sys

num = 10**6
li = [0]*num
for k in a:
    li[k-1] += 1

i=2
while i<=num:
    if sum([li[k*i-1] for k in range(1,num//i+1)])>1:
        break
    i+=1
else:
    print("pairwise coprime")
    sys.exit()

import math
import functools
g = functools.reduce(math.gcd,a)
if g==1:
    print("setwise coprime")
    sys.exit()

print("not coprime")

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

num = 10**2 
li = [0]*num
for k in a:
    if li[k-1]==0:
        li[k-1] += 1
    else:
        if k-1!=0:
            print("not coprime")
            sys.exit()

i=2
while i<=num:
    if sum([li[k*i-1] for k in range(1,num//i+1)])>1:
        break
    i+=1
else:
    print("pairwise coprime")
    sys.exit()

import math
import functools
g = functools.reduce(math.gcd,a)
if g==1:
    print("setwise coprime")
    sys.exit()

print("not coprime")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
import sys
import math
import functools
g = functools.reduce(math.gcd,a)

num = 10**2   
li = [0]*num
for k in a:
    if li[k-1]==0:
        li[k-1] += 1
    else:
        if k-1!=0:
            print("not coprime")
            sys.exit()

i=2
while i<=num:
    #print([li[k*i-1] for k in range(1,num//i+1)])
    if sum([li[k*i-1] for k in range(1,num//i+1)])>1:
        break
    i+=1
else:
    print("pairwise coprime")
    sys,exit()


if g==1:
    print("setwise coprime")
    sys.exit()

print("not coprime")
sys.exit()
Problem p02640 (python)

Fixed submission:
import sys
x,y = map(int,input().split())

#2a+4b =y
#a+b =x
#b=x-a
#y =2a+4(x-a)=4x-2a

for i in range(x+1):
    if y == 4*x-2*i:
        print("Yes")
        sys.exit()
else:
    print("No")

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


if i in range(x):
    if y == 4x-2a:
        print("Yes")
else:
    print("No")
Problem p02713 (python)

Fixed submission:
import math
from functools import reduce
import sys
sys.setrecursionlimit(2000000)

k = int(input())

wa = 0

for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            li = [a,b,c]
            wa += reduce(math.gcd,li)*6

for a in range(1,k+1):
    for b in range(a+1,k+1):
        wa += math.gcd(a,b)*6

for a in range(1,k+1):
    wa += a
    

print(wa)

Buggy submission (verdict: Runtime Error):
from functools import reduce

k = int(input())

wa = 0

for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            li = [a,b,c]
            wa += reduce(math.gcd,li)*6

for a in range(1,k+1):
    for b in range(a+1,k+1):
        wa += math.gcd(a,b)*6

for a in range(1,k+1):
    wa += a
    
print(wa)
Problem p03103 (python)

Fixed submission:
n,m = map(int,input().split())
c = [list(map(int,input().split())) for i in range(n)]
ca = sorted(c,key=lambda x:x[0])

import sys
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    #print(str(i)+"だよ")
    if num + ca[i][1] < m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        #print(num,money)
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
c = [list(map(int,input().split())) for i in range(n)]
ca = sorted(c,key=lambda x:x[0])

import sys
sys.setrecursionlimit(200000000)
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    #print(str(i)+"だよ")
    if num + ca[i][1] <= m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        #print(num,money)
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
c = [list(map(int,input().split())) for i in range(n)]
ca = sorted(c,key=lambda x:x[0])

import sys
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    #print(str(i)+"だよ")
    if num + ca[i][1] <= m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        #print(num,money)
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)
Problem p03210 (python)

Fixed submission:
x = int(input())
li = [3,5,7]
if x in li:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
x = int(input())
li = [3,5,7]
if x in li:
    print('YES')
else:
    print('NO'
Problem p03239 (python)

Fixed submission:
n,T = map(int,input().split())
ct = [list(map(int,input().split())) for _ in range(n)]
li = []
for k in ct:
    if k[1]<=T:
        li += [k[0]]
if li ==[]:
    print("TLE")
else:
    print(min(li))

Buggy submission (verdict: Runtime Error):

n,T = map(int,input().split())
ct = [list(map(int,input().split())) for _ in range(n)]
li = []
for k in ct:
    if k[1]<=T:
        li += [k[0]]
print(min(li))
Problem p03243 (python)

Fixed submission:
n = int(input())
li = [int(str(i)*3) for i in range(10)]
import bisect
x = bisect.bisect_left(li,n)
print(li[x])

Buggy submission (verdict: Runtime Error):
n = int(input())
li = [int(str(i)*3) for i in range(9)]
import bisect
x = bisect.bisect_left(li,n)
print(li[x])
Problem p03281 (python)

Fixed submission:
n = int(input())

li = [3,5,7,11,13]
ans = 0
for i in range(1,n+1):
    cnt = 0
    for j in range(5):
        if i%li[j]==0:
            cnt += 1
    if cnt ==3:
        ans +=1

if n>=135:
    ans += 1
if n>=189:
    ans += 1

print(ans)

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

li = [3,5,7,11,13]
ans = 0
for i in range(1,n+1):
    cnt = 0
    for j in range(10):
        if i%li[j]==0:
            cnt += 1
    if cnt ==3:
        ans +=1

if n>=135:
    ans += 1
if n>=189:
    ans += 1

print(ans)
Problem p03289 (python)

Fixed submission:
s = input()
if s[0]=="A" and s[2:-1].count("C")==1:
    sc = s.index("C")
    if (s[1:sc]+s[sc+1:]).islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Buggy submission (verdict: Runtime Error):
s = input()
sc = s.index("C")
if s[0]=="A" and s[2:-1].count("C")==1 and (s[1:sc]+s[sc+1:]).islower():
    print("AC")
else:
    print("WA")
Problem p03309 (python)

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

li = sorted([a[i]-(i+1) for i in range(n)])
if n%2==0:
    ave = (li[n//2]+li[n//2-1])//2
else:
    ave = li[(n-1)//2]

import math
ave1 = math.floor(ave)
ave2 = math.ceil(ave)

ll = []
c = 0
for i in range(n):
    c += abs(a[i]-(ave1+i+1))
else:
    ll += [c]

c =0
for i in range(n):
    c += abs(a[i]-(ave2+i+1))
else:
    ll += [c]

print(min(ll))

Buggy submission (verdict: Runtime Error):
li = sorted([a[i]-(i+1) for i in range(n)])
if n%2==0:
    ave = (li[n//2]+li[n//2-1])//2
else:
    ave = li[(n-1)//2]

import math
ave1 = math.floor(ave)
ave2 = math.ceil(ave)

ll = []
c = 0
for i in range(n):
    c += abs(a[i]-(ave1+i+1))
else:
    ll += [c]

c =0
for i in range(n):
    c += abs(a[i]-(ave2+i+1))
else:
    ll += [c]

print(min(ll))
Problem p03353 (python)

Fixed submission:
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if j-i<=6:
            li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
li = []
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        li += [s[i:j]]
li2 = set(li)
li3 = sorted(li2)
print(li3[k-1]
Problem p03469 (python)

Fixed submission:
print("2018"+input()[4:])

Buggy submission (verdict: Runtime Error):
import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b,c in itertools.product(list,list,list):
    v = 10*a + 5*b + c
    w = a + b + c
    if v == z and w == n:
        break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))
Problem p02555 (python)

Fixed submission:
s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 10000
fact[0], fact[1] = 1, 1
for i in range(2, 10000):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return fact[n] * pow(fact[n-r], -1, MOD) * pow(fact[r], -1, MOD)

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m+i-1, m)
        ans %= MOD
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 10000
fact[0], fact[1] = 1, 1
for i in range(2, 10000):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return fact[n] * pow(fact[n-r], -1, MOD) * pow(fact[r], -1, MOD)

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m+i-1, m)
        ans %= MOD
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 4000
fact[0], fact[1] = 1, 1
for i in range(2, 4000):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return (fact[n+(r-1)] * pow(fact[n], -1, MOD) * pow(fact[r-1], -1, MOD))%MOD

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m, i)
        ans %= MOD
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 4000
fact[0], fact[1] = 1, 1
for i in range(2, 4000):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return (fact[n+(r-1)] * pow(fact[n], -1, MOD) * pow(fact[i-1], -1, MOD))%MOD

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m, i)
        ans %= MOD
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 2001
fact[0], fact[1] = 1, 1
for i in range(2, 2001):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return (fact[n+(r-1)] * pow(fact[n], -1, MOD) * pow(fact[i-1], -1, MOD))%MOD

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m, i)
        ans %= MOD
print(ans%MOD)
Problem p02573 (python)

Fixed submission:
from collections import Counter
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]

if m == 0:
    print(1)
    exit()
    
g = [[] for _ in range(n)]
visited = [-1] * n
for a, b in ab:
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
# print(g)
def dfs(start):
    global visited
    if visited[start] != -1:
        return 1
    stack = []
    stack.append(start)
    visited[start] = start
    while stack:
        root = stack.pop()
        for j in g[root]:
            if visited[j] == -1:
                visited[j] = start
                stack.append(j)

for i in range(n):
    dfs(i)
# print(visited)
tmp = Counter(visited)
# print(tmp)
p = sorted([v for i, v in tmp.items() if v != 1])
island = len(p)
# print(island)
if island == 1:
    print(n)
else:
    print(p[-1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
g = [[] for _ in range(n)]
visited = [-1] * n
for a, b in ab:
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
# print(g)
def dfs(start):
    global visited
    if visited[start] != -1:
        return 
    stack = []
    stack.append(start)
    visited[start] = start
    while stack:
        root = stack.pop()
        for j in g[root]:
            if visited[j] == -1:
                visited[j] = start
                stack.append(j)

for i in range(n):
    dfs(i)
# print(visited)
tmp = Counter(visited)
# print(tmp)
p = sorted([v for i, v in tmp.items() if v != 1])
island = len(p)
# print(island)
if island == 1:
    print(n)
else:
    print(p[-1])
Problem p02574 (python)

Fixed submission:
from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

# sieve[n]は、その数を最初にふるいに落とした数を格納
def prime_factor_table(n):
    # sieveとはふるいの意味
    sieve = [i for i in range(n+1)]
    # n以下の整数を最初にふるい落とす数(√n以下に必ず存在)を求める.
    for i in range(2, int(n**0.5)+1):
        if sieve[i] == i:
            for j in range(2*i, n+1, i):
                if sieve[j] == j:
                    sieve[j] = i
    return sieve

sieve = prime_factor_table(10**6+1)

def prime_factor(n):
    # 素数は英語でprime number
    prime = set()
    while n > 1:
        prime.add(sieve[n])
        n //= sieve[n]
    return prime

for i, v in enumerate(a):
    if i == 0:
        tmp = prime_factor(v)
    else:
        prime = prime_factor(v)
        for j in prime:
            if j in tmp:
                if reduce(gcd, a) == 1:
                    print("setwise coprime")
                    exit()
                else:
                    print("not coprime")
                    exit()
            tmp.add(j)
print("pairwise coprime")

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

tmp = [set() for _ in range(10**2+1)]
for i in range(2, 10**2//2+1):
    for j in range(i, 10**2+1, i):
        tmp[j].add(i)


flag = False
for i in range(n-1):
    if len(tmp[a[i]] & tmp[max(a)]) > 0:
        flag = True
        break

if flag == False:
    print("pairwise coprime")
else:
    if reduce(gcd, a) == 1:
        print("setwise coprime")
    else:
        print("not coprime")

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

tmp = [set() for _ in range(10**2+1)]
for i in range(2, 10**2//2+1):
    for j in range(i, 10**2+1, i):
        tmp[j].add(i)

acc = [set() for _ in range(n)]
for i, v in enumerate(a):
    if i == 0:
        acc[i] = tmp[v]
    else:
        acc[i] = acc[i-1] | tmp[v]

flag = False
for i in range(n-1):
    acc[i].remove(i)
    if len(acc[i] & acc[n-1]) != 0:
        flag = True
        break

if flag == False:
    print("pairwise coprime")
else:
    if reduce(gcd, a) == 1:
        print("setwise coprime")
    else:
        print("not coprime")