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

N,M = map(int,input().split())
edge_from = [set() for _ in range(N+1)]
edge_to = [set() for _ in range(N+1)]
ans = [-1]*(N+1)
child = set()
parent = set()
for _  in range(N-1+M):
    go,to = map(int,input().split())
    edge_from[go].add(to)
    edge_to[to].add(go)
    child.add(to)
for i in range(1,N+1):
    if i not in child:
        parent.add(i)
        par = i
        break
from collections import deque
stack = deque()
stack.append(par)
distance = [-1]*(N+1)
distance[par] = 0
while stack:
    v = stack.popleft()
    for i in edge_from[v]:
        ok = True
        for j in edge_to[i]:
            if j not in parent:
                ok = False
        if ok:
            distance[i] = distance[v] + 1
            stack.append(i)
            parent.add(i)
        else:
            continue
dis = [set() for _ in range(max(distance)+1)]
for i in range(1,N+1):
    dis[distance[i]].add(i)
for i in range(1,N+1):
    if i == par :
        ans[i] = 0
    else:
        for j in dis[distance[i]-1]:
            if j in edge_to[i]:
                ans[i] = j
                break
for i in range(1,N+1):
    print(ans[i])           

### FIXED CODE ###

from collections import defaultdict, deque
import heapq
v, n = map(int, input().split())
es = [[int(x) for x in input().split()] for _ in range(v+n-1)]

outs = defaultdict(list)
ins = defaultdict(int)
edge_from = [[] for _ in range(v+1)]
edge_to = [[] for _ in range(v+1)]
ans = [-1]*(v+1)
for v1, v2 in es:
    edge_from[v1].append(v2)
    edge_to[v2].append(v1)
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
rev = [0]*(v+1)
for i in range(1,v+1):
    rev[res[i]] = i
redge_to = [[] for _ in range(v+1)]
for i in range(1,v+1):
    for j in edge_to[i]:
        ri = rev[i]
        rj = rev[j]
        heapq.heappush(redge_to[ri],-rj)
for ri in range(1,v+1):
    if redge_to[ri]:
        rj = redge_to[ri][0]
        i = res[ri]
        j = res[-rj]
        ans[i] = j
    else:
        i =res[ri]
        ans[i] = 0
for i in ans[1:]:
    print(i)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline


def reachable_by_3steps_from(node, edges):
    dist1 = edges[node]
    reachable = []
    for d1 in dist1:
        dist2 = edges[d1]
        for d2 in dist2:
            reachable += edges[d2]
    return reachable


n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    _from, to = map(int, input().split())
    edges[_from-1].append(to-1)

start, goal = map(int, input().split())
skip_path = [[] for _ in range(n)]
for i in range(n):
    skip_path[i] = reachable_by_3steps_from(i, edges)

todo = deque([])
seen = [False] * n
seen[start-1] = True
for to in skip_path[start-1]:
    todo.append([to, 1])
    if to == goal-1:
        print(1)
        exit()

while todo:
    node, dist = todo.popleft()
    if seen[node]:
        continue
    seen[node] = True
    for to in skip_path[node]:
        if seen[to]:
            continue
        todo.append([to, dist+1])
        if to == goal-1:
            print(dist+1)
            exit()

print(-1)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline


n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    _from, to = map(int, input().split())
    edges[_from-1].append(to-1)

start, goal = map(int, input().split())

todo = deque([])
seen = [[False] * n for i in range(3)]
seen[0][start-1] = True
for to in edges[start-1]:
    dim = 1
    dist = 1
    todo.append([to, dim, dist])

while todo:
    node, dim, dist = todo.popleft()
    if seen[dim][node]:
        continue
    seen[dim][node] = True
    dim += 1
    if dim == 3:
        dim = 0
    for to in edges[node]:
        if seen[dim][to]:
            continue
        todo.append([to, dim, dist+1])
        if to == goal-1 and dim == 0:
            print((dist+1)//3)
            exit()

print(-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
j = -1
num = 0
for i in range(1,n+1):
    if num != n:
        b = a.count(i)
        print(b)
        num += b
    else:
        j = i
        break
if j != -1:
    for h in range(n-j):
        print(0)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a += list(range(1,n+1))
a = Counter(a).most_common()
a.sort()
for i,j in a:
    print(j-1)
### BUGGY CODE ###

import math
import sys
A,B,N=map(int, input().split())
NUM=0
if N<B:
    NUM=math.floor(A*N/B)-A*math.floor(N/B)
    print(NUM)
    sys.exit()
for x in range(1,N+1):
    TGT=math.floor(A*x/B)-A*math.floor(x/B)
    if TGT>NUM:
        NUM=TGT
print(NUM)


### FIXED CODE ###

A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))
### BUGGY CODE ###

iteration_count = int(input())
for my_target in range(1,iteration_count+1):
  guess_max_range = int((my_target + 50) ** 0.5)
  number_of_match = 0
  for xx in range(1,guess_max_range):
    for yy in range(1,guess_max_range):
      for zz in range(1,guess_max_range):
        result = (xx)**2 + (yy)**2 + (zz)**2 + (xx)*(yy) + (yy)*(zz) + (zz)*(xx)
        if result == my_target:
          number_of_match = number_of_match + 1
  print(number_of_match)

### FIXED CODE ###

nn = int(input())
number_of_match = [0 for _ in range(10005)]
for xx in range(1,105):
  xxxx = xx**2
  for yy in range(1,105):
    yyyy = yy**2
    xxyy = xx*yy
    for zz in range(1,105):
      result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
      if result < 10005:
        number_of_match[result] += 1
for i in range(1,nn+1):
  print(number_of_match[i])
### BUGGY CODE ###

from collections import Counter 
import itertools

N = int(input())
D = list(map(int, input().split()))
M = Counter(D)
if max(M.values()) > 2:
    print(0)
elif 0 in D:
    print(0)
else:
    D = [[x, 24-x] for x in D]
    generator = list(itertools.product([0, 1], repeat=N))
    D_gen = [[D[i][g[i]] for i in range(N)] for g in generator]
    ans = 0
    for d in D_gen:
        if len(set(d)) < N:
            pass
        else:
            tmp = [0] + sorted(d) + [24]
            s = 13
            for i in range(N+1):
                s = min(s, tmp[i+1]-tmp[i])
            ans = max(ans, s)
    print(ans)


### FIXED CODE ###

from collections import Counter 
import itertools

N = int(input())
D = list(map(int, input().split()))
D.append(12)
M = Counter(D)
if max(M.values()) > 2:
    print(0)
elif 0 in D:
    print(0)
elif N > 11:
    print(1)
else:
    D.remove(12)
    D = [[x, 24-x] for x in D]
    generator = list(itertools.product([0, 1], repeat=N))
    D_gen = [[D[i][g[i]] for i in range(N)] for g in generator]
    ans = 0
    for d in D_gen:
        if len(set(d)) < N:
            pass
        else:
            tmp = [0] + sorted(d) + [24]
            s = 13
            for i in range(N+1):
                s = min(s, tmp[i+1]-tmp[i])
            ans = max(ans, s)
    print(ans)
### BUGGY CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0 for _ in range(S+1)] for _ in range(N)]

for i in range(0, S+1):
    if i == A[0]:
        dp[0][i] = 1

for i in range(0, N):
    for j in range(0, S+1):
        if j > A[i]:
            dp[i][j] = (dp[i-1][j]+dp[i-1][j-A[i]])%mod
        elif j == A[i]:
            dp[i][j] = (dp[i-1][j]+(i+1))%mod
        else:
            dp[i][j] = dp[i-1][j]
            
ans = 0
for i in range(0, N):
    ans = (ans+dp[i][S])%mod

print (ans)

### FIXED CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0 for _ in range(S+1)] for _ in range(N)]

for j in range(0, S+1):
    if j == A[0]:
        dp[0][j] = 1
        break

for i in range(1, N):
    for j in range(0, S+1):
        if j > A[i]:
            dp[i][j] = (dp[i-1][j]+dp[i-1][j-A[i]])%mod
        elif j == A[i]:
            dp[i][j] = (dp[i-1][j]+(i+1))%mod
        else:
            dp[i][j] = dp[i-1][j]
            
ans = 0
for i in range(0, N):
    ans = (ans+dp[i][S])%mod
    
print (ans)
### BUGGY CODE ###

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

count = 0

for i in range(0, N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        for k in range(j+1, N):
            if i -j == j - k:
                continue
            if S[i] != S[j] and S[k] != S[j] and S[i] != S[k]:
                count += 1
print(count)

### FIXED CODE ###

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

count = 0

R_count = [0] * (N+1)
R = 0
G_count = [0] * (N+1)
G = 0
B_count = [0] * (N+1)
B = 0

for i, s in enumerate(reversed(list(S))):
    if s == 'R':
        R += 1
    if s == 'G':
        G += 1
    if s == 'B':
        B += 1

    R_count[N - i - 1] = R
    G_count[N-i-1] = G
    B_count[N-i-1] = B
# print(R_count)
# print(G_count)
# print(B_count)

for i in range(0, N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        if (S[i] == 'R' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'R'):
            count += B_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'B':
                count -= 1
        elif (S[i] == 'R' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'R'):
            count += G_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'G':
                count -= 1
        if (S[i] == 'B' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'B'):
            count += R_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'R':
                count -= 1
print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

args = input().split()
n = int(args[0])
m = int(args[1])
ok_list = [0] * 100000
ng_dict = {}
ok_cnt = 0
ng_cnt = 0
args_results = [input().split() for i in range(m)]
for args_result in args_results:
    target = int(args_result[0])
    score = args_result[1]
    if target in ok_list:
        continue
    else:
        if score == 'AC':
            ok_list[ok_cnt] = target
            ok_cnt += 1
        else:
            if target in ng_dict:
                ng_dict[target] += 1
            else:
                ng_dict[target] = 1

for num in ok_list:
    if num in ng_dict:
        ng_cnt += ng_dict[num]

print ok_cnt, ng_cnt

### FIXED CODE ###

import sys
input = sys.stdin.readline

args = input().split()
n = int(args[0])
m = int(args[1])
ok = [False] * n
ng = [0] * n
for _ in range(m):
    target, score = input().split()
    target = int(target) - 1
    if score == 'AC':
        ok[target] = True
    else:
        if not ok[target]:
            ng[target] += 1

ok_cnt = 0
ng_cnt = 0
for i in range(n):
    if ok[i]:
        ok_cnt += 1
        ng_cnt += ng[i]
print(ok_cnt, ng_cnt)
### BUGGY CODE ###

def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    if operations >= number - 1:
        print(*([number] * number))
        return

    for _ in range(operations):
        dists_new = [0] * number
        for i, d in enumerate(dists):
            start = max(0, i - d)
            end = min(i + d, number - 1)
            for j in range(start, end + 1):
                dists_new[j] += 1
        dists = dists_new
        if min(dists) == number:
            # すべての光が両端まで届く，変化しなくなる。
            break

    print(*dists)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for ope_count in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = list(accumulate(temp))
        if templi == dists:
            break
        else:
            dists = templi

    print(*list(dists)[:-1])


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

M,N = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]
Z=list(range(1,M+1))
ans = set(Z)
for s in L:
  k = set(range(s[0], s[1]+1))
  ans = ans & k
print(len(ans))

### FIXED CODE ###

M,N = map(int,input().split())
ans=set(range(1,M+1))
START=0
END=10**5
for s in range(N):
  S,Z = map(int,input().split())
  if START <= S:
    START = S
  if END >= Z:
    END = Z
ans = range(START,END+1)
print(len(ans))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
flag = True
l = []
r = set(list(range(n)))
while True:
    if l and not r:
        print(ans)
        break
    ne = set()
    for j in r:
        if not a[j]:
            continue
        c = a[j][0]
        if c == "-":
            continue
        if j + 1 == a[c-1][0]:
            a[j][0] = "-"
            a[c-1][0] = "-"
            ne.add(j)
            ne.add(c-1)
    l = list(ne)
    for j in l:
        if a[j]:
            if a[j][0] == "-":
                a[j] = a[j][1:]
                flag = False
                if not a[j]:
                    ne.remove(j)
    if flag:
        print(-1)
        break
    else:
        r = ne
        ans += 1


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
r = set(list(range(n)))
N = n*(n-1) // 2 + 1
for _ in range(N):
    if not r:
        print(_)
        break
    ne = set()
    flag = True
    for j in r:
        if not a[j]:
            continue
        c = a[j][0]
        if c == "-":
            continue
        if j + 1 == a[c-1][0]:
            a[j][0] = "-"
            a[c-1][0] = "-"
            ne.add(j)
            ne.add(c-1)
    for j in list(ne):
        if a[j]:
            if a[j][0] == "-":
                a[j].pop(0)
                flag = False
                if not a[j]:
                    ne.remove(j)
    if flag:
        print(-1)
        break
    else:
        r = ne
### BUGGY CODE ###

n=int(input())
s=list(input())
q=int(input())
k=list(map(int,input().split()))
di=s.count("D")
ma=max(k)
h=[]
for r in range(di):
    f=s.index("D")
    p=s[:]
    p=p[f+1:]
    s=s[f+1:]
    while p.count("C")!=0:
        j=p.index("C")
        if j+1<ma:
            h.append([j+1,p[:j].count("M")])
            p[j]="0"
        else:
            break
h.sort()
for i in range(q):
    c=0
    for t in range(len(h)):
        if h[t][0]<k[i]:
            c+=h[t][1]
        else:
            print(c)
            break
print(c)        


### FIXED CODE ###

n=int(input())
s=input()
q=int(input())
for i in list(map(int,input().split())):
    a=0
    v=[0,0,0]
    for j in range(n):
        if s[j]=="D":
            v[0]+=1
        elif s[j]=="M":
            v[1]+=1
            v[2]+=v[0]
        if j>=i:
            if s[j-i]=="D":
                v[0]-=1
                v[2]-=v[1]
            elif s[j-i]=="M":
                v[1]-=1
        if s[j]=="C":
            a+=v[2]
    print(a)
### BUGGY CODE ###

N = int(input())
for h in range(1,3500+1):
    for n in range(1,3500+1):
        if 4 * n * h - N * h - N * n == 0:
            continue
        w = N * h * n / (4 * n * h - N * n - N * h)
        if w > 0 and int(w) == w:
            print(h,n,int(w))
            exit()

### FIXED CODE ###

N = int(input())
for h in range(1,3500+1):
    for n in range(1,3500+1):
        if 4 * n * h - N * h - N * n == 0:
            continue
        w = N * h * n / (4 * n * h - N * n - N * h)
        if w > 0 and int(w) == w:
            print(h,n,int(w))
            exit()
### BUGGY CODE ###

from collections import Counter
N=int(input())
S=[Counter(input()) for n in range(N)]
c=0
l=[]
for s in S:
    if s in l:
        continue
    else:
        l.append(s)
    c+=(S.count(s)*(S.count(s)-1))//2
print(c)


### FIXED CODE ###

N=int(input())
S=["".join(sorted(input())) for n in range(N)]
d={}
for s in S:
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
c=0
for k in d:
    n=d[k]
    c+=(n*(n-1))//2
print(c)
### BUGGY CODE ###

n, k=[int(x) for x in input().split()]
a=input().split()
s=set(a)
d=[]
for i in s:
  d.append(a.count(i))
p=len(s)-k
if p<=0:
  print("0")
  exit()
d=sorted(d, key=lambda x:x)
r=0
for i in range(p):
  r+=d[i]
print(r)


### FIXED CODE ###

n, k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
d={i:0 for i in set(a)}
for i in a: d[i]+=1
print(n-sum([t[1] for t in sorted(d.items(), key=lambda x:-x[1])][:k]))
### BUGGY CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))

a = []
tmp = 1
r = 0
for l in range(n):
    tmp *= A[l]
    if l >= k - 1:
        a.append(tmp)
        tmp //= A[r]
        r += 1

for i in range(1, len(a)):
    if a[i - 1] < a[i]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))

# a = []
# tmp = 1
# r = 0
# for l in range(n):
#     tmp *= A[l]
#     if l >= k - 1:
#         a.append(tmp)
#         tmp //= A[r]
#         r += 1

for i in range(k, n):
    if A[i] > A[i - k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
dic = sorted(dic.items(), key=lambda x: x[1])
while len(dic) > k:
    ans += dic[0][1]    
    del dic[0]
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
dic = sorted(dic.items(), key=lambda x: x[1])
#while len(dic) > k:
#    ans += dic[0][1]    
#    del dic[0]
for i in range(len(dic)-k):
    ans += dic[i][1]
print(ans)
### BUGGY CODE ###

n,m =map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
test = []
for i in range(1,n+1):
    check = [j[1] for j in ab if j[0] == i] + [j[0] for j in ab if j[1] == i]
    check = list(set(check))
    test.append(check)
result = 0
for j in range(len(test)):
    flag = 1
    for k in test[j]:
        if h[k-1] >= h[j]:
            flag = 0
            break
    if flag == 1:
        result += 1
print(result)

### FIXED CODE ###

#c
n,m =map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
result = []
for i in ab:
    if h[i[0]-1] > h[i[1]-1]:
        result.append(i[1])
    elif h[i[1]-1] > h[i[0]-1]:
        result.append(i[0])
    else:
        result.append(i[0])
        result.append(i[1])
result = list(set(result))
print(n - len(result))
### BUGGY CODE ###

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

sum=[0]*n
sum[0]=a[0]
for i in range(1,n):
    sum[i]=sum[i-1]*a[i]
p=[0]*n
for i in range(k-1,n):
    if i==k-1:
        p[i]=sum[i]
    else:
        p[i]=sum[i]/sum[i-k]


for i in range(k,n):
    if p[i]>p[i-1]:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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

for i in range(k,n):
    if a[i]>a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

bc = [i + j for i in b for j in c]
bc.sort(reverse=True)

abc = [i + j for i in a for j in bc[:min(k, len(bc))]]
abc.sort(reverse=True)

for i in range(k):
    print(abc[i])


### FIXED CODE ###

# -*- coding: utf-8 -*-
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

bc = [i + j for i in b for j in c]
bc.sort(reverse=True)

abc = [i + j for i in a for j in bc[:min(k, len(bc))]]
abc.sort(reverse=True)

for i in range(k):
    print(abc[i])
### BUGGY CODE ###

import time
import random

timestart = time.time() 
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
ta = []
ta_buf = [0 for i in range(D)]

man = 0
man_buf = 0
kankaku = [0 for i in range(27)]
last = [0 for i in range(27)]
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))

for i in range(D):
    p = 0
    t = 0
    for i2 in range(26):
        if p < s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2:
            p = s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2
            t = i2 + 1
    kankaku[t - 1] = -1
    ta.append(t -1)
    for i in range(26):
        kankaku[i] += 1

ta.append(-1)

for i in range(D):
    man += s[i][ta[i]]
    last[ta[i]] = i + 1
    for i2 in range(26):
        man -= (i + 1 - last[i2]) * c[i2]

while timestart + 1.900 > time.time():
    man_buf = 0
    for i in range(D):
        ta_buf[i] = ta[i]
    a = random.randint(0,360)
    b = a + random.randint(1,4)
    ta_buf[a], ta_buf[b] = ta_buf[b],ta_buf[a]

    for i in range(D):
        man_buf += s[i][ta_buf[i]]
        last[ta_buf[i]] = i + 1
        for i2 in range(26):
            man_buf -= (i + 1 - last[i2]) * c[i2]

    if man_buf > man:
        man = man_buf
        for i in range(D):
            ta[i] = ta_buf[i]

for i in range(D):
    print(ta[i] + 1)


### FIXED CODE ###

D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
kankaku = [0 for i in range(27)]
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))

for i in range(D):
    p = 0
    t = 0
    for i2 in range(26):
        if p < s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2:
            p = s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2
            t = i2 + 1
    kankaku[t - 1] = -1
    print(t)
    for i in range(26):
        kankaku[i] += 1
### BUGGY CODE ###

c = []
for i in range(3):
    x, y, z = map(int, input().split())
    c.append(x)
    c.append(y)
    c.append(z)

I = max(c[0:3]) + 1
J = max(c[3:6]) + 1
K = max(c[6:9]) + 1
L = max(c[0], c[3], c[6]) + 1
M = max(c[1], c[4], c[7]) + 1
N = max(c[2], c[5], c[8]) + 1

for i in range(I):
    for j in range(J):
        for k in range(K):
            for l in range(L):
                for m in range(M):
                    for n in range(N):
                        if c[0] == i + l and c[1] == i + m and c[2] == i + n and c[3] == j + l and c[4] == j + m and c[5] == j + n and c[6] == k + l and c[7] == k + m and c[8] == k + n:
                            print('Yes')
                            exit()
print('No')


### FIXED CODE ###

c = []
for i in range(3):
    x, y, z = map(int, input().split())
    c.append(x)
    c.append(y)
    c.append(z)

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0] - a1
            b2 = c[1] - a1
            b3 = c[2] - a1
            if c[3] == a2 + b1 and c[4] == a2 + b2 and c[5] == a2 + b3 and c[6] == a3 + b1 and c[7] == a3 + b2 and c[8] == a3 + b3:
                print('Yes')
                exit()
print('No')
### BUGGY CODE ###

n = int(input().strip())

l = []
for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        l = l[1:]
    elif cmd == "deleteLast":
        l.pop()
    elif cmd.startswith("insert "):
        _, e = cmd.split(" ")
        l = [e] + l
    elif cmd.startswith("delete "):
        _, e = cmd.split(" ")
        if e in l:
            l.remove(e)

print(" ".join(l))

### FIXED CODE ###

from collections import deque

q = deque()

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        q.popleft()
    elif cmd == "deleteLast":
        q.pop()
    elif cmd.startswith("insert "):
        v = cmd[7:]
        q.appendleft(v)
    elif cmd.startswith("delete "):
        v = cmd[7:]
        try:
            q.remove(v)
        except ValueError:
            pass
print(" ".join(q))