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

from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
cnt=0
for i in range(N):
    if cnt%2==0:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.appendleft(Q[i][4])
                S=list(T)
            if Q[i][2]=="2":
                T.append(Q[i][4])
                S=list(T)
    if cnt%2==1:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.append(Q[i][4])
                S=list(T)
            if Q[i][2]=="2":
                T.appendleft(Q[i][4])
                S=list(T)
    if Q[i][0]=="1":
        cnt+=1
if cnt%2==1:
    S=S[::-1]
print(''.join(S))

### FIXED CODE ###

from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
cnt=0
for i in range(N):
    if Q[i][0]=="1":
        cnt+=1
    if cnt%2==0:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.appendleft(Q[i][4])
            if Q[i][2]=="2":
                T.append(Q[i][4])
    if cnt%2==1:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.append(Q[i][4])
            if Q[i][2]=="2":
                T.appendleft(Q[i][4])
if cnt%2==1:
    T.reverse()
print(''.join(T))
### BUGGY CODE ###

import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
gb = sorted(g + b)
br = sorted(b + r)
rg = sorted(r + g)
for i, si in enumerate(s):
    tmp = None
    if si == 'R':
        tmp = gb
    elif si == 'G':
        tmp = br
    else:
        tmp = rg
    for j in tmp:
        if j < i + 1:
            continue
        tmp2 = None
        # print(si, s[j-1])
        if (si == 'R' and s[j-1] == 'G') or (si == 'G' and s[j-1] == 'R'):
            tmp2 = b
        elif (si == 'R' and s[j-1] == 'B') or (si == 'B' and s[j-1] == 'R'):
            tmp2 = g
        elif (si == 'G' and s[j-1] == 'B') or (si == 'B' and s[j-1] == 'G'):
            tmp2 = r
        for k in tmp2:
            if k < j:
                continue
            if j - (i + 1) != k - j:
                # print(i + 1, j, k)
                count += 1
print(count)

### FIXED CODE ###

import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count += 1
print(len(r) * len(g) * len(b) - count)
### BUGGY CODE ###

def solve():
    from itertools import combinations
    
    mod = 10 ** 9 + 7
    N = int(input())
    A = tuple(map(int, input().split()))
    
    ans = sum(ai ^ aj for ai, aj in combinations(A, 2)) % mod
    
    print(ans)

solve()

### FIXED CODE ###

def solve():
    import numpy as np
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = np.array(f_i.readline().split(), dtype=np.int64)
    
    ans = 0
    for i in range(60):
        cnt = np.count_nonzero((A >> i) & 1)
        ans += (1 << i) * cnt * (N - cnt)
    
    print(ans % mod)

solve()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)

n = int(sys.stdin.readline().strip())
S = [int(_) for _ in sys.stdin.readline().strip().split()]
q = int(sys.stdin.readline().strip())
T = [int(_) for _ in sys.stdin.readline().strip().split()]
cnt = 0


def binary_search(ary, target):

    if ary:
        ind = len(ary) // 2
        if target == ary[ind]:
            return True
        elif target < ary[ind]:
            return binary_search(ary[:ind], target)
        else:
            return binary_search(ary[ind + 1:], target)

    else:
        return False


for target in T:
    if binary_search(S, target):
        cnt += 1

if __name__ == '__main__':
    print(cnt)



### FIXED CODE ###

# def binary_search_original(ary, target):

#     if ary:
#         ind = len(ary) // 2
#         if target == ary[ind]:
#             return True
#         elif target < ary[ind]:
#             return binary_search(ary[:ind], target)
#         else:
#             return binary_search(ary[ind + 1:], target)

#     else:
#         return False


def binary_search(ary, target):

    left = 0
    right = len(ary)

    while left < right:
        mid = (left + right) // 2

        if ary[mid] == target:
            return True
        elif ary[mid] < target:
            left = mid + 1
        else:
            right = mid

    return False


if __name__ == '__main__':

    n = int(input())
    S = [int(_) for _ in input().split()]
    q = int(input())
    T = [int(_) for _ in input().split()]
    cnt = 0

    for target in T:
        if binary_search(S, target):
            cnt += 1

    print(cnt)
### BUGGY CODE ###

S = list(input())
string = [list("dream") ,  list("dreamer") , list("erase") ,list("eraser")]
for i in range(4):
    string[i] = string[i][::-1]
#print(string)
S = S[::-1]
#print(S[0:5])
while len(S) != 0:
    if S[0:5] == string[0]:
        for _ in range(5):
            S.pop(0)
    elif S[0:7] == string[1]:
        for _ in range(7):
            S.pop(0)
    elif S[0:5] == string[2]:
        for _ in range(5):
            S.pop(0)
    elif S[0:6] == string[3]:
        for _ in range(6):
            S.pop(0)
    else:
        print("NO")
        exit()
print("YES")

### FIXED CODE ###

S = list(input())
#S = list("dream" * 20000)
string = [list("dream") ,  list("dreamer") , list("erase") ,list("eraser")]
for i in range(4):
    string[i] = string[i][::-1]
#print(string)
S = S[::-1]
#print(S[0:5])
idx = 0
#print(S[idx:5])
while idx != len(S):
    if S[idx:idx + 5] == string[0]:
        idx += 5
    elif S[idx:idx + 7] == string[1]:
        idx += 7
    elif S[idx:idx + 5] == string[2]:
        idx += 5
    elif S[idx:idx + 6] == string[3]:
        idx += 6
    else:
        print("NO")
        exit()
print("YES")
### BUGGY CODE ###

N, M, K = map(int, input().split())
tempA = [int(i) for i in input().split()]
tempB = [int(i) for i in input().split()]
A = [0] * (N+1)
for i in range(1, N+1):
    A[i] = A[i-1] + tempA[i-1]
B = [0] * (M+1)
for i in range(1, M+1):
    B[i] = B[i-1] + tempB[i-1]

ans = 0
for a in range(N+1):
    for b in range(M+1):
        if A[a] + B[b] <= K:
            ans = max(ans, a+b)

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
tempA = [int(i) for i in input().split()]
tempB = [int(i) for i in input().split()]
A = [0] * (N+1)
for i in range(1, N+1):
    A[i] = A[i-1] + tempA[i-1]
B = [0] * (M+1)
for i in range(1, M+1):
    B[i] = B[i-1] + tempB[i-1]

ans = 0
for a in range(N+1):
    if A[a] > K:
        break
    for b in range(ans-a+1, M+1):
        if A[a] + B[b] <= K:
            ans = max(ans, a+b)
        else:
            break

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

# -*- coding: utf-8 -*-
"""
http://abc070.contest.atcoder.jp/tasks/abc070_d
"""
# TLEするので、ダイクストラのアルゴリズムからの高速化が必要。
# 隣接行列をやめて隣接リストにしたところ、だいぶ速度が改善された。しかし、今度はWAが出るようになった。

from enum import Enum
from heapq import heappush, heappop


class Sssp(object):
    """ single source shortest path """
    class Status(Enum):
        """ ノードの訪問状態 """
        white = 1  # 未訪問
        gray = 2  # 訪問中
        black = 3  #訪問済

    def __init__(self, N, data):
        num_of_nodes = N+1
        self.color = [Sssp.Status.white] * num_of_nodes  # 各ノードの訪問状態
        self.d = [float('inf')] * num_of_nodes  # 始点からの重み
        self.adj = [[] for _ in range(num_of_nodes)]
        self.make_adj(data)

    def make_adj(self, data):
        # 隣接リストの作成 (接続先 コスト)のタプル
        for f, t, c in data:
            self.adj[f].insert(0, (t, c))
            self.adj[t].insert(0, (f, c))

    def dijkstra(self, start):
        self.d[start] = 0
        pq = [(0, start)]
        #heappush(pq, (0, start))

        while pq:
            cost, u = heappop(pq)
            self.color[u] = Sssp.Status.black
            if self.d[u] < cost:
                continue

            for v, c in self.adj[u]:
                if self.color[v] == Sssp.Status.black:
                    continue
                if self.d[v] > self.d[u] + c:
                    self.d[v] = self.d[u] + c
                    heappush(pq, (self.d[v], v))
                    self.color[v] = Sssp.Status.gray


def main():
    # データの入力
    N = int(input())
    data = []
    for i in range(N-1):
        data.append(list(map(int, input().split(' '))))
    queries = []
    Q, K = [int(x) for x in input().split(' ')]
    for i in range(Q):
        queries.append([int(x) for x in input().split(' ')])

    # 経路の探索
    s = Sssp(N, data)
    s.dijkstra(K)

    # 結果の表示
    for q in queries:
        print(s.d[q[0]] + s.d[q[1]])



if __name__ == '__main__':
    main()
    


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://abc070.contest.atcoder.jp/tasks/abc070_d
"""
# TLEするので、ダイクストラのアルゴリズムからの高速化が必要。
# 隣接行列をやめて隣接リストにしたところ、だいぶ速度が改善された。しかし、今度はWAが出るようになった。
# WAはコスト無限大の設定値が低すぎたため、経路コストがオーバーしてしまっていたため。float('inf')にして TLEのみになった
# d[]をnumpyの行列にしてみた → 遅くなっただけ
# クラスをやめてベタ書きに
from heapq import heappush, heappop


# データの入力
N = int(input())
adj = [[] for _ in range(N+1)]
for i in range(N-1):
    f, t, c = [int(x) for x in input().split(' ')]
    adj[f].append((t, c))
    adj[t].append((f, c))

queries = []
Q, K = [int(x) for x in input().split(' ')]
for _ in range(Q):
    queries.append([int(x) for x in input().split(' ')])

# 経路の探索
WHITE, GRAY, BLACK = 0, 1, 2
color = [WHITE] * (N+1)  # 各ノードの訪問状態
d = [float('inf')] * (N+1)  # 始点からの重み

# dijkstra
d[K] = 0
pq = [(0, K)]

while pq:
    cost, u = heappop(pq)
    color[u] = BLACK
    if d[u] < cost:
        continue

    for v, c in adj[u]:
        if color[v] == BLACK:
            continue
        if d[v] > d[u] + c:
            d[v] = d[u] + c
            heappush(pq, (d[v], v))
            color[v] = GRAY

# 結果の表示
for x, y in queries:
    print(d[x] + d[y])
### BUGGY CODE ###

import itertools

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

# tmp = itertools.combinations_with_replacement(P, K)
tmp = itertools.combinations(P, K)

hoge = []
for i in tmp:
    hoge.append(sum(i))

print(min(hoge))


### FIXED CODE ###

# import itertools

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

# tmp = itertools.combinations_with_replacement(P, K)
# tmp = itertools.combinations(P, K)

P.sort()
print(sum(P[0:K]))

# hoge = []
# for i in tmp:
#     hoge.append(sum(i))

# print(min(hoge))
### BUGGY CODE ###

K, S = map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        if (S-(x+y) <= K)&(S-(x+y) >= 0):
            count += 1
print(count)

### FIXED CODE ###

K, S = map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S-x-y
        if (z>=0)&(z<=K):
            count += 1
print(count)
### BUGGY CODE ###

import math
n,m = map(int,input().split())
price = list(map(int,input().split()))
price.sort(reverse=True)
real_price = 0
while m != 0:
    price[0] = price[0]//2
    price.sort(reverse=True)
    m -= 1

#for i in range(n):
#    real_price += math.floor(price[i])
#print(real_price)
print(sum(price))

### FIXED CODE ###

import heapq
n,m = map(int,input().split())
p = list(map(int,input().split()))
price = [x*(-1) for x in p]
heapq.heapify(price)
while m != 0:
    max_price = heapq.heappop(price)*(-1)
    heapq.heappush(price,(max_price//2)*(-1))
    m -= 1
print(sum(price)*(-1))
### BUGGY CODE ###

s = input()
l = len(s)
mod = [1] + [0 for _ in range(2019)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = (int(degit) * (10 ** idx) + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)


### FIXED CODE ###

s = input()
l = len(s)
mod = [1] + [0 for _ in range(2019)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = int(degit) * pow(10, idx, 2019)
    m = (m + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

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

import copy
n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
   
      
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  for i in rs.keys():
    for j in gs.keys():
      bs_tmp = copy.deepcopy(bs)
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < 0 or e > len(s):
          continue
        if e in bs_tmp:
          del bs_tmp[e]
          saidai -= 1
  print(int(saidai))

### FIXED CODE ###

n = int(input())
s = input()

rs = {}
gs = {}
bs = {}

for i, e in enumerate(s):
  if e == 'R':
    rs[i] = ''
  if e == 'G':
    gs[i] = ''
  if e == 'B':
    bs[i] = ''
    
saidai = len(rs) * len(gs) * len(bs)
if saidai == 0:
  print('0')
else:
  a = max(bs.keys())
  b = min(bs.keys())
  for i in rs.keys():
    for j in gs.keys():
      mi = i if i < j else j
      ma = j if i < j else i
      p = [mi - (ma - mi), mi + (ma - mi)/2, ma + (ma - mi)]
      for e in p:
        if e%1 != 0 or e < b or e > a:
          continue
        if e in bs:
          saidai -= 1
  print(int(saidai))
### BUGGY CODE ###

def warshall_floyd(d):
	for k in range(N):
		for i in range(N):
			for j in range(N):
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
	return d
	
N,M = map(int,input().split())
d = [[float("inf")]*N for i in range(N)]
lines = []
for i in range(M):
	lines.append(list(map(int,input().split())))
	d[lines[i][0]-1][lines[i][1]-1] = 1
	d[lines[i][1]-1][lines[i][0]-1] = 1
for i in range(N):
	d[i][i] = 0
warshall_floyd(d)

count1 = 0
count2 = 1
H = [-1]*N
H[0] = 0
P = [-1]*N
l = []
while count1 < N-1:
	lnext =[]
	if count2 == 1:
		l.append(0)
	for i in range(M):
		if (lines[i][0]-1 in l and H[lines[i][1]-1] == -1):
			count1 += 1
			lnext.append(lines[i][1]-1)
			P[lines[i][1]-1] = lines[i][0]
			H[lines[i][1]-1] = count2
		if lines[i][1]-1 in l and H[lines[i][0]-1] == -1:
			count1 += 1
			lnext.append(lines[i][0]-1)
			P[lines[i][0]-1] = lines[i][1]
			H[lines[i][0]-1] = count2
	count2 += 1
	l = lnext
count3 = 0
for i in range(1,N):
	if H[i] == d[0][i]:
		count3 += 1
if count3 == N-1:
	print('Yes')
	for i in range(1,N):
		print(P[i])
else:
	print('No')
		
		
	
	


### FIXED CODE ###

import queue
import math
q = queue.Queue()
A = []
B = []
N,M = map(int,input().split())
check = [-1]*N
graph = [[] for i in range(N+1)]
flag = [0]*N
for i in range(M):
	lines = list(map(int,input().split()))
	A.append(lines[0])
	B.append(lines[1])
	graph[lines[0]].append(lines[1])
	graph[lines[1]].append(lines[0])

q.put(1)
check[0] = 0
while not q.empty():
	p = q.get()
	for np in graph[p]:
		if check[np-1] == -1:
			check[np-1] = check[p-1] + 1
			q.put(np)

for i in range(M):
	if check[A[i]-1] - check[B[i]-1] == 1:
		flag[A[i]-1] = B[i]
	if check[B[i]-1] - check[A[i]-1] == 1:
		flag[B[i]-1] = A[i]

print('Yes')
for i in range(1,N):
	print(flag[i])
### BUGGY CODE ###

K = int(input())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sm += gcd_3(a,b,c)

print(sm)


### FIXED CODE ###

K = int(input())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    sm += a
    for b in range(a+1, K+1):
        for c in range(b+1, K+1):
            sm += gcd_3(a,b,c) * 6
    for b in range(1, K+1):
        if a != b:
            sm += gcd(a,b) * 3

print(sm)
### BUGGY CODE ###

def main():
    n, p = map(int, input().split())
    if n == 1:
        print(p)
    else:
        ans = 1
        x = 1
        while x**n <= p:
            if p % (x**n) == 0:
                ans = x
            x += 1
        print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
from math import log
def main():
    n, p = map(int, input().split())
    if n == 1:
        print(p)
    else:
        ans = 1
        if n > int(log(p, 2))+2:
            print("1")
            sys.exit()
        if p % (2**n) == 0:
            while p % (2**n) == 0:
                ans *= 2
                p //= (2**n)
        for i in range(3, 10**6+1, 2):
            while p % (i**n) == 0:
                ans *= i
                p //= (i**n)
        print(ans)

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

n=int(input())
a = list(map(int,input().split()))
def p(val):
    print(val)

sho = 10**9 +7
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        count += (a[i]*a[j]) % sho
        if count > sho:
            count = count%sho
p(count)

### FIXED CODE ###

n=int(input())
a = list(map(int,input().split()))
def p(val):
    print(val)
 
sho = 10**9 +7
a1 = sum(a)**2
b1 = list(map(lambda y:y**2,a))
b2=sum(b1)
result = ((a1-b2)//2)% sho
p(result)
### BUGGY CODE ###

h, w = map(int, input().split())

field = [input() for _ in range(h)]

dist = [[h*w*100 for i in range(w)] for j in range(h)]
dist[0][0] = 1

import queue

q = queue.Queue()
q.put((0,0))

dx = [-1,1,0,0]
dy = [0,0,1,-1]
while not q.empty() :
    (x,y) = q.get()
    for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
        nx = x + dx
        ny = y + dy
        if nx < 0 or nx >= h or ny < 0 or ny>= w :
            continue
        if field[nx][ny] == '#':
            continue
        if dist[nx][ny] > dist[x][y] :
            dist[nx][ny] = dist[x][y] + 1
            q.put((nx,ny))

if dist[h-1][w-1] >= h*w :
    print(-1)
    exit(0)

# print(dist)

ans = h*w - dist[h-1][w-1]
for v in field:
    for c in v:
        if c == '#':
            ans -= 1

print(ans)


### FIXED CODE ###

import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#' :
                continue
            if dist[nx][ny] > dist[x][y] + 1 :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

from collections import deque

def main():
    h, w = map(int, input().split())
    G = [("#",)*(w+2)]+[("#",)+tuple(input())+("#",) for i in range(h)]+[("#",)*(w+2)]
    dy, dx = [-1, 1, 0, 0], [0, 0, -1, 1]
    dist = [[-1 for j in range(w+2)] for i in range(h+2)]
    que = deque()
    
    for i in range(1, h+1):
        for j in range(1, w+1):
            if G[i][j] == "#":
                dist[i][j] = 0
                que.append((i, j))
    ans = 0
    while (len(que) != 0):
        y, x = que[0][0], que[0][1]
        que.popleft()

        for i in range(4):
            ny, nx = y+dy[i], x+dx[i]
            if G[ny][nx] == "#":
                continue
            if dist[ny][nx] == -1:
                dist[ny][nx] = dist[y][x] + 1
                que.append((ny, nx))
                ans = max(ans, dist[ny][nx])
    print(ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque

def main():
    h, w = map(int, input().split())
    G = [["#"]*(w+2)]+[["#"]+list(input())+["#"] for i in range(h)]+[["#"]*(w+2)]
    dy, dx = [-1, 1, 0, 0], [0, 0, -1, 1]
    dist = [[-1 for j in range(w+2)] for i in range(h+2)]
    que = deque()
    
    for i in range(1, h+1):
        for j in range(1, w+1):
            if G[i][j] == "#":
                dist[i][j] = 0
                que.append((i, j))
    
    while (len(que) != 0):
        y, x = que[0][0], que[0][1]
        que.popleft()

        for i in range(4):
            ny, nx = y+dy[i], x+dx[i]
            if G[ny][nx] == "#":
                continue
            if dist[ny][nx] == -1:
                dist[ny][nx] = dist[y][x] + 1
                que.append((ny, nx))
    
    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            ans = max(ans, dist[i][j])
    print(ans)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

L = int(input(),2)
K = 2**100000
ans = 0
t = 0
c = 100001
for p in [None]*100001:
	c -= 1
	if (L & K):
		ans = (ans + (2**t)*(3**c)%1000000007)%1000000007
		t += 1
	K //= 2
print((ans+2**t)%1000000007)

### FIXED CODE ###

L = input()
length = len(L)
a = 2
b = 1
c = 4
for l in L[1:]:
	if l  == '1':
		a = (a * 3) % 1000000007
		b = (b * 3) % 1000000007
		c = (c * 2) % 1000000007
	else:
		a = (a * 3 - c) % 1000000007
		b = (b * 3) % 1000000007
print((a + b)%1000000007)
### BUGGY CODE ###

import itertools

a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for _ in range(m)]
kumiawase_kingaku = float('inf')
for ab in itertools.product(a_list, b_list):
    if ab[0] + ab[1] < kumiawase_kingaku:
        kumiawase_kingaku = ab[0] + ab[1]

for x, y, c in m_list:
    reizouko = a_list[x-1]
    denshirenji = b_list[y-1]
    kingaku = reizouko + denshirenji - c
    if kingaku < kumiawase_kingaku:
        kumiawase_kingaku = kingaku

print(kumiawase_kingaku)


### FIXED CODE ###

import itertools

a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for _ in range(m)]

kumiawase_kingaku = min(a_list) + min(b_list)

for x, y, c in m_list:
    reizouko = a_list[x-1]
    denshirenji = b_list[y-1]
    kingaku = reizouko + denshirenji - c
    if kingaku < kumiawase_kingaku:
        kumiawase_kingaku = kingaku

print(kumiawase_kingaku)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

def main():
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    count = 0
    for i in range(n):
      count_temp = 0
      for k in range(n):
        if i != k and a[i] % a[k] == 0:
        	count_temp += 1
      if count_temp == 0:
        count += 1
    print(count)
  
if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter
import sys
n=int(input())
a=sorted(list(map(int,input().split())))
 
c=[1 for i in range(10**6+1)]
d = Counter(a)
s = list(set(a))
count = 0
if d[1] == 1:
  print(1)
  sys.exit()
elif d[1] >=2:
  print(0)
  sys.exit()
for x in s:
  t = x * 2
  while t <= 10 ** 6:
    c[t] = 0
    t += x
 
for x in a:
  if d[x] == 1 and c[x] == 1:
    count += 1
print(count)