Buggy python submission (verdict: Runtime Error):
def primes(n):
    is_prime = [i % 2 != 0 and i % 3 != 0 and i % 5 != 0 and i % 7 != 0 for i in range(n + 1)]
    is_prime[1] = False
    is_prime[2] = is_prime[3] = is_prime[5] = is_prime[7] = True
    for p in range(3, int(n**0.5) + 1, 2):
        if not is_prime[p]:
            continue
        for i in range(p**2, n + 1, p):
            is_prime[i] = False
    return {i for i, p in enumerate(is_prime) if p}


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    if a[0] == 1:
        print(n - 1 + (a[1] == 1))
        return
    p = primes(10**6)
    b = set()
    c = 0
    for i in range(n):
        if i < n - 1 and a[i] == a[i + 1] or i > 0 and a[i] == a[i - 1]:
            b.add(a[i])
            continue
        if a[i] in p:
            c += 1
            b.add(a[i])
            continue
        for j in range(1, int(a[i]**0.5) + 1):
            if a[i] % j:
                continue
            if j in b or a[i] // j in b:
                break
        else:
            c += 1
            b.add(a[i])
    print(c)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    b = 0
    dp = [True] * (a[-1] + 1)
    for ai in a:
        if not dp[ai]:
            continue
        for j in range(ai * 2, a[-1] + 1, ai):
            dp[j] = False
        if ai == b:
            dp[ai] = False
        b = ai
    print(sum(dp[ai] for ai in a))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def primes(n):
    is_prime = [i % 2 != 0 and i % 3 != 0 and i % 5 != 0 and i % 7 != 0 for i in range(n + 1)]
    is_prime[1] = False
    is_prime[2] = is_prime[3] = is_prime[5] = is_prime[7] = True
    for p in range(3, int(n**0.5) + 1, 2):
        if not is_prime[p]:
            continue
        for i in range(p**2, n + 1, p):
            is_prime[i] = False
    return {i for i, p in enumerate(is_prime) if p}


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    if a[0] == 1:
        print(n - 1 + (a[1] == 1))
        return
    p = primes(10**6)
    b = set()
    c = 0
    for i in range(n):
        if i < n - 1 and a[i] == a[i + 1] or i > 0 and a[i] == a[i - 1]:
            b.add(a[i])
            continue
        if a[i] in p:
            c += 1
            b.add(a[i])
            continue
        for j in range(1, int(a[i]**0.5) + 1):
            if a[i] % j:
                continue
            if j in b or a[i] // j in b:
                break
        else:
            c += 1
            b.add(a[i])
    print(c)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    b = 0
    dp = [True] * (a[-1] + 1)
    for ai in a:
        if not dp[ai]:
            continue
        for j in range(ai * 2, a[-1] + 1, ai):
            dp[j] = False
        if ai == b:
            dp[ai] = False
        b = ai
    print(sum(dp[ai] for ai in a))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    b = set()
    c = 0
    for i in range(n):
        if i < n - 1 and a[i] == a[i + 1]:
            b.add(a[i])
            continue
        for j in range(1, int(a[i]**0.5) + 1):
            if a[i] % j:
                continue
            if j in b or a[i] // j in b:
                break
        else:
            c += 1
            b.add(a[i])
    print(c)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    b = 0
    dp = [True] * (a[-1] + 1)
    for ai in a:
        if not dp[ai]:
            continue
        for j in range(ai * 2, a[-1] + 1, ai):
            dp[j] = False
        if ai == b:
            dp[ai] = False
        b = ai
    print(sum(dp[ai] for ai in a))


if __name__ == '__main__':
    main()