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

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

for i in range(N-1):
    h = H[i+1:] # i+1以降のリストをスライス
    minh = min(h)
    if H[i] - minh >= 2:
        print('No')
        break
    else:
        continue
else:
    print('Yes')

"""
# よく考えたら最大だけじゃダメだった
m = H.index(max(H)) # 複数の候補がある場合は最初のインデックスを返す
print(m)
for i in range(m+1, N):
    if H[m] - H[i] >= 2:
        print('No')
        break
    else:
        continue
else:
    print('Yes')
"""

### FIXED CODE ###

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

highest = 0
for i in range(N-1):
    highest = max(highest, H[i])
    if highest - 1 <= H[i+1]:
        continue
    else:
        print('No')
        break
else:
    print('Yes')
### BUGGY CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans_list = []
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        l_list = sorted(D[0 : l])
        r_list = sorted(D[N - r : N])

        for discard_l in range(K - (l + r) + 1):
            for discard_r in range(K - (l + r + discard_l) + 1):
                value = sum(l_list[discard_l:])
                value += sum(r_list[discard_r:])

                ans_list.append(value)
        
print(sorted(ans_list, reverse=True)[0])


### FIXED CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        value_list.sort()
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)
### BUGGY CODE ###

N = int(input())
a = [int(input())-1 for i in range(N)]
ans = 0
index = 0
b = [False]*N
b[0] = True
while index!=1:
    index = a[index]
    if b[index]:
        ans = -1
        break
    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
a = [int(input())-1 for i in range(N)]
cnt = 0
index = 0
while True:
    if index == 1:
        print(cnt)
        break
    elif cnt>N:
        print(-1)
        break
    index = a[index]
    cnt += 1
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

h,w=map(int,input().split())
s=[input() for _ in range(h)]
flag = [[0]*w for _ in range(h)]

def dfs(th,tw):
    global flag,h,w,s
    flag[th][tw] = True
    tblack = 0
    twhite = 0
    if s[th][tw] == "#":
        tblack += 1
    else:
        twhite += 1 
    for x,y in ([0,1],[0,-1],[1,0],[-1,0]):
        nth = th + x
        ntw = tw + y
        if nth >= 0 and nth < h and ntw >= 0 and ntw < w:
            if not flag[nth][ntw] and s[th][tw] != s[nth][ntw]:
                ttb,ttw = dfs(nth,ntw)
                tblack += ttb
                twhite += ttw
    return [tblack,twhite]
                
def main():
    global flag,h,w,s
    res = 0
    for i in range(h):
        for j in range(w):
            if not flag[i][j]:
                black,white = dfs(i,j)
                res += black * white 

    return res
print(main())

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

h,w=map(int,input().split())
s=[input() for _ in range(h)]
flag = [[0]*w for _ in range(h)]

def dfs(th,tw):
    global flag,h,w,s
    flag[th][tw] = True
    tblack = 0
    twhite = 0
    if s[th][tw] == "#":
        tblack += 1
    else:
        twhite += 1 
    for x,y in ([0,1],[0,-1],[1,0],[-1,0]):
        nth = th + x
        ntw = tw + y
        if nth >= 0 and nth < h and ntw >= 0 and ntw < w:
            if not flag[nth][ntw] and s[th][tw] != s[nth][ntw]:
                ttb,ttw = dfs(nth,ntw)
                tblack += ttb
                twhite += ttw
    return [tblack,twhite]
                
def main():
    global flag,h,w,s
    res = 0
    for i in range(h):
        for j in range(w):
            if not flag[i][j]:
                black,white = dfs(i,j)
                res += black * white 

    return res
print(main())
### BUGGY CODE ###

a=input()
num=len(a)
mod_map={0:1}
moji_int=0
for i in range(-1,-num-1,-1):
    moji_int+=int(a[i])*(10**(-i-1)%2019)
    mod=moji_int%2019
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1

res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)

### FIXED CODE ###

a=reversed(input())
#num=len(a)
mod_list=[1]+[0]*2019
moji_int=0
Sn=0
tens=1
for i in a:
    tmp=int(i)*(tens)
    Sn=(Sn+tmp)%2019
    mod=Sn
    tens=tens*10%2019
    mod_list[mod]+=1
res=0
for i in mod_list:
    res+=int(i*(i-1)/2)
print(res)
### BUGGY CODE ###

import math

N = int(input())
An = [int(i) for i in input().split()]

mod = int(math.pow(10, 9) + 7)

sum_result = 0

for i in range(N - 1):
    Ai = An[i]
    An_ = An[i + 1:]
    sum_result += (Ai * sum(An_)) % mod


print(sum_result % mod)


### FIXED CODE ###

import math

N = int(input())
An = [int(i) for i in input().split()]


mod = int(math.pow(10, 9) + 7)

sum_an = sum(An)
sum_result = 0

for i in range(N - 1):
    Ai = An[i]
    sum_an -= Ai
    sum_result += (Ai * sum_an) % mod


print(sum_result % mod)
### BUGGY CODE ###

def main():
  n = int(input())
  As = map(int, input().split())
  Bs = map(int, input().split())

  diffs = [a - b for a, b in zip(As, Bs)]
  positives = list(sorted(filter(lambda x: x>0, diffs), reverse=True))
  negatives = list(sorted(filter(lambda x: x<0, diffs)))
  if abs(sum(negatives)) > sum(positives):
    print(-1)
    return
  changed = set()
  for neg in negatives:
    for i, pos in enumerate(positives):
      neg += pos
      changed.add(i)
      if neg >= 0:
        positives[i] = neg
        break
      else:
        positives[i] = 0
  print(len(negatives) + len(changed))


if __name__ == '__main__':
  main()


### FIXED CODE ###

from itertools import accumulate


def main():
  n = int(input())
  As = map(int, input().split())
  Bs = map(int, input().split())

  diffs = [a - b for a, b in zip(As, Bs)]
  pos_acc = list(accumulate(sorted(filter(lambda x: x>0, diffs), reverse=True)))
  negatives = list(filter(lambda x: x<0, diffs))
  neg_sum = abs(sum(negatives))
  num_negs = len(negatives)
  if num_negs == 0:
    print(0)
    return
  for i, pa in enumerate(pos_acc):
    if neg_sum <= pa:
      print(num_negs + i + 1)
      return
  print(-1)


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

h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            if k+d[nowh][nxtw] < 6400:
                dp[nowh*w + nxtw][k+d[nowh][nxtw]] = 1
            dp[nowh*w + nxtw][abs(k-d[nowh][nxtw])] = 1
        if nxth<h:
            if k+ d[nxth][noww]< 6400:
                dp[nxth*w + noww][k+d[nxth][noww]] = 1
            dp[nxth*w + noww][abs(k-d[nxth][noww])] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()

### FIXED CODE ###

h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            if k+d[nowh][nxtw] < 6400:
                dp[nowh*w + nxtw][k+d[nowh][nxtw]] = 1
            dp[nowh*w + nxtw][abs(k-d[nowh][nxtw])] = 1
        if nxth<h:
            if k+ d[nxth][noww]< 6400:
                dp[nxth*w + noww][k+d[nxth][noww]] = 1
            dp[nxth*w + noww][abs(k-d[nxth][noww])] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()
### BUGGY CODE ###

import itertools

def prime_factorize(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n //= 2
	f = 3
	while f * f <= n:
		if n % f == 0:
			a.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		a.append(n)
	return a

def calc_dist(x, y):
	return abs(x - 1) + abs(y - 1)

n = int(input())
ll = prime_factorize(n)

min_dist = 10 ** 12
for bb in itertools.product([0, 1], repeat = len(ll)):
	l = 1
	r = 1
	for i in range(len(ll)):
		if bb[i] == 1:
			l *= ll[i]
		else:
			r *= ll[i]
	#print(bb, l, r, calc_dist(l, r))
	min_dist = min(min_dist, calc_dist(l, r))
print(min_dist)

### FIXED CODE ###

import itertools
import collections

def prime_factorize(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n //= 2
	f = 3
	while f * f <= n:
		if n % f == 0:
			a.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		a.append(n)
	return a

def calc_dist(x, y):
	return abs(x - 1) + abs(y - 1)

n = int(input())
ll = prime_factorize(n)
c = collections.Counter(ll)
kk = list(c.keys())
vv = list(c.values())
pp = [list(range(vv[i] + 1)) for i in range(len(kk))]

min_dist = 10 ** 12
# print(c)
# print(kk)
# print(vv)
for bb in itertools.product(*pp):
	l = 1
	r = 1
	for i in range(len(kk)):
		l *= max(kk[i] ** bb[i], 1)
		r *= max(kk[i] ** (vv[i] - bb[i]), 1)
	#print(bb, l, r, calc_dist(l, r))
	min_dist = min(min_dist, calc_dist(l, r))
print(min_dist)
### BUGGY CODE ###

import sys
import bisect
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))
    dp = [0] * 31
    for i in range(28, -1, -1):
        mdr = pow(2, i + 1)
        for j in range(n-1, -1, -1):
            b[j] %= mdr
            a[j] %= mdr
        a.sort(reverse=True)
        b.sort()
        for av in a:
            p1 = bisect.bisect_right(b, mdr // 2 - 1 - av, 0, n)
            p2 = bisect.bisect_right(b, 2 * mdr // 2 - 1 - av, p1, n)
            p3 = bisect.bisect_right(b, 3 * mdr // 2 - 1 - av, p2, n)
            dp[i] += n - (p1 + p3 - p2)
    t = 0
    for i in range(31):
        t += pow(2, i) * (dp[i] % 2)
    print(t)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import bisect

readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))


def f(md):
    pos = n - 1
    res = 0
    for av in a:
        while True:
            if pos != -1 and av + b[pos] >= md:
                pos -= 1
            else:
                res += pos + 1
                break
    return res


def solve():
    dp = [0] * 31
    for i in range(28, -1, -1):
        md = pow(2, i + 1)
        for j in range(n-1, -1, -1):
            b[j] %= md
            a[j] %= md
        a.sort()
        b.sort()
        res1, res2, res3 = f(md // 2), f(md // 2 * 2), f(md // 2 * 3)
        dp[i] += (n - (res1 + res3 - res2)) % 2
    t = 0
    for i in range(31):
        t += pow(2, i) * (dp[i] % 2)
    print(t)


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

N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
b_list.reverse()
while True:
    if len(b_list) >= 1:
        if b_list[0] >= a:
            b = b_list.pop(0)
            H -= b
            count += 1
            if H <= 0:
                break
        else:
            H -= a
            count += 1
            if H <= 0:
                break
    else:
        H -= a
        count += 1
        if H <= 0:
            break
        
print(count)

### FIXED CODE ###

N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1 and H >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
int_list = []
val_list = []
for _ in range(N):
    A, B = map(int, input().split())
    int_list.append(A)
    val_list.append(B)

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = bin(int_list[i])[2:].zfill(max_len)

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == '1':
        or_list.append(K_bin[:i] + '0' + '1' * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for i in range(N):
        A = int_list[i]
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == '1' and k[j] == '0':
                ok = 0
        if ok:
            ans_k += val_list[i]
    ans = max(ans, ans_k)

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
int_list = []
for _ in range(N):
    A, B = map(int, input().split())
    int_list.append([A, B])

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_list[i][1])

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == '1':
        or_list.append(K_bin[:i] + '0' + '1' * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for A, B in int_list:
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == '1' and k[j] == '0':
                ok = 0
                break
        if ok:
            ans_k += B
    ans = max(ans, ans_k)

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

import bisect
N,K = map(int,input().split())
h_list = []
result = []
for i in range(N):
    bisect.insort(h_list,int(input()))
print(min([h_list[i+K-1]-h_list[i] for i in range(N-K+1)]))


### FIXED CODE ###

N,K = map(int,input().split())
h_list = [int(input()) for i in range(N)]
h_list.sort()
result = []
print(min([h_list[i+K-1]-h_list[i] for i in range(N-K+1)]))
### BUGGY CODE ###

f=input
n,s,q=int(f()),list(f()),int(f())
L=[[] for i in range(26)]
for i in range(n):
  L[ord(s[i])-97]+=[i]
from bisect import *
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    l=L[ord(s[b])-97]
    l.pop(bisect(l,b)-1)
    s[b]=c
    insort(L[ord(c)-97],b)
  else:
    t=0
    for l in L:
      m=bisect(l,b-1)
      if m<len(l) and l[m]<int(c): t+=1
    print(t)

### FIXED CODE ###

n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))
### BUGGY CODE ###

N=int(input())
P=[int(i) for i in input().split()]
cnt=0
for r in range(N):
    if P[r]==min(P[0:r+1]):
        cnt+=1
    else:
        continue
print(cnt)

### FIXED CODE ###

N=int(input())
P=[int(i) for i in input().split()]
min=2*(10**5)+1
cnt=0
for r in P:
    if min>=r:
        min=r
        cnt+=1
    else:
        continue
print(cnt)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
A_B = [list(map(int, input().split())) for i in range(M)]
A = [A_B[i][0] for i in range(M)]
B = [A_B[i][1] for i in range(M)]
N_set = [{0} for i in range(N)]
ans = 0

# print(N, M, H, A, B)
# print(N_set)

for i in range(N):
    for j in range(M):
        if i+1 == A[j] or i+1 == B[j]:
            N_set[i].add(H[A[j] - 1])
            N_set[i].add(H[B[j] - 1])
            # N_set[i].remove(i+1)

for i in range(N):
    N_set[i].remove(0)
    N_set[i] = list(N_set[i])


for i in range(N):
    if len(N_set[i]) == 0:
        ans += 1
        continue
    if len(N_set[i]) == 1:
        continue
    if H[i] == max(N_set[i]):
        ans += 1
print(ans)

### FIXED CODE ###

N, M = list(map(int, input().split()))
h = list(map(int, input().split()))
ma = [0] * N

for i in range(M):
    a, b = list(map(int, input().split()))
    ma[a-1] = max(ma[a-1], h[b-1])
    ma[b-1] = max(ma[b-1], h[a-1])

ans = 0
for i in range(N):
    if ma[i] < h[i]:
        ans += 1

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

N=int(input())

def waru(N):
    if N%2==0:
        print("-1")
        return
    a="7"
    for i in range(1,100000000):
        ia=int(a)
        if N>ia:
            a+="7"
            continue
        if N%ia==0:
            print(i)
            return
        a+="7"

    print("-1")

waru(N)

### FIXED CODE ###

K=int(input())
def waru(K):
    a=[]
    if K%2==0 or K%5==0:
        print("-1")
        return
    a.append(7%K)
    for i in range(1,K):
        a.append((10*a[i-1]+7)%K)
    for i in range(K):
        if a[i]==0:
            print(i+1)
            return
    print(-1)
waru(K)
### BUGGY CODE ###

a,b,x = map(int,input().split())
ans = 0
for i in range(a,b+1):
  if i%x == 0:
    ans += 1
print(ans)

### FIXED CODE ###

a,b,x = map(int,input().split())
b = b//x
if a%x==0 or a==0:
  a=a//x -1
else:
  a=a//x
print(b-a)
### BUGGY CODE ###

K,S=map(int, input().split())
cnt=0
for i in range(K+1):
  X=i
  for j in range(K+1):
    Y=j
    for k in range(K+1):
      Z=k
      if X+Y+Z==S:
        cnt+=1
print(cnt)

### FIXED CODE ###

K,S=map(int, input().split())
cnt=0
if K <= S:
  for i in range(K+1):
    for j in range(K+1):
      if S - (i+j) <= K and S >= i+j:
        cnt += 1
else:
  for i in range(S+1):
    for j in range(S+1):
      if S - (i+j) <= K and S >= i+j:
        cnt += 1
print(cnt)
### BUGGY CODE ###

from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    cnt = 0
    que = deque()
    que.append([0, 0])
    if s[0][0] == '#':
        d[0][0] = 1
    else:
        d[0][0] = 0

    while que:
        p = que.popleft()
        if p[0] == h-1 and p[1] == w-1:
            if cnt == 0:
                cnt += 1
            else:
                break

        for i in range(2):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                que.append([ny, nx])
                if s[p[0]][p[1]] == '.' and  s[ny][nx] == '#':
                    d[ny][nx] = min(d[ny][nx], d[p[0]][p[1]]+1)
                else:
                    d[ny][nx] = min(d[ny][nx], d[p[0]][p[1]])

    return d[h-1][w-1]

h, w = MAP()
s = [input() for i in range(h)]
d = [[inf]*w for i in range(h)]

dy = [1, 0]
dx = [0, 1]

print(bfs())

### FIXED CODE ###

from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    que = deque()
    que.append([0, 0])
    if s[0][0] == '#':
        d[0][0] = 1
    else:
        d[0][0] = 0

    while que:
        p = que.popleft()
        if p[0] == h-1 and p[1] == w-1:
            break

        for i in range(2):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                if s[p[0]][p[1]] == '.' and  s[ny][nx] == '#':
                    if d[ny][nx] > d[p[0]][p[1]]+1:
                        d[ny][nx] = d[p[0]][p[1]]+1
                        que.append([ny, nx])
                else:
                    if d[ny][nx] > d[p[0]][p[1]]:
                        d[ny][nx] = d[p[0]][p[1]]
                        que.append([ny, nx])

    return d[h-1][w-1]

h, w = MAP()
s = [input() for i in range(h)]
d = [[inf]*w for i in range(h)]

dy = [1, 0]
dx = [0, 1]

print(bfs())
### BUGGY CODE ###

from functools import reduce
import math
K = int(input())


def gcd(*numbers):
    return reduce(math.gcd, numbers)


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, b, c)

print(ans)


### FIXED CODE ###

from fractions import gcd
K = int(input())


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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(gcd(a, b), c)

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

def main():
    s = input()
    q = int(input())
    hanten = False
    for i in range(q):
        query = input().split()
        if query[0] == "1":
            hanten = not hanten
        else:
            if query[1] == "1":
                if hanten:
                    s = s + query[2]
                else:
                    s = query[2] + s
            if query[1] == "2":
                if hanten:
                    s = query[2] + s
                else:
                    s = s + query[2]
    print(s if not hanten else s[::-1])



if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    left = ""
    right = ""
    hanten = False
    for i in range(q):
        query = input().split()
        if query[0] == "1":
            hanten = not hanten
        else:
            c = query[2]
            if query[1] == "1":
                if not hanten:
                    left += c
                else:
                    right += c
            else:
                if not hanten:
                    right += c
                else:
                    left += c
        #print(query)
        #print(s,left,right)
    left = left[::-1]
    answer = left + s + right

    if not hanten:
        print(answer)
    else:
        print(answer[::-1])


if __name__ == '__main__':
    main()