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

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

ans=1145141919
for i in range(n+1):
    ans = min(ans, (s[:i].count("#")+s[i:].count(".")))
print(ans)


### FIXED CODE ###

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

white=s.count(".")
black=0
ans=white

for s_i in s:
    if s_i == "#":
        black+=1
    else:
        white-=1
    ans = min(ans, white+black)
print(ans)
### BUGGY CODE ###

import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
ans = hhh[0][1] + www[0][1]
hhhh = deque([hhh[0][0]])
wwww = deque([www[0][0]])
for i in range(1, len(hhh)):
    if hhh[i][1] == hhh[i-1][1]:
        deque.append(hhhh, hhh[i][0])
    else:
        break
for i in range(1, len(www)):
    if www[i][1] == www[i-1][1]:
        deque.append(wwww, www[i][0])
    else:
        break
for h in hhhh:
    for w in wwww:
        if (h, w) not in S:
            print(ans)
            sys.exit()
print(ans-1)


### FIXED CODE ###

import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
h = hhh[0][1]
w = www[0][1]
ans = h+w
Nh = 0
Nw = 0
for i in range(len(hhh)):
    if h == hhh[i][1]:
        Nh += 1
    else:
        break
for i in range(len(www)):
    if w == www[i][1]:
        Nw += 1
    else:
        break
tt = Nh*Nw
if tt > M:
    print(ans)
    sys.exit()

for tmp in S:
    if hh[tmp[0]] == h and ww[tmp[1]] == w:
        tt -= 1
if tt > 0:
    print(ans)
else:
    print(ans-1)
### BUGGY CODE ###

[N, X, Y] = input().split()
N = int(N)
X = int(X)
Y = int(Y)
dist_list = []

for i in range(N):
    for j in range(i+1, N):
        if i+1 <= X and j+1 >= Y:
            dist_list.append(j - Y + X - i + 1)
        else:
            dist_list.append(min(j - i, abs(i+1 - X) + abs(j+1 -Y) + 1))

for k in range(N-1):
    print(dist_list.count(k+1))



### FIXED CODE ###

N, X, Y = map(int, input().split())
dist_list = [0]*N

for i in range(N-1):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        dist_list[min(a,b)] += 1

for k in range(N-1):
    print(dist_list[k+1])
### BUGGY CODE ###

x = int(input())
a = 0
cnt = 0
while x > 0:
  if a%2==0:
    x -= 6
  else:
    x -= 5
  a += 1
  cnt += 1
print(cnt)

### FIXED CODE ###

x = int(input())
a = x // 11
if (x-11*a) == 0:
  print(a*2)
elif 0 < (x-11*a) <= 6:
  print(a*2+1)
else:
  print(a*2+2)
### BUGGY CODE ###

h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)
M=[]
M.append(0)
for i in range(h):
  M.append(10000000000000)
for i in range(0,h+1):
  for j in range(n):
    c=min(h,a[j]+i)
    if M[c]>M[i]+b[j]:
      M[c]=M[i]+b[j]
print(M[h])

### FIXED CODE ###

h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)
M=[]
M.append(0)
for i in range(h):
  M.append(10000000000000)
for i in range(0,h+1):
  for j in range(n):
    c=min(h,a[j]+i)
    if M[c]>M[i]+b[j]:
      M[c]=M[i]+b[j]
print(M[h])
### BUGGY CODE ###

import numpy as np

N=int(input())
A=np.array([int(input()) for i in range(N)],dtype=np.int32)
B=[0 for i in range(N)]
C=sorted(A)
count=0
for i in range(N):

    if B[i]:
        continue

    else:
        temp=A[i]
        for m in range(i,N):
            if not B[m]:
                if A[m]==C[-1]:
                    B[m]=1
                    C.pop()
                    break
                else:
                    if temp<A[m]:
                        temp=A[m]
                        B[m]=1
        count+=1
    #print(i,count,B)
print(count)


### FIXED CODE ###

import bisect
import collections

N=int(input())
A=[int(input()) for i in range(N)]
B=[0 for i in range(N)]
C=sorted(A)
count=0
lst=collections.deque([])
for i in range(N):
    if A[i]==C[-1]:
        C.pop()
        if lst:
            lst.pop()
        else:
            count+=1
        continue
    idx=bisect.bisect_left(lst,A[i])-1
    #print(idx,lst,A[i])
    if idx<0:
        lst.appendleft(A[i])
        count+=1
    else:
        lst[idx]=A[i]

print(count)
### BUGGY CODE ###

value = int(input())
have_array = input().split()
have_array = [int(x) for x in have_array]

value2 = int(input())
problem_array = input().split()
problem_array = [int(x) for x in problem_array]

try:
    for i in range(0, value2):
        have_array.remove(problem_array[i])
except ValueError:
    print("NO")

if len(have_array) == value - len(problem_array):
    print("YES")


### FIXED CODE ###

n = int(input())
d_array = [int(x) for x in input().split()]
d_dict = {}
for d in d_array:
    d_dict.setdefault(d, 0)
    d_dict[d] += 1
m = int(input())
t_array = sorted([int(x) for x in input().split()])

try:
    for t in t_array:
        if d_dict[t] > 0:
            d_dict[t] -= 1
        else:
            print("NO")
            break
    else:
        print("YES")
except KeyError:
    print("NO")
    exit()
### BUGGY CODE ###

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

import numpy

def calc_lcs(s, t):
  dp = numpy.zeros((len(s)+1, len(t)+1))
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max((dp[i-1][j-1] + (1 if si==tj else 0), dp[i-1][j], dp[i][j-1]))

  lcs = ''
  i, j = len(s), len(t)
  while i > 0 and j > 0:
    if   dp[i][j] == dp[i-1][j-1]+1:
      lcs = s[i-1] + lcs
      i -= 1
      j -= 1
    elif dp[i][j] == dp[i-1][j]:
      i -= 1
    elif dp[i][j] == dp[i][j-1]:
      j -= 1
  return lcs

def main():
  s = input().strip()
  t = input().strip()
  print(calc_lcs(s, t))


if __name__=='__main__':
  main()

### FIXED CODE ###

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

# @profile
def calc_lcs(s, t):
  dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
  # dp = numpy.zeros((len(s)+1, len(t)+1))
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max((dp[i-1][j-1] + 1) if si==tj else 0, dp[i-1][j], dp[i][j-1])

  lcs = ''
  i, j = len(s), len(t)
  while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
      i -= 1
    elif dp[i][j] == dp[i][j-1]:
      j -= 1
    else:
      lcs = s[i-1] + lcs
      i -= 1
      j -= 1
  return lcs

def main():
  s = input().strip()
  t = input().strip()
  print(calc_lcs(s, t))


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

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

dp=[0]*(n+1)

dp[0]=1

if 1 in a:
  dp[1]=0
else:
  dp[1]=1
  

for i in range(2,n+1):
  if i in a:
    dp[i]=0
  else:
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    
print(dp[n])

### FIXED CODE ###

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

dp=[-1]*(n+1)

dp[0]=1

dp[1]=1

for i in a:
  dp[i]=0
  

for i in range(2,n+1):
  if dp[i]!=0:
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    
print(dp[n])
### BUGGY CODE ###

from collections import namedtuple
import sys

input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    Edge = namedtuple('Edge', 'cost from_ to')

    def bellman_ford(s):
        # 始点sから各頂点への最短距離
        dist = [inf] * n
        dist[s] = 0

        while True:
            update = False
            for e_ in e:
                if dist[e_.from_] != inf and dist[e_.to] > dist[e_.from_] + e_.cost:
                    dist[e_.to] = dist[e_.from_] + e_.cost
                    update = True
            if not update:
                break
        return dist

    n = int(input())
    e = set()
    for _ in range(n - 1):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        e.add(Edge(cost=c, from_=a, to=b))
        e.add(Edge(cost=c, from_=b, to=a))

    q, v = map(int, input().split())
    v -= 1

    d = bellman_ford(v)

    for _ in range(q):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        print(d[x] + d[y])


if __name__ == '__main__':
    solve()


### FIXED CODE ###

from collections import namedtuple
from heapq import heappop, heappush
import sys

input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    Edge = namedtuple('Edge', ('cost', 'to'))

    def dijkstra(s):
        used = [False] * n
        used[s] = True

        dist = [inf] * n
        dist[s] = 0

        h = []
        for e_ in e[s]:
            heappush(h, e_)

        while h:
            c, v = heappop(h)
            if used[v]:
                continue
            used[v] = True
            dist[v] = c
            for e_ in map(lambda x: (x.cost + dist[v], x.to), e[v]):
                heappush(h, e_)
        return dist

    n = int(input())
    e = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        e[a].append(Edge(cost=c, to=b))
        e[b].append(Edge(cost=c, to=a))

    q, v = map(int, input().split())
    v -= 1

    g = dijkstra(v)

    for _ in range(q):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        print(g[x] + g[y])


if __name__ == '__main__':
    solve()

# warshall_floyd
# n大で無理

# inf = 10 ** 14 + 10
#
# n = int(input())
# g = [[inf] * n for _ in range(n)]
# for i in range(n):
#     g[i][i] = 0
# for _ in range(n - 1):
#     a, b, c = map(int, input().split())
#     a -= 1
#     b -= 1
#     g[a][b] = c
#     g[b][a] = c
#
# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             g[i][j] = min(g[i][j], g[i][k] + g[k][j])
#
# q, v = map(int, input().split())
# v -= 1
# for _ in range(q):
#     x, y = map(int, input().split())
#     x -= 1
#     y -= 1
#     print(g[x][v] + g[v][y])
#
### BUGGY CODE ###

# 2019-11-14 10:01:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

mod = 10 ** 9 + 7
def main():
    n, m, *broken_treads = [int(x) for x in sys.stdin.read().split()]
    safe = sorted((set(range(1, n+1)) - set(broken_treads)))

    p = [0, 1] # p[i] は連続するi段の、1~i段目までの登り方の総パターン
    for _ in range(n):
        p.append(p[-1] + p[-2])

    count = 1 # 最初に0th stepを踏んでいるので1
    sections = []
    for i in range(1, n+1):
        if i in safe:
            count += 1
        else:
            if count >= 1:
                sections.append(p[count])
                count = 0
            else: # countが0だったら一つ前も壊れている
                print(0)
                sys.exit()
    
    if count >= 1:    # if the last is not broken.
        sections.append(p[count])

    ans = reduce(lambda x, y: x * y % mod, sections)
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

mod = 10 ** 9 + 7
n, m, *a = [int(x) for x in sys.stdin.read().split()]

safe = sorted(set(range(1,n+1)) - set(a))
dp = [0] * (n + 2)
dp[0] = 0
dp[1] = 1
for i in safe:
    dp[i+1] = (dp[i] + dp[i-1]) % mod

print(dp[-1])
### BUGGY CODE ###

import sys
input=sys.stdin.readline

# 頂点 s からの最短距離を求める (存在しないときはinf) O(|w|log|n|)
# n: 頂点数, w: 辺の数, cost[u][v]: 辺uvのコスト (cost が dict の場合 cost[(u,v)] など適宜)
# 前提条件: u < v
def dijkstra(s,n,w,cost):
    d = [float("inf")] * n # s からの距離
    d[s] = 0
    used = [False] * n # 使用済みの頂点か
    
    while True:
        v = -1
        # 未使用の頂点のうち、最小の距離のものを探す
        for i in range(n):
            if used[i]:
                continue
            if v == -1 or d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True
               
        for j in range(n):
            e = (min(v,j), max(v,j))
            c = cost[e] if e in cost else float("inf")
            # cost が list のときは普通に c = cost[v][j] などとする
            d[j] = min(d[j], d[v] + c)
    return d

def main():
    N = int(input())
    E = dict()
    for _ in range(N-1):
        a,b,c = map(int, input().split())
        a0 = min(a,b)-1
        b0 = max(a,b)-1
        E[(a0, b0)] = c
    Q,K = map(int, input().split())
    D = dijkstra(K-1, N, N-1, E)
    for _ in range(Q):
        x,y = map(int, input().split())
        print(D[x-1] + D[y-1])

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline

# 頂点 s からの最短距離を求める (存在しないときはinf)
# n: 頂点数, edge[i]: 頂点 i からの [cost, dst] の list (heapq のため cost が先)
# O(|E|log|V|)
import heapq
def dijkstra(s,n,edge):
    d = [float("inf")] * n # s からの距離
    d[s] = 0
    q = [] # 頂点への距離を管理する。ヒープにする
    for e in edge[s]:
        heapq.heappush(q, e)
    
    while q:
        minedge = heapq.heappop(q)
        v = minedge[1]
        if d[v] < minedge[0]:
            continue # 最小のもの以降はスルー
        d[v] = minedge[0]
        for e in edge[v]:
            heapq.heappush(q, [e[0]+d[v], e[1]])

    return d

def main():
    N = int(input())
    edge = [[] for i in range(N)]
    # edge[i] : 頂点 i から出る経路の [重み,行先] の配列
    for _ in range(N-1):
        a,b,c = map(int, input().split())
        edge[a-1].append([c,b-1])
        edge[b-1].append([c,a-1])

    Q,K = map(int, input().split())
    D = dijkstra(K-1, N, edge)

    for _ in range(Q):
        x,y = map(int, input().split())
        print(D[x-1] + D[y-1])

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

N, Y = map(int,input().split())
x, y, z = -1, -1, -1
for i in range(N+1):
    for j in range(0,N-i+1):
        for k in range(0,N-i-j+1):
            if 10000*i + 5000*j + 1000*k == Y and i + j + k == N:
                x, y, z = i, j, k
                break
print(x,y,z)                


### FIXED CODE ###

N, Y = map(int,input().split())
x, y, z = -1, -1, -1
k = 0
for i in range(N+1):
    for j in range(0,N-i+1):
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y and 0 <= k <= 2000:
            x, y, z = i, j, k
            break
print(x, y, z)
### BUGGY CODE ###

n = int(input()) * 3

arr = list(map(int, input().split(" ")))
arr.sort()

# print(arr)
total = 0
while arr != []:
  arr.pop(0)
  arr.pop(-1)
  total += arr.pop(-1)

print(total)

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split(" ")))
arr.sort()
# print(arr)

new_arr = arr[n::2]
print(sum(new_arr))
### BUGGY CODE ###

from collections import deque
def bfs(vertices, start):      
    q = deque()
    q.append(start)
    while q:
        u = q.popleft()                          
        for v in vertices[u]:
            if vis[v]==0 or (vis[u]+1>vis[v]) :
                vis[v]=vis[u]+1
                q.append(v)
    return max(vis)
n,m=map(int,input().split())
v=[[] for i in range(n+1)]
for i in range(m):
	x,y=map(int,input().split())
	v[x].append(y)
vis = [0]*(n+1) 
vis[0]=1
m=0
while 0 in vis:
	i=vis.index(0)
	vis[i]=1
	m=max(m,bfs(v,i))
print(m-1)

### FIXED CODE ###

import sys
input=sys.stdin.readline
#for _ in range(int(input())):
#	n=int(input())
#	n,m=map(int,input().split())
#	s=input().strip()
sys.setrecursionlimit(10**9)
def dfs(i):
	if dp[i]!=-1:return dp[i]
	c=0
	for j in v[i]:c=max(c,dfs(j)+1)
	dp[i]=c
	return c

n,m=map(int,input().split())
v=[[] for i in range(n+1)]
for i in range(m):
	x,y=map(int,input().split())
	v[x].append(y)
dp = [-1]*(n+1) 
m=0
for i in range(1,n+1):
	m=max(m,dfs(i))
print(m)
### BUGGY CODE ###

n,m  =map(int,input().split())
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
mon = 0
lm.sort(key = lambda x:x[0])
 
while s + lm[0][1] < m:
    s += lm[0][1]
    mon += lm[0][1]*lm[0][0]
    lm = lm[1::]
if s +lm[0][1] >= m:
    mon += lm[0][0]*(m-s)
    
print(mon)

### FIXED CODE ###

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
 
AB.sort()
Ans = 0
for i in AB:
  if i[1] >= M:
    Ans += i[0] * M
    break
  else:
    Ans += i[0] * i[1]
    M -= i[1]
 
print(Ans)
### BUGGY CODE ###

import sys
from operator import itemgetter

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    def dfs(i=0, cnt=0):
        if i == n: return cnt
        bx, by = b[i]
        res = dfs(i + 1, cnt)
        for j in range(n):
            if fin[j]: continue
            rx, ry = r[j]
            if rx >= bx: break
            if ry < by:
                fin[j] = True
                tmp = dfs(i + 1, cnt + 1)
                fin[j] = False
                res = max(res, tmp)
        return res

    n = int(input())
    r = [list(map(int, input().split())) for _ in range(n)]
    b = [list(map(int, input().split())) for _ in range(n)]
    r.sort(key=itemgetter(0, 1))
    b.sort(key=itemgetter(0, 1))
    # print(r)
    # print(b)
    fin = [False] * n
    print(dfs())

main()


### FIXED CODE ###

from heapq import *
from bisect import *
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    hp = []
    for _ in range(n):
        a, b = map(int, input().split())
        heappush(hp, [a, 1, b])
    for _ in range(n):
        a, b = map(int, input().split())
        heappush(hp, [a, 0, b])
    yy = []
    ans = 0
    while hp:
        x, q, y = heappop(hp)
        if q:
            insort(yy, y)
        else:
            i = bisect_left(yy, y)
            if i > 0:
                del yy[i - 1]
                ans += 1
    print(ans)

main()
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


n = int(readline())
memo = prime_decomposition(n)
ans = float('inf')
if len(memo) == 1:
    print(memo[0] - 1)
else:
    bit = list(itertools.product([0, 1], repeat=len(memo)))
    for i in range(2 ** len(memo)):
        x, y = 1, 1
        for j in range(len(memo)):
            if bit[i][j] == 0:
                x *= memo[j]
            else:
                y *= memo[j]
        if ans > x + y - 2:
            ans = x + y - 2
    print(ans)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ans = float('inf')
for i in range(1, int(n ** 0.5) + 1):
    x, y = divmod(n, i)
    if y == 0:
        ans = min(ans, x + i)
print(ans - 2)
### BUGGY CODE ###

import math
N = int(input())
x = list(map(int,input().split()))

d = [0]*(N-1)
for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= 10**9+7


kaijou = 1
for i in range(1,N):
    kaijou *= i%(10**9+7)

kaijou = math.factorial(N-1)%(10**9+7)
ans=0
x=0
k=10**9+5

def pow_r(x, n):
    """
    O(log n)
    """
    x %= (k+2)
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%(k+2)
    else:  # standard case ② n is odd
        return (x * pow_r(x ** 2, (n - 1) // 2))%(k+2)

for i in range(N-1):
    #(i+1)**(10**9+5)を計算してyへ
    y = pow_r(i+1,k) 
    #x+= kaijou//(i+1))%(10**9+7)
    x += (kaijou*y)%(10**9+7)
    ans+= d[i]*x

print(ans%(10**9+7))

### FIXED CODE ###

import math
import sys 
input = sys.stdin.readline

N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)

for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod


kaijou = 1
for i in range(1,N):
    kaijou *= i
    kaijou %= mod


ans=0
x=0

def pow_r(x, n):
    """
    O(log n)
    """
    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

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

S = input()
Q = int(input())
flg = 0
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if int(A[1]) == 1:
        if flg == 0:
            S = A[2] + S
        else:
            S = S + A[2]
    else:
        if flg == 0:
            S = S + A[2]
        else:
            S = A[2] + S
if flg == 0:
    print(S)
if flg == 1:
    print(S[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
flg = 0
senntou = ''
ushiro = ''
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if (int(A[1]) == 1 and flg == 0) or (int(A[1]) == 2 and flg == 1):
        senntou = A[2] + senntou
    else:
        ushiro = ushiro + A[2]
if flg == 0:
    print(senntou + S + ushiro)
if flg == 1:
    print(ushiro[::-1] + S[::-1] + senntou[::-1])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()

while A[-2] != 0:
    A[-1] -= A[-2] * (A[-1] // A[-2])
    A.sort()

print(A[-1])

### FIXED CODE ###

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

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.append(mod)
    A = tempA

print(A[0])
### BUGGY CODE ###

import itertools
n = int(input())
l=list(map(int, input().split()))
res = [ c for c in itertools.combinations(l,3) if c[0] < c[1] + c[2] and c[1] < c[0] + c[2] and c[2] < c[0] + c[1] ]
print(len(res))

### FIXED CODE ###

from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        ans += bisect_left(L, L[i] + L[j])  - j - 1
print(ans)
### BUGGY CODE ###

number = int(input())
text = [int(x.strip()) for x in input().split()]

cnt = 0
for i in range(number):
    for j in range(i+1,number):
        if text[i] > text[j]:
            cnt += 1
print(cnt)


### FIXED CODE ###

cnt = 0
def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid

    L = [A[i] for i in range(left, mid)]
    R = [A[i] for i in range(mid, right)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            cnt += n1 - i
            A[k] = R[j]
            j += 1

def mergeSort(A,left,right):
        if left + 1 < right:
            mid = (left+right) // 2
            mergeSort(A,left,mid)
            mergeSort(A,mid,right)
            merge(A,left,mid,right)

input()
a = list(map(int, input().split()))
mergeSort(a, 0, len(a))
print(cnt)