Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations, accumulate
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, K = read_ints()
A = read_ints()
# 愚直に実装するとO(N**3)ぐらいO(N√N)以下じゃないと間に合わない
# 一回あたりの操作はO(N)(imos法)
# 操作回数はmin(K,logN)に気づくと通る

for _ in range(min(50, K)):
    imos = [0] * (N + 1)
    for i, d in enu(A):
        imos[max(i - d, 0)] += 1
        imos[min(i + d + 1, N)] -= 1
    A = list(accumulate(imos))[:-1]
print(*A)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations, accumulate
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, K = read_ints()
A = read_ints()
# N = K = 2 * 100000
# A = [0] * N

# 愚直に実装するとO(N**3)ぐらいO(N√N)以下じゃないと間に合わない
# 一回あたりの操作はO(N)(imos法)
# 操作回数はmin(K,logN)に気づくと通る

for _ in range(min(50, K)):
    imos = [0] * (N + 1)
    for i, d in enu(A):
        imos[max(i - d, 0)] += 1
        imos[min(i + d + 1, N)] -= 1
    A = list(accumulate(imos))[:-1]
print(*A)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
count=1
n-k
while(n>0):
    n-(k-1)
    count+=1
print(count)


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
count=1
n=n-k
while(n>0):
    n=n-(k-1)
    count+=1
print(count)
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))

ans=0

for i in range(N):
    for j in range(i):
        if P[i] < P[j]:
            continue
        else:
            ans += 1
            break
print(len(P) - ans)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))

ans=0
minCount=2*10**6

for i in range(N):
    if minCount >= P[i]:
        ans += 1
    minCount=min(minCount, P[i])

print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
a = list(s)
#print(a)
b = 1
while b != 0:
    b = 0
    #i = 1
    #print(i)
    for i in range(1,len(a)):
        if a[i-1] == a[i]:
            del a[i]
            #print(a)
            b = b + 1
            #print(b)
            break
print(len(a))

### FIXED CODE ###

N = int(input())
S = input()
s = S[0]
ans = 1
for i in range(1,N):
    if S[i] != s:
        ans += 1
        s = S[i]
print(ans)
### BUGGY CODE ###

import itertools

n, k = map(int, input().split())
alist = sorted(list(map(int, input().split())))
mod = 10**9 + 7

def comb(n, k):
    n1 = n+1
    r = min(k, n-k)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i)%mod
        denom = denom * i % mod
    return numer * pow(denom, mod - 2, mod) % mod

    #return math.factorial(n) // (math.factorial(n-k) * math.factorial(k))

amax = 0
i = n-1
while i >= k-1:
    amax += alist[i] * comb(i, k-1)
    i -= 1

amin = 0
i = 0
while i <= n-k:
    amin += alist[i] * comb(n-i-1, k-1)
    i += 1

print((amax - amin) % mod)

### FIXED CODE ###

n, k = map(int, input().split())
alist = sorted(map(int, input().split()))
mod = 10**9 + 7

def comb(n, r, p=mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
p = mod
N = n
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

amax = 0
amin = 0
i = 0
while i <= n-k:
    cnt = comb(n-i-1, k-1)
    amax += (alist[n-i-1] * cnt)%mod
    amin += (alist[i] * cnt)%mod
    i += 1

print((amax - amin) % mod)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = list(map(int,input().split(' ')))
mod = 10**9+7
high = 0
mid = 0
low = 0
ans = 1
for i in A:
    ans *= sum(np.array([high, mid, low]) == i)
    if i == high:
        high += 1
    elif i == mid:
        mid += 1
    else:
        low += 1
    ans %= mod
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
c = [0, 0, 0]
ans = 1
for i in A:
    ans *= c.count(i)
    if i == c[0]:
        c[0] += 1
    elif i == c[1]:
        c[1] += 1
    else:
        c[2] += 1
    ans %= mod
print(ans)
### BUGGY CODE ###

from collections import defaultdict
mod = 10**9+7
n = int(input())
c = [0]
d = defaultdict(list)
r = defaultdict(list)

idx = 1
for i in range(n):
    tmp = int(input())
    if c[-1] != tmp:
        r[idx] += d[tmp]
        d[tmp].append(idx)
        c.append(tmp)
        idx += 1

n = len(c)
dp = [0]*(n)
dp[0] = 1
for i in range(1, n):
    dp[i] = dp[i-1]
    for j in r[i]:
        dp[i] += (dp[j-1]%mod)
    dp[i] %= mod

print(dp[-1])


### FIXED CODE ###

from collections import defaultdict
mod = 10**9+7
n = int(input())
c = [0]
d = defaultdict(list)
r = defaultdict(int)

idx = 1
for i in range(n):
    tmp = int(input())
    if c[-1] != tmp:
        if d[tmp]:
            r[idx] = d[tmp][-1]
        d[tmp].append(idx)
        c.append(tmp)
        idx += 1

n = len(c)
dp = [0]*(n)
dp[0] = 1
for i in range(1, n):
    dp[i] = dp[i-1]
    if r[i]:
        dp[i] += dp[r[i]]
    dp[i] %= mod
print(dp[-1])
### BUGGY CODE ###

import math
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j] - 0.5
        st = L[j] - L[i] + 0.5
        m2 = bisect_left(L[j+1:],st)
        m1 = bisect_right(L[j+1:],lg)
        c += max(0,m1-m2)
print (c)

### FIXED CODE ###

import math
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
L = list(map(int,input().split()))
L.sort()
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lg = L[i] + L[j]
        st = L[j] - L[i]
        if lg > L[j+1] and st < L[n-1]:
            if lg > L[n-1]:
                m1 = n - (j+1)
            else:
                m1 = bisect_left(L[j+1:],lg)
            c += max(0,m1)
print (c)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
if N > 1:
    for i in range(M):
        index = A.index(max(A))
        A[index] = A[index] >> 1
else:
    A[0] = A[0] >> M
print(sum(A))


### FIXED CODE ###

# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
import heapq

# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
    A[i] *= -1

heapq.heapify(A)

for _ in range(M):
    heapq.heappush(A, ((heapq.heappop(A) * -1) >> 1) * -1)

print(sum(A) * -1)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G)//B
        if r*R + g*G + b*B == N and b >= 0:
            ans += 1
print(ans)

### FIXED CODE ###

R, G, B, N = map(int, input().split())

ans = 0
b = 0
for r in range(N+1):
    for g in range(N+1):
        b = (N - r*R - g*G)//B
        if r*R + g*G + b*B == N and b >= 0:
            ans += 1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,q=map(int,input().split())
c=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  c[a].append(b)
  c[b].append(a)
px=[0]*n
for I in range(q):
    p,x=map(int,input().split())
    px[p-1]+=x 
ans=[0]*n
def dfs(g,h=-1):
  ans[g]=ans[h]+px[g]
  for i in c[g]:
    if i==h:continue
    dfs(i,g)
dfs(0)
print(*ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,q=map(int,input().split())
c=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  c[a].append(b)
  c[b].append(a)
px=[0]*n
for I in range(q):
    p,x=map(int,input().split())
    px[p-1]+=x 
ans=[0]*n
def dfs(g,h=-1):
  ans[g]=ans[h]+px[g]
  for i in c[g]:
    if i==h:continue
    dfs(i,g)
dfs(0)
print(*ans)
### BUGGY CODE ###

from collections import Counter
n=int(input())
l=[]
count=0
for i in range(n):
  b=input()
  l.append(Counter(b))
for i in range(n):
  for j in range(i+1,n):
    if l[i]==l[j]:
      count+=1
print(count)

### FIXED CODE ###

n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  count+=i*(i-1)/2
print(int(count))
### BUGGY CODE ###

s = input()
K = int(input())
ans = []
length = len(s)
for i in range(length):
    for j in range(i + 1, length + 1):
        if s[i:j] not in ans:
            ans.append(s[i:j])
ans.sort()
print(ans[K - 1])

### FIXED CODE ###

s = input()
K = int(input())
sub = set()
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if j - i > 5:
            break
        sub.add(s[i:j])
sub = list(sub)
sub.sort()
print(sub[K-1])
### BUGGY CODE ###

from collections import defaultdict 

N,M=map(int,input().split())

if M == 0:
  print(-1)
  exit()

INF = 10**20
pqc = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(M)]

to1d={}
count=2
for p,q,c in pqc:
  if not to1d.get((p,c)):
    to1d[(p,c)] = count
    count += 1
  if not to1d.get((q,c)):
    to1d[(q,c)] = count
    count += 1

G = [{} for _ in range(len(to1d)+2)]
lines = [set() for _ in range(N)]
for p,q,c in pqc:
  v1,v2 = to1d[(p,c)],to1d[(q,c)]
  G[v1][v2] = G[v2][v1] = 0
  lines[p].add(c)
  lines[q].add(c)
  
for v in range(N):
  if len(lines[v])>1:
    tmp = list(lines[v])
    for i in range(len(tmp)-1):
      for j in range(i+1,len(tmp)):
        v1,v2 = to1d[(v,tmp[i])],to1d[(v,tmp[j])]
        G[v1][v2] = G[v2][v1] = 1
        
def dijkstra(start = 0):
    from heapq import heappop, heappush
    d = [INF]*len(G)
    d[start] = 0
    que = []
    heappush(que, (0, start))
    while que:
        p = heappop(que)
        v = p[1]
        if d[v] < p[0]: continue
        for u in G[v].keys():
            if d[u] > d[v] + G[v][u]:
                d[u] = d[v] + G[v][u]
                heappush(que, (d[u], u))
    return d

for c in lines[0]:
  v = to1d[(0,c)]
  G[0][v] = 1
for c in lines[N-1]:
  v = to1d[(N-1,c)]
  G[v][1] = 0
  
d = dijkstra(0)
ans = d[1]
print(ans if ans < INF else -1)

### FIXED CODE ###

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

  if M == 0:
    print(-1)
    exit()

  INF = 10**6
  pqc = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(M)]

  to1d={v:{} for v in range(N)}
  count=2
  for p,q,c in pqc:
    if not to1d[p].get(c):
      to1d[p][c] = count
      count += 1
    if not to1d[q].get(c):
      to1d[q][c] = count
      count += 1

  G = [{} for _ in range(N+count)]
  for p,q,c in pqc:
    v1,v2 = to1d[p][c],to1d[q][c]
    G[v1][v2] = G[v2][v1] = 0

  for i in range(N):
    if len(to1d[i])<=1: continue
    for c in to1d[i].keys():
      v = to1d[i][c]
      G[v][count] = 1
      G[count][v] = 0
    count += 1

  def dijkstra(start = 0, goal = 1):
      from heapq import heappop, heappush
      NN = len(G)
      d = [INF]*NN
      d[start] = 0
      que = []
      heappush(que, start)
      while que:
          p = divmod(heappop(que),NN)
          v = p[1]
          if d[v] < p[0]: continue
          for u in G[v].keys():
              if d[u] > d[v] + G[v][u]:
                  d[u] = d[v] + G[v][u]
                  heappush(que, d[u]*NN+u)
          if v == goal: return d[goal]
      return d[goal]

  for c in to1d[0].keys():
    v = to1d[0][c]
    G[0][v] = 1
  for c in to1d[N-1].keys():
    v = to1d[N-1][c]
    G[v][1] = 0

  ans = dijkstra(0,1)
  print(ans if ans < INF else -1)
  
if __name__=="__main__":
  main()
### BUGGY CODE ###

# atcoder problems solving
# League
from collections import deque
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    graph = {(i, j): [] for i in range(1, N+1) for j in range(i+1, N+1)}
    indegree = {(i, j): 0 for i in range(1, N+1) for j in range(i+1, N+1)}

    for i in range(N):
        a = list(map(int, input().split()))
        for j in range(N-2):
            x, y = a[j], a[j+1]
            z, w = i+1, i+1
            graph[(min(z, x), max(z, x))].append((min(w, y), max(w, y)))
            indegree[(min(w, y), max(w, y))] += 1

    d = deque()
    e = deque()
    visited = {(i, j): False for i in range(1, N+1) for j in range(i+1, N+1)}

    cnt = 1
    match = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if indegree[(i, j)] == 0:
                d.append((i, j))
                visited[(i, j)] = True
                match += 1

    while d:
        while d:
            x = d.popleft()
            for node in graph[x]:
                indegree[node] -= 1
                if indegree[node] == 0:
                    e.append(node)
                    visited[node] = True
                    match += 1
        if e:
            d = e
            e = deque()
            cnt += 1

    if match == N*(N-1)//2:
        print(cnt)
    else:
        print(-1)
if __name__=="__main__":
    main()


### FIXED CODE ###

n=int(input())
import time
T=time.time()
data_set=[0 for i in range(n)]
for i in range(n):
    a=list(map(int,input().split()))
    a.append(-1)
    data_set[i]=a
index=[0 for i in range(n)]
ans=-1
flag=True
semi=False
now=[data_set[i][index[i]] for i in range(n)]
finished=[False for i in range(n)]
while flag:
    visited=[False for i in range(n)]
    sub=False
    for i in range(n):
        #nowリストのうち日ありからi+1番目のものについての一致条件の確認
        K=now[i]
        if now[K-1]==i+1 and not(visited[i] or visited[K-1]) and not(finished[i] or finished[K-1]):
                    visited[i]=True
                    visited[K-1]=True
                    index[i]+=1
                    index[K-1]+=1
                    sub=True
                    if index[i]==n-1:
                        finished[i]=True             
                    now[i]=data_set[i][index[i]]
                    if index[K-1]==n-1:
                        finished[K-1]=True                   
                    now[K-1]=data_set[K-1][index[K-1]]
    if not sub:
        flag=False
    if time.time()-T>1.5:
        flag=False
        semi=True
    ans+=1
judge=True
for i in range(n):
  if finished[i]==False:
    judge=False
    break
if judge:
  print(ans)
else:
  if not semi:
    print(-1)
  if semi:
    print(499500)
### BUGGY CODE ###

N = int(input())
S = input()
answer = 0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            if (j-i) != (k-j):
                if S[i-1] != S[j-1] and S[i-1] != S[k-1] and S[j-1] != S[k-1]:
                    answer += 1

print(answer)

### FIXED CODE ###

N = int(input())
S = input()

ans = S.count('R')*S.count('G')*S.count('B')

for i in range(N-2):
  for j in range(i+1,N-1):
    k = 2*j-i
    
    if k >= N:
      break
    
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      ans -= 1
      
print(ans)
### BUGGY CODE ###

n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
f=lambda x:((x[0]-1)*(n-1+n-x[0]+1))//2+x[1]-x[0]-1
import sys
sys.setrecursionlimit(10**7)

m=(n*(n-1))//2
g=[[] for _ in range(m)]
for i in range(n):
  for j in range(n-2):
    if i+1>a[i][j]:
      t0=f((a[i][j],i+1))
    else:
      t0=f((i+1,a[i][j]))
    if i+1>a[i][j+1]:
      t1=f((a[i][j+1],i+1))
    else:
      t1=f((i+1,a[i][j+1]))
    g[t0].append(t1)
def dfs(t):
  if v[t]:
    if c[t]==0:
      return -1
    else:
      dp[t]
  v[t]=1
  for l in g[t]:
    ret=dfs(l)
    if ret==-1:return -1
    dp[t]=max(dp[t],ret+1)
  c[t]=1
  return dp[t]
ans=0
for i in range(m):
  v=[0]*m
  c=[0]*m
  dp=[0]*m
  tmp=dfs(i)
  if tmp==-1:
    print(-1)
    exit()
  ans=max(ans,tmp)
print(ans+1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def main():
  n=int(input())
  a=[list(map(int,input().split())) for _ in range(n)]
  f=lambda x:((x[0]-1)*(n-1+n-x[0]+1))//2+x[1]-x[0]-1
  m=(n*(n-1))//2
  g=[[] for _ in range(m)]
  for i in range(n):
    for j in range(n-2):
      if i+1>a[i][j]:
        t0=f((a[i][j],i+1))
      else:
        t0=f((i+1,a[i][j]))
      if i+1>a[i][j+1]:
        t1=f((a[i][j+1],i+1))
      else:
        t1=f((i+1,a[i][j+1]))
      g[t0].append(t1)
  def dfs(t):
    if v[t]:
      if c[t]==0:
        return -1
      else:
        return dp[t]
    v[t]=1
    for l in g[t]:
      ret=dfs(l)
      if ret==-1:return -1
      dp[t]=max(dp[t],ret+1)
    c[t]=1
    mi.discard(t)
    return dp[t]
  ans=0
  v=[0]*m
  c=[0]*m
  dp=[0]*m
  #print(g)
  mi=set(list(range(m)))
  while mi:
    i=mi.pop()
    tmp=dfs(i)
    if tmp==-1:
      print(-1)
      exit()
    ans=max(ans,tmp)
    #print(dp)
  print(ans+1)

if __name__=='__main__':
  main()
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(1, len(A) + 1):
    num = A.index(i) + 1
    ans.append(num)
print(*ans)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(n)]
for i, v in enumerate(A):
    B[v-1] = i+1
print(*B)
### BUGGY CODE ###

import decimal

N = int(input())
A = [int(decimal.Decimal(input()) * 10 ** 9) for _ in range(N)]
B = []
for a in A:
    cnt = 0
    while a % 10 == 0:
        cnt += 1
        a //= 10
    B.append((a, cnt))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        x, cnt1 = B[i]
        y, cnt2 = B[j]
        if cnt1 + cnt2 >= 18:
            ans += 1
            continue
        z = x * y
        cnt3 = 0
        while z % 10 == 0:
            cnt3 += 1
            z //= 10
        if cnt1 + cnt2 + cnt3 >= 18:
            ans += 1

print(ans)

### FIXED CODE ###

import decimal

N = int(input())
A = [int(decimal.Decimal(input()) * 10 ** 9) for _ in range(N)]
B = [[0] * 19 for _ in range(19)]
for a in A:
    cnt2 = 0
    while a % 2 == 0:
        cnt2 += 1
        a //= 2
    cnt5 = 0
    while a % 5 == 0:
        cnt5 += 1
        a //= 5
    B[min(cnt2, 18)][min(cnt5, 18)] += 1
ans = 0
for i in range(361):
    a, r = divmod(i, 19)
    if a >= 9 and r >= 9:
        ans -= B[a][r]
    for j in range(361):
        b, s = divmod(j, 19)
        if a + b >= 18 and r + s >= 18:
            ans += B[a][r] * B[b][s]

ans //= 2
print(ans)
### BUGGY CODE ###

n, k = list(map(int, input().split()))
s = list(map(int, input().split()))
T = list(input())
ans = 0
stoi = {'r' : 2, 's' : 0, 'p' : 1}
for i in range(k):
    T_sub = [stoi[t] for j, t in enumerate(T) if j % k == i]
    score = 0
    pre = 3
    for j in range(len(T_sub)):
        if T_sub[j] == pre:
            pre = 3
        else:
            score += s[T_sub[j]]
            pre = T_sub[j]
    ans += score
print(ans)

### FIXED CODE ###

n, k = list(map(int, input().split()))
s = list(map(int, input().split()))
T = list(input())
ans = 0
for i in range(k):
    T_sub = T[i::k]
    score = 0
    pre = 3
    for t_sub in T_sub:
        if t_sub == pre:
            pre = 3
        else:
            if t_sub == 'r':
                score += s[2]
            elif t_sub == 's':
                score += s[0]
            else:
                score += s[1]
            pre = t_sub
    ans += score
print(ans)
### BUGGY CODE ###

from collections import deque

# 上下左右1マスを検索するために必要とする
dis_x = [1, 0, -1, 0]
dis_y = [0, 1, 0, -1]

# 迷路の縦幅,横幅
max_h, max_w = map(int, input().split())

s = []
for _ in range(max_h):
    line = input()
    # 横1マスを壁でPadding. これでindex out of boundを防ぐ
    s.append(list("#{}#".format(line)))

# 縦1マスを壁でPadding. これでindex out of boundを防ぐ
s = [list("#" * (max_w + 2))] + s + [list("#" * (max_w + 2))]
dist = [ [0] * (max_w + 2) for _ in range(max_h+2)]

queue = deque()
for i in range(1, max_h+1):
    for j in range(1, max_w+1):
        if s[i][j] == '#':
            queue.append((i, j))

while queue:
    # 先頭の値を取り出す
    h, w = queue.popleft()

    # 上下左右4マスに対し処理
    for i in range(4):

        # 移動距離
        dx, dy = dis_x[i], dis_y[i]

        # もし次のマスの黒塗りが終わっていないなら
        if s[h+dy][w+dx] == '.':
            s[h+dy][w+dx] = '#'
            dist[h+dy][w+dx] = dist[h][w] + 1

            queue.append((h+dy, w+dx))


print(max(max(l) for l in dist))

### FIXED CODE ###

from collections import deque

# 上下左右1マスを検索するために必要とする
dis_x = [1, 0, -1, 0]
dis_y = [0, 1, 0, -1]

# 迷路の縦幅,横幅
max_h, max_w = map(int, input().split())

s = []
for _ in range(max_h):
    line = input()
    # 横1マスを壁でPadding. これでindex out of boundを防ぐ
    s.append(list("#{}#".format(line)))

# 縦1マスを壁でPadding. これでindex out of boundを防ぐ
s = [list("#" * (max_w + 2))] + s + [list("#" * (max_w + 2))]
dist = [ [0] * (max_w + 2) for _ in range(max_h+2)]

queue = deque()
for i in range(1, max_h+1):
    for j in range(1, max_w+1):
        if s[i][j] == '#':
            queue.append((i, j))

while queue:
    # 先頭の値を取り出す
    h, w = queue.popleft()

    # 上下左右4マスに対し処理
    for i in range(4):

        # 移動距離
        dx, dy = dis_x[i], dis_y[i]

        # もし次のマスの黒塗りが終わっていないなら
        if s[h+dy][w+dx] == '.':
            s[h+dy][w+dx] = '#'
            dist[h+dy][w+dx] = dist[h][w] + 1

            queue.append((h+dy, w+dx))


print(max(max(l) for l in dist))
### BUGGY CODE ###

from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, (input().split())))
cntA = Counter(A)
A = sorted(list(set(A)))
setA = set()
for k, v in cntA.items():
    if v==1:
        setA.add(k)
# print(setA)
for i in range(len(A)-1):
    for j in range(i+1, len(A)):
        if A[j] % A[i] == 0:
            if A[j] in setA:
                setA.remove(A[j])
print(len(setA))


### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, (input().split())))
A.sort()
cnt = np.zeros(10**6+10, dtype=np.int32)
for x in A:
    if cnt[x] != 0:
        cnt[x] = 2
        continue
    cnt[x::x] += 1
ans = 0
for x in A:
    if cnt[x] == 1:
        ans += 1
print(ans)