Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
paths = [list(map(int, input().split())) for _ in range(M)]

minimumScore = [-float('inf') for _ in range(N)]
minimumScore[0] = 0
count = 0
while count < N:
    flag = False
    for a, b, c in paths:
        if minimumScore[a-1] == -float('inf'):
            continue
        if minimumScore[a-1] + c > minimumScore[b-1]:
            minimumScore[b-1] = minimumScore[a-1] + c
            minimumScore[b-1] = minimumScore[a-1] + 1
            flag = True
    if not flag:
        break
    count += 1
tmp = minimumScore[-1]
for a, b, c in paths:
    if minimumScore[a-1] == -float('inf'):
        continue
    if minimumScore[a-1] + c > minimumScore[b-1]:
        minimumScore[b-1] = minimumScore[a-1] + c
        minimumScore[b-1] = minimumScore[a-1] + 1
        flag = True
if tmp != minimumScore[-1]:
    print('inf')
else:
    print(minimumScore[N-1][0])
#print(minimumScore[-1])


Fixed submission:
N, M = map(int, input().split())
paths = [list(map(int, input().split())) for _ in range(M)]

minimumScore = [float('inf') for _ in range(N)]
minimumScore[0] = 0
for _ in range(N-1):
    flag = False
    for a, b, c in paths:
        c = -c
        if minimumScore[a-1] == -float('inf'):
            continue
        if minimumScore[a-1] + c < minimumScore[b-1]:
            minimumScore[b-1] = minimumScore[a-1] + c
            flag = True
    if not flag:
        break


negative = [False for i in range(N)]
for _ in range(N):
    for a, b, c in paths:
        c = -c
        if negative[a-1]:
            negative[b-1] = True
        if minimumScore[a-1] == -float('inf'):
            continue
        if minimumScore[a-1] + c < minimumScore[b-1]:
            negative[b-1] = True
            flag = True
if negative[-1]:
    print('inf')
else:
    print(-minimumScore[N-1])
#print(minimumScore[-1])
Buggy python submission (verdict: Runtime Error):
import math


def divisor(num):
    if num < 0:
        return 0
    elif num == 1:
        return 1
    else:
        divisor_list = [1, ]
        for i in range(2, int(math.sqrt(num) + 1)):
            if num % i == 0:
                divisor_list.append(i)
        return divisor_list


n = int(input())

divisor_list = divisor(n)
minA = divisor_list[-1]
print(len(str(n//minA)))


Fixed submission:
import math


def divisor(num):
    if num < 0:
        return 0
    elif num == 1:
        return [1, ]
    else:
        divisor_list = [1, ]
        for i in range(2, int(math.sqrt(num) + 1)):
            if num % i == 0:
                divisor_list.append(i)
        return divisor_list


n = int(input())
divisor_list = divisor(n)
minA = divisor_list[-1]
print(len(str(n//minA)))
Buggy python submission (verdict: Runtime Error):
import numpy as np
MOD = 10**9 + 7


def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2, N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum


N = int(input())
N_list = seachPrimeNum(N)
ans_list = [0 for i in range(len(N_list))]
for i in range(2, N+1):
    temp_i = i
    for j in range(len(N_list)):
        while temp_i % N_list[j] == 0:
            temp_i = temp_i // N_list[j]
            ans_list[j] += 1
ans = 1
for i in range(len(ans_list)):
    ans = ans * (ans_list[i]+1) % MOD
print(ans)


Fixed submission:
import numpy as np
MOD = 10**9 + 7


def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2, N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum


N = int(input())
if N == 1:
    print(1)
    exit()
N_list = seachPrimeNum(N)
ans_list = [0 for i in range(len(N_list))]
for i in range(2, N+1):
    temp_i = i
    for j in range(len(N_list)):
        while temp_i % N_list[j] == 0:
            temp_i = temp_i // N_list[j]
            ans_list[j] += 1
ans = 1
for i in range(len(ans_list)):
    ans = ans * (ans_list[i]+1) % MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split(' '))
t = list(map(int, input().split(' ')))
t_interval = [t[i+1]-t[i] for i in range(N-1)]
ans = 0
for i in range(N-1):
    if t_interval[i] <= T:
        ans += t_interval[i]
    elif t_interval[i] > T:
        ans += T
ans += T
print(ans)


Fixed submission:
N, K = map(int, input().split(' '))
D = input().split(' ')
for i in range(N, 10*N+1):
    flag = True
    ans = str(i)
    for n in ans:
        if n in D:
            flag = False
    if flag:
        print(ans)
        exit()
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())

arr = np.array(list(map(int, input().split())))
unique, cnts = np.unique(arr, return_counts=True)

counts = {}
sum = arr.sum()

for key, val in zip(unique, cnts):
    counts[key] = val

Q = int(input())

for i in range(Q):
    B, C = list(map(int, input().split()))
    counts[C] += counts[B]
    sum += counts[B] * (C - B)
    counts[B] = 0
    print(sum)


Fixed submission:
import numpy as np
from collections import defaultdict

N = int(input())

arr = np.array(list(map(int, input().split())))
unique, cnts = np.unique(arr, return_counts=True)

counts = defaultdict(int)
sum = arr.sum()

for key, val in zip(unique, cnts):
    counts[key] = val

Q = int(input())

for i in range(Q):
    B, C = list(map(int, input().split()))
    counts[C] += counts[B]
    sum += counts[B] * (C - B)
    counts[B] = 0
    print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
arr = np.array(list(map(int, input().split())))

Q = int(input())

for i in range(Q):
    B, C = list(map(int, input().split()))
    arr[arr == B] = C
    print(arr.sum())


Fixed submission:
import numpy as np
from collections import defaultdict

N = int(input())

arr = np.array(list(map(int, input().split())))
unique, cnts = np.unique(arr, return_counts=True)

counts = defaultdict(int)
sum = arr.sum()

for key, val in zip(unique, cnts):
    counts[key] = val

Q = int(input())

for i in range(Q):
    B, C = list(map(int, input().split()))
    counts[C] += counts[B]
    sum += counts[B] * (C - B)
    counts[B] = 0
    print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
import random
D = int(input())
C = input().split()
C = [int(c) for c in C]
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)
#T = [1,17,13,14,13]
T = [12] * D
def value():
  M = 0
  last = [0] * 26
  for d in range(1,D+1):
    N = 0
    t = T[d-1]
    last[t-1] = d
    #print(last)
    for j in range(26):
      N = N + C[j]*(d-last[j])
    M = M + S[d-1][t-1] - N
  return(M)
Vmax = value()
#print(Vmax)
Q = []
for i in range(2000):
  Q.append([random.randint(1,D), random.randint(1,26)])
for i in range(2000):
  Tprev = T
  T[Q[i][0]-1] = Q[i][1]
  V = value()
  if V > Vmax:
    Vmax = V
  else:
    T = Tprev
  #print(Vmax)
#print(T)
for t in T:
  print(t)

Fixed submission:
import random
D = int(input())
C = input().split()
C = [int(c) for c in C]
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)
T = [1] * D
def value():
  M = 0
  last = [0] * 26
  for d in range(1,D+1):
    N = 0
    t = T[d-1]
    last[t-1] = d
    #print(last)
    for j in range(26):
      N = N + C[j]*(d-last[j])
    M = M + S[d-1][t-1] - N
  return(M)
Vmax = value()
Q = []
for i in range(10):
  Q.append([random.randint(1,D), random.randint(1,26)])
for i in range(10):
  Tprev = T
  T[Q[i][0]-1] = Q[i][1]
  V = value()
  if V > Vmax:
    Vmax = V
  else:
    T = Tprev
  #print(Vmax)
#print(T)
for t in T:
  print(t)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [int(s) for s in input().split()]
l = 1
for s in S:
  l = l * s
if l > 10**18:
  l = -1
print(l)

Fixed submission:
N = int(input())
S = [int(s) for s in input().split()]
if 0 in S:
  l = 0
else:
  l = 1
  for s in S:
    l = l * s
    if l > 10**18:
      l = -1
      break
print(l)
Buggy python submission (verdict: Runtime Error):
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
a = str(A*B/100)[:-3]
a = int(a)
print(a)


Fixed submission:
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
if len(str(A*B)) <= 2:
  a = 0
else:
  a = str(A*B)[:-2]
  a = int(a)
print(a)

Buggy python submission (verdict: Runtime Error):
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
a = str(A*B/100)[:-3]
a = int(a)
print(a)


Fixed submission:
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
if len(str(A*B)) <= 2:
  a = 0
else:
  a = str(A*B)[:-2]
  a = int(a)
print(a)

Buggy python submission (verdict: Runtime Error):
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
a = str(A*B)[:-2]
a = int(a)
print(a)


Fixed submission:
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
if len(str(A*B)) <= 2:
  a = 0
else:
  a = str(A*B)[:-2]
  a = int(a)
print(a)

Buggy python submission (verdict: Runtime Error):
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
print(A*B)
a = str(A*B)[:-2]
a = int(a)
print(a)


Fixed submission:
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
if len(str(A*B)) <= 2:
  a = 0
else:
  a = str(A*B)[:-2]
  a = int(a)
print(a)

Buggy python submission (verdict: Runtime Error):
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
a = str((A*B)/100)[:-2]
a = int(a)
print(a)


Fixed submission:
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
if len(str(A*B)) <= 2:
  a = 0
else:
  a = str(A*B)[:-2]
  a = int(a)
print(a)
Buggy python submission (verdict: Runtime Error):
import math
A = int(input())
a = a * 2 * math.pi
print(a)

Fixed submission:
import math
A = int(input())
a = A * 2 * math.pi
print(a)
Buggy python submission (verdict: Runtime Error):
S = input()
sort(S)
a = 'Yes'
if S[0] == S[-1]:
  a = 'No'
print(a)

Fixed submission:
S = input()
S = sorted(S)
a = 'Yes'
if S[0] == S[-1]:
  a = 'No'
print(a)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if len(dictV1) == 1:
  a = a + 0
else:
  a = a + N/2 - sortdictV1[0][1]
if len(dictV2) == 1:
  a = a + 0
else:
  a = a + N/2 - sortdictV2[0][1]
if sortdictV1[0][0] == sortdictV2[0][0]:
  a = 0
  a = a + min(N/2 - sortdiictV1[0][1] + N/2 - sortdictV2[1][1], N/2 - sortdiictV2[0][1] + N/2 - sortdictV1[1][1])
print(a)


Fixed submission:
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if sortdictV1[0][0] != sortdictV2[0][0]:
    a = N - sortdictV1[0][1] - sortdictV2[0][1]
else:
  if len(dictV1) == len(dictV2) == 1:
    a = N // 2
  else:
    if len(dictV1) == 1:
      a = N - sortdictV1[0][1] - sortdictV2[1][1]
    elif len(dictV2) == 1:
      a = N - sortdictV1[1][1] - sortdictV2[0][1]
    else:
      a = min(N - sortdictV1[0][1] - sortdictV2[1][1], N - sortdictV1[1][1] - sortdictV2[0][1])
print(a)
Buggy python submission (verdict: Runtime Error):
D=input()
c=list(map(int, list(input())))
for i in range(365):
    s=list(map(int, list(input())))
for i in range(365):
    print(s.index(max(s)) + 1)

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

Buggy python submission (verdict: Runtime Error):
D=input()
c=list(map(int, list(input())))
for i in range(365):
    s=list(map(int, list(input())))
    print(s.index(max(s)) + 1)

Fixed submission:
D=int(input())
c=list(map(int, (input().split(' '))))
s=[]
for i in range(D):
    s.append(list(map(int, (input().split(' ')))))
for i in range(D):
    print(s[i].index(max(s[i])) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
nk=list(map(int,input().split(' ')))
while(True):
    if abs(nk[0]-nk[1])<nk[0]:
        nk[0]=abs(nk[0]-nk[1])
    else:
        break
print(nk[0])

Fixed submission:
nk=list(map(int,input().split(' ')))
nk[0]=nk[0]%nk[1]
while(True):
    if abs(nk[0]-nk[1])<nk[0]:
        nk[0]=abs(nk[0]-nk[1])
    else:
        break
print(nk[0])
Buggy python submission (verdict: Runtime Error):
a = list(input())
if a[2]==a[3] & a[4]==a[5]:
    print("Yes")
else:
    print("No")

Fixed submission:
a = list(input())
if a[2]==a[3] and a[4]==a[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math
a=input().split()
print(int(a[0]) * int(a[1]) / math.gcd(int(a[0]), int(a[1])))

Fixed submission:
import fractions
a=input().split()
print(int(a[0]) * int(a[1]) // fractions.gcd(int(a[0]), int(a[1])))

Buggy python submission (verdict: Runtime Error):
import math
a=input().split()
print(a[0] * a[1] / math.gcd(a[0], a[1]))

Fixed submission:
import fractions
a=input().split()
print(int(a[0]) * int(a[1]) // fractions.gcd(int(a[0]), int(a[1])))

Buggy python submission (verdict: Runtime Error):
import math
a=input().split()
print(math.lcm(int(a[0]), int(a[1])))

Fixed submission:
import fractions
a=input().split()
print(int(a[0]) * int(a[1]) // fractions.gcd(int(a[0]), int(a[1])))

Buggy python submission (verdict: Runtime Error):
import math
a=input().split()
print(math.lcm(a[0], a[1]))

Fixed submission:
import fractions
a=input().split()
print(int(a[0]) * int(a[1]) // fractions.gcd(int(a[0]), int(a[1])))

Buggy python submission (verdict: Runtime Error):
import math
a=input().split()
print(math.gcd(a[0], a[1]))

Fixed submission:
import fractions
a=input().split()
print(int(a[0]) * int(a[1]) // fractions.gcd(int(a[0]), int(a[1])))
Buggy python submission (verdict: Runtime Error):
a = input().split(" ")
mem = [0] * int(a[0])
for i in range(int(a[2])):
  mem[int(input())-1] += 1
for i in mem:
  if int(a[1])-int(a[2])+mem[i] < 1:
    print("No")
  else:
    print("Yes")

Fixed submission:
a = input().split(" ")
mem = [0] * int(a[0])
for i in range(int(a[2])):
  mem[int(input())-1] += 1
for i in range(int(a[0])):
  if int(a[1])-int(a[2])+mem[i] < 1:
    print("No")
  else:
    print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
def minus(a):
  return a-1

a = input().split(" ")
mem = [int(a[1])] * int(a[0])
for i in range(int(a[2])):
  mem[int(input())-1] += 1
  mem = list(map(minus, mem))
for i in mem:
  if i < 1:
    print("No")
  else:
    print("Yes")

Fixed submission:
a = input().split(" ")
mem = [0] * int(a[0])
for i in range(int(a[2])):
  mem[int(input())-1] += 1
for i in range(int(a[0])):
  if int(a[1])-int(a[2])+mem[i] < 1:
    print("No")
  else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
a = input().split()
ans = []
for i in a:
  if a == "1":
    ans.append("9")
  elif a == "9":
    ans.append("1")
  else:
    ans.append(a)
print("".join(ans))

Fixed submission:
a = list(input())
ans = []
for i in a:
  if i == "1":
    ans.append("9")
  elif i == "9":
    ans.append("1")
  else:
    ans.append(i)
print(''.join(ans))

Buggy python submission (verdict: Runtime Error):
a = input().split()
ans = []
for i in a:
  if a == "1":
    ans.append("9")
  elif a == "9":
    ans.append("1")
  else:
    ans.append(a)
print(ans.join())

Fixed submission:
a = list(input())
ans = []
for i in a:
  if i == "1":
    ans.append("9")
  elif i == "9":
    ans.append("1")
  else:
    ans.append(i)
print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
a = list(input().split(" "))
b = list(input().split(" "))
oyu = []
for i in b:
    oyu[int(i):int(i)+int(a[1])] = [1] * int(a[1])
sum(oyu)

Fixed submission:
a = list(input().split(" "))
b = list(input().split(" "))
t = 0
for k, i in enumerate(b):
    if k < len(b)-1:
        if int(i)+int(a[1]) > int(b[k+1]):
            t += int(b[k+1]) - int(b[k])
        else:
            t += int(a[1])
    else:
        t += int(a[1])
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
from random import randint

D = int(input())
cl = list(map(int, input().split()))
sl = [list(map(int, input().split())) for _ in range(D)]

def score(d, ti, last):
    s = sl[d-1][ti]
    for i in range(len(cl)):
        c = cl[i]
        s -= c*(d-last[i])
    return s

def scores(tl):
    s = 0
    last = [0]*26
    for d in range(D):
        t = tl[d] - 1
        last[t] = d+1
        s += score(d+1,t,last)
    return s


tl = [randint(1,26) for _ in range(D)]
s = scores(tl)
for _ in range(100000):
    d = randint(1,D)
    q = randint(1,26)
    x = tl[d-1]
    tl[d-1] = q
    s2 = scores(tl)
    if s2>s:
        s = s2
    else:
        tl[d-1] = x


for t in tl:
    print(t)



Fixed submission:
D = int(input())
cl = list(map(int, input().split()))
sl = [list(map(int, input().split())) for _ in range(D)]

def score(d, ti, last):
    s = sl[d-1][ti]
    for i in range(len(cl)):
        c = cl[i]
        s -= c*(d-last[i])
    return s

res = []
last = [0]*26
for d in range(D):
    ti = 0
    s = 0
    for t in range(26):
        l = last[t]
        last[t] = d+1
        ss = score(d+1,t,last)
        if ss>s:
            s = ss
            ti = t
        last[t] = l
    last[ti] = d+1
    res.append(ti+1)

for t in res:
    print(t)
Buggy python submission (verdict: Time Limit Exceeded):
class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

mod = 10**9 + 7
k = int(input())
s = input()
n = len(s)

b = BiCoeff(n+k+10,mod)
res = 0
for i in range(n,k+n+1):
    res += b.calc(n+k,i)*pow(25,n+k-i,mod)
    res %= mod
print(res)

Fixed submission:
class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

mod = 10**9 + 7
k = int(input())
s = input()
n = len(s)

b = BiCoeff(n+k+10,mod)
res = 0
for i in range(n,k+n+1):
    res += b.calc(n+k,i)*pow(25,n+k-i,mod)
    res %= mod
print(res)
Buggy python submission (verdict: Runtime Error):
from numba import njit
@njit()
def check(s, a, next):
    if a==next:
        return False
    x = 1
    while a>=x*x:
        if a%x==0:
            if x in s:
                return False
            if a//x in s:
                return False
        x += 1
    return True

n = int(input())
al = list(map(int, input().split()))
al.sort()

s = set()
res = 0
for i in range(n):
    a = al[i]
    next = -1
    if i<n-1:
        next = al[i+1]
    if check(s,a,next):
        res += 1
    s.add(a)
print(res)



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

cnt = [0]*(10**6+10)
for a in al:
    if cnt[a]>1:
        continue
    for i in range(0,10**6+10,a):
        cnt[i] += 1

res = 0
for a in al:
    if cnt[a]==1:
        res += 1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
def check(s, a, next):
    if a==next:
        return False
    x = 1
    while a>=x*x:
        if a%x==0:
            if x in s:
                return False
            if a//x in s:
                return False
        x += 1
    return True

n = int(input())
al = list(map(int, input().split()))
al.sort()

s = set()
res = 0
for i in range(n):
    a = al[i]
    next = -1
    if i<n-1:
        next = al[i+1]
    if check(s,a,next):
        res += 1
    s.add(a)
print(res)



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

cnt = [0]*(10**6+10)
for a in al:
    if cnt[a]>1:
        continue
    for i in range(0,10**6+10,a):
        cnt[i] += 1

res = 0
for a in al:
    if cnt[a]==1:
        res += 1
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353

n,s = map(int, input().split())
al = list(map(int, input().split()))

dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    a = al[i]
    for j in range(s+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

        if j+a<=s:
            dp[i+1][j+a] += dp[i][j]
            dp[i+1][j+a] %= mod

print(dp[n][s])

Fixed submission:
mod = 998244353

n,s = map(int, input().split())
al = list(map(int, input().split()))

dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    a = al[i]
    for j in range(s+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

        if j+a<=s:
            dp[i+1][j+a] += dp[i][j]
            dp[i+1][j+a] %= mod

print(dp[n][s])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
al = list(map(int, input().split()))

next = [[0]*n for _ in range(60)]
for i in range(n):
    next[0][i] = al[i]-1

for p in range(1,60):
    for i in range(n):
        next[p][i] = next[p-1][next[p-1][i]]

res = 0
for p in range(59,-1,-1):
    if (k>>p)&1 == 1:
        res = next[p][res]

print(res+1)

Fixed submission:
n,k = map(int, input().split())
al = [0]+list(map(int, input().split()))

s = 1
visited = [0]*(n+1)
cnt = 0
for i in range(k):
    s = al[s]
    cnt += 1
    if visited[s]>0:
        r = k - cnt
        l = cnt - visited[s]
        for _ in range(r%l):
            s = al[s]
        break
    else:
        visited[s] = cnt
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
s = input()
n = len(s)

d = defaultdict(int)
d[0] = 1
for i in range(n):
    x = int(s[i:])
    d[x%2019] += 1

res = 0
for k in d:
    c = d[k]
    res += c*(c-1)//2
print(res)


Fixed submission:
P = 2019
S = input()
N = len(S)
 
if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()
 
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1
 
print(ans)