Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
INF=10**9+7
def modcomb(n,k,m):
    fac=[0]*(n+1)
    finv=[0]*(n+1)
    inv=[0]*(n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,n+1):
        fac[i]=fac[i-1]*i%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m
for i in range(1,k+1):
    if n-k>=i-1:
        a=modcomb(k-1,i-1,INF)
        b=modcomb(n-k+1,i,INF)
        ans=(a*b)%INF
        print(ans)
    else:
        print(0)


Fixed submission:
n,k=map(int,input().split())
INF=10**9+7
def modcomb(n,k,m):
    fac=[0]*(n+1)
    finv=[0]*(n+1)
    inv=[0]*(n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,n+1):
        fac[i]=fac[i-1]*i%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m
for i in range(1,k+1):
    if n-k>=i-1:
        if k-1==0 and i-1==0:
            a=1
        else:
            a=modcomb(k-1,i-1,INF)
        if n-k+1==0 and i==0:
            b=1
        else:
            b=modcomb(n-k+1,i,INF)
        ans=(a*b)%INF
        print(ans)
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
n=int(input())
point=[]
answer=[]
already=[]
for i in range(n):
    point.append([])
    answer.append(0)
    already.append(0)
for i in range(n-1):
    u,v,w=map(int,input().split())
    point[u-1].append((v-1,w))
    point[v-1].append((u-1,w))
def dfs(now,c):
    answer[now]=c
    already[now]=1
    for i in point[now]:
        if already[i[0]]==1:
            pass
        else:
            if i[1]%2==0:
                dfs(i[0],c)
            else:
                if c==0:
                    dfs(i[0],1)
                else:
                    dfs(i[0],0)
dfs(0,0)
for i in answer:
    print(i)
            


        


Fixed submission:
import sys
sys.setrecursionlimit(100002)
n=int(input())
point=[]
answer=[]
already=[]
for i in range(n):
    point.append([])
    answer.append(0)
    already.append(0)
for i in range(n-1):
    u,v,w=map(int,input().split())
    point[u-1].append((v-1,w))
    point[v-1].append((u-1,w))
def dfs(now,c):
    answer[now]=c
    already[now]=1
    for i in point[now]:
        if already[i[0]]==1:
            pass
        else:
            if i[1]%2==0:
                dfs(i[0],c)
            else:
                if c==0:
                    dfs(i[0],1)
                else:
                    dfs(i[0],0)
dfs(0,0)
for i in answer:
    print(i)
Buggy python submission (verdict: Runtime Error):
s=input()
s_list=[]
length=0
for i in s:
    if i=='A' or i=='T' or i=='C' or i=='G':
        length=length+1
    else:
        s_list.append(length)
        length=0
print(max(s_list))


Fixed submission:
s=input()
s_list=[]
length=0
for i in s:
    if i=='A' or i=='T' or i=='C' or i=='G':
        length=length+1
    else:
        s_list.append(length)
        length=0
s_list.append(length)
print(max(s_list))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
dict_ab={}
for i in range(0,n):
    a,b=map(int,input().split())
    dict_ab[a]=b
list_ab=sorted(dict_ab.items())
cost=0
for i in range(0,n):
    a=list_ab[i][0]
    b=list_ab[i][1]
    if m<=b:
        cost=cost+a*m
        break
    else:
        cost=cost+a*b
        m=m-b
print(cost)



Fixed submission:
n,m=map(int,input().split())
list_ab=[]
for i in range(0,n):
    a,b=map(int,input().split())
    list_ab.append((a,b))
list_ab=sorted(list_ab)
cost=0
for i in range(0,n):
    a=list_ab[i][0]
    b=list_ab[i][1]
    if m<=b:
        cost=cost+a*m
        break
    else:
        cost=cost+a*b
        m=m-b
print(cost)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a_list=list(map(int,input().split()))
import math
answer=a_list[0]
for i in range(1,n):
    answer=math.gcd(answer,a_list[i])
print(answer)


Fixed submission:
n=int(input())
a_list=list(map(int,input().split()))
import fractions
answer=a_list[0]
for i in range(1,n):
    answer=fractions.gcd(answer,a_list[i])
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
import math
sosuu=[]
m0=m
i=2
while i**2<=m:
    if m0%i==0:
        sosuu.append(0)
    while m0%i==0:  
        m0=m0//i
        sosuu[-1]=sosuu[-1]+1
    i=i+1
if m0>1:
    sosuu.append(1)
def c(n,r):
    return math.factorial(n)//(math.factorial(r)*math.factorial(n-r))
answer=1
for i in sosuu:
    a=c(i+n-1,i)
    answer=(answer*a)%(10**9+7)
print(answer)



Fixed submission:
n,M=map(int,input().split())
from math import factorial
i=2
c_list=[]
m=M
while not m==1:
    count=0
    while m%i==0:
        m=m//i
        count=count+1
    if not count==0:
        c_list.append(count)
    i=i+1
if M==1:
    print(1)
else:
    INF=10**9+7
    Sum=1
    for i in c_list:
        Sum=Sum*(factorial(n-1+i)//(factorial(n-1)*factorial(i)))
        Sum=Sum%INF
    print(Sum)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
n,m=map(int,input().split())
divisors=[]
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        divisors.append(i)
        if not i**2==m:
            divisors.append(m//i)
divisors.sort()
dp={}
def f(i,l):
    if (i,l) in dp:
        return dp[(i,l)]
    else:
        if i==n:
            if l==1:
                return 1
            else:
                return 0
        else:
            Sum=0
            for j in divisors:
                if j>l:
                    break
                else:
                    if l%j==0:
                        Sum=Sum+f(i+1,l//j)
            Sum=Sum%(10**9+7)
            dp[(i,l)]=Sum
            return Sum
print(f(0,m))


Fixed submission:
n,M=map(int,input().split())
from math import factorial
i=2
c_list=[]
m=M
while not m==1:
    count=0
    while m%i==0:
        m=m//i
        count=count+1
    if not count==0:
        c_list.append(count)
    i=i+1
if M==1:
    print(1)
else:
    INF=10**9+7
    Sum=1
    for i in c_list:
        Sum=Sum*(factorial(n-1+i)//(factorial(n-1)*factorial(i)))
        Sum=Sum%INF
    print(Sum)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
x_list=list(map(int,input().split()))
d_list=[]
for i in x_list:
    d_list.append(abs(x-i))
import fractions
answer=fractions.gcd(d_list[0],d_list[1])
for i in range(2,n):
    answer=fractions.gcd(answer,d_list[i])
print(answer)


Fixed submission:
n,x=map(int,input().split())
x_list=list(map(int,input().split()))
d_list=[]
for i in x_list:
    d_list.append(abs(x-i))
import fractions
if n==1:
    answer=d_list[0]
else:
    answer=fractions.gcd(d_list[0],d_list[1])
    for i in range(2,n):
        answer=fractions.gcd(answer,d_list[i])
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
d,g=map(int,input().split())
g=g//100
p_list=[0]
c_list=[0]
for i in range(d):
    p,c=map(int,input().split())
    p_list.append(p)
    c_list.append(c//100)
dp=[]
for i in range(d+1):
    sub_list=[]
    for j in range(g+1):
        sub_list.append(10**9)
    dp.append(sub_list)
dp[0][0]=0
for i in range(1,d+1):
    for j in range(g+1):
        for k in range(p_list[i]+1):
            if k==p_list[i]:
                if j-i*k-c_list[i]>=0:
                    dp[i][j]=min(dp[i][j],dp[i-1][j-i*k-c_list[i]]+k)
                else:
                    dp[i][j]=min(dp[i][j],dp[i-1][0]+k)
            else:
                if j-i*k>=0:
                    dp[i][j]=min(dp[i][j],dp[i-1][j-i*k]+k)
                else:
                    dp[i][j]=min(dp[i][j],dp[i-1][0]+k)
print(dp[d][g])


Fixed submission:
d,g=map(int,input().split())
g=g//100
p_list=[]
c_list=[]
s_list=[]
for i in range(d):
    p,c=map(int,input().split())
    c=c//100
    p_list.append(p)
    c_list.append(c)
    s_list.append(p*(i+1)+c)
Min=1000
for i in range(2**d):
    Sum=0
    Num=0
    for j in range(d):
        if (i>>j)&1==1:
            Sum=Sum+s_list[j]
            Num=Num+p_list[j]
        else:
            M=j
    if Sum>=g:
        if Num<Min:
            Min=Num
    else:
        r=((g-Sum)+M)//(M+1)
        if r<=p_list[M]:
            Num=Num+r
            if Num<Min:
                Min=Num
print(Min)

Buggy python submission (verdict: Time Limit Exceeded):
d,g=map(int,input().split())
g=g//100
p_list=[0]
c_list=[0]
for i in range(d):
    p,c=map(int,input().split())
    p_list.append(p)
    c_list.append(c//100)
dp=[]
for i in range(d+1):
    sub_list=[]
    for j in range(g+1):
        sub_list.append(10**9)
    dp.append(sub_list)
dp[0][0]=0
for i in range(1,d+1):
    for j in range(g+1):
        for k in range(p_list[i]+1):
            if k==p_list[i]:
                if j-i*k-c_list[i]>=0:
                    dp[i][j]=min(dp[i][j],dp[i-1][j-i*k-c_list[i]]+k)
                else:
                    dp[i][j]=min(dp[i][j],dp[i-1][0]+k)
            else:
                if j-i*k>=0:
                    dp[i][j]=min(dp[i][j],dp[i-1][j-i*k]+k)
                else:
                    dp[i][j]=min(dp[i][j],dp[i-1][0]+k)
print(dp[d][g])


Fixed submission:
d,g=map(int,input().split())
g=g//100
p_list=[]
c_list=[]
s_list=[]
for i in range(d):
    p,c=map(int,input().split())
    c=c//100
    p_list.append(p)
    c_list.append(c)
    s_list.append(p*(i+1)+c)
Min=1000
for i in range(2**d):
    Sum=0
    Num=0
    for j in range(d):
        if (i>>j)&1==1:
            Sum=Sum+s_list[j]
            Num=Num+p_list[j]
        else:
            M=j
    if Sum>=g:
        if Num<Min:
            Min=Num
    else:
        r=((g-Sum)+M)//(M+1)
        if r<=p_list[M]:
            Num=Num+r
            if Num<Min:
                Min=Num
print(Min)
Buggy python submission (verdict: Runtime Error):
s=input()
x,y=map(int,input().split())
h=[]
v=[]
num=0
m=1
for i in s:
    if i=='F':
        num+=1
    else:
        if num!=0:
            if m==1:
                h.append(num)
            else:
                v.append(num)
        m=-m
        num=0
if num!=0:
    if m==1:
        h.append(num)
    else:
        v.append(num)
if s[0]=='F':
    x=x-h[0]
    del h[0]
sumh=sum(h)
nh=len(h)
dph=[]
if nh!=0:
    for i in range(nh+1):
        sub_list=[False]*(1+2*sumh)
        dph.append(sub_list)
    dph[0][sumh]=True
    for i in range(1,nh+1):
        for j in range(1+2*sumh):
            if j-h[i-1]>=0:
                dph[i][j]=dph[i][j] or dph[i-1][j-h[i-1]]
            if j+h[i-1]<=2*sumh:
                dph[i][j]=dph[i][j] or dph[i-1][j+h[i-1]]
    sh=dph[nh][x+sumh]
else:
    if x==0:
        sh=True
    else:
        sh=False
sumv=sum(v)
nv=len(v)
dpv=[]
if nv!=0:
    for i in range(nv+1):
        sub_list=[False]*(1+2*sumv)
        dpv.append(sub_list)
    dpv[0][sumv]=True
    for i in range(1,nv+1):
        for j in range(1+2*sumv):
            if j-v[i-1]>=0:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j-v[i-1]]
            if j+v[i-1]<=2*sumv:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j+v[i-1]]
    sv=dpv[nv][y+sumv]
else:
    if y==0:
        sv=True
    else:
        sv=False
if sh and sv:
    print('Yes')
else:
    print('No')


Fixed submission:
s=input()
x,y=map(int,input().split())
h=[]
v=[]
num=0
m=1
for i in s:
    if i=='F':
        num+=1
    else:
        if num!=0:
            if m==1:
                h.append(num)
            else:
                v.append(num)
        m=-m
        num=0
if num!=0:
    if m==1:
        h.append(num)
    else:
        v.append(num)
if s[0]=='F':
    x=x-h[0]
    del h[0]
sumh=sum(h)
nh=len(h)
dph=[]
if nh!=0:
    for i in range(nh+1):
        sub_list=[False]*(1+2*sumh)
        dph.append(sub_list)
    dph[0][sumh]=True
    for i in range(1,nh+1):
        for j in range(1+2*sumh):
            if j-h[i-1]>=0:
                dph[i][j]=dph[i][j] or dph[i-1][j-h[i-1]]
            if j+h[i-1]<=2*sumh:
                dph[i][j]=dph[i][j] or dph[i-1][j+h[i-1]]
    if 0<=x+sumh<=2*sumh:
        sh=dph[nh][x+sumh]
    else:
        sh=False
else:
    if x==0:
        sh=True
    else:
        sh=False
sumv=sum(v)
nv=len(v)
dpv=[]
if nv!=0:
    for i in range(nv+1):
        sub_list=[False]*(1+2*sumv)
        dpv.append(sub_list)
    dpv[0][sumv]=True
    for i in range(1,nv+1):
        for j in range(1+2*sumv):
            if j-v[i-1]>=0:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j-v[i-1]]
            if j+v[i-1]<=2*sumv:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j+v[i-1]]
    if 0<=y+sumv<=2*sumv:
        sv=dpv[nv][y+sumv]
    else:
        sv=False
else:
    if y==0:
        sv=True
    else:
        sv=False
if sh and sv:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)!=[]:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])



Fixed submission:
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])

Buggy python submission (verdict: Runtime Error):
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
import deque
stack=deque(stack)
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])



Fixed submission:
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind:
    def __init__(self, n):
        self.par = [-1]*(n+1)
        self.sizes=[1]*(n+1)

    # 検索
    def find(self, x):
        if self.par[x]<0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        d1=self.par[x]
        d2=self.par[y]
        if d1<=d2:
            self.par[y]=x
            self.sizes[x]=self.sizes[x]+self.sizes[y]
            if d1==d2:
                self.par[x]=self.par[x]-1
        else:
            self.par[x]=y
            self.sizes[y]=self.sizes[x]+self.sizes[y]

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
import sys
input=sys.stdin.readline
n=int(input())
pointx=[]
pointy=[]
for i in range(n):
    x,y=map(int,input().split())
    pointx.append((x,i))
    pointy.append((y,i))
pointx.sort()
pointy.sort()
E=[]
for i in range(n-1):
    dx=abs(pointx[i+1][0]-pointx[i][0])
    E.append((dx,pointx[i][1],pointx[i+1][1]))
    dy=abs(pointy[i+1][0]-pointy[i][0])
    E.append((dy,pointy[i][1],pointy[i+1][1]))
E.sort()
U=UnionFind(n)
ans=0
count=0
for i in range(len(E)):
    if not U.same_check(E[i][1],E[i][2]):
        ans+=E[i][0]
        count+=1
        U.union(E[i][1],E[i][2])
        if count==n-1:
            break
print(ans)

        





Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
pointx=[]
pointy=[]
for i in range(n):
    x,y=map(int,input().split())
    pointx.append((x,i))
    pointy.append((y,i))
pointx.sort()
pointy.sort()
G=[[] for i in range(n)]
for i in range(n-1):
    dx=abs(pointx[i+1][0]-pointx[i][0])
    G[pointx[i][1]].append((dx,pointx[i+1][1]))
    G[pointx[i+1][1]].append((dx,pointx[i][1]))
    dy=abs(pointy[i+1][0]-pointy[i][0])
    G[pointy[i][1]].append((dy,pointy[i+1][1]))
    G[pointy[i+1][1]].append((dy,pointy[i][1]))
import heapq
q=[]
check=[False]*n
check[0]=True
for i in G[0]:
    heapq.heappush(q,i)
ans=0
while len(q)>0:
    now=heapq.heappop(q)
    if not check[now[1]]:
        ans+=now[0]
        check[now[1]]=True
        for i in G[now[1]]:
            heapq.heappush(q,i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n=int(input())
s=input().rstrip()
start=['SS','SW','WS','WW']
import sys
for k in range(4):
    ans=start[k]
    for i in range(2,n):
        if (ans[i-2:i]=='SS' and s[i-1]=='o') or (ans[i-2:i]=='SW' and s[i-1]=='x') or (ans[i-2:i]=='WS' and s[i-1]=='x') or (ans[i-2:i]=='WW' and s[i-1]=='o'):
            ans=ans+'S'
        else:
            ans=ans+'W'
    if (s[0]=='o' and ans[0]=='S') or (s[0]=='x' and ans[0]=='W'):
        if ans[1]==ans[n-1]:
            pass
        else:
            continue
    else:
        if ans[1]==ans[n-1]:
            continue
    if (s[n-1]=='o' and ans[n-1]=='S') or (s[n-1]=='x' and ans[n-1]=='W'):
        if ans[0]==ans[n-2]:
            pass
        else:
            continue
    else:
        if ans[0]==ans[n-2]:
            continue
    print(ans)
    sys.exit()
print(-1)
    




Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
s=input().rstrip()
start=['SS','SW','WS','WW']
import sys
for k in start:
    ans=[k[0],k[1]]
    for i in range(2,n):
        if (ans[i-2]=='S' and ans[i-1]=='S' and s[i-1]=='o') or (ans[i-2]=='S' and ans[i-1]=='W' and s[i-1]=='x') or (ans[i-2]=='W' and ans[i-1]=='S' and s[i-1]=='x') or (ans[i-2]=='W' and ans[i-1]=='W' and s[i-1]=='o'):
            ans.append('S')
        else:
            ans.append('W')
    if (s[0]=='o' and ans[0]=='S') or (s[0]=='x' and ans[0]=='W'):
        if ans[1]==ans[n-1]:
            pass
        else:
            continue
    else:
        if ans[1]==ans[n-1]:
            continue
    if (s[n-1]=='o' and ans[n-1]=='S') or (s[n-1]=='x' and ans[n-1]=='W'):
        if ans[0]==ans[n-2]:
            pass
        else:
            continue
    else:
        if ans[0]==ans[n-2]:
            continue
    for i in ans:
        print(i,end='')
    sys.exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)


Fixed submission:
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
import sys
import math
from scipy.special import comb

mod = 10 ** 9 + 7

N = int(input())

if N <= 1:
    print(0)
    sys.exit()

# ans = comb(N, 2, exact=True) * 2 * (8 ** (N - 2)) + (9 ** N - 8 ** N) * 2
ans = 10 ** N - 8 ** N - (9 ** N - 8 ** N) * 2
print(ans % mod)



Fixed submission:
import sys
import math

mod = 10 ** 9 + 7

N = int(input())

if N <= 1:
    print(0)
    sys.exit()

# ans = comb(N, 2, exact=True) * 2 * (8 ** (N - 2)) + (9 ** N - 8 ** N) * 2
ans = 10 ** N - 8 ** N - (9 ** N - 8 ** N) * 2
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
A = sorted(A)

maxA = A[-1]
halfA = maxA // 2

ans = [False] * maxA
for a in A:
    if A.count(a) > 1:
        continue
    ans[a - 1] = True

for i in A:
    if i > halfA:
        break
    j = i + i
    while j <= maxA:
        ans[j - 1] = False
        j += i

print(sum(ans))



Fixed submission:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
A = sorted(A)

maxA = A[-1]
halfA = maxA // 2

ans = [False] * maxA
for i in range(N):
    if i != N - 1 and A[i + 1] == A[i]:
        continue
    if i != 0 and A[i - 1] == A[i]:
        continue
    ans[A[i] - 1] = True

for i in A:
    if i > halfA:
        break
    j = i + i
    while j <= maxA:
        ans[j - 1] = False
        j += i

print(sum(ans))
Buggy python submission (verdict: Runtime Error):
import sys

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

town_line = []
town_set = set()
last_town = None


def search(town=0):
    global last_town
    if town not in town_set:
        town_line.append(town)
        town_set.add(town)
        search(town=A[town]-1)
    else:
        last_town = town
        return


search(0)
town_loop = town_line[town_line.index(last_town):]

if K < len(town_line):
    print(town_line[K] + 1)
else:
    k = K - len(town_line) + 1
    k = k % len(town_loop)
    print(town_loop[k - 1] + 1)


Fixed submission:
import sys
sys.setrecursionlimit(2 * 10 ** 5)

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

town_line = []
town_set = set()
last_town = None


def search(town=0):
    global last_town
    if town not in town_set:
        town_line.append(town)
        town_set.add(town)
        search(town=A[town]-1)
    else:
        last_town = town
        return


search(0)
town_loop = town_line[town_line.index(last_town):]

if K < len(town_line):
    print(town_line[K] + 1)
else:
    k = K - len(town_line) + 1
    k = k % len(town_loop)
    print(town_loop[k - 1] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))

for i in range(N):
    index = A.index(i + 1)
    print(index + 1, end='')
    if i != N - 1:
        print(' ', end='')

Fixed submission:
import sys
N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))


school = [0] * N
j = 1
for i in A:
    school[i - 1] = j
    j += 1

print(' '.join(map(str, school)))