Problem p02642 (python)

Fixed submission:
import collections

def main():
    N  = int(input()) 
    A=list(map(int, input().split()))
    C = collections.Counter(A)
    B = list(set(A))
    B.sort()
    lenb = len(B)
    Boo = [True]*lenb
    ZENBU = [False]*(10**6+4)

    if C[1]>1:
        print(0)
        return
    if C[1]==1:
        print(1)
        return

    for i in range(lenb):
        temp = 2
        if ZENBU[B[i]]==False:
            while B[i]*temp < 1000002:
                ZENBU[B[i]*temp] = True
                temp+=1

    cnt = 0
    for i in range(lenb):
        if ZENBU[B[i]]==False and C[B[i]]==1:
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N  = int(input()) 
    A=list(map(int, input().split()))
    B = list(set(A))
    B.sort()
    lenb = len(B)
    Boo = [True]*lenb
    _,s = sieve((10**6)+7)

    zero =  A.count(1)
    if zero>1:
        print(0)
        return
    if zero==1:
        print(1)
        return

    for i in range(lenb):
        for j in range(i+1,lenb):
            if Boo[j] and s[B[j]] and B[j] % B[i] == 0:
                Boo[j] = False

    cnt = 0
    for i in range(lenb):
        if Boo[i] and A.count(B[i])==1:
            cnt += 1

    print(cnt)


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N  = int(input()) 
    A=list(map(int, input().split()))
    B = list(set(A))
    B.sort()
    Boo = [True]*len(B)
    _,s = sieve((10**6)+7)

    zero =  A.count(1)
    if A.count(1)>1:
        print(0)
        return
    if A.count(1)==1:
        print(1)
        return

    for i in range(len(B)):
        for j in range(i+1,len(B)):
            if Boo[j] and s[j] and B[j] % B[i] == 0:
                Boo[j] = False

    cnt = 0
    for i in range(len(B)):
        if Boo[i] and A.count(B[i])==1:
            cnt += 1

    print(cnt)


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N  = int(input()) 
    A=list(map(int, input().split()))
    B = list(set(A))
    B.sort()
    Boo = [True]*len(B)
    _,s = sieve((2*10**5)+7)

    zero =  A.count(1)
    if A.count(1)>1:
        print(0)
        return
    if A.count(1)==1:
        print(1)
        return

    for i in range(len(B)):
        for j in range(i+1,len(B)):
            if Boo[j] and s[j] and B[j] % B[i] == 0:
                Boo[j] = False

    cnt = 0
    for i in range(len(B)):
        if Boo[i] and A.count(B[i])==1:
            cnt += 1

    print(cnt)


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N  = int(input()) 
    A=list(map(int, input().split()))
    B = list(set(A))
    _ ,s = sieve(10**6+5)
    B.sort(reverse=True)
    cnt = 0

    if A.count(1)>1:
        print(0)
        return
    elif A.count(1)==1:
        print(1)
        return


    for i in range(len(B)):
        if A.count(B[i])>1:
            continue
        if s[B[i]]==False:
            cnt += 1
            continue

        Flag = True
        for j in range(i+1,len(B)):
            if B[i] % B[j] == 0:
                Flag = False
                break
        if Flag:
            cnt += 1
    
    print(cnt)


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N  = int(input()) 
    A=list(map(int, input().split()))
    B = list(set(A))
    _ ,s = sieve(10**6+5)
    B.sort(reverse=True)
    cnt = 0

    if A.count(1)>1:
        print(0)
    elif A.count(1)==1:
        print(1)


    for i in range(len(B)):
        if A.count(B[i])>1:
            continue
        if s[B[i]]==False:
            cnt += 1
            continue

        Flag = True
        for j in range(i+1,len(B)):
            if B[i] % B[j] == 0:
                Flag = False
                break
        if Flag:
            cnt += 1
    
    print(cnt)


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table



if __name__ == '__main__':
    main()