Problem p02642 (python)

Fixed submission:
#!python3.8
# -*- coding: utf-8 -*-
# abc170/abc170_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = sorted(int(c) for c in i2s().split(' '))
    max_ = A[-1]
    B = {}
    if N == 1:
        print(1)
        return
    for i in range(0, N):
        if i == 0:
            if A[i + 1] == A[i]:
                B[A[i]] = 2
                continue
        elif i == N - 1:
            if A[i - 1] == A[i]:
                B[A[i]] = 2
                continue
        elif A[i - 1] == A[i] or A[i + 1] == A[i]:
            B[A[i]] = 2
            continue
        B[A[i]] = 1
    # print(*B.items())
    for b in B:
        if B[b] == 0:
            continue
        if B[b] == 2:
            B[b] = 0
        for i in range(2, max_ // b + 1):
            if b * i in B:
                B[b * i] = 0
                # print(b * i)
    res = 0
    for v in B.values():
        if v:
            res += 1
    # print(*B.items())
    print(res)
    return

main()

Buggy submission (verdict: Runtime Error):
#!python3.8
# -*- coding: utf-8 -*-
# abc170/abc170_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = sorted(int(c) for c in i2s().split(' '))
    max_ = A[-1]
    B = {}
    if N == 1:
        print(1)
        return
    if A[0] == A[1]:
        B[A[i]] = 2
    else:
        B[A[i]] = 1
    for i in range(1, N - 1):
        if A[i-1] == A[i] or A[i+1] == A[i]:
            B[A[i]] = 2
        else:
            B[A[i]] = 1
    if A[-2] == A[-1]:
        B[A[i]] = 2
    else:
        B[A[i]] = 1
    for b in B:
        if B[b] == 0:
            continue
        if B[b] == 2:
            B[b] = 0
        for i in range(2, max_ // b + 1):
            if b * i in B:
                B[b * i] = 0
    res = 0
    for v in B.values():
        if v:
            res += 1
    print(res)
    return

main()

Buggy submission (verdict: Runtime Error):
#!python3.8
# -*- coding: utf-8 -*-
# abc170/abc170_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = sorted(int(c) for c in i2s().split(' '))
    max_ = A[-1]
    B = {}
    for i in range(N):
        if i == 0:
            if A[i] == A[i+1]:
                continue
        elif i == N - 1:
            if A[i] == A[i-1]:
                continue
        elif A[i-1] == A[i] or A[i+1] == A[i]:
            continue
        B[A[i]] = True
    for b in B:
        if not B[b]:
            continue
        for i in range(2, max_ // b + 1):
            if b * i in B:
                B[b * i] = False
    res = 0
    for v in B.values():
        if v:
            res += 1
    print(res)
    return

main()