Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from bisect import *
from heapq import *
up=2*10**5
maxi=10**10
kind=[heapify([]) for i in range(up)]

class segtree:
    x_unit=maxi # 要素として入れられる最大値
    x_func=min
    def __init__(self,n):
        self.n=n
        self.x=[self.x_unit]*(2*n)
    def build(self, seq):
        for i,j in enumerate(seq, start=self.n):  # n番目からseqをx配列に移していく
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = self.x_func(self.x[i*2], self.x[i*2+1])
            # セグ木トーナメント表の左右を比較
            # 例えばn=8の時、seq[4]はx[12]に、seq[5]はx[13]に入っている
            # さらにx[14]とx[15]の間に来るのはx[7]、x[12]とx[13]の間に来るのはx[6]
            # x_funcに従って値を取得
    def set_val(self,i,j): # 1点更新
        i += self.n
        self.x[i]=j
        while i>1:
            i//=2 # 更新後、木の上へと登っていくついでに更新
            self.x[i]=self.x_func(self.x[i*2], self.x[i*2+1])
    def fold(self,l,r): # 区間[l, r)の最小値などを取得 
        l+=self.n
        r+=self.n
        val_l=self.x_unit
        val_r=self.x_unit
        while l<r:
            if l & 1: # lが奇数
                val_l=self.x_func(val_l,self.x[l])
                l+=1 # 偶数に調節
            if r & 1: # rが奇数
                r-=1 # 開区間なので1個前は偶数番目の要素
                val_r=self.x_func(val_r,self.x[r])
            l //= 2
            r //= 2
        return self.x_func(val_l,val_r)

n,q=map(int, input().split())
shozoku=[-1]*n
rating=[0]*n
for i in range(n):
    a,b=map(int, input().split())
    heappush(kind[b-1],a)
    shozoku[i]=b-1
    rating[i]=a
#print(kind)
seg=segtree(up)
root=[maxi for i in range(up)]

for i in range(up):
    if kind[i]!=[]:
        rate=kind[i][-1]
        root[i]=rate
seg.build(root)

for i in range(q):
    c,d=map(int, input().split())
    c-=1
    d-=1
    if rating[c]==kind[shozoku[c]][-1] and len(kind[shozoku[c]])==1:
        kind[shozoku[c]]=heapify([])
        seg.set_val(shozoku[c], 2<<30)
    elif rating[c]==kind[shozoku[c]][-1]:
        kind[shozoku[c]]=kind[shozoku[c]][:-1]
        seg.set_val(shozoku[c], kind[shozoku[c]][-1])
    else:
        ind=bisect_right(kind[shozoku[c]],rating[c])
        kind[shozoku[c]]=kind[shozoku[c]][:ind-1]+kind[shozoku[c]][ind:]
    heappush(kind[d], rating[c])
    seg.set_val(d, kind[d][-1])
    shozoku[c]=d
    print(seg.x[1])


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A=sorted(A)
up=max(A)
table=[0]*(up+1)
for i in range(n):
    table[A[i]]+=1
aset=set(A)

for i in range(len(aset)):
    if table[A[i]]>0:
        j=2
        while A[i]*j<up+1:
            if table[A[i]*j]>0:
                table[A[i]*j]=-1
            j+=1

cnt=0
for x in table:
    if x==1:
        cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
A=sorted(A)

table=[0]*(10**6+1)
for i in range(n):
    table[A[i]]+=1

for i in range(n):
    if A[i]>0:
        j=2
        while A[i]*j<10**6+1:
            if table[A[i]*j]>0:
                table[A[i]*j]=-1
            j+=1

cnt=0
for x in table:
    if x==1:
        cnt+=1
print(cnt)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A=sorted(A)
up=max(A)
table=[0]*(up+1)
for i in range(n):
    table[A[i]]+=1
aset=set(A)

for i in range(len(aset)):
    if table[A[i]]>0:
        j=2
        while A[i]*j<up+1:
            if table[A[i]*j]>0:
                table[A[i]*j]=-1
            j+=1

cnt=0
for x in table:
    if x==1:
        cnt+=1
print(cnt)