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

N = int(input())
a = [int(i) for i in input().split()]
M = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort()
p=0
for i in range (len(b)):
    for j in range(len(a)):
        if b[i] == a[j]:
            a = a[j+1:N]
            break
        else:
            if j ==len(a)-1:
                print("NO")
                p =1
                break
    if p ==1:
        break    
    if i == len(b)-1:
        print("YES")

### FIXED CODE ###

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
d_dict = {}
for d in D:
    if d not in d_dict:
        d_dict[d] = 0
    d_dict[d] += 1
 
count = 0
for t in T:
    if t in d_dict and d_dict[t] > 0:
        d_dict[t] -= 1
        count += 1
if count == M:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

import numpy as np

#n, d = map(int, input().split())
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

for i in range(n):
    ii = a[i]
    a[i]= 0
    m = max(a)
    a[i] = ii
    print(m)


def max(mat):
    max = 0
    for i in range(len(mat)):
        if mat[i] > max:
            max = mat[i]

    return max

### FIXED CODE ###

import numpy as np
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
    
b = np.array(a)
b = np.sort(b)[::-1]

ans = [0]*n

for i in range(n):
    if a[i] == b[0]:
        ans[i] = b[1]
    else:
        ans[i] = b[0]
        
for i in range(n):
  print(ans[i])
### BUGGY CODE ###

import math

n = int(input())
arr = [0] * n

for x in range(1,201):
    for y in range(1,201):
        for z in range(1,201):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= n:
                arr[ans - 1] += 1

for i in range(n):
    print(arr[i])

### FIXED CODE ###

#!/usr/bin/env python3
import math

n = int(input())
arr = [0] * n

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= n:
                arr[ans - 1] += 1

for i in range(n):
    print(arr[i])
### BUGGY CODE ###

N = int(input())

S = input()
len_S = len(S)

key_list = []

for a in range(len_S - 2):
    for b in range(a+1, len_S-1):
        for c in range(b+1, len_S):
            key = S[a] + S[b] + S[c]
            if key not in key_list:
                key_list.append(key)

print(len(key_list))


### FIXED CODE ###

import copy

N = input()
S = input()

key_list = range(0, 1000)
key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []
for key in key_list:
    flg = True
    cS = copy.copy(S)
    for i in key:
        index = cS.find(i)
        if index == -1:
            flg = False
            break
        cS = cS[index+1:]
    if flg:
        ans_list.append(key)
        
print(len(ans_list))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BCs = [list(map(int,input().split())) for _ in range(Q)]
max_A = max(A)

# Aの値について数列を作る
A_num = [A.count(i) for i in range(10 ** 5 + 1)]
Si = sum(A)

for BC in BCs:
    # BC[0] ...　置換前の値
    # BC[1] ...　置換後の値
    
    if A_num[BC[0]] > 0: 
        Si += A_num[BC[0]] * (BC[1] -BC[0])
        A_num[BC[1]] += A_num[BC[0]]
        A_num[BC[0]] = 0

    print(Si)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BCs = [list(map(int,input().split())) for _ in range(Q)]
max_A = max(A)

# Aの値について数列を作る
# A_num = [A.count(i) for i in range(10 ** 5 + 1)]

A_num = [0 for i in range(10 ** 5 + 1)]
for a in A:
    A_num[a] += 1

Si = sum(A)

for BC in BCs:
    # BC[0] ...　置換前の値
    # BC[1] ...　置換後の値
    
    if A_num[BC[0]] > 0: 
        Si += A_num[BC[0]] * (BC[1] -BC[0])
        A_num[BC[1]] += A_num[BC[0]]
        A_num[BC[0]] = 0

    print(Si)
### BUGGY CODE ###

L, R = map(int, input().split())
mn = 2020
 
for i in range(L, R):
    for j in range(i+1, R+1):
        if mn > (i*j)%2019:
            mn = (i*j)%2019
        elif mn == 0:
            break
print(mn)

### FIXED CODE ###

L, R = map(int, input().split())
mn = 2020

for i in range(L, R):
    for j in range(i+1, R+1):
        if R - L >= 2019:
            mn = 0
            break
        elif mn > (i*j)%2019:
            mn = (i*j)%2019
        elif mn == 0:
            break
    if R - L >= 2019:
            break
    elif mn == 0:
            break
print(mn)
### BUGGY CODE ###

#ABC-137-C
from collections import Counter
N = int(input())
S = []
for _ in range(N):
    si = Counter(input())
    S.append(si)

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if S[i] == S[j]:
            ans += 1

print(ans)

### FIXED CODE ###

#ABC-137-C
N = int(input())
S = []
for _ in range(N):
    si = sorted(input())
    S.append("".join(si))

ans = 0
already_exist = {}

for i in range(N):
    if S[i] not in already_exist:
        already_exist[S[i]] = 0
    else:
        already_exist[S[i]] += 1
        ans += already_exist[S[i]]

# TLEになるので却下
# for i in range(N-1):
#     for j in range(i+1, N):
#         if S[i] == S[j]:
#             ans += 1

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

from collections import deque

N = int(input())

def pToHW(p):
    p = int(p) - 1
    return divmod(p, N)

P = list(map(pToHW, input().split()))

isFilled = [[False] * N for _ in range(N)]

def calcDist():
    minDist = [[10**18] * N for _ in range(N)]
    que = deque([])
    for h in range(N):
        if isFilled[h][0]:
            que.append((h, 0, 1))
        else:
            que.appendleft((h, 0, 0))
        if isFilled[h][N - 1]:
            que.append((h, N - 1, 1))
        else:
            que.appendleft((h, N - 1, 0))
    for w in range(1, N - 1):
        if isFilled[0][w]:
            que.append((0, w, 1))
        else:
            que.appendleft((0, w, 0))
        if isFilled[N - 1][w]:
            que.append((N - 1, w, 1))
        else:
            que.appendleft((N - 1, w, 0))

    while que:
        h, w, dist = que.popleft()

        if minDist[h][w] < dist:
            continue
        minDist[h][w] = dist

        for toH, toW in ((h + 1, w), (h - 1, w), (h, w + 1), (h, w - 1)):
            if not (0 <= toH < N and 0 <= toW < N):
                continue

            d = dist
            if isFilled[toH][toW]:
                d += 1

            if minDist[toH][toW] > d:
                minDist[toH][toW] = d
                if isFilled[toH][toW]:
                    que.append((toH, toW, d))
                else:
                    que.appendleft((toH, toW, d))

    return minDist

ans = 0
for h, w in P[::-1]:
    ans += calcDist()[h][w]
    isFilled[h][w] = True
print(ans)


### FIXED CODE ###

import sys
import numpy as np

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')

    @cc.export('solve', 'i4(i4, i4[:])')
    def solve(N, P):
        minDist = np.ones((N, N), dtype=np.int32)
        isFilled = np.ones((N, N), dtype=np.int32)

        for h in range(N):
            for w in range(N):
                minDist[h][w] = min(h, N - h - 1, w, N - w - 1)

        ans = 0
        for p in P:
            h, w = divmod(p, N)
            ans += minDist[h][w]
            isFilled[h][w] = False

            st = [(h, w)]
            while st:
                h, w = st.pop()
                dist = minDist[h][w] + isFilled[h][w]

                if h + 1 < N and minDist[h + 1][w] > dist:
                    minDist[h + 1][w] = dist
                    st.append((h + 1, w))
                if h - 1 >= 0 and minDist[h - 1][w] > dist:
                    minDist[h - 1][w] = dist
                    st.append((h - 1, w))
                if w + 1 < N and minDist[h][w + 1] > dist:
                    minDist[h][w + 1] = dist
                    st.append((h, w + 1))
                if w - 1 < N and minDist[h][w - 1] > dist:
                    minDist[h][w - 1] = dist
                    st.append((h, w - 1))
        return ans

    cc.compile()
    exit(0)

from my_module import solve

N = int(input())
P = np.asarray(list(map(lambda a: int(a) - 1, input().split())), dtype=np.int32)

print(solve(N, P))
### BUGGY CODE ###

import numpy as np

N = int(input())

*A,  = map(int, input().split())
A    = np.array(A)
min = float('INF')

for i in range(N-1):

    min_temp = (np.abs(np.sum(A)-2*np.sum(A[0:i+1])))
    if min_temp < min:
        min = min_temp

print(min)

### FIXED CODE ###

import sys

N= int(input())

*A, = map(int, input().split())


S = [0]*(len(A)+1)

for i in range(1, len(S), 1):

    S[i] = S[i-1] + A[i-1]

x = 0
y = 0
min = float('inf')

for i in range(1, N, 1):
    x = S[i]
    y = S[len(S)-1] - S[i]

    if min > abs(x-y):
        min = abs(x-y)
print(min)
### BUGGY CODE ###

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

from collections import deque, defaultdict
INF = 10**9
d = defaultdict(int)
def bfs(n):
    reached = [INF] * N
    reached[n] = 0
    q = deque()
    q.append(n)
    while q:
        x = q.popleft()
        dx = [-1, 1]
        for i in dx:
            nx = x + i
            if nx < 0 or nx > N - 1 or reached[nx] != INF:
                continue
            reached[nx] = reached[x] + 1
            q.append(nx)
        if x == X and reached[Y] == INF:
            reached[Y] = reached[x] + 1
            q.append(Y)
        if x == Y and reached[X] == INF:
            reached[X] = reached[x] + 1
            q.append(X)
    for i in range(N):
        k = reached[i]
        d[k] += 1

for i in range(N):
    bfs(i)
for i in range(1, N):
    print(d[i]//2)

### FIXED CODE ###

from collections import deque
N, X, Y = map(int, input().split())

K = [0 for _ in range(N)]
INF = 10 ** 9
def bfs(n):
    d = deque()
    d.append(n)
    reached = [INF for _ in range(N)]
    reached[n] = 0
    dx = [-1, 1]
    while d:
        x = d.popleft()
        for i in range(2):
            nx = x + dx[i]
            if nx < 0 or nx > N - 1 or reached[nx] != INF:
                continue
            d.append(nx)
            reached[nx] =reached[x] + 1
        if x == X-1 and reached[Y-1] == INF:
            reached[Y-1] = reached[x] + 1
            d.append(Y-1)
        if x == Y-1 and reached[X-1] == INF:
            reached[X-1] = reached[x] + 1
            d.append(X-1)
    for i in range(N):
        K[reached[i]] += 1            

for i in range(N):
    bfs(i)

for i in range(1, N):
    print(K[i]//2)
### BUGGY CODE ###

n = int(raw_input())
c = [int(raw_input()) for i in range(n)]
mod = 1000000007

dp = [0] * len(c)
dp[-1] = 1
for i in range(len(c) - 2, -1, -1):
    dp[i] = dp[i + 1]
    try:
        j = c.index(c[i], i + 1)
        if j > i + 1:
            dp[i] = (dp[i] + dp[j]) % mod
    except:
        pass

print dp[0]

### FIXED CODE ###

n = int(raw_input())
c = [int(raw_input()) for i in range(n)]
mod = 1000000007

dp = [0] * len(c)
last = [-1] * 200001
dp[0] = 1
last[c[0]] = 0
for i in range(1, len(c)):
    dp[i] = dp[i - 1]
    if last[c[i]] >= 0 and last[c[i]] < i - 1:
        dp[i] = (dp[i] + dp[last[c[i]]]) % mod
    last[c[i]] = i

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

S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  d *= 10

print(sum([i*(i-1)//2 for i in counter]))

### FIXED CODE ###

S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)
### BUGGY CODE ###

import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])

A=np.sort(A)
s=A[0]
for i in range(max([n, s])):
    c = A[0]
    A = A % c
    A[0] = c
    A=np.sort(A)
    for j in range(len(A)):
        if A[0] != 0:
            break
        A = np.delete(A, 0)
    if len(A) == 1:
        break
print (A[0])

### FIXED CODE ###

import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])

A=np.sort(A)
s=A[0]
for i in range(max([n, s])):
    c = A[0]
    A = A % c
    A[0] = c
    z=len(A) - np.count_nonzero(A)
    A=np.sort(A)[z:]
    if len(A) == 1:
        break
print (A[0])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = []

cnt = 0
for _ in range(H):
    l = input()
    cnt += l.count('.')
    grid.append([v for v in l])

# 動的計画法 dp[i][j]->grid[i][j]に行くための最短距離
dp = [[float('inf')]*W for _ in range(H)]


def dfs(i, j, dist):
    if 0 <= i < H and 0 <= j < W:
        if grid[i][j] != '#':
            if dp[i][j] < dist:
                return
            else:
                dp[i][j] = dist

                new_dist = dist+1
                dfs(i+1, j, new_dist)
                dfs(i-1, j, new_dist)
                dfs(i, j+1, new_dist)
                dfs(i, j-1, new_dist)


def solve():
    dfs(0, 0, 1)
    min_dist = dp[H-1][W-1]
    if min_dist == float('inf'):
        return -1
    else:
        return cnt - min_dist


print(solve())


### FIXED CODE ###


from collections import deque
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


H, W = map(int, input().split())
grid = [[0]*W for _ in range(H)]

cnt = 0
for i in range(H):
    l = input()
    for j in range(W):
        grid[i][j] = l[j]
        if l[j] == '.':
            cnt += 1


# 動的計画法 dp[i][j]->grid[i][j]に行くための最短距離
dp = [[float('inf')]*W for _ in range(H)]


def check_in(x, y):
    return 0 <= x < W and 0 <= y < H


def bfs():
    dx = [1, -1, 0, 0]
    dy = [0, 0, 1, -1]
    Q = deque([[0, 0]])
    dp[0][0] = 0

    while Q:
        s = Q.popleft()
        if s[0] == H-1 and s[1] == W-1:
            return
        else:
            s_x = s[1]
            s_y = s[0]
            for x, y in zip(dx, dy):
                n_x = s_x+x
                n_y = s_y+y

                if check_in(n_x, n_y):
                    if grid[n_y][n_x] != "#" and dp[n_y][n_x] == float('inf'):
                        Q.append([n_y, n_x])
                        dp[n_y][n_x] = dp[s_y][s_x]+1


def solve():
    bfs()
    min_dist = dp[H-1][W-1]
    if min_dist == float('inf'):
        return -1
    else:
        return cnt - min_dist-1


print(solve())
### BUGGY CODE ###

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

a,b = map(int, input().split())
g = gcd(a,b)
N = int(g*0.5)
ans = 1
for i in range(2, N+1):
  flag = 0
  while(g%i==0):
    g /= i
    flag = 1
  ans += flag
if g != 1:
  ans += 1
print(ans)

### FIXED CODE ###

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

a,b = map(int, input().split())
g = gcd(a,b)
N = int(g**0.5)
ans = 1
for i in range(2, N+1):
  if g%i==0:
    ans += 1
  while(g%i==0):
    g /= i
if g != 1:
  ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = 0
ansk = 0
tmp = 0
for i in range(N-1):
    if tmp > 0:
        tmp -= 1
        continue
    ans = 0
    for j in range(i+1,N):
            if H[j-1] < H[j]:
                tmp = ans
                ansk = max(ansk,ans)
                break
            ans += 1
            if j == N-1:
                ansk = max(ansk,ans)
                break
print(ansk)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = 0
ansk = 0
tmp = -1
while tmp < N:
    tmp += 1
    if ans > 0:
        tmp += ans-1
        ans = 0
        continue
    for j in range(tmp+1,N):
            if H[j-1] < H[j]:
                ansk = max(ansk,ans)
                break
            ans += 1
            if j == N-1:
                ansk = max(ansk,ans)
                tmp = N
                break
print(ansk)
### BUGGY CODE ###

A,B,K = map(int,input().split())
nums = [i for i in range(A,B+1)]
anss = []
anss.extend(nums[:K])
anss.extend(nums[-K:])
anss = sorted(set(anss))
for i in anss:
    print(i)

### FIXED CODE ###

A,B,K = map(int,input().split())
ansnums = [A+k for k in range(K) if A+K<=B]
ansnums.extend([B-k for k in range(K) if B-k>=A])
ansnums = sorted(set(ansnums))
for i in ansnums:
    print(i)
### BUGGY CODE ###

from bisect import bisect_left,bisect_right
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
ll=sorted(list(map(int,input().split())))
c=0
lll=len(ll)
for i in range(lll-2):
    for j in range(i+1, lll-1):
        uk = bisect_left(ll, ll[i] + ll[j], j+1)
        lk = bisect_right(ll, abs(ll[j] - ll[i]), j+1, uk)
        c+=uk-lk
print(c)

### FIXED CODE ###

from bisect import bisect_left,bisect_right
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
ll=sorted(list(map(int,input().split())))
c=0
lll=len(ll)
for i in range(lll-2):
    for j in range(i+1, lll-1):
        uk = bisect_left(ll, ll[i] + ll[j], j+1)
        lk = bisect_right(ll, abs(ll[j] - ll[i]), j+1, uk)
        c+=uk-lk
print(c)
### BUGGY CODE ###

N,M=list(map(int,input().split()))
cards=list(map(int,input().split()))
new=[]
cards.sort()
mod=N
for i in range(M):
    time,val=list(map(int,input().split()))
    mod-=time
    tmp=[val for _ in range(time)]
    new.extend(tmp)
new.sort()
new=new[::-1]
total=0
if mod>0:
    total+=sum(cards[-mod:])
for i,j in zip(cards,new):
    total+=max(i,j)
print(total)

### FIXED CODE ###

from collections import Counter
N,M=list(map(int,input().split()))
cards=list(map(int,input().split()))
all_c=Counter(cards)

for i in range(M):
    time,val=list(map(int,input().split()))
    try:
        all_c[val]+=time
    except:
        all_c[val]=time

tmp=list(all_c.keys())
tmp.sort(reverse=True)
total=0
sum_time=0
for i in tmp:
    if sum_time>=N:
        break
    sum_time+=all_c[i]
    if sum_time<N:
        total+=i*all_c[i]
    else:
        total+=i*(all_c[i]+N-sum_time)
print(total)
### BUGGY CODE ###

s = input()

ans = 0
for l in range(len(s)):
    for r in range(l+1, len(s)):
        # print("idx", l, r)
        s_l0 = s[l:]
        s_r10 = s[r+1:]
        if len(s_r10) != 0:
            x_l0 = int(s_l0)
            x_r10 = int(s_r10)
            if (x_l0 % 2019) == (x_r10 % 2019):
                ans += 1
                # print("l, r ({},{})".format(l+1, r+1))
        else:
            x_l0 = int(s_l0)
            if x_l0 % 2019 == 0:
                ans += 1
                # print("l, r ({},{})".format(l+1, r+1))
print(ans)

### FIXED CODE ###

from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)
### BUGGY CODE ###

N=int(input())
S=list(map(int,input().split()))
count=0
P=[0]*(N*N+1)
for j in range(N*N):
  P[j+1]=S.index(j+1)
for i in range(N*N):
  player=S[i]
  hayasa=P[player]
  
  que=[[] for _ in range(N)]
  d=[-1]*(N*N+1)
  que[0].append(player)
  d[player]=0
  
  j=0
  finish=0
  while True:
    for kouho in que[j]:
      if kouho%N==0:
        finish=1
        break
      if kouho%N==1:
        finish=1
        break
      if kouho+N>N*N:
        finish=1
        break
      if kouho<N:
        finish=1
        break
        
      if d[kouho+N]==-1:
        if P[kouho+N]>hayasa:
          que[j+1].append(kouho+N)
          d[kouho+N]=0
        else:
          que[j].append(kouho+N)
          d[kouho+N]=0
          
      if d[kouho-N]==-1:
        if P[kouho-N]>hayasa:
          que[j+1].append(kouho-N)
          d[kouho-N]=0
        else:
          que[j].append(kouho-N)
          d[kouho-N]=0
          
      if d[kouho+1]==-1:
        if P[kouho+1]>hayasa:
          que[j+1].append(kouho+1)
          d[kouho+1]=0
        else:
          que[j].append(kouho+1)
          d[kouho+1]=0
          
      if d[kouho-1]==-1:
        if P[kouho-1]>hayasa:
          que[j+1].append(kouho-1)
          d[kouho-1]=0
        else:
          que[j].append(kouho-1)
          d[kouho-1]=0
    if finish==1:
      count+=j

### FIXED CODE ###

from numba import njit
import numpy as np

@njit
def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    stack = np.empty_like(d)
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        stack[0] = player
        num = 0
        while num >= 0:
            p = stack[num]
            num -= 1
            a = d[p-1]+sit[p-1]
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p+i-1] > a:
                    d[p+i-1] = a
                    num += 1
                    stack[num] = p+i
    print(count)

N = int(input())
P = np.array(input().split(), np.int32)

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

N = int(input())
A = input()

S = [int(A[i])-1 for i in range(N)]

oddness = 0
for i in range(N):
  m, n = N-1, i
  if S[i] % 2 != 0:
    parity = 1
    while m != 0:
      if m % 2 == 0 and n % 2 == 1:
        parity = 0
        break
      m //= 2
      n //= 2
    oddness += parity
    oddness %= 2

if oddness == 1:
  print(1)
else:
  if 1 in S:
    print(0)
  else:
    S = [S[i]//2 for i in range(N)]
    oddness = 0
    for i in range(N):
      m, n = N-1, i
      if S[i] % 2 != 0:
        parity = 1
        while m != 0:
          if m % 2 == 0 and n % 2 == 1:
            parity = 0
            break
          m //= 2
          n //= 2
        oddness += parity
        oddness %= 2
    if oddness == 1:
      print(2)
    else:
      print(0)


### FIXED CODE ###

N = int(input())
A = input()

S = [int(A[i])-1 for i in range(N)]
Lucas = [0 for i in range(N)]
D = {0: 1}
base, m = 1, N - 1
while m != 0:
  if m % 2 == 1:
    L = [i for i in D]
    for i in L:
      D[i+base] = 1
  m //= 2
  base *= 2
for i in D:
  Lucas[i] = 1
oddness = 0
for i in range(N):
  if S[i] % 2 != 0:
    oddness += Lucas[i]
    oddness %= 2

if oddness == 1:
  print(1)
else:
  if 1 in S:
    print(0)
  else:
    S = [S[i]//2 for i in range(N)]
    oddness = 0
    for i in range(N):
      if S[i] % 2 != 0:
        oddness += Lucas[i]
        oddness %= 2
    if oddness == 1:
      print(2)
    else:
      print(0)
### BUGGY CODE ###

# coding:utf-8
# Doubly Linked List

class DLL:

    def __init__(self):
        self.array = []

    def insert(self, x):
        self.array = [x] + self.array
    
    def delete(self, x):
        try:
            del self.array[self.array.index(x)]
        except:
            pass

    def deleteFirst(self):
        del self.array[0]

    def deleteLast(self):
        del self.array[len(self.array)-1]


def main():

    dll = DLL()
    n = int(input())

    for _ in range(n):
        operation = input().split()
        command = operation[0]
        if command in ["insert", "delete"]:
            key = operation[1]
            eval("dll." + command + '(' + key + ')')

        else:
            eval("dll." + command + "()")

    ans = ""
    for x in dll.array:
        ans += str(x) + ' '
    print(ans.strip())
        

if __name__ == "__main__":
    main()

### FIXED CODE ###

# coding:utf-8
# Doubly Linked List

from collections import deque

def main():

    n = int(input())
    dll = deque()

    for _ in range(n):
        operation = input().split(' ')
        if operation[0] in ["insert", "delete"]:
            key = operation[1]
            if operation[0] == "insert":
                dll.appendleft(key)
            else:
                try:
                    dll.remove(key)
                except:
                    pass

        else:
            if operation[0][6] == 'F':
                dll.popleft()

            else:
                dll.pop()

    print(' '.join(dll))

if __name__ == "__main__":
    main()