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

# -*- coding: utf-8 -*-

n=int(input())  #数値入力 「N」だけの入力のとき
i=0
lst ={}
while i < n: 
    s = input()
    if s not in lst:
        lst[s]=1
    else:
        lst[s]+=1
    i+=1

max_lst = [kv[0] for kv in lst.items() if kv[1] == max(lst.values())]
max_lst.sort()
for i in max_lst:
    print(i)
# ans = sorted(lst.items(), key=lambda x:x[1])
# for key in ans:
#     print(key)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n=int(input())  #数値入力 「N」だけの入力のとき
i=0
lst ={}
while i < n: 
    s = input()
    if s not in lst:
        lst[s]=1
    else:
        lst[s]+=1
    i+=1
maxi = max(lst.values())
res = []
for i,j in lst.items():
    if j == maxi:
       res.append(i) 
res.sort()
for i in res:
     print(i)
### BUGGY CODE ###

num = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = []

for i in range(num):
    c.append(a[i] ^ a[(i+1)%num])
    d.append(b[i] ^ b[(i+1)%num])

for k in range(num):
    c_rotated_k = []
    for i in range(num):
        c_rotated_k.append(c[(i+k)%num])
    if c_rotated_k == d:
        print(k, a[k] ^ b[0])

### FIXED CODE ###

num = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = []

for i in range(num):
    c.append(a[i] ^ a[(i+1)%num])
    d.append(b[i] ^ b[(i+1)%num])
    
c += c

# print(c)
# print(d)

# テーブル作成
table = [0]
k = 0
for i in range(1, num+1):
    table.append(k)
    if i == num:
        continue
    
    if d[i] == d[k]:
        k += 1
    else:
        k = 0

# print(table)

i = 0 # 探索される文字列の位置
j = 0 # 探索する文字列の位置
k = 0 # kの初期値
while k < num:
    
    while True:
        # print(i, j, k)
        if c[i] == d[j]:
            if j == num - 1:
                print(k, a[k] ^ b[0])
                i += 1
                j = table[num]
                k = i - j
                break
            
            i += 1
            j += 1
        elif j != 0:
            j -= 1
        else:    
            i += 1
            j = table[j]
            break
    
    k = i - j
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split()))
assert len(a) == N

# 解説を参照
# https://img.atcoder.jp/arc101/editorial.pdf

def mergesort(S, f, t, T=None):
    """f <= i < j <= t かつ S[i] <= S[j] である(i,j)の個数.
       実行後, S[f:t]は整列済みになる."""
    if t - f <= 1:
        return 0

    # 作業スペース
    if T == None:
        T = [0] * len(S)

    mid = (f + t) // 2
    n1 = mergesort(S, f, mid, T)
    n2 = mergesort(S, mid, t, T)

    # マージ
    n = n1 + n2
    i = f
    j = mid
    k = f
    while i < mid:
        if j >= t or S[i] <= S[j]:
            T[k] = S[i]
            i += 1
            n += t - j
        else:
            T[k] = S[j]
            j += 1
        k += 1
    for i in range(f, k):
        S[i] = T[i]
    return n

def n_median_larger_than_or_equal_to(x):
    """aの部分列の中央値のうちx以上のものの個数"""

    # aの要素を -1, 1 に置換したリスト
    b = [-1 if e < x else 1 for e in a]

    # bの累積和
    S = [0]
    for e in b:
        S.append(S[-1] + e)

    # 和が0以上であるbの部分列の個数
    # == i < j and S[i] <= S[j] である(i,j)の個数
    return mergesort(S, 0, len(S))

# 条件を満たす x の最大値を2分探索で探す
lo = 1
hi = max(a)

ncomb = N * (N + 1) // 2    # 部分列の個数

while lo < hi:
    mid = (lo + hi + 1) // 2
    nm = n_median_larger_than_or_equal_to(mid)
    if nm >= (ncomb + 1) // 2:
        lo = mid
    else:
        hi = mid - 1

print(lo)


### FIXED CODE ###

#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split()))
assert len(a) == N

# 解説を参照
# https://img.atcoder.jp/arc101/editorial.pdf

def mergesort(S, f, t):
    global T

    if t - f <= 1:
        return 0

    mid = (f + t) // 2
    n1 = mergesort(S, f, mid)
    n2 = mergesort(S, mid, t)
    n = n1 + n2
    i = f
    j = mid
    k = f
    while i < mid and j < t:
        if S[i] <= S[j]:
            T[k] = S[i]
            i += 1
            n += t - j
        else:
            T[k] = S[j]
            j += 1
        k += 1

    while i < mid:
        T[k] = S[i]
        i += 1
        k += 1
    assert k == j
    for i in range(f, k):
        S[i] = T[i]
    return n

def inversion(S):
    """リストSの転倒数"""
    global T
    T = [0] * len(S)
    return mergesort(S, 0, len(S))

def n_median_larger_than_or_equal_to(x):
    """aの部分列の中央値のうちx以上のものの個数"""

    # aの要素を -1, 1 に置換したリスト
    b = [-1 if e < x else 1 for e in a]
    # bの累積和
    S = [0]
    for e in b:
        S.append(S[-1] + e)
    # Sの転倒数
    return inversion(S)

# 条件を満たす x の最大値を2分探索で探す
lo = 1
hi = max(a)

ncomb = N * (N + 1) // 2    # 部分列の個数

while lo < hi:
    mid = (lo + hi + 1) // 2
    nm = n_median_larger_than_or_equal_to(mid)
    if nm >= (ncomb + 1) // 2:
        lo = mid
    else:
        hi = mid - 1

print(lo)
### BUGGY CODE ###

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
for i in t:
    if i in d:
        d.remove(i)
    else:
        print("NO")
        exit()
print("YES")

### FIXED CODE ###

import collections

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dc = collections.Counter(d)
tc = collections.Counter(t)
for i in tc:
    if tc[i] > dc[i]:
        print("NO")
        exit()
print("YES")
### BUGGY CODE ###

S = input()
counter = 0
ans_bf = len(S)
while True:
    S = list(S)
    len_bf = len(S)
    for i in range(0,(len_bf-1)):
        if (S[i] == '0' and S[i+1] == '1') or(S[i] == '1' and S[i+1] == '0') :
            S[i] = ""
            S[i+1] = ""
    S = "".join(S)
    if len_bf == len(S):
        break
print(ans_bf - len(S))


### FIXED CODE ###

import collections
S = input()
col_S = collections.Counter(S) 
print(min(col_S['0'],col_S['1'])*2)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=a[:]

x=0#pmpm
y=0

for i in range(n):
  if(i%2==0):
    if(sum(a[:i+1])<=0):
      x+=1-sum(a[:i+1])
      a[i]+=1-sum(a[:i+1])
    if(sum(b[:i+1])>=0):
      y+=sum(b[:i+1])+1
      b[i]-=sum(b[:i+1])+1
  else:
    if(sum(a[:i+1])>=0):
      x+=sum(a[:i+1])+1
      a[i]-=1+sum(a[:i+1])
    if(sum(b[:i+1])<=0):
      y+=1-sum(b[:i+1])
      b[i]+=1-sum(b[:i+1])
print(min(x,y))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=a[:]

x=0#pmpm
y=0
sum1=0
sum2=0

for i in range(n):
  sum1+=a[i]
  sum2+=b[i]
  if(i%2==0):
    if(sum1<=0):
      x+=1-sum1
      a[i]+=1-sum1
      sum1+=1-sum1
    if(sum2>=0):
      y+=sum2+1
      b[i]-=sum2+1
      sum2-=sum2+1
  else:
    if(sum1>=0):
      x+=sum1+1
      a[i]-=1+sum1
      sum1-=1+sum1
    if(sum2<=0):
      y+=1-sum2
      b[i]+=1-sum2
      sum2+=1-sum2
print(min(x,y))
### BUGGY CODE ###

N,P = map(int,input().split())
S = str(input())

if P == 2 or P == 5:
    S = list(map(int,list(S)))
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1

else:
    data = [0] * P
    s = int(S)
    for i in range(N):
        data[s%P] += 1
        s -= int(S[i]) * (10**(N-i-1))
    #print(data)
    ans = data[0]
    for i in range(P):
        ans += (data[i]*(data[i]-1))//2

print(ans)

### FIXED CODE ###

N,P = map(int,input().split())
S = str(input())

if P == 2 or P == 5:
    S = list(map(int,list(S)))
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1

else:
    data = [0] * P
    s = int(S)
    x = 1 ##10**iをPで割った数
    y = 0 ##S[i:N]をPで割った数
    for i in range(N):
        y += int(S[N-i-1]) * x
        y %= P
        data[y] += 1
        x *= 10
        x %= P
    #print(data)
    ans = data[0]
    for i in range(P):
        ans += (data[i]*(data[i]-1))//2

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

a,b,n = map(int, input().split())
max = 0
for i in range(n+1):
    score = int(a*i/b) - a*int(i/b)
    if score > max:
        max = score

print(max)

### FIXED CODE ###

a,b,n = map(int, input().split())
m = min(n,b-1)
print(int(a*m/b)-a*int(m/b))
### BUGGY CODE ###

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

if m==0:
    print(1)
    exit()
else:
    ab = [map(int, input().split()) for _ in range(m)]
    a,b = [list(i) for i in zip(*ab)]

indexlist=[-1]*n

def findroot(x):
    while 1:
        if indexlist[x-1] < 0:
            return x
        else:
            x=indexlist[x-1]
            


def merge(a,b):
    art=findroot(a)
    brt=findroot(b)
    if not art == brt:
        indexlist[art-1]+=indexlist[brt-1]
        indexlist[brt-1]=a
        return
    else:
        return
        

for j in range(m):
    a1=a[j]
    b1=b[j]
    merge(a1,b1)

ans=min(indexlist)*(-1)
print(ans)

### FIXED CODE ###

import sys

#UnionFindTreeクラスの定義
class UnionFind():
    #クラスコンストラクタ
    #selfはインスタンス自身
    def __init__(self, n):
        #親ノードを-1に初期化する
        self.parents = [-1] * n

    #根を探す（再帰関数）
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    #xとyの木を併合する
    def union(self, x, y):
        #x,yの根をX,Yとする
        X = self.find(x)
        Y = self.find(y)

        #根が同じなら結合済み
        if X == Y:
            return

        #ノード数が多い方をXとする
        if self.parents[X] > self.parents[Y]:
            X, Y = Y, X

        #XにYのノード数を足す
        self.parents[X] += self.parents[Y]
        #Yの根をXとする
        self.parents[Y] = X


N, M = map(int, input().split())
info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]

#UnionFindインスタンスの生成
uf = UnionFind(N)
for a, b in info:
    #インデックスを調整し、a,bの木を結合
    a -= 1; b -= 1
    uf.union(a, b)

ans = min(uf.parents)

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

n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[]
for i in range(n-k+1):
    for j in range(i,k+i):
        count+=(p[j]/2+0.5)

    ans.append(count)
    count=0
print(max(ans))

### FIXED CODE ###


n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[0]*(n-k+2)

for j in range(0,k):
    count+=(p[j]/2+0.5)
ans[0]=count
z=1
#print(ans)
for i in range(k,n):
    #print(p[i],p[z-1])
    ans[z]=ans[z-1]-(p[z-1]/2+0.5)+(p[i]/2+0.5)
    z+=1
#print(ans)
print(max(ans))
"""
n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[]
for i in range(n-k+1):
    for j in range(i,k+i):
        count+=(p[j]/2+0.5)

    ans.append(count)
    count=0
print(ans)
print(max(ans))
"""
### BUGGY CODE ###

def main():
    N, D, A = map(int, input().split())
    XH = [None] * N

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

    XH.sort()
    
    # 何回爆弾を当てれば倒せるか
    nums = [(XH[i][1]+A-1)//A  for i in range(N)]
    
    ans = 0
    for i in range(N):
        if nums[i] == 0:
            continue
        ans += nums[i]
        for j in range(i+1,N):
            if XH[j][0] - XH[i][0] <= 2*D:
                nums[j] = max(0,nums[j]-nums[i])
            else:
                break
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, D, A = map(int, input().split())
    XH = [None] * N
    X = [None] * N

    for i in range(N):
        XH[i] = tuple(map(int, input().split()))
        X[i] = XH[i][0]

    XH.sort()
    X.sort()
    
    ans = 0
    S = [0] * (N+1)# 与えたダメージ
    for i in range(N):
        if S[i] < XH[i][1]:
            # あと何回攻撃する？
            need = (XH[i][1]-S[i]+A-1)//A
            # 爆弾が届く範囲
            j = bisect_right(X,X[i]+2*D)
            # imos法
            S[i] += need*A
            S[j] -= need*A
            ans += need
        S[i+1] += S[i]
    print(ans)


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

s = input()
k = int(input())

index = []

for i in range(len(s)):
    for j in range(i+1,i+6):
        jyuhuku = 0
        for a in index:
            if(a == s[i:j]):
                jyuhuku = 1
                break
            
        if(jyuhuku == 0):
            index.append(s[i:j])
    

print(sorted(index)[k-1])


### FIXED CODE ###

s = input()
k = int(input())

index = []

for i in range(len(s)):
    for j in range(i+1,i+k+1):
        index.append(s[i:j])
    
print(sorted(list(set(index)))[k-1])
### BUGGY CODE ###

a,b,c,k = map(int,input().split())

ans = 0
for i in range(1,k+1) :
    if i <= a :
        ans += 1
    if i >= a+b+1 :
        ans -= 1

print(ans)

### FIXED CODE ###

a,b,c,k = map(int,input().split())


if k <= a :
    ans = k
elif k <= a+b :
    ans = a
else :
    ans = a - (k-a-b)

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

N = int(input())

mod = (N-1)*N/2
for i in range(1,N+1):
    if N%i == N:
        break

print(int(mod+N-i))

### FIXED CODE ###

n = int(input())
print(n*(n-1)//2)
### BUGGY CODE ###

from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,m = inpl()
aa = [[] for i in range(m)]
ans = 0
max_b = [0] * m
for i in range(n):
    a,b = inpl()
    if a <= m:
        aa[a-1].append(b)
for i in range(m):
    if aa[i]:
        max_b[i] = max(aa[i])

for i in range(m):
    mmm = 0
    max_i = -1
    for j in range(i+1):
        if max_b[j] > mmm:
            mmm = max_b[j]
            max_i = j
    ans += mmm
    if len(aa[max_i]) and max_i != -1:
        aa[max_i].remove(mmm)
        if aa[max_i]:
            max_b[max_i] = max(aa[max_i])
        else :
            max_b[max_i] = 0
print(ans)




### FIXED CODE ###

from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
hq = []
n,m = inpl()
ab = [[] for i in range(m)]
for i in range(n):
    a,b = inpl()
    if a <= m:
        ab[a-1].append(b)

heapq.heapify(hq)
for i in range(m):
    for j in ab[i]:
        heapq.heappush(hq,-j)
    if hq:
        ans -= heapq.heappop(hq)
print(ans)
### BUGGY CODE ###

def  isOk(arg):
    if arg > mn:
        return True
    else:
        return False

def bisect_m(ng,ok):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOk(l[mid]):
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
    a = l[n-1-i]
    for j in range(i+1,n-1):
        b = l[n-1-j]
        #print(a,b)
        mn = a - b
        ng = -1
        ok = n-1-j
        ok = bisect_m(ng,ok)
        ans += n-1-j - ok
        #print(a,b,l[ok],mn,ok)


print(ans)



### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
    a = l[n-1-i]
    for j in range(i+1,n-1):
        b = l[n-1-j]
        #print(a,b)
        mn = a - b
        ng = -1
        ok = n-1-j
        if mn >= b:
            continue
        while abs(ok - ng) > 1:
            hf = (ng + ok) // 2
            #print(a,b,l[hf])
            if l[hf] > mn:
                ok = hf
            else:
                ng = hf
        ans += n-1-j - ok
        #print(a,b,l[ok],mn,ok)


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

N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N

for i in range(N):
    x[i], y[i], h[i] = list(map(int, input().split()))

for i in range(101):
    for j in range(101):
        for k in range(N):
            H = h[k] + abs(x[k]-i) + abs(y[k]-j)
            if H < 1:
                continue
            flg = True
            for l in range(N):
                if max (H-abs(x[l]-i)-abs(y[l]-j),0) != h[l] :
                    flg = False
                    break
            if flg:
                print("{} {} {}".format(i,j,H))
                exit()

### FIXED CODE ###

N=int(input())

A=[]
for i in range(N):
    x,y,h=map(int,input().split())
    A.append([h,x,y])
A.sort(reverse=True)

for i in range(101):
    for j in range(101):
        for k in range(N):
            H = A[k][0] + abs(j-A[k][1]) + abs(i-A[k][2])
            flg = True
            for l in A:
                if l[0]!=max(0,H-abs(j-l[1])-abs(i-l[2])):
                    flg = False
                    break
            if flg == True:
                print(j,i,H)
                exit()
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
f_string = "AC"
for i in range(Q):
    l,r = map(int,input().split())
    temp = S[l-1:r]
    print(temp.count(f_string))

### FIXED CODE ###

n,q = map(int,input().split())
s = input()
ls = [0]*(n+1)
for i in range(len(s)):
    if s[i:i+2]=="AC":
        ls[i+1] += ls[i]+1
    else:
        ls[i+1] = ls[i]
for j in range(q):
    l,r = map(int,input().split())
    print(ls[r-1]-ls[l-1])
### BUGGY CODE ###

# C
k = int(input())

def gcd(x, y): 
    while(y): 
        x, y = y, x % y
    return x 

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, gcd(b, c))
            
print(ans)

### FIXED CODE ###

from  math import gcd
 
 
k = int(input())
sum_c = 0
 
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum_c += gcd(gcd(a, b), c)
            
print(sum_c)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(1000000)

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
a.append(N+1)
sum_move = 1
fact = [-1] * (N+1)
fact[0] = 1


def factorial(num, fact):
    if fact[num] > 0:
        return fact[num]
    else:
        fact[num] = factorial(num-1, fact) * num
        return fact[num]


step_begin = 0
for i in range(M+1):
    tmp_sum = 0
    step_end = a[i] - 1
    step_num = step_end - step_begin
    for j in range(step_num//2 + 1):
        tmp_sum += factorial(step_num - j, fact) \
            // factorial(j, fact) // factorial(step_num - 2 * j, fact)
    if tmp_sum != 0:
        sum_move *= tmp_sum
    else:
        sum_move = 0
        break
    step_begin = a[i] + 1

print(sum_move % 1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
oks = [True] * (N+1)
a = [int(input()) for _ in range(M)]
for i in a:
    oks[i] = False

dp = [0] * (N+1)
dp[0] = 1
for i in range(N+1):
    for j in range(i+1, min(i+2, N)+1):
        if oks[j]:
            dp[j] += dp[i]
            dp[j] %= int(1e9+7)


print(dp[N])
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
for i in range(N-2):
    for k in range(i+3, N):
        if S[i] != S[k]:
            A = ["R", "G", "B"]
            A.remove(S[i])
            A.remove(S[k])
            ans += S[i+1:k].count(A[0])
            if (k-i) % 2 == 0:
                if S[int((k-i)/2 + i)] == A[0]:
                    ans -= 1


print(ans)

### FIXED CODE ###

import copy
N = int(input())
S = input()

R = set()
G = set()
B = set()

for i in range(N):
    if S[i] == "R":
        R.add(i)
    elif S[i] == "G":
        G.add(i)
    else:
        B.add(i)

ans = len(R)*len(G)*len(B)

for r in R:
    for g in G:
        L = g - r
        if g + L in B:
            ans -= 1
        if r - L in B:
            ans -= 1
        if L % 2 == 0 and L//2 + r in B:
            ans -= 1
            



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

N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(2,N+2):
        if i not in a[prev_index:N]:
            count += N - (prev_index + 1)
            print(count)
            break
        else:
            count += a.index(i,prev_index) - prev_index -1
            two_ago_index = prev_index
            prev_index = a.index(i,prev_index)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)
### BUGGY CODE ###

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

    values = [0] * N
    links = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop(0)
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))
    print(*values)

main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n, *a = map(int, read().split())

b = [0] * n

a = sorted(a, reverse=True)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if a[i] % a[j] == 0:
            b[i] = 1
            break

print(n - sum(b))


### FIXED CODE ###

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n = int(readline())
a = np.array(read().split(), np.int32)

b = np.zeros(10**6 + 10, np.int32)
cnt = 0

for x in a:
    if b[x] > 1:
        continue
    b[::x] += 1

for x in a:
    if b[x] == 1:
        cnt += 1

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

S = input()
Q = int(input())

cnt = 0

#空の文字列にqueryで追加する文字を加えていく
ss = " "
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            ss = "".join([query[2],ss])
        else:
            ss = "".join([ss,query[2]])

#反転回数が奇数の場合、元の文字列とqueryにより作成した文字列を反転
if cnt%2 == 1:
    S = S[::-1]
    ss = ss[::-1]

#スペースに元の文字列を追加
print(ss.replace(" ", S))

### FIXED CODE ###

s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))