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

from random import shuffle

n = int(input())
a = list(map(int, input().split()))

b = []
c = []

f = a.count(2)

a = [i for i in a if i != 2]

for i in range(len(a)):
    if a[i] % 4:
        b.append(a[i])
    else:
        c.append(a[i])

d = []

while b and c:
    d.append(b.pop())
    d.append(c.pop())

e = d.copy()

d.extend(b)
d.extend([2] * f)
d.extend(c)

for i in range(1, n):
    if (d[i] * d[i-1]) % 4:
        break
else:
    print('Yes')
    exit()

e.extend(b)
e.extend(c)
e.extend([2] * f)

for i in range(n - 1):
    if (e[i] * e[i+1]) % 4:
        break
else:
    print('Yes')
    exit()

e.sort()

for i in range(n - 1):
    if (e[i] * e[i+1]) % 4:
        break
else:
    print('Yes')
    exit()

for _ in range(100):
    shuffle(e)

    for i in range(n - 1):
        if (e[i] * e[i+1]) % 4:
            break
    else:
        print('Yes')
        break

print('No')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

c0 = c1 = c2 = 0

for i in a:
    if i % 4 == 0:
        c0 += 1
    elif i % 2:
        c1 += 1
    else:
        c2 += 1

if c2:
    if c1 <= c0:
        print('Yes')
    else:
        print('No')
else:
    if c1 <= c0 + 1:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n,m = map(int,input().split())
l,r = [0] * m, [0] * m
for i in range(m):
    l[i], r[i] = map(int, input().split())

ans = 0
for i in range(l[0],n + 1):
    for j in range(m):
        if not((i) >= l[j] and (i) <= r[j]):
            break
        if j == m - 1:
            ans += 1

print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
l,r = [0] * m, [0] * m
for i in range(m):
    l[i], r[i] = map(int, input().split())

lmax = 0
rmin = 10 ** 5
for i in range(m):
    lmax = max(lmax,l[i])
    rmin = min(rmin,r[i])

if lmax <= rmin:
    print(rmin - lmax + 1)
else:
    print("0")
### BUGGY CODE ###


# coding: utf-8

# In[1]:

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


# In[2]:

import copy
#import numpy as np


# In[3]:

def get_divisor_list(A):
    divisor_list = [1]
    if A == 1:
        return divisor_list
    else:
        for i in range(2, A//2+1):
            if A%i == 0:
                divisor_list.append(i)
        divisor_list.append(A)
        return divisor_list


# In[4]:

all_db = []
for i in range(N):
    all_db.append(set(get_divisor_list(A[i])))
#print(all_db)


# In[5]:

gcd_list = []
for i in range(N):
    all_dbc = copy.copy(all_db)
    all_dbc.pop(i)
    gcds = all_dbc[0].intersection(*all_dbc)
    gcd_list.append(max(gcds))
print(max(gcd_list))


# In[ ]:





### FIXED CODE ###


# coding: utf-8

# In[1]:

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


# In[2]:

#import copy
#import numpy as np
try:
    from fractions import gcd
except:
    from math import gcd


# In[ ]:

# 左からn個の最大公約数を求める O(n)
# 右からn個の最大公約数を求める O(n)
# n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数


# In[3]:

lg = [1]*(N)
rg = [1]*(N)
ans = 0


# In[4]:

#print(lg)
#print(rg)
#print(A)


# In[5]:

lg[0] = A[1]
rg[0] = A[N-2]
lg[1] = A[0]
rg[1] = A[N-1]
#print(lg, rg)
for i in range(1, N-1):
    #print(i)
    lg[i+1] = gcd(lg[i], A[i])
    #print(lg[i], A[i])
    rg[i+1] = gcd(rg[i], A[N-1-i])
    #print(rg[N-1-i], A[N-1-i])
#print(lg, rg)

for i in range(N):
    #print(i, lg[i], rg[N-i-1])
    tmp = gcd(lg[i], rg[N-i-1])
    #print(tmp)
    if ans < tmp:
        ans = tmp
    #print(ans)


# In[6]:

print(ans)


# In[ ]:

"""
[42 54 69 92 12 23]のとき
 1 [54 69 92 12 23]の最大公約数
 2 [42 69 92 12 23]
 3 [42 54 92 12 23]
 4 [42 54 69 12 23]

"""
### BUGGY CODE ###

import heapq
N,M = map(int,input().split())
edge = [[] for i in range(N)]
double_edge = [[] for i in range(N)]
triple_edge = [[] for i in range(N)]

for i in range(M):
	u,v = map(int,input().split())
	u -= 1
	v -= 1
	edge[u].append(v)
S,T = map(int,input().split())
S -= 1
T -= 1
for i in range(N):
	e = edge[i]
	l = []
	for x in e:
		l += edge[x]
	double_edge[i] = list(set(l))
for i in range(N):
	e = edge[i]
	l = []
	for x in e:
		l += double_edge[x]
	l = list(set(l))
	if i in l:
		l.remove(i)
	triple_edge[i] = l

INF = 10**10
dist = [INF if i != S else 0 for i in range(N)]
search = []
searched = [False for i in range(N)]
heapq.heapify(search)
heapq.heappush(search, (0,S))
while len(search) > 0 and dist[T] == INF:
	x = heapq.heappop(search)
	d, node = x[0], x[1]
	if searched[node]:
		continue
	searched[S] = True
	dist[node] = d
	for i in triple_edge[node]:
		if not searched[i]:
			heapq.heappush(search, (min(d+1, dist[i]), i))
if dist[T] < INF:
	print(dist[T])
else:
	print(-1)

### FIXED CODE ###

import heapq
N,M = map(int,input().split())
edge = [[[] for i in range(N)] for j in range(3)]

for i in range(M):
	u,v = map(int,input().split())
	u -= 1
	v -= 1
	edge[0][u].append(v)
	edge[1][u].append(v)
	edge[2][u].append(v)
S,T = map(int,input().split())
S -= 1
T -= 1
INF = 10**10
dist = [[0 if i == S and j == 0 else INF for i in range(N)] for j in range(3)]
search = []
searched = [[False for i in range(N)] for j in range(3)]
heapq.heapify(search)
heapq.heappush(search, (0, 0, S))
while len(search) > 0 and dist[0][T] == INF:
	x = heapq.heappop(search)
	d, t, node = x[0], x[1], x[2]
	if searched[t][node]:
		continue
	searched[t][node] = True
	dist[t][node] = d
	for i in edge[t][node]:
		if not searched[(t+1)%3][i]:
			heapq.heappush(search, (d+(t+1)//3, (t+1) % 3, i))
if dist[0][T] < INF:
	print(dist[0][T])
else:
	print(-1)
### BUGGY CODE ###

N = int(input())
X = input().strip()

def popcount(n):
    cnt = 0
    while n > 0:
        cnt += n & 1
        n //= 2
    return cnt

def f(n):
    cnt = 0
    while n != 0:
        n = n % popcount(n)
        cnt += 1
    return cnt

nX = int(X, 2)
pcnt = X.count('1')
MOD1 = pcnt + 1
MOD2 = pcnt - 1

nXp = nX % MOD1
if MOD2 != 0:
    nXm = nX % MOD2

delta = 2**(N-1)
pow1 = [1] * N
pow2 = [0] * N
for i in range(1, N):
    pow1[i] = (pow1[i-1] * 2) % MOD1
if MOD2 != 0:
    pow2[0] = 1
    for i in range(1, N):
        pow2[i] = (pow2[i-1] * 2) % MOD2

for i in range(0, N):
    if X[i] == '0':
        k = (nXp + pow1[N-1-i]) % MOD1
        print(f(k) + 1)
    else:
        if MOD2 == 0:
            print(0)
        else:
            k = (nXm - pow2[N-1-i]) % MOD2
            print(f(k) + 1)
    delta //= 2

### FIXED CODE ###

import sys

N = int(sys.stdin.readline().strip())
X = sys.stdin.readline().strip()

def popcount(n):
    cnt = 0
    while n > 0:
        cnt += n & 1
        n //= 2
    return cnt

def f(n):
    cnt = 0
    while n != 0:
        n = n % popcount(n)
        cnt += 1
    return cnt

#nX = int(X, 2)
pcnt = X.count('1')
MOD1 = pcnt + 1
MOD2 = pcnt - 1

nXp = 0
nXm = 0

pow1 = [1] * N
pow2 = [0] * N
for i in range(1, N):
    pow1[i] = (pow1[i-1] * 2) % MOD1
if MOD2 != 0:
    pow2[0] = 1
    for i in range(1, N):
        pow2[i] = (pow2[i-1] * 2) % MOD2

for i in range(N):
    if X[i] == '1':
        nXp += pow1[N-1-i]
nXp %= MOD1

if MOD2 != 0:
    for i in range(N):
        if X[i] == '1':
            nXm += pow2[N-1-i]

    nXm %= MOD2
    

for i in range(0, N):
    if X[i] == '0':
        k = (nXp + pow1[N-1-i]) % MOD1
        print(f(k) + 1)
    else:
        if MOD2 == 0:
            print(0)
        else:
            k = (nXm - pow2[N-1-i]) % MOD2
            print(f(k) + 1)
### BUGGY CODE ###

n=int(input())
l=[]
x={}
ans=0
for j in range(n):
    s=list(input())
    s.sort()
    p=''.join(s)
    if s not in l:
        l.append(s)
        x[p]=1
    else:
        ans+=x[p]
        x[p]+=1
print(ans)

### FIXED CODE ###

n=int(input())
x={}
ans=0
for j in range(n):
    s=list(input())
    s.sort()
    p=''.join(s)
    if p not in x:
        x[p]=1
    else:
        ans+=x[p]
        x[p]+=1
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

#input
N, M = map(int, input().split())
s = [0] * M
t = [0] * M
for i in range(M):
    s[i], t[i] = map(int, input().split())

#output
#（便宜的に地点から-1としておく）
u = [[]] * N
for v in s:
    u[v-1] = [t-1 for i, t in enumerate(t) if s[i] == v]

#地点vにたどり着く確率をp[v]とする。
p = [0] * N
p[0] = 1
for v in range(N):
    for i in range(v):
        if v in u[i]:
            p[v] += p[i]/len(u[i])

#期待値をゴールから逆順に求めていく。点vからゴールまでの移動距離の期待値をq[v]とする。
q = [0] * N
q[N-1] = 0
for v in reversed(range(N)):
    for i in u[v]:
        q[v] += (1 + q[i])/len(u[v])

v = [0] * M
for i in range(M):
    a = s[i] - 1
    b = t[i] - 1
    c = len(u[a])
    if c > 1:
        d = max([q[e] for e in u[a]])
        v[i] = p[a]*(q[a] - (1+d))/(c-1)
        
print(q[0]+min(v))

### FIXED CODE ###

import sys
input = sys.stdin.readline

#input
N, M = map(int, input().split())
u = [[] for i in range(N-1)]
#（便宜的に地点から-1としておく）
for i in range(M):
    s, t = map(int, input().split())
    u[s-1].append(t-1)

#output
#地点vにたどり着く確率をp[v]とする。
p = [0] * N
p[0] = 1
for x, y in enumerate(u):
    for z in y:
        p[z] += p[x]/len(y)

#期待値をゴールから逆順に求めていく。点vからゴールまでの移動距離の期待値をq[v]とする。
q = [0] * N
q[N-1] = 0
for x, y in list(enumerate(u))[::-1]:
    q[x] = sum(q[z] for z in y)/len(y) + 1

v = [0] * N
for i in range(N-1):
    a = len(u[i])
    if a > 1:
        b = max(q[c] for c in u[i])
        v[i] = p[i]*(q[i] - (1+b))/(a-1)

print(q[0]+min(v))
### BUGGY CODE ###

N, M = map(int,input().split())
A_list = [int(input()) for _ in range(M)]
Dp_list = [0] * (N+1)
Dp_list[0] = 1
#for i in range(M):
#    A_list.append(int(input()))
if A_list:
    if A_list[0] == 1:
        Dp_list[1] = 0
    else:
        Dp_list[1] = 1
else:
    Dp_list[1] = 1
if N != 1:
    for i in range(2, N + 1):
        if i in A_list:
            continue
#        elif i in A_list and i-1 in A_list:
#            Dp_list = [0] * (N + 1)
#            break
        Dp_list[i] = Dp_list[i-2] + Dp_list[i-1]
#        else:
#            Dp_list[i] = 0
        if Dp_list[i] > 1000000007:
            Dp_list[i] -= 1000000007
    print(Dp_list[N])
else:
    print(1)

### FIXED CODE ###

N, M = map(int,input().split())
A_list = set([int(input()) for _ in range(M)])
Dp_list = [0] * (N+1)
Dp_list[0] = 1

if 1 in A_list:
    Dp_list[1] = 0
else:
    Dp_list[1] = 1

if N != 1:
    for i in range(2, N + 1):
        if i in A_list:
            continue

        Dp_list[i] = Dp_list[i-2] + Dp_list[i-1]
        Dp_list[i] %= 1000000007
    print(Dp_list[N])
else:
    print(1)
### BUGGY CODE ###

import fractions
n = int(input())
al = list(map(int,input().split()))
al = sorted(al, reverse=True)
p = al[0]
for i in range(1, n):
    p = p * al[i] // fractions.gcd(p, al[i])

ans = 0

for a in al:
    ans += p // a
    ans %= 10**9 + 7

print(ans)

### FIXED CODE ###

import fractions
n = int(input())
al = list(map(int,input().split()))
al = sorted(al)
p = al[0]
for i in range(1, n):
    p = p * al[i] // fractions.gcd(p, al[i])

ans = 0

for a in al:
    ans += p // a

print(ans % (10**9 + 7))
### BUGGY CODE ###

import collections
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    c = collections.Counter(A)

    i = 0
    ans = 0
    for num, cnt in c.most_common()[::-1]:
        if i >= len(set(A)) - K:
            break
        ans += cnt
        i += 1

    print(ans)

main()

### FIXED CODE ###

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

# サイコロで1が出るまでにサイコロを振る回数の期待値は、1が出る確率の逆数で1/(1/6) = 6
# 
# 皿に乗った寿司が1,0,0であるとき、寿司1が乗った皿を選ぶまでの試行回数の期待値は3
# [1,1,1]　に対して、最初に寿司が乗った皿を選ぶ試行回数の期待値は1/(3/3) = 1
# 残る状態は[0,1,1] (皿は区別しない)
# ここから寿司が乗った皿を選ぶ試行回数の期待値は1/(2/3) = 1.5
# 残る状態は[0,0,1]
# ここから寿司が乗った皿を選ぶ試行回数の期待値は1/(1/3) = 3
# すべて足し合わせると1 + 1.5 + 3 = 5.5

# 寿司が乗ってる皿の数が分かれば、次の状態に移行するときの期待値が分かるので足し上げていく
# dp[i][j][k] = 寿司が1個乗った皿がi個、寿司が2個乗った皿がj個、寿司が3個乗った皿がk個の
# 状態から最終状態までの期待値
# 寿司が1個乗った皿を選ぶとき
# dp[i][j][k] から dp[i - 1][j][k]に遷移
# N個からi個の皿を選ぶときの試行回数の期待値はN / i
# 寿司が2個乗った皿を選ぶとき (寿司が1個の皿が一つ増える)
# dp[i][j][k] から dp[i + 1][j - 1][k]に遷移
# N個からj個の皿を選ぶときの試行回数の期待値はN / j
# 寿司が3個乗った皿を選ぶとき (寿司が2個の皿が一つ増える)
# dp[i][j][k] から dp[i][j + 1][k - 1]に遷移
# dp[0][0][0] = 0 (寿司が乗った皿が残った状態は最終状態)

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

# sushi[n] : 寿司がn個乗った皿の枚数
sushi = [0] * 4
for a in A:
  if a > 0:
    sushi[a] += 1
    
dp = [[[-1 for k in range(N + 1)] for j in range(N + 1)] for i in range(N + 1)]

def solve(i,j,k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  if i == 0 and j == 0 and k == 0:
    return 0.0
  ret = 0.0
  if i > 0:
    ret += solve(i - 1,j,k) * i
  if j > 0:
    ret += solve(i + 1,j - 1,k) * j
  if k > 0:
    ret += solve(i,j + 1,k - 1) * k
  ret += N
  ret *= 1.0 / (i + j + k)
  dp[i][j][k] = ret
  return ret

print(solve(sushi[1],sushi[2],sushi[3]))

### FIXED CODE ###

import sys
readline = sys.stdin.readline

# dp[i][j][k] = 寿司が3つの皿がi個、2つの皿がj個、1つの皿がk個からの操作回数の期待値
# dp[0][0][0] = 0で正しいので、ここから順に埋めていけばよい。

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

cnt = [0] * 4

for a in A:
  cnt[a] += 1

dp = [[[0 for k in range(N + 2)] for j in range(N + 2)] for i in range(N + 2)]

for i in range(N + 1):
  for j in range(N + 1):
    for k in range(N + 1):
      nonzero = i + j + k
      if nonzero == 0:
        continue
      dp[i][j][k] = N / nonzero
      if i - 1 >= 0:
        dp[i][j][k] += dp[i - 1][j + 1][k] * i / nonzero
      if j - 1 >= 0:
        dp[i][j][k] += dp[i][j - 1][k + 1] * j / nonzero
      if k - 1 >= 0:
        dp[i][j][k] += dp[i][j][k - 1] * k / nonzero

print(dp[cnt[3]][cnt[2]][cnt[1]])
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = map(int, input().split())
    uf = UnionFind(N+1)

    for i in range(M):
        A, B = map(int, input().split())
        uf.union(A, B)
    # print(uf.all_group_members())
    ans = max([len(m) for g, m in uf.all_group_members().items()])
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = map(int, input().split())
    uf = UnionFind(N+1)

    for i in range(M):
        A, B = map(int, input().split())
        uf.union(A, B)
    # print(uf.all_group_members())
    # print(uf.parents)
    ans = -min(uf.parents)
    print(ans)

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

N = int(input().strip())

X = {}
Y = {}

for _ in range(N):
  x, y = map(int, input().strip().split())
  if x not in X: X[x] = set()
  X[x].add(y)
  if y not in Y: Y[y] = set()
  Y[y].add(x)

count = 0
for x, y_set in X.items():
  if len(y_set) < 2:
    continue

  for y in y_set:
    x_set = Y[y]
    if len(x_set) < 2:
      continue

    for _x in x_set:
      if x == _x:
        continue

      count += len(y_set - X[_x])
      X[_x] = y_set | X[_x]

print(count)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N = int(input().strip())

X = {}
Y = {}
G = (X, Y)

for _ in range(N):
  x, y = map(int, input().strip().split())
  if x not in X: X[x] = []
  if y not in Y: Y[y] = []
  X[x].append(y)
  Y[y].append(x)


def dfs_visit(visited, u, i):
  if u in visited[i]: return
  visited[i].add(u)
  for v in G[i][u]:
    dfs_visit(visited, v, (i + 1) % 2)


count = 0
i = 0
while len(X) > 0:
  visited = (set(), set())
  x = X.__iter__().__next__()
  dfs_visit(visited, x, 0)

  for x in visited[0]:
    count += len(visited[1]) - len(X.pop(x))

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

import re
n,q = map(int, input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int, input().split())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

cum_counts = [sum(counts[:i]) for i in range(n)]

#print(s)
#print(cum_counts)

for i in range(q):
  ret = cum_counts[r[i]-1] - cum_counts[l[i]-1]
  print(ret)

### FIXED CODE ###

n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

for i in range(q):
  l,r = map(int, input().split())
  print(cum_counts[r-1] - cum_counts[l-1])
### BUGGY CODE ###

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

Es = [[] for _ in range(N)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A-1].append(B-1)
    Es[B-1].append(A-1)


i = 1
j = 1
dis = 0
ans = [-1 for _ in range(N)]
cand = []
used = [False for i in range(N)]
used[0] = True
tar = 0
cnt = 1
while True:
    for each in Es[tar]:
        if not used[each]:
            used[each]= True
            ans[each] = tar
            cand.append(each)
            cnt += 1
    if len(cand) == 0:
        break
    if cnt == N:
        break
    tar = cand.pop(0)

print("Yes")
for i in range(1,N):
    print(ans[i]+1)

### FIXED CODE ###

import math, sys
from collections import deque
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N+1)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A].append(B)
    Es[B].append(A)

used = [False]*(N+1)
used[1] = True

ans = [-1]*(N+1)

cand = deque([1])
while len(cand)>0:
    tar = cand.popleft()
    for each in Es[tar]:
        if used[each]:
            continue
        cand.append(each)
        ans[each]=tar
        used[each]= True

print("Yes")
for i in range(2,N+1):
    print(ans[i])
### BUGGY CODE ###

n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=0
if(mn!=1):
    print("-1")
    exit()
r=len(h)
i=-1
while(True):
    i=i+1
    if i==r:
        break
    for j in range(r-1):
        if(h[i]==i+1):
            break
        else:
            cnt=cnt+1
            del h[i]
            r=len(h)
print(cnt)


### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=0
if(mn!=1):
    print("-1")
    exit()
i=1
for k in h:
    if(k==i):
        i=i+1
    else:
        cnt=cnt+1
print(cnt)
### BUGGY CODE ###

import numpy as np
S = input().strip()

MOD = 10**9 + 7
dp = np.zeros((100005, 13))
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)


### FIXED CODE ###

S = input().strip()

MOD = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(100005)]
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)
### BUGGY CODE ###

from collections import Counter

N = int(input())
S = input()

mod = 10 ** 9 + 7
s = list(Counter(S).values())

ans = 0 
for i in range(1, 1 << len(s)):
    k = 1
    for j in range(len(s)):
        if (i >> j) & 1 == 1:
            k *= s[j]
            k %= mod
    ans += k
    ans %= mod
    
print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = input()

mod = 10 ** 9 + 7
s = list(Counter(S).values())

ans = 1 
for i in s:
    ans *= (i+1)
    ans %= mod
print(ans-1)
### BUGGY CODE ###

n = int(input())
l = []
for i in range(n):
    com = input().split()
    if com[0] == "insert":
        key = int(com[1]) 
        l.insert(0, int(key))
    elif com[0] == "delete":
        key = int(com[1]) 
        if int(key) in l:
            l.remove(int(key))
    elif com[0] == "deleteFirst":
        del l[0]
    else:
        del l[-1]
print(*l)

### FIXED CODE ###

import sys
from collections import deque
 
n = int(sys.stdin.readline())
que = deque()
for i in range(n):
    line = sys.stdin.readline()
    op = line.rstrip().split()
    if "insert" == op[0]:
        que.appendleft(op[1])
    elif "delete" == op[0]:
        if op[1] in que:
            que.remove(op[1])
    elif "deleteFirst" == op[0]:
        que.popleft()
    else:
        que.pop()
 
print(*que)