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

s = input()
g = 0
q = int(input())
for i in range(q):
	d = input().split(" ")
	if d[0] == "1":
		if g == 0:
			g = 1
		else:
			g = 0
	if d[0] == "2":
		f = d[1]
		if g == 0:
			if f == "1":
				s = d[2] + s
			else:
				s = s + d[2]
		else:
			if f == "1":
				s = s + d[2]
			else:
				s = d[2] + s
if g == 1:
	ans = s[::-1]
	print(ans)
else:
	print(s)			


### FIXED CODE ###

from collections import deque
s = deque()
l = input()
for i in range(len(l)):
	s.append(l[i:i+1])
g = 0
q = int(input())
for i in range(q):
	d = input().split(" ")
	if d[0] == "1":
		if g == 0:
			g = 1
		else:
			g = 0
	if d[0] == "2":
		f = d[1]
		if g == 0:
			if f == "1":
				s.appendleft(d[2])
			else:
				s.append(d[2])
		else:
			if f == "1":
				s.append(d[2])
			else:
				s.appendleft(d[2])
if g == 1:
	s.reverse()
	ans = "".join(s)
	print(ans)
else:
	ans = "".join(s)
	print(ans)
### BUGGY CODE ###

h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = []
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb.append([inp[0]-1, inp[1] - 1])
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            for k in range(len(bomb)):
                if bomb[k] == [j, i]:
                    flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)

### FIXED CODE ###

h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = [set() for i in range(h)]
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb[inp[0]-1].add(inp[1]-1)
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            if i in bomb[j]:
                flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)
### BUGGY CODE ###

from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
S = input()

former = defaultdict(int)
latter = defaultdict(int)

def power(n):
  return chain(*(combinations(range(n), r) for r in range(n+1)))

for p in power(N):
  bs1 = []; rs1 = []; bs2 = []; rs2 = []
  for i in range(N):
    if i in p:
      rs1.append(S[i])
      rs2.append(S[-1-i])
    else:
      bs1.append(S[i])
      bs2.append(S[-1-i])
  former["".join(rs1), "".join(bs1)] += 1
  latter["".join(bs2), "".join(rs2)] += 1

ans = 0
for k, v in former.items():
  if k in latter:
    ans += v * latter[k]

print(ans)

### FIXED CODE ###

from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
S = input()

former = defaultdict(int)
latter = defaultdict(int)

for bits in range(1 << N):
  bs1 = []; rs1 = []; bs2 = []; rs2 = []
  for i in range(N):
    if (1 << i) & bits:
      rs1.append(S[i])
      rs2.append(S[-1-i])
    else:
      bs1.append(S[i])
      bs2.append(S[-1-i])
  former["".join(rs1), "".join(bs1)] += 1
  latter["".join(bs2), "".join(rs2)] += 1

ans = 0
for k, v in former.items():
  if k in latter:
    ans += v * latter[k]

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

N, M = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
  A[i], B[i] = map(int, input().split())
INF = 10** 9
# dp[i][j]: i+1番目までの商品で、j+1本の栄養ドリンクを買い集めるための最小コスト
dp = [[INF for i in range(M)] for j in range(N)]

for i in range(N):
  for j in range(M):
    array = []
    for k in range(min([j+1, B[i]])+1):
      array.append(dp[i-1][j-k] + A[i]*k if j>=k else A[i]*k)
    #dp[i][j] = min([dp[i-1][j], dp[i-1][j-1]+A[i], ... dp[i-1][j-B[i]] + A[i]*B[i]])
    dp[i][j] = min(array) if i > 0 else A[i]*(j+1)

print(dp[N-1][M-1])

### FIXED CODE ###

N, M = map(int, input().split())
array = []
for i in range(N):
  elm = list(map(int, input().split()))
  array.append(elm)

array.sort(key=lambda x: x[0])
ans = 0
cnt = 0
for i in range(N):
  #何本買うか
  buy = min([array[i][1], M-cnt])
  cnt += buy
  ans += array[i][0]*buy

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

h,n=map(int,input().split())
m=list(map(int, input().split()))
m.sort(reverse=True)
a=0
for i in range(n):
  m.pop(0)
  if len(m)==0:
  	break
  
for i in range(len(m)):
  a=a+m[i]
  
print(a)

### FIXED CODE ###

h,n=map(int,input().split())
m=list(map(int, input().split()))
m.sort(reverse=True)
del m[:n]
a=0

for i in range(len(m)):
  a=a+m[i]
  
print(a)
### BUGGY CODE ###

def calc(x):
    return (x+1)/2

n, k = map(int, input().split())
p = list(map(calc,(map(int, input().split()))))

_p = [sum(p[i:i+k]) for i in range(n-k+1)]

print(max(_p))


### FIXED CODE ###

def calc(x):
    return (x+1)/2

n, k = map(int, input().split())
p = list(map(calc,(map(int, input().split()))))

_ans = sum(p[0:k])
ans = _ans
for x in range(n-k):
    # print(x, x + k)
    _ans = _ans - p[x] + p[x + k]
    ans = max(ans, _ans)

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

import bisect
import math
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
cnt=[]
for i in range(max(A)):
  cnt.append(A.count(i+1))
combs=[]
for c in cnt:
  combs.append(comb(c,2))
total=sum(combs)
for a in A:
  print(total-combs[a-1]+comb(cnt[a-1]-1,2))

### FIXED CODE ###

from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))
### BUGGY CODE ###

S=input()
Q=int(input())
import sys


for _ in range(Q):
  input = sys.stdin.readline
  s = list(input())
  if s[0]=="1":
    S=S[::-1]
  else:
    if s[2]=="1":
      S="".join([s[4],S])
    else:
      S="".join([S,s[4]])
      
print(S)

### FIXED CODE ###

S=input()
Q=int(input())
import sys
from collections import deque
d=deque()
for _ in S:
  d.append(_)
flag=False

for _ in range(Q):
  s = list(sys.stdin.readline())
  if s[0]=="1":
    if flag:
      flag=False
    else:
      flag=True
  else:
    if s[2]=="1":
      if flag:
        d.append(s[4])
      else:
        d.appendleft(s[4])
    else:
      if flag:
        d.appendleft(s[4])
      else:
        d.append(s[4])
      
if flag:
  d.reverse()
  
print("".join(d))
### BUGGY CODE ###

n, m = map(int, input().split())
r = [[0, 0] for _ in range(m)]
ln = []
l1 = []
for i in range(m):
    r[i][0], r[i][1] = map(int, input().split())
    if r[i][1] == n:
        ln.append(i)
    if r[i][0] == 1:
        l1.append(i)
ans = "IMPOSSIBLE"
for i in l1:
    for j in ln:
        if r[i][1] == r[j][0]:
            ans = "POSSIBLE"
            break
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
l = [0] * n
r = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        r.append(b)
    if b == n:
        l[a - 1] = 1
ans = "IMPOSSIBLE"
for i in r:
    if l[i - 1] == 1:
        ans = "POSSIBLE"
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
mod2 = 2 ** (mod-2) % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) * mod2) % mod
sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) * mod2) % mod
sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0

if k%2 == 0:
    sigmakp = (int(k/2) * (k+1)) % mod
    sigmakn = (int(k/2) * (k-1)) % mod
else:
    sigmakp = (int((k+1)/2) * k) % mod
    sigmakn = (int((k-1)/2) * k) % mod

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)
### BUGGY CODE ###

S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i])%p) * (pow(10,N-i-1)%p)
  k %= p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = cnt[0]
for i in range(1,p):
  if cnt[i] > 0:
    ans += cnt[i]-1

print(ans)

### FIXED CODE ###

S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = 0
for i in range(p):
  m = cnt[i]
  if i == 0 and m > 0:
    ans +=  (m*(m+1))//2
  else:
    ans += (m*(m-1))//2
print(ans)
### BUGGY CODE ###

N = input()
INF = 10 ** 9
N = N[::-1] + '0'
dp = [[INF for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0] = 0

for i in range(len(N)):
    for j in range(2):
        x = int(N[i])
        x += j
        for k in range(10):
            nexti = i + 1
            nextj = 0
            b = k - x
            if b < 0:
                nextj = 1
                b += 10
            dp[nexti][nextj] = min(dp[nexti][nextj], dp[i][j] + k + b)
print(dp[len(N)][0])

### FIXED CODE ###

N = input()
INF = 10 ** 9
N = N[::-1] + '0'
dp = [[INF for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0] = 0

for i in range(len(N)):
    for j in range(2):
        x = int(N[i])
        x += j
        for k in range(10):
            nexti = i + 1
            nextj = 0
            b = k - x
            if b < 0:
                nextj = 1
                b += 10
            dp[nexti][nextj] = min(dp[nexti][nextj], dp[i][j] + k + b)
print(dp[len(N)][0])
### BUGGY CODE ###

from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]###(*)
  ###これまでのやつに与えたダメージは引き継がれるものとする
  d = ds[i]
  if d>=h:
    continue###すでに体力以上のダメージを与えた敵
  h -= d###ダメージを与える
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  ###(*)のせいで, 2Dよりも向こう側にも、今考えたダメージの影響が
  ###出てしまうので. それを打ち消すために与えるダメージを引いておく
  b += times
print(b)


### FIXED CODE ###

from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]###(*)
  ###これまでのやつに与えたダメージは引き継がれるものとする
  d = ds[i]
  if d>=h:
    continue###すでに体力以上のダメージを与えた敵
  h -= d###ダメージを与える
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  ###(*)のせいで, 2Dよりも向こう側にも、今考えたダメージの影響が
  ###出てしまうので. それを打ち消すために与えるダメージを引いておく
  b += times
print(b)
### BUGGY CODE ###

import bisect

S=int(input())
A=[int(i) for i in input().split()]

T=int(input())
B=[int(i) for i in input().split()]

l=0
r=len(A)
c=(r+l)/2

n=0


for i in B:
    if i in A:
        n+=1
    elif i>c:
        l=c+1
        c=(r+l)/2
    elif i<c:
        r=c
        c=(r+l)/2

print(n)



### FIXED CODE ###


def bs(A, n):
    l=0
    r=len(A)
    while l<r:
        mid=int((l+r)/2)
        if A[mid]==n:
            return mid
        else:
            if n<A[mid]:
                r=mid
            else:
                l=mid+1

    return -1

S=int(input())
A=[int(i) for i in input().split()]

T=int(input())
B=[int(j) for j in input().split()]

A.sort()

cnt=0
for i in range(T):
    x=bs(A,B[i])
    if x!=(-1):
        cnt=cnt+1

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

import bisect
N = int(input())
a = list(map(int,input().split()))
a_left = sorted(a[:N])
a_right = sorted(a[N:])
sum_left = sum(a_left)
sum_right = sum(a_right[:N])
res = sum_left - sum_right

len_left = N
for elem in a[N:2*N]:
    le = bisect.bisect_left(a_right, elem)
    a_right.remove(elem)
    if le < N:
        sum_right -= elem
        sum_right += a_right[N-1]
    ri = bisect.bisect_left(a_left, elem)
    if ri >= len_left - N:
        a_left.insert(ri, elem)
        len_left += 1
        sum_left -= a_left[len_left-N-1]
        sum_left += elem
    res = max(res, sum_left-sum_right)
print(res)

### FIXED CODE ###

import bisect
import heapq
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
a_left = sorted(a[:N])
a_right = sorted(a[2*N:])
sum_left = sum(a_left)
sum_right = sum(a_right)
#res = sum_left - sum_right
res = sum_left - sum(sorted(a[N:])[:N])
a_right = [-elem for elem in a_right]
heapq.heapify(a_right)
heapq.heapify(a_left)
sr = [0]*(N+1)
sr[0] = sum_right

for i,elem in enumerate(reversed(a[N:2*N])):
    now = -heapq.heappop(a_right)
    if now > elem:
        heapq.heappush(a_right, -elem)
        sum_right += (elem-now)
    else:
        heapq.heappush(a_right, -now)
    sr[i+1] = sum_right

for i,elem in enumerate(a[N:2*N]):
    now = heapq.heappop(a_left)
    if now < elem:
        heapq.heappush(a_left, elem)
        sum_left += (elem-now)
    else:
        heapq.heappush(a_left, now)
    res = max(res, sum_left-sr[N-i-1])
print(res)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for i in range(q)]

c = [0]
for i in range(n-1):
  c.append(s[i:i+2]=='AC') 
    
for x in a:
  print(sum(c[x[0]:x[1]]))

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for i in range(q)]

c = [0] * n
for i in range(1,n):
  c[i] = c[i-1] + (s[i-1]+s[i] == 'AC')

for x in a:
  print(c[x[1]-1]-c[x[0]-1])
### BUGGY CODE ###

import math

def main():
    N = int(input())
    dam_list  = list(map(int, input().split(" ")))
    water_list = []

    for i in range(N):
        sign = 1
        total = 0
        for j in range(i, N+i):
            if j >= N:
                j = j-N
            total = total + dam_list[j] * sign
            sign = sign * -1
        print(total, end=" ")
    
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math

def main():
    N = int(input())
    dam_list  = list(map(int, input().split(" ")))
    water_list = [0 for i in range(N)]
    upstream = dam_list[N-1]
    downstream = 0
    
    for i in range(N):
        water_list[N-1-i] = water_list[N-1-i] + upstream
        water_list[i] = water_list[i] + downstream

        if i == N-1:
            break

        upstream = upstream * -1 + dam_list[N-1 - (i+1)]
        downstream = downstream * -1 + dam_list[i]

    for i in water_list:
        print(i, end=" ")
    return


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

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
R=[tuple(map(int,input().split())) for i in range(M)]

E=[set() for i in range(N)]

for x,y in R:
    E[x-1].add(y-1)


LEFT=[[0]*N for i in range(N)]

RIGHT=[0]*N

for i in range(N):
    LEFT[i][i]+=1

    kei=len(E[i])

    for to in E[i]:
        LEFT[i][to]=-1/kei

    RIGHT[i]=1

RIGHT[N-1]=0
    
import numpy
ANS=numpy.linalg.solve(LEFT,RIGHT)[0]


for i in range(M):
    x,y=R[i]
    E[x-1].remove(y-1)

    LEFT=[[0]*N for i in range(N)]

    RIGHT=[0]*N

    for i in range(N-1):
        kei=len(E[i])
        if kei==0:
            continue
        
        LEFT[i][i]+=1

        for to in E[i]:
            LEFT[i][to]=-1/kei

        RIGHT[i]=1

    LEFT[N-1][N-1]+=1

    RIGHT[N-1]=0

    #print(LEFT)

    #print(numpy.linalg.det(LEFT))

    if numpy.linalg.det(LEFT)!=0:
        ANS=min(ANS,numpy.linalg.solve(LEFT,RIGHT)[0])

    #print(numpy.linalg.solve(LEFT,RIGHT)[0])
    #print(numpy.linalg.solve(LEFT,RIGHT))

    E[x-1].add(y-1)

print(ANS)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
R=[tuple(map(int,input().split())) for i in range(M)]

E=[set() for i in range(N)]

for x,y in R:
    E[x-1].add(y-1)

DP=[M]*N
DP[N-1]=0

for i in range(N-2,-1,-1):
    score=0
    for x in E[i]:
        score+=1+DP[x]

    DP[i]=score/len(E[i])
        
ANS=DP[0]

for i in range(N-2):
    rem=-1
    remsc=0
    for j in E[i]:
        if DP[j]>remsc:
            rem=j
            remsc=DP[j]

    if remsc==0:
        continue

    E[i].remove(rem)

    NDP=[M]*N
    NDP[N-1]=0

    for l in range(N-2,-1,-1):
        
        score=0
        
        if len(E[l])==0:
            continue
        
        for x in E[l]:
            score+=1+NDP[x]

        NDP[l]=score/len(E[l])

    #print(i,rem,E,NDP)

    ANS=min(ANS,NDP[0])
    E[i].add(rem)

print(ANS)
### BUGGY CODE ###

import itertools

n,m,q = map(int,input().split())

abcd = [input() for _ in range(q)]

x = itertools.combinations_with_replacement(range(1,m+1),n)
tmp = 0
ans = 0
for xi in x:
  tmp = 0

  for i in abcd:
    a,b,c,d = map(int,i.split())
    if xi[b-1] - xi[a-1] == c:
      tmp += d
  ans = max(ans,tmp)

print(ans)

### FIXED CODE ###

import itertools

n,m,q = map(int,input().split())

a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q

for i in range(q):
  a1,b1,c1,d1 = map(int,input().split())
  a[i] = a1
  b[i] = b1
  c[i] = c1
  d[i] = d1

x = itertools.combinations_with_replacement(range(1,m+1),n)
tmp = 0
ans = 0
for xi in x:
  tmp = 0

  for i in range(q):
    if xi[b[i]-1] - xi[a[i]-1] == c[i]:
      tmp += d[i]
  ans = max(ans,tmp)

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

import sys
input = sys.stdin.readline

class Unionfind:

    __slots__ = ['nodes','size']

    def __init__(self, n):
        self.nodes = list(range(n))
        self.size = [1]*n

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.size[x] += self.size[y]
        self.nodes[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

N,K,L = map(int,input().split())
road = [[int(e)-1 for e in input().split()] for _ in range(K)]
rail = [[int(e)-1 for e in input().split()] for _ in range(L)]

uf1 = Unionfind(N)
uf2 = Unionfind(N)

for p,q in road:
    uf1.unite(p,q)

for r,s in rail:
    uf2.unite(r,s)

set1 = [set() for _ in range(N)]
set2 = [set() for _ in range(N)]

for node in range(N):
    set1[node] = set1[uf1.root(node)]
    set1[node].add(node)
    set2[node] = set2[uf2.root(node)]
    set2[node].add(node)

ans = []

for node in range(N):
    ans.append(str(len(set1[node] & set2[node])))

print(" ".join(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline

class Unionfind:

    __slots__ = ['nodes','size']

    def __init__(self, n):
        self.nodes = list(range(n))
        self.size = [1]*n

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.size[x] += self.size[y]
        self.nodes[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

N,K,L = map(int,input().split())

uf1 = Unionfind(N)
uf2 = Unionfind(N)

for _ in range(K):
    p,q = map(int,input().split())
    p -= 1; q -= 1
    uf1.unite(p,q)

for _ in range(L):
    r,s = map(int,input().split())
    r -= 1; s -= 1
    uf2.unite(r,s)

keys = []
dic = {}

for node in range(N):
    key = (uf1.root(node),uf2.root(node))
    keys.append(key)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = [str(dic[key]) for key in keys]
print(" ".join(ans))
### BUGGY CODE ###

import sys
import collections
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    n = I()
    mylist = list(MI())
    mylist.sort(reverse = True)
    mylist = tuple(mylist)

    if mylist[n-1] in mylist[:n-1]:
        result = 0
    else:
        result = 1
    for i in range(n-1):
        temp = mylist[i]
        if mylist.count(temp) <= 1:
            divide = True
            for j in range(i+1,n):
                if temp % mylist[j] == 0:
                    divide = False
                    break
            if divide:
                result += 1
    print(result)

main()

### FIXED CODE ###

import sys
import collections
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    n = I()
    mylist = list(MI())
    max_a = max(mylist)
    exclude_set = set()
    tlist = [False] * (max_a+1)
    for a in mylist:
        if tlist[a]:
            exclude_set.add(a)
        else:
            tlist[a] = True
    ans = 0
    
    for i in range(1, max_a//2 + 1):
        if not tlist[i]:
            continue
        else:
            for j in range(2*i, max_a+1, i):
                tlist[j]=False
    for i in range(len(tlist)):
        if tlist[i] and not i in exclude_set:
            ans += 1
    print(ans)
                
    

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

s = input()
k = int(input())
n = len(s)

ansset= set()
from itertools import combinations_with_replacement

c = list(combinations_with_replacement(range(n),2))
#print(c)

for i in range(len(c)):
    ansset.add(s[c[i][0]:c[i][1]+1])
ans = sorted(list(ansset))

print(ans[k-1])

### FIXED CODE ###

s = input()
k = int(input())
n = len(s)

ansset= set()
for i in range(1,k+1):
    for j in range(n-i+1):
        ansset.add(s[j:j+i])

anslist = sorted(list(ansset))

print(anslist[k-1])