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

sn, tn, qn = map(int, input().split())

sa = []
ta = []
qa = []
for i in range(sn):
    sa.append(int(input()))
for i in range(tn):
    ta.append(int(input()))
for i in range(qn):
    qa.append(int(input()))


def find_nearest(q, al, s, e):
    while True:
        if e - s < 2:
            if al[s] == q:
                return [al[s], al[s]]
            if al[e] == q:
                return [al[e], al[e]]
            return [al[s], al[e]]
        idx = (e - s) // 2 + s
        if al[idx] == q:
            return [al[idx], al[idx]]
        if al[idx] > q:
            e = idx
        else:
            s = idx

def move_cost(q, al, bl):
    a1, a2 = find_nearest(q, al, 0, len(al) - 1)
    b1, b2 = find_nearest(q, bl, 0, len(bl) - 1)

    def calc(x1, x2, x3):
        y1 = min(x1, x2)
        y2 = max(x1, x2)
        if x3 >= y1 and x3 <= y2:
            return abs(x1 - x2)
        return abs(x1 - x2) + abs(x2 - x3)
    return min(
        calc(q, a1, b1),
        calc(q, a1, b2),
        calc(q, a2, b1),
        calc(q, a2, b2),
        calc(q, b1, a1),
        calc(q, b1, a2),
        calc(q, b2, a1),
        calc(q, b2, a2),
    )

for q in qa:
    print(move_cost(q, sa, ta))


### FIXED CODE ###

import bisect
sn, tn, qn = map(int, input().split())

LARGE = -100000000
sa = []
ta = []
qa = []
for i in range(sn):
    sa.append(int(input()))
for i in range(tn):
    ta.append(int(input()))
for i in range(qn):
    qa.append(int(input()))

def find_nearest(q, al, s, e):
    idx = bisect.bisect_right(al, q)
    if idx == 0:
        return [al[0], al[0]]
    if idx == len(al):
        return [al[idx - 1], al[idx - 1]]
    return [al[idx - 1], al[idx]]

def move_cost(q, al, bl):
    a1, a2 = find_nearest(q, al, 0, len(al) - 1)
    b1, b2 = find_nearest(q, bl, 0, len(bl) - 1)

    def calc(x1, x2, x3):
        y1 = min(x1, x2)
        y2 = max(x1, x2)
        if x3 >= y1 and x3 <= y2:
            return abs(x1 - x2)
        return abs(x1 - x2) + abs(x2 - x3)
    return min(
        calc(q, a1, b1),
        calc(q, a1, b2),
        calc(q, a2, b1),
        calc(q, a2, b2),
        calc(q, b1, a1),
        calc(q, b1, a2),
        calc(q, b2, a1),
        calc(q, b2, a2),
    )

for q in qa:
    print(move_cost(q, sa, ta))
### BUGGY CODE ###

def main(N,A):
    B=[0]
    count = 0
    for i in range(N):
        T = A[i] + B[i]
        #print(B)


            #print('count:',count)
        count += B.count(T)


    # B = [A[i] +B[i] for i in range(N)]
    #
    # count = [ count + 1 for m in range(len(B)) if B[i] - B[i-m] == 0]

        # for m in range(len(B)):
        #     if T - B[m] == 0:
        #         # print(i, m)
        #         # print(B[i],B[i-m])
        #         # print(T)
        #         # print("kore",B[i],B[i-m])
        #         count += 1
        B.append(T)


    #print(count)
    #print(B)
    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))

    main(N,A)

### FIXED CODE ###

import collections

def main(N,A):
    B=[0]
    count = 0
    for i in range(N):
        T = A[i] + B[i]

        B.append(T)
    c = collections.Counter(B)

    for i in range(len(c)):
        k, v = c.popitem()
        for z in range(v):
            count += z

    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))

    main(N,A)
### BUGGY CODE ###

from collections import deque
INF = int(1e9) + 7
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))



def bfs(x, y):
    d = [[INF] * w for i in range(h)]
    dx = [1,0]
    dy = [0,1]
    if s[0][0] == '#':
        d[0][0] = 1
    else:
        d[0][0] = 0
    que = deque([(0, 0)])

    while len(que) != 0:
        val = que.popleft()

        for i in range(2):
            nx = val[0] + dx[i]
            ny = (val[1] + dy[i])
            if nx < h and ny < w:

                que.append((nx, ny))
                if (s[nx][ny] == '#') and (d[nx][ny] > d[val[0]][val[1]]):
                    d[nx][ny] = d[val[0]][val[1]] + 1
                elif s[nx][ny] != '#' and d[nx][ny] < d[val[0]][val[1]]:
                    d[nx][ny] = d[nx][ny]

                else:
                    d[nx][ny] = d[val[0]][val[1]]
    return d[h-1][w-1]
print(bfs(h, w))

### FIXED CODE ###

INF = int(1e9) + 7
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

dp = [[INF] * w for i in range(h)]
if s[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0
#print(dp)

for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            continue
        val1 = dp[i-1][j]
        if s[i][j] == '#' and s[i-1][j] == '.':
            val1 += 1
        val2 = dp[i][j-1]
        if s[i][j] == '#' and s[i][j-1] == '.':
            val2 += 1
        dp[i][j] = min(val1, val2)
        #print(i, j,val1, val2)
print(dp[h-1][w-1])
#print(dp)
### BUGGY CODE ###

import math
k=int(input())

ans=0
for i in range(k):
  for j in range(k):
    for l in range(k):
      ans+=math.gcd(math.gcd(i+1,j+1),l+1)
print(ans)

### FIXED CODE ###

import math
k=int(input())

ans=0
for i in range(k):
  for j in range(k):
    q=math.gcd(i+1,j+1)
    for l in range(k):
      ans+=math.gcd(q,l+1)
print(ans)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    a = LI()
    c = collections.defaultdict(lambda: inf)
    c[(0,0)] = 0
    for t in a:
        nc = collections.defaultdict(lambda: inf)
        for ck,cv in c.items():
            k1,k2 = ck
            if k1 >= t:
                if nc[(t,k2)] > cv:
                    nc[(t,k2)] = cv
            else:
                if nc[(t,k2)] > cv + t-k1:
                    nc[(t,k2)] = cv + t-k1
            if k2 < k:
                if nc[(k1,k2+1)] > cv:
                    nc[(k1,k2+1)] = cv
        c = nc

    return min(c.values())


print(main())




### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    a = LI()
    c = collections.defaultdict(lambda: inf)
    c[(0,0)] = 0
    for t in a:
        nc = collections.defaultdict(lambda: inf)
        for ck,cv in c.items():
            k1,k2 = ck
            if k1 >= t:
                if nc[(t,k2)] > cv:
                    nc[(t,k2)] = cv
            else:
                if nc[(t,k2)] > cv + t-k1:
                    nc[(t,k2)] = cv + t-k1
            if k2 < k:
                if nc[(k1,k2+1)] > cv:
                    nc[(k1,k2+1)] = cv
        c = nc

    return min(c.values())


print(main())
### BUGGY CODE ###

A,B,K = map(int,input().split())
box = [i for i in range(A,B+1)]
for j in range(len(box)):
	if box[j] in box[:K]:
		print(box[j])
	elif box[j] in box[-K:]:
		print(box[j])


### FIXED CODE ###

a,b,k = map(int,input().split())
ans = []
for i in range(a,a+k):
    if i <= b:
        ans.append(i)
if b-a+1 >= 2*k:
    for j in range(b-k+1,b+1):
        ans.append(j)
else:
    for j in range(a+k,b+1):
        if j <= b:
            ans.append(j)

for i in range(len(ans)):
    print(ans[i])
### BUGGY CODE ###

import math
a,b=map(int,input().split())
flag=True
for i in range(10**7):
    if math.floor(i*0.08)==a and math.floor(i*0.1)==b:
        print(i)
        flag=False
        exit()
if flag:
    print(-1)

### FIXED CODE ###

import math
a,b=map(int,input().split())
flag=True
for i in range(10**7):
    if math.floor(i*0.08)==a and math.floor(i*0.1)==b:
        print(i)
        flag=False
        exit()
if flag:
    print(-1)
### BUGGY CODE ###

import collections
import sys
input = sys.stdin.readline
N = int(input())
abc = [map(int, input().split()) for i in range(N-1)]

Q, K = map(int, input().split())

k = [set() for i in range(N)]
g = [[-1]*N for i in range(N)]
for a, b, c in abc:
    g[a-1][b-1] = c
    g[b-1][a-1] = c
    k[a-1].add(b-1)
    k[b-1].add(a-1)
c = [-1]*N
reached = [0]*N
c[K-1] = 0
q = collections.deque([K])
reached[K-1] = 1
while(len(q) > 0):
    x = q.popleft()

    for y in k[x-1]:
        if not reached[y]:
            q.append(y+1)
            c[y] = c[x-1]+g[x-1][y]
            reached[y] = 1
for i in range(Q):
    x, y = map(int, input().split())
    print(c[x-1] + c[y-1])


### FIXED CODE ###

N=int(input())
abc=[tuple(map(int,input().split())) for i in range(N-1)]
g=[set() for i in range(N)]
for a,b,c in abc:
  g[a-1].add((b-1,c))
  g[b-1].add((a-1,c))
memo=[-1]*N

Q,K=map(int,input().split())
import collections
q=collections.deque([(K-1,0)])
memo[K-1]=0
while(q):
  
  x,w = q.popleft()
  for a,b in g[x]:
    if memo[a]==-1:
      memo[a]=w+b
      q.append((a,w+b))
  
for i in range(Q):
  x,y=map(int,input().split())
  print(memo[x-1]+memo[y-1])
### BUGGY CODE ###

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

max_num = 0
j = 0
j_max = M + 1
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    while j < j_max:

        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)


### FIXED CODE ###

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

max_num = 0
j = 0
j_max = M
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while A_sums[i]+B_sums[j_max] > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)
### BUGGY CODE ###

n = int(input())
s = input()
while s.count("WE"):
    s = s.replace("WE", "")
ans = (n - len(s)) // 2
print(ans)


### FIXED CODE ###

n = int(input())
s = input()
wcount = 0
wecount = 0
prev = ""
for c in s:
    if c == "W":
        if prev == "E": wcount = 0
        wcount += 1
    if wcount and c == "E":
        wcount -= 1
        wecount += 1
print(wecount)
### BUGGY CODE ###

N = int(input())
a = [int(x) for x in input().split()]
# a = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

target = 1
res = 0
flag = False

for i in range(N):
	x = a.pop(0)
	if x == target:
		target += 1
		flag = True
	else:
		res += 1

if flag:
	print(res)
else:
	print(-1)

### FIXED CODE ###

N = int(input())
a = [int(x) for x in input().split()]
# a = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

target = 1
res = 0
flag = False

for x in a:
	if x == target:
		target += 1
		flag = True
	else:
		res += 1

if flag:
	print(res)
else:
	print(-1)
### BUGGY CODE ###

from collections import deque

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

def bfs(y, x):
    cnt = [[-1] * w for _ in range(h)]
    queue = deque([[y, x]])
    cnt[y][x] = 1
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                if s[i + di][j + dj] == ".":
                    cnt[i + di][j + dj] = cnt[i][j] + 1
                    queue.append([i + di, j + dj])
                else:
                    return cnt[i][j]

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, bfs(i, j))
print(ans)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
cnt = [[-1] * w for _ in range(h)]

def bfs():
    queue = deque()
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                queue.append([i, j])
                cnt[i][j] = 0
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                queue.append([i + di, j + dj])
                cnt[i + di][j + dj] = cnt[i][j] + 1

bfs()
print(max([max(l) for l in cnt]))
### BUGGY CODE ###

import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
for i in As:
  ls[i]=ls[i]-1
  l=ls.values()
  ans=0
  for k in l:
    ans+=k*(k-1)//2
  ls[i]=ls[i]+1
  print(ans)
  

### FIXED CODE ###

import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
ans=0
for k in an:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline

# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
q = []
for i, b in enumerate(B):
    q.append([-b, i])
heapq.heapify(q)
ans = 0
while len(q)>0:
    b, idx = q[0]
    b = -b
    b_p1, b_m1 = B[(idx+1)%N], B[idx-1]
    d = b_p1 + b_m1

    p = min((b-A[idx])//d, (b-b_m1)//d+1, (b-b_p1)//d+1)

    b -= p * d
    B[idx] = b
    ans += p
    if b > A[idx]:
        heapq.heapreplace(q, [-b, idx])
        if q[0][1] == idx:
            print(-1)
            exit()
    else:
        heapq.heappop(q)
print(ans)


### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline

# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
# 💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
q = []
q = [(-b, i) for i, b in enumerate(B)]
heapq.heapify(q)
ans = 0
N_m1 = N-1
while len(q)>0:
    b, idx = q[0]
    b = -b
    b_p1, b_m1 = B[idx+1 if idx<N_m1 else 0], B[idx-1]
    d = b_p1 + b_m1

    a = A[idx]
    p = min((b-a)//d, (b-b_m1)//d+1, (b-b_p1)//d+1)

    b -= p * d
    B[idx] = b
    ans += p
    if b > a:
        heapq.heapreplace(q, (-b, idx))
        if q[0][1] == idx:
            print(-1)
            exit()
    else:
        heapq.heappop(q)
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
for i in range(N):
  B = A.pop(i)
  print(max(A))
  A.insert(i,B)

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)
### BUGGY CODE ###

MOD = 10 ** 9 + 7

s = str(input())

s = list(s)

dp = [[0 for _ in range(13)] for __ in range(len(s))] 

if s[0] != "?":
    dp[0][int(s[0])] = 1
else:
    for j in range(10):
        dp[0][j] = 1

for i in range(1,len(s)):
    if s[i] != "?":
        for j in range(13):
            dp[i][(j * 10 + int(s[i])) % 13] += dp[i-1][j] % MOD
    else:
        for j in range(13):
            for k in range(10):
                dp[i][(j * 10 + k) % 13] += dp[i-1][j] % MOD

print(dp[len(s)-1][5] % MOD)

### FIXED CODE ###

MOD = 10 ** 9 + 7
 
s = str(input())
 
s = list(s)
 
cur = [0] * 13
 
if s[0] != "?":
    cur[int(s[0])] = 1
else:
    for j in range(10):
        cur[j] = 1
 
for i in range(1,len(s)):
    pre = cur[:]
    cur = [0] * 13
    if s[i] != "?":
        for j in range(13):
            q = (j * 10 + int(s[i])) % 13
            cur[q] += pre[j] % MOD
    else:
        for j in range(13):
            for k in range(10):
                p = (j * 10 + k) % 13
                cur[p] += pre[j] % MOD
 
print(cur[5] % MOD)
### BUGGY CODE ###

X = int(input())
ans = []

def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
        
    else:
        return 100000000

for i in range(1, 50000):
    ans.append(move(X, i))

print(min(ans))


### FIXED CODE ###

X = int(input())
ans = []
def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
    else:
        return 50000

for i in range(1, 45000):
    ans.append(move(X, i))

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

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

for a in A:
    if not a in check:
        check.append(a)
    else:
        print('NO')
        break
else:
    print('YES')

### FIXED CODE ###

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

if len(set(A)) == len(A):
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

n, m, Q = map(int, input().split())
A = [[0]*(n) for i in range(n)]
C = [[0]*(n+1) for i in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    A[r-1][l-1] += 1

for i in range(n):
    a = A[i]
    c = C[i]
    for j in range(n):
        c[j+1] = c[j] + a[j]

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p-1, q):
        ans+=C[i][q] - C[i][p-1]
    print(ans)


### FIXED CODE ###

n, m, Q = map(int, input().split())
A = [[0]*(n) for i in range(n)]
C = [[0]*(n+1) for i in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    A[r-1][l-1] += 1

for i in range(n):
    a = A[i]
    c = C[i]
    for j in range(n):
        c[j+1] = c[j] + a[j]

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p-1, q):
        ans+=C[i][q] - C[i][p-1]
    print(ans)
### BUGGY CODE ###

N,K,L=map(int,input().split())
PQ=[list(map(int,input().split())) for i in range(K)]
RS=[list(map(int,input().split())) for i in range(L)]

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)
    return Root

PQN=UF_make(PQ,N)
RSN=UF_make(RS,N)
PQRS=[]
for i in range(N):
    PQRS.append([PQN[i],RSN[i]])

ans=[1]*N
for i in range(N):
    ans[i]=PQRS.count(PQRS[i])
print(*ans)

### FIXED CODE ###

N,K,L=map(int,input().split())
PQ=[list(map(int,input().split())) for i in range(K)]
RS=[list(map(int,input().split())) for i in range(L)]

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

PQN=UF_make(PQ,N)
RSN=UF_make(RS,N)
PQRS=[PQN[i]*10**6+RSN[i] for i in range(N)]
D=len(set(PQRS))
PQRS=[[PQRS[i],i,0] for i in range(N)]
PQRS.sort()

p=0
while p<N:
    i=1
    c=0
    if p+i>N-1:
        break
    while PQRS[p][0]==PQRS[p+i][0]:
        c+=1
        i+=1
        if p+i>N-1:
            break
    for j in range(p,p+i):
        PQRS[j][2]=c
    p+=i
PQRS.sort(key=lambda x:x[1])
for i in range(N):
    print(PQRS[i][2]+1,end=' ')
### BUGGY CODE ###

s = input()
q = int(input())
hanten = False
query = []
for i in range(q):
    query.append(list(input().split()))

for i in range(q):
    if hanten == False:
        if len(query[i]) == 1:
            hanten = True
        else:
            if int(query[i][1]) == 1:
                #先頭にquery[i][2]を追加
                s = query[i][2] + s
            else:
                #末尾にquery[i][2]を追加
                s = s + query[i][2]
        #print(s)
    else:
        if len(query[i]) == 1:
            hanten = False
        else:
            if int(query[i][1]) == 1:
                #末尾にquery[i][2]を追加
                s = s + query[i][2]
            else:
                #先頭にquery[i][2]を追加
                s = query[i][2] + s
        #print(s)
                
if hanten == False:
    print(s)
else:
    print(s[::-1])

### FIXED CODE ###

s = input()
q = int(input())
hanten = False
sentou = ""
matubi = ""
query = []
for i in range(q):
    query.append(list(input().split()))

for i in range(q):
    if hanten == False:
        if len(query[i]) == 1:
            hanten = True
        else:
            if int(query[i][1]) == 1:
                #先頭にquery[i][2]を追加
                sentou = query[i][2] + sentou
            else:
                #末尾にquery[i][2]を追加
                matubi = matubi + query[i][2]
        #print(s)
    else:
        if len(query[i]) == 1:
            hanten = False
        else:
            if int(query[i][1]) == 1:
                #末尾にquery[i][2]を追加
                matubi = matubi + query[i][2]
            else:
                #先頭にquery[i][2]を追加
                sentou = query[i][2] + sentou
        #print(s)

s = sentou + s + matubi
if hanten == False:
    print(s)
else:
    print(s[::-1])