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

Fixed submission:
from collections import Counter

S = input()
counter = Counter(S)
if len(counter) == 1:
    k = list(counter.keys())[0]
    if counter[k] > 1:
        print('NO')
    else:
        print('YES')
elif len(counter) == 2:
    # a, b → OK
    # a, a, b, b → NG
    for k in counter.keys():
        if counter[k] != 1:
            print('NO')
            exit()
    print('YES')
else:
    # abcabcb → bacbacb OK
    # abbccc → cabc これのどこにcを追加してもNG
    # abcba → abcab OK
    # aabc → abca OK
    min_v = 10 ** 5
    max_v = 0
    for k in counter.keys():
        min_v = min(min_v, counter[k])
        max_v = max(max_v, counter[k])
    if max_v - min_v > 1:
        print('NO')
    else:
        print('YES')

Buggy submission (verdict: Runtime Error):
from collections import Counter

S = input()
counter = Counter(S)
if len(counter) == 1:
    k = counter.keys()[0]
    if counter[k] > 1:
        print('NO')
    else:
        print('YES')
elif len(counter) == 2:
    print('NO')
else:
    # 通らない気がする
    print('YES')
Problem p03633 (python)

Fixed submission:
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N = int(input())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
if N > 1:
    ans = lcm(t_li[0], t_li[1])
    for i in range(2, N):
        ans = lcm(ans, t_li[i])
else:
    ans = t_li[0]
print(ans)

Buggy submission (verdict: Runtime Error):
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N = int(input())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
ans = lcm(t_li[0], t_li[1])
for i in range(2, N):
    ans = lcm(ans, t_li[i])
print(ans)
Problem p02609 (python)

Fixed submission:
N = int(input())
X = input()
tmp = sum(X[i] == '1' for i in range(N))

for_zero = tmp + 1
for_one = tmp - 1
zero_S = 0
one_S = 0


numbers = [0] * N
counts = [1] * N

if tmp == 1:
    for i in range(N):
        if X[i] == '1':
            counts[i] = 0
    # =====================first sweep
    tmp_zero = 1
    for i in range(N):
        if X[-i - 1] == '1':
            zero_S += tmp_zero
            zero_S %= for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero

    # =====================second sweep
    tmp_zero = 1
    for i in range(N):
        if X[-i - 1] == '1':
            pass
        else:
            numbers[-i - 1] = (zero_S + tmp_zero) % for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero

else:
    # =====================first sweep
    tmp_zero = 1
    tmp_one = 1
    for i in range(N):
        if X[-i - 1] == '1':
            one_S += tmp_one
            one_S %= for_one
            zero_S += tmp_zero
            zero_S %= for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero
        tmp_one *= 2
        tmp_one %= for_one

    # =====================second sweep
    tmp_zero = 1
    tmp_one = 1
    for i in range(N):
        if X[-i - 1] == '1':
            numbers[-i - 1] = (one_S - tmp_one) % for_one
        else:
            numbers[-i - 1] = (zero_S + tmp_zero) % for_zero
        tmp_zero *= 2
        tmp_zero %= for_zero
        tmp_one *= 2
        tmp_one %= for_one




def solution(number):
    loop = 0
    while number != 0:
        popcount = 0
        for i in range(30):
            if (1 << i) & number:
                popcount += 1
        number %= popcount
        loop += 1
    return loop

for i in range(N):
    counts[i] += solution(numbers[i])

print(*counts, sep='\n')

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()
tmp = sum(X[i] == '1' for i in range(N))

for_zero = tmp + 1
for_one = tmp - 1
zero_S = 0
one_S = 0


numbers = [-1] * N
counts = [1] * N

if tmp == 1:
    for i in range(N):
        if X[i] == '1':
            counts[i] = 0

# =====================first sweep
tmp_zero = 1
tmp_one = 1
for i in range(N):
    if X[-i-1] == '1':
        one_S += tmp_one
        one_S %= for_one
        zero_S += tmp_zero
        zero_S %= for_zero
    tmp_zero *= 2
    tmp_zero %= for_zero
    tmp_one *= 2
    tmp_one %= for_one


# =====================second sweep
tmp_zero = 1
tmp_one = 1
for i in range(N):
    if X[-i-1] == '1':
        numbers[-i - 1] = (one_S - tmp_one) % for_one
    else:
        numbers[-i - 1] = (zero_S + tmp_zero) % for_zero
    tmp_zero *= 2
    tmp_zero %= for_zero
    tmp_one *= 2
    tmp_one %= for_one


def solution(number):
    loop = 0
    while number != 0:
        popcount = 0
        for i in range(30):
            if (1 << i) & number:
                popcount += 1
        number %= popcount
        loop += 1
    return loop

for i in range(N):
    counts[i] += solution(numbers[i])

print(*counts, sep='\n')
Problem p02642 (python)

Fixed submission:
N = int(input())
A = sorted(map(int, input().split()))
if A[0] == 1:
    if N > 1 and A[1] == 1:
        print(0)
    else:
        print(1)
else:
    ans = 0
    MAX = 10 ** 6 + 3
    C = [False] * MAX
    for i in range(N):
        if not C[A[i]]:
            if i != N - 1 and A[i] != A[i + 1]:
                ans += 1
            elif i == N - 1:
                ans += 1
            cur = 1
            while cur * A[i] <= MAX:
                C[cur * A[i]] = True
                cur += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int, input().split()))
if A[0] == 1:
    print(1)
else:
    ans = 0
    MAX = 1000001
    C = [False] * MAX
    for i in range(N):
        if not C[A[i]]:
            if i != N - 1 and A[i] != A[i + 1]:
                ans += 1
            elif i == N - 1:
                ans += 1
            cur = 1
            while cur * A[i] <= MAX:
                C[cur * A[i]] = True
                cur += 1
    print(ans)
Problem p02727 (python)

Fixed submission:
import sys
input = sys.stdin.readline

X, Y, A, B, C = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)

pq = p[:X] + q[:Y]
if len(pq) < X + Y:
    pq += [0] * (X + Y - len(pq))
pq.sort()
for i in range(min(C, len(pq))):
    if pq[i] < r[i]:
        pq[i] = r[i]
print(sum(pq))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X, Y, A, B, C = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)

pq = p[:X] + q[:Y]
if len(pq) < X + Y:
    pq += [0] * (X + Y - len(pq))
pq.sort()
for i in range(min(C, A + B)):
    if pq[i] < r[i]:
        pq[i] = r[i]
print(sum(pq))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X, Y, A, B, C = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)

pq = p[:X] + q[:Y]
pq.sort()
for i in range(min(C, A + B)):
    if pq[i] < r[i]:
        pq[i] = r[i]
print(sum(pq))
Problem p02642 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())

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

AList.sort()

dp = [0] *  (AList[-1] + 1)

for i in AList:
    dp[i] += 1
    
    if dp[i] == 1:
        for p in range(2 * i, len(dp), i):
            dp[p] += 2

print(dp.count(1))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())

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

AList.sort()

dp = [0] *  (AList[-1] + 1)

for i in AList:
    dp[i] += 1
    
    if dp[i] == 1:
        for p in range(2 * i, len(dp), i):
            dp[j] += 2

print(dp.count(1))
Problem p02658 (python)

Fixed submission:
N = int(input())

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

NList.sort()
result = 1
for i in range(N):
    result *= NList[i]

    if result > 10 ** 18:
        break

if result > 10 ** 18:
    print('-1')
else:
    print(result)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())

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

NList.sort()
result = 1
for i in range(N):
    result *= NList[i]

    if result > 10 ** 18:
        print('-1')
        sys.exit(1)

if result > 10 ** 18:
    print('-1')
    sys.exit(1)
else:
    print(result)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())

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

result = 1
for i in range(N):
    result *= NList[i]
    
    if result > 10 ** 18:
        print('-1')
        sys.exit(1)

if result > 10 ** 18:
    print('-1')
    sys.exit(1)
else:
    print(result)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())

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

result = 1
for i in range(N):
    result *= NList[i]
    
    if result > 10 ** 18:
        print('-1')
        sys.exit(1)

if result > 10 ** 18:
        print('-1')
        sys.exit(1)
else:
    print(result)

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

result = 1
for i in range(N):
    result *= int(input())

if result > 10 ** 18:
    print('-1')
else:
    print(result)
Problem p02760 (python)

Fixed submission:
import sys

AList = []
BingoList = [[0, 0, 0],
             [0, 0, 0],
             [0, 0, 0]]

for i in range(3):
    AList.append(list(map(int, input().split())))
    

N = int(input())

tmp = -1
for i in range(N):
    tmp = int(input())
    for p in range(3):
        for q in range(3):
            if AList[p][q] == tmp:
                BingoList[p][q] = 1

for i in range(3):
    if BingoList[i][0] == 1 and BingoList[i][1] == 1 and BingoList[i][2] == 1:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if BingoList[0][i] == 1 and BingoList[1][i] == 1 and BingoList[2][i] == 1:
        print('Yes')
        sys.exit(0)

if BingoList[0][0] == 1 and BingoList[1][1] == 1 and BingoList[2][2] == 1:
    print('Yes')
elif BingoList[2][0] == 1 and BingoList[1][1] == 1 and BingoList[0][2] == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys

AList = []
BingoList = [[0, 0, 0],
             [0, 0, 0],
             [0, 0, 0]]

for i in range(3):
    AList.append(list(map(int, input().split())))
    

N = int(input())

tmp = -1
for i in range(N):
    tmp = int(input())
    for p in range(3):
        for q in range(3):
            if AList[p][q] == tmp:
                BingoList[i][q] = 1

for i in range(3):
    if BingoList[i][0] == 1 and BingoList[i][1] == 1 and BingoList[i][2] == 1:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if BingoList[0][i] == 1 and BingoList[1][i] == 1 and BingoList[2][i] == 1:
        print('Yes')
        sys.exit(0)

if BingoList[0][0] == 1 and BingoList[1][1] == 1 and BingoList[2][2] == 1:
    print('Yes')
elif BingoList[2][0] == 1 and BingoList[1][1] == 1 and BingoList[0][2] == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys

AList = []
BingoList = [[0, 0, 0],
             [0, 0, 0],
             [0, 0, 0]]

for i in range(3):
    AList.append(list(map(int, input().split())))
    

N = int(input())

tmp = -1
for i in range(N):
    tmp = int(input())
    for p in range(3):
        for q in range(3):
            if AList[p][q] == tmp:
                BingoList[i][q] = 1

for i in range(3):
    if BingoList[i][0] == 1 and BingoList[i][1] == 1 and BingoList[i][2] == 1:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if BingoList[0][i] == 1 and BingoList[1][i] == 1 and BingoList[2][i] == 1:
        print('Yes')
        sys.exit(0)

if BingoList[0][0] == 1 and BingoList[1][1] == 1 and BingoList[2][2] == 1:
    print('Yes')
elif BingoList[2][0] == 1 and BingoList[1][1] == 1 and BingoList[0][2] == 1:
    print('Yes')
else:
    print('No')
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 = map(int, input().split())

if N == M:
    print('Yes')
else:
    printf('No')
Problem p02838 (python)

Fixed submission:
import numpy as np

mod = 10 ** 9 + 7

N = int(input())
 
AList = np.array(input().split(), dtype=np.int64)
count = 0
for i in range(60):
    Plus = np.count_nonzero(AList >> i & 1)
    count += 2 ** i * (Plus * (N - Plus))
print(count % mod)

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

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

for i in range(0, N):
    for q in range(i, N):
        count += int(AList[i] ^ AList[q])
print(count % (10 ** 9 + 7))
Problem p03813 (python)

Fixed submission:
if int(input()) < 1200:
  print("ABC")
else:
  print("ARC")

Buggy submission (verdict: Runtime Error):
if input() > 1200:
  print("ABC")
else:
  print("ARC")
Problem p02582 (python)

Fixed submission:
S = input()
if S == "RRR":
  print(3)
elif S == "SSS":
  print(0)
elif S == "SRR" or S == "RRS":
  print(2)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
S = input()
if S == "RRR":
  print(0)
elif S == "SSS":
  print(3)
elif S == "SSR" or S = "RSS":
  print(2)
else:
  print(1)
Problem p02603 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
kabu = 0
money = 1000
for i in range(N):
  money += kabu*A[i]
  kabu = 0
  if i!=N-1:
    if A[i]<=A[i+1]:
      kabu += money//A[i]
      money %= A[i]
    else:
      pass
print(money)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
kabu = 0
money = 1000
for i in range(N):
  money += kabu*A[i]
  kabu = 0
  if i!=N-1:
    if A[i]<A[i+1]:
      kabu += money//A[i]
      money %= 0
    else:
      continue
print(money)
Problem p02664 (python)

Fixed submission:
T = list(input())
if len(T) == 1:
  if T[0] == "?":
    print("D")
  else:
    print("".join(T))
else:
  for i in range(len(T)):
    if i > 0 and T[i] == "?" and T[i-1] == "P":
      T[i] = "D"
    elif i < len(T) -1 and T[i] == "?" and (T[i+1] == "D" or T[i+1] == "?"):
      T[i] = "P"
    elif T[i] == "?":
      T[i] = "D"
  print("".join(T))

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

Buggy submission (verdict: Runtime Error):
T = list(input())
for i in range(len(T)):
  if i > 0 and T[i] == "?" and T[i-1] == "P":
    T[i] = "D"
  elif i <= len(T) -1 and T[i] == "?" and (T[i+1] == "D" or T[i+1] == "?"):
    T[i] = "P"
  elif T[i] == "?":
    T[i] = "D"
print("".join(T))

Buggy submission (verdict: Runtime Error):
T = list(input())
for i in range(1, len(T)):
  if T[i] == "?" and T[i-1] == "P":
    T[i] = "D"
  elif T[i] == "?" and (T[i+1] == "D" or T[i+1] == "?"):
    T[i] = "P"
  elif T[i] == "?":
    T[i] = "D"
print("".join(T))
Problem p02684 (python)

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

X = 0
town = 1
counted = [0 for _ in range(N)]
List = [0 for _ in range(N)]
for k in range(N):
  X += 1
  counted[k] = town
  town = A[town-1]
  if List[town-1] == 1:
    ini = counted.index(town)
    Q = X - ini
    break
  else:
    List[town-1] = 1
if K >= ini:    
  num = (K-ini) % Q
  print(counted[ini+num])
else:
  print(counted[K])

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

X = 0
town = 1
counted = []
for k in range(N):
  X += 1
  counted.append(town)
  town = A[town-1]
  if town in counted:
    Q = len(counted[counted.index(town):])
    roop = counted[counted.index(town):]
    I = counted[:counted.index(town)]
    ini = X - Q
    break
print(I)
print(roop)
ans = 1
if K > ini:    
  num = (K-ini) % Q
  print(roop[num])
else:
  print(I[K])
Problem p02760 (python)

Fixed submission:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k] == b:
        A[j][k] = "x"
      else:
        pass
if A[0] == ["x","x","x"]:
  print("Yes")
elif A[1] == ["x","x","x"]:
  print("Yes")
elif A[2] == ["x","x","x"]:
  print("Yes")
elif A[0][0] == "x" and A[1][0] == "x" and A[2][0] == "x":
  print("Yes")
elif A[0][1] == "x" and A[1][1] == "x" and A[2][1] == "x":
  print("Yes")
elif A[0][2] == "x" and A[1][2] == "x" and A[2][2] == "x":
  print("Yes")
elif A[0][0] == "x" and A[1][1] == "x" and A[2][2] == "x":
  print("Yes")
elif A[0][2] == "x" and A[1][1] == "x" and A[2][0] == "x":
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k] == b:
        A[j][k] = "x"
if A[0] == ["x","x","x"]:
  print("Yes")
elif A[1] == ["x","x","x"]:
  print("Yes")
elif A[2] == ["x","x","x"]:
  print("Yes")
elif A[0][0] == "x" and A[1][0] == "x" and A[2][0] == "x":
  peint("Yes")
elif A[0][1] == "x" and A[1][1] == "x" and A[2][1] == "x":
  print("Yes")
elif A[0][2] == "x" and A[1][2] == "x" and A[2][2] == "x":
  print("Yes")
elif A[0][0] == "x" and A[1][1] == "x" and A[2][2] == "x":
  print("Yes")
elif A[0][2] == "x" and A[1][1] == "x" and A[2][0] == "x":
  print("Yes")
else:
  print("No")
Problem p02783 (python)

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

Buggy submission (verdict: Runtime Error):
H, A=map(int, input().split)
if H % A == 0:
  print(H / A)
else:
  print(H // A + 1)
Problem p02784 (python)

Fixed submission:
H, N=map(int, input().split())
List=list(map(int,input().split()))
a = 0
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
H, N=map(int, input().split())
List=list(map(int,input().split()))
a = 0:
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
H, N=map(int, input().split())
List=[int(i) for i in input().split()]
a = 0:
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")
Problem p02802 (python)

Fixed submission:
N, M = map(int, input().split())
Counted = [0 for _ in range(N)]
num1 = 0
num2 = 0
subnum2 = [0 for l in range(N)]
for j in range(M):
  p, S = input().split()
  p_ = int(p)
  if S == "AC" and Counted[p_ -1] == 0:
    num1 += 1
    num2 += subnum2[p_ - 1]
    Counted[p_ -1] = 1
  elif S == "WA" and Counted[p_-1] == 0:
    subnum2[p_ - 1] += 1
print("{} {}".format(num1, num2))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
Counted = [0 for _ in range(N)]
num1 = 0
num2 = 0
subnum2 = [0 for l in range(N)]
for j in range(M):
  p, S = input().split()
  p_ = int(p)
  if S == "AC" and Counted[p_] == 0:
    num1 += 1
    num2 += subnum2[p_ - 1]
    Counted[p_] = 1
  elif S == "WA" and Counted[p_] == 0:
    subnum2[p_ - 1] += 1
print("{} {}".format(num1, num2))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
Counted = [0 for _ in range(M)]
num1 = 0
num2 = 0
subnum2 = [0 for l in range(N)]
for j in range(M):
  p, S = input().split()
  p_ = int(p)
  if S == "AC" and Counted[p_] == 0:
    num1 += 1
    num2 += subnum2[p_ - 1]
    Counted[p_] = 1
  elif S == "WA" and Counted[p_] == 0:
    subnum2[p_ - 1] += 1
print("{} {}".format(num1, num2))
Problem p02988 (python)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
num = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        num += 1
print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
num = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
            num += 1
    print(num)
Problem p02574 (python)

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

se = A[0]
for i in range(1,N):
    se = math.gcd(se,A[i])
set_wise = se==1

NMAX = 10**6+2
divisors = [i for i in range(NMAX+1)]
p=2
while p*p <=NMAX:
    if divisors[p]==p:
        for r in range(2*p,NMAX+1,p):
            if divisors[r]==r:
                divisors[r]=p
    p+=1
    
from collections import defaultdict
def soinsu_osak(to_devide):
    d = defaultdict(int)
    while to_devide>1:
        d[divisors[to_devide]]+=1
        to_devide //= divisors[to_devide]
    return list(d.keys())

been=[0]*NMAX
pair_wise=True
f=False
for aa in A:
    soinsu = soinsu_osak(aa)
    for s in soinsu:
        if been[s]==0:
            been[s]=1
        else:
            pair_wise=False
            f=True
            break
    if f:
        break

if pair_wise:
    print("pairwise coprime")
elif set_wise:
    print("setwise coprime")
else:
    print("not coprime")

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

se = A[0]
for i in range(1,N):
    se = math.gcd(se,A[i])
set_wise = se==1

NMAX = 10**6+2
divisors = [i for i in range(NMAX+1)]
p=2
while p*p <=NMAX:
    if divisors[p]==p:
        for r in range(2*p,NMAX+1,p):
            if divisors[r]==r:
                divisors[r]=p
    p+=1
    
from collections import defaultdict
def soinsu_osak(to_devide):
    d = defaultdict(int)
    while to_devide>1:
        d[divisors[to_devide]]+=1
        to_devide //= divisors[to_devide]
    return list(d.keys())

been=[0]*NMAX
f=False
for aa in A:
    soinsu = soinsu_osak(aa)
    for s in soinsu:
        if been[s]==0:
            been[s]=1
        else:
            pair_wise=False
            f=True
            break
    if f:
        break

if pair_wise:
    print("pairwise coprime")
elif set_wise:
    print("setwise coprime")
else:
    print("not coprime")
Problem p02618 (python)

Fixed submission:
d=int(input())
c = list(map(int,input().split()))

s=[None]*d
for i in range(d):
    s[i] = list(map(int,input().split()))

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

for ss in s:
    print(maxarg(ss)[0]+1)

Buggy submission (verdict: Runtime Error):
import time
t0 =time.time()
D=int(input())
c = list(map(int,input().split()))

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

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

last=[0]*26
t_greed = []
for j,ss in enumerate(s):
    
    cand = [ss[i]+c[i]*(j+1-last[i]) for i in range(26)]
    idx,val = maxarg(cand)
    last[idx]=j+1
    t_greed.append(idx+1)
    
def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    delta_pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        delta_pena += sumc - c[tt-1]*(j+1-last[tt-1])
        last[tt-1]=j+1   
        pena += delta_pena
    return satis-pena

import random
t_old=t_greed[:]
while True:
    if time.time()-t0>=1.7:
        break
    d = random.randrange(D+1)
    q = random.randrange(26+1)
    
    t_new = t_old[:]
    t_new[d-1] = q
    if calc_score(t_new)>calc_score(t_old):
        t_old=t_new[:]
        
for tt in t_old:
    print(tt)