Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    x, k, d = map(int, input().split())

    for i in range(k):
        if x > 0:
            x -= d
            if x < 0 and (k-1-i)%2 == 0:
                print(abs(x))
                return
            elif x < 0 and (k-1-i)%2 == 1:
                print(abs(x+d))
                return
        else:
            x += d
            if x > 0 and (k-1-i)%2 == 0:
                print(abs(x))
                return
            elif x > 0 and (k-1-i)%2 == 1:
                print(abs(x-d))
                return
    print(abs(x))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    x, k, d = map(int, input().split())
    desired = abs(x) // d
    if k <= desired:
        if x < 0:
            x += k * d
        else:
            x -= k * d
        print(abs(x))
        return
    if x < 0:
        x += desired * d
    else:
        x -= desired * d
    if (k - desired) % 2 == 0:
        print(abs(x))
        return
    if x == 0:
        print(d)
    elif x > 0:
        x -= d
        print(abs(x))
    elif x < 0:
        x += d
        print(abs(x))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    x, k, d = map(int, input().split())

    for i in range(k):
        if x > 0:
            x -= d
            if x < 0 and (k-1-i)%2 == 0:
                print(abs(x))
                return
            elif x < 0 and (k-1-i)%2 == 1:
                print(abs(x+d))
                return
        else:
            x += d
            if x > 0 and (k-1-i)%2 == 0:
                print(abs(x))
                return
            elif x > 0 and (k-1-i)%2 == 1:
                print(abs(x-d))
                return
    print(abs(x))


if __name__ == '__main__':
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    x, k, d = map(int, input().split())
    desired = abs(x) // d
    if k <= desired:
        if x < 0:
            x += k * d
        else:
            x -= k * d
        print(abs(x))
        return
    if x < 0:
        x += desired * d
    else:
        x -= desired * d
    if (k - desired) % 2 == 0:
        print(abs(x))
        return
    if x == 0:
        print(d)
    elif x > 0:
        x -= d
        print(abs(x))
    elif x < 0:
        x += d
        print(abs(x))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
                                                                               │➜  typical
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

import itertools

def main():
  N, M, Q = map(int, input().split())
  all_num = [i for i in range(1, M+1)]
  q_kumi = []
  for i in range(Q):
    q_kumi.append(list(map(int, input().split())))

  ans = 0
  for com in list(itertools.combinations_with_replacement(all_num, N)):
    tmp_ans = 0
    if com != tuple(sorted(com)):
      continue
    for q in q_kumi:
      if com[q[1]-1] - com[q[0]-1] == q[2]:
        tmp_ans += q[3]
    ans = max(ans, tmp_ans)
  print(ans)

if __name__ == '__main__':
  main()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

import itertools

def main():
  N, M, Q = map(int, input().split())
  all_num = [i for i in range(1, M+1)]
  q_kumi = []
  for i in range(Q):
    q_kumi.append(list(map(int, input().split())))

  ans = 0
  for com in list(itertools.combinations_with_replacement(all_num, N)):
    tmp_ans = 0
    if com != tuple(sorted(com)):
      continue
    for q in q_kumi:
      if com[q[1]-1] - com[q[0]-1] == q[2]:
        tmp_ans += q[3]
    ans = max(ans, tmp_ans)
  print(ans)

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
  N, K = map(int, input().split())

  z = abs(N-K)
  if z > K:
    print(z%K)
  else:
    print(K%z)

if __name__ == '__main__':
  main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
  N, K = map(int, input().split())

  a = N%K
  if a > abs(a-K):
    print(abs(a-K))
  else:
    print(a)

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
  S = input()
  N = int(input())

  ans = ""
  for i in range(N):
    list = input().split()
    if list[0] == '1':
      S = S[::-1]
      continue
    if list[1] == '1':
      S = list[2] + S
      continue
    S += list[2]
  print(S)

if __name__ == '__main__':
  main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():
  S = deque(input())
  N = int(input())

  d = True
  for i in range(N):
    list = input().split()
    if list[0] == '1':
      d = not d
      continue
    if list[1] == '1':
      S.appendleft(list[2]) if d else S.append(list[2])
      continue
    S.append(list[2]) if d else S.appendleft(list[2])
  return ''.join(S) if d else ''.join(S)[::-1]

if __name__ == '__main__':
  print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d


def main():
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]
    dist = [[-1]*W for _ in range(H)]

    black_cells = deque()
    for h in range(H):
        for w in range(W):
            if grid[h][w] == '#':
                black_cells.append((h, w))
                dist[h][w] = 0
    print(bfs(H, W, black_cells, dist))


if __name__ == '__main__':
    main()

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d


def main():
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]
    dist = [[-1]*W for _ in range(H)]

    black_cells = deque()
    for h in range(H):
        for w in range(W):
            if grid[h][w] == '#':
                black_cells.append((h, w))
                dist[h][w] = 0
    print(bfs(H, W, black_cells, dist))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,inptu().split()))

count = 0
for i in range(len(L)):
    for j in range(len(L)):
        for k in range(len(L)):
            if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j] and i != j and j != k and i != k:
                count += 1
print(count)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j] and L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
                count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
c = input()
li = list(c)
count = li.count('R')
num = 0

for i in range(count):
    if li[i] == 'W':
        for j in range(len(li)-count):
            if li[j*(-1)-1] == 'R':
                li[i] = "R"
                li[j*(-1)-1] = 'W'
                num += 1



print(num)

Fixed submission:
N = int(input())
c = input()
li = list(c)
count = li.count('R')
num = 0

#for i in range(count):
    #if li[i] == 'W':
        #for j in range(len(li)-count):
            #if li[j*(-1)-1] == 'R':
                #li[i] = "R"
                #li[j*(-1)-1] = 'W'
                #num += 1

#for i in range(int(N/2)):
    #if li[i] == 'W' and li[j*(-1)-1] == 'R':
        #li[i] = 'R'
        #li[j*(-1)-1] = 'W'
        #num += 1

#for i in range(count):
    #if li[i] == 'W':
        #li[i] == 

for i in range(count):
    if li[i] == 'W':
        num += 1

print(num)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(str,input().split()))
Q = int(input())
b = []
c = []
for i in range(Q):
    B,C = map(str,input().split())
    b.append(B)
    c.append(C)

for i in range(Q):
    if b[i] in A:
        A = [s.replace(b[i],c[i]) for s in A]
    print(sum(int(i) for i in A))

Fixed submission:
α = str(input())

if α == α.upper():
    print("A")
else:
    print("a")
Buggy python submission (verdict: Runtime Error):
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 0
i = 0
count = 0
while True:
    if abs(X - i) == min:
        if i not in p:
            break
        elif i in p and min != 0:
            count += 1
            if count == 2:
                min += 1
                count = 0
                i = 0
        else:
            min += 1
            i = 0
    i += 1

print(i)

Fixed submission:
x = list(map(int,input().split()))

for i in range(5):
    if x[i] == 0:
        print(i+1)
        exit()
Buggy python submission (verdict: Runtime Error):
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    for mou in range(K):
        newA = [0]*N
        count = 0
        for i in A:
            for j in range(-i,i+1):
                if count+j >= 0 and count + j < N:
                    newA[count+j] += 1
            count +=1
        A = newA
    print(' '.join(map(str,A)))

if __name__ == '__main__':
    main()

Fixed submission:
import random
S = input()

ran = random.randint(0,len(S)-3)

print(S[ran:ran+3])

Buggy python submission (verdict: Runtime Error):
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if abs(B - A) > abs((V-W)*T):
    print("NO")
else:
    print("YES")

Fixed submission:
import random
S = input()

ran = random.randint(0,len(S)-3)

print(S[ran:ran+3])
Buggy python submission (verdict: Runtime Error):
moji = []
ans=""
s = str(input())
s = list(s)

def keyboard(key,list):
    if key == "0":
        list.append("0")
    elif key == "1":
        list.append("1")
    elif key == "B":
        list.pop(-1)

for i in range(len(s)):
    keyboard(s[i],moji)

for x in moji:
    ans += x

print(ans)

Fixed submission:
moji = []
ans=""
s = str(input())
s = list(s)

def keyboard(key,list):
    if key == "0":
        list.append("0")
    elif key == "1":
        list.append("1")
    elif key == "B" and len(list) != 0:
        list.pop(-1)

for i in range(len(s)):
    keyboard(s[i],moji)

for x in moji:
    ans += x

print(ans)
Buggy python submission (verdict: Runtime Error):
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:03 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:38 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    #from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()
c = nl()

for i in range(n):
  p[i]-=1

ans = -10**(18)
for si in range(n):
  x = si
  s = []
  tot = 0
  while(True):
    x = p[x]
    s.append(c[x])
    tot += c[x]
    if x == si:
      break
  l = len(s)
  t = 0
  for i in range(l):
    t += s[i]
    if i+1>k:
      break
    now = t
    if tot > 0:
      e = (k-(i+1))//l
      now += tot*e
    ans = max(ans,now)

print(ans)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()
c = nl()

for i in range(n):
  p[i]-=1

ans = -10**(18)
for si in range(n):
  x = si
  s = []
  tot = 0
  while(True):
    x = p[x]
    s.append(c[x])
    tot += c[x]
    if x == si:
      break
  l = len(s)
  t = 0
  for i in range(l):
    t += s[i]
    if i+1>k:
      break
    now = t
    if tot > 0:
      e = (k-(i+1))//l
      now += tot*e
    ans = max(ans,now)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,d=map(int,input())
cnt=0
for i in range(n):
  x,y =map(int,input())
  if x**2+y**2 <= d**2:
    cnt+=1
print(cnt)

Fixed submission:
n,d=map(int,input().split())
cnt=0
for i in range(n):
  x,y =map(int,input().split())
  if x**2+y**2 <= d**2:
    cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k=nm()
a=nl()
b=[1]*(n+1)

for i in range(n):
  b[i+1] = a[i]*b[i]

for i in range(n-k):
  if b[i+k+1]//b[i+1] > b[i+k]//b[i]:
    print('Yes')
  else:
    print('No')


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import log10

n,k=nm()
a=nl()
b=[1]*(n+1)

for i in range(n):
  b[i+1] = log10(a[i])+b[i]

for i in range(n-k):
  if b[i+k+1]-b[i+1] > b[i+k]-b[i]:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k=nm()
a=nl()
b=[1]*(n+1)

for i in range(n):
  b[i+1] = a[i]*b[i]

for i in range(n-k):
  if b[i+k+1]/b[i+1] > b[i+k]/b[i]:
    print('Yes')
  else:
    print('No')


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import log10

n,k=nm()
a=nl()
b=[1]*(n+1)

for i in range(n):
  b[i+1] = log10(a[i])+b[i]

for i in range(n-k):
  if b[i+k+1]-b[i+1] > b[i+k]-b[i]:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

ans = 0
for i in range(2**n):
  mo = 1000
  st = 0
  for j in range(n):
    if ((i>>j) & 1):
      s = mo//a[j]
      st += s
      mo -=a[j]*s
    else:
      mo+=st*a[j]
      st = 0
  ans = max(ans, mo)
print(ans) 


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

dp=[0]*(n+1)
dp[0] = 1000

for i in range(1,n):
  dp[i]=dp[i-1]
  for j in range(i):
    v = dp[j] // a[j]
    w = dp[j] + (a[i]-a[j])*v
    dp[i] = max(dp[i],w)
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()


cnt=[0]*(n+1)

for x in range(1,n+1):
  if x**2+x>n+1:
    break
  for y in range(x,n+1):
    if x**2+y**2+x*y+x+y>n+1:
      break
    for z in range(y,n+1):
      num = x**2+y**2+z**2+x*y+y*z+x*z
      if num > n+1:
        break
      if x==y==z:
        cnt[num]+=1
      elif x==y:
        cnt[num]+=3
      elif y==z:
        cnt[num]+=3
      elif x==z:
        cnt[num]+=3
      else:
        cnt[num]+=6

for i in range(1,n+1):
  print(cnt[i])


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()


cnt=[0]*(n+1)

for x in range(1,n+1):
  if x**2+x>n:
    break
  for y in range(x,n+1):
    if x**2+y**2+x*y+x+y>n:
      break
    for z in range(y,n+1):
      num = x**2+y**2+z**2+x*y+y*z+x*z
      if num > n:
        break
      if x==y==z:
        cnt[num]+=1
      elif x==y:
        cnt[num]+=3
      elif y==z:
        cnt[num]+=3
      elif x==z:
        cnt[num]+=3
      else:
        cnt[num]+=6

for i in range(1,n+1):
  print(cnt[i])
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]

# val next
l=[(-1,-1)]*(n+1)
l[0]=(a[0],0)
nx_idx=1

ans = 0

for i in range(1,n):
  aa = a[i]
  now = 0
  mx_idx=0
  mx=-1

  cnt=0
  while True:
    cnt+=1

    val = l[now][0]
    nxt = l[now][1]

    nxtv=0
    nxtv=l[nxt][0]
    
    n_val = min(val,nxtv)

    if mx < n_val:
      mx = n_val
      mx_idx = now

    if nxt == a[i]:
      break
    
    if cnt==nx_idx:
      break

    now = nxt

  ans+=mx

  val = l[mx_idx][0]
  nxt = l[mx_idx][1]

 
  l[nx_idx]=(a[i],l[mx_idx][1])
  l[mx_idx]=(mx,nx_idx)

  nx_idx+=1
print(ans)


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]
 
ans=0

cur=0
now=1
for i in range(n-1):
  ans+=a[cur]
  if now==1:
    now=0
    cur+=1
  elif now==0:
    now=1


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]

# val next
l=[(-1,-1)]*(n+1)
l[0]=(a[0],0)
nx_idx=1

ans = 0

for i in range(1,n):
  aa = a[i]
  now = 0
  mx_idx=0
  mx=-1

  cnt=0
  while True:
    cnt+=1

    val = l[now][0]
    nxt = l[now][1]

    nxtv=0
    nxtv=l[nxt][0]
    
    n_val = min(val,nxtv)

    if mx < n_val:
      mx = n_val
      mx_idx = now
    
    if cnt==nx_idx:
      break

    now = nxt

  ans+=mx

  val = l[mx_idx][0]
  nxt = l[mx_idx][1]

 
  l[nx_idx]=(a[i],l[mx_idx][1])
  l[mx_idx]=(mx,nx_idx)

  nx_idx+=1
print(ans)


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]
 
ans=0

cur=0
now=1
for i in range(n-1):
  ans+=a[cur]
  if now==1:
    now=0
    cur+=1
  elif now==0:
    now=1


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()
nums = [0]*10**6
for i in range(n):
  nums[a[i]]+=1
q=ni()
for i in range(q):
  b,c=nm()
  nums[c]+=nums[b]
  nums[b]=0
  ans=0
  for j in range(len(nums)):
    ans+=nums[j]*j

  print(ans)


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()
nums = [0]*10**6
for i in range(n):
  nums[a[i]]+=1
q=ni()
ans=0
for i in range(len(nums)):
  ans+=nums[i]*i

for i in range(q):
  b,c=nm()
  ans-=nums[b]*b
  ans+=nums[b]*c
  nums[c]+=nums[b]
  nums[b]=0
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=nl()

s = [0]*(MAX)

for ai in a:
  if s[ai]==2:
    continue
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=nl()

s = [0]*(MAX)

for ai in a:
  if s[ai]!=0:
    s[ai]=2
    continue
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=nl()

s = [0]*(MAX)

for ai in a:
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=nl()

s = [0]*(MAX)

for ai in a:
  if s[ai]!=0:
    s[ai]=2
    continue
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=sorted(nl())

s = [0]*(MAX)

for ai in a:
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=nl()

s = [0]*(MAX)

for ai in a:
  if s[ai]!=0:
    s[ai]=2
    continue
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=sorted(nl())

s = [0]*(MAX)

for ai in a:
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

MAX=10**6+1

n=ni()
a=nl()

s = [0]*(MAX)

for ai in a:
  if s[ai]!=0:
    s[ai]=2
    continue
  for i in range(ai,MAX,ai):
    s[i]+=1

cnt=0
for ai in a:
  if s[ai]==1:
    cnt+=1

print(cnt)