Harryxun/stf_run huggingface dataset:
import bisect
import sys
input = sys.stdin.readline
def main():
    N,M = map(int,input().split())
    A= list(map(int,input().split()))
    A = sorted(A)

    BC=[list(map(int,input().split())) for i in range(M)]
    BC = sorted(BC, key=lambda x: x[1],reverse=True)
    index=0
    
    for B,C in BC:
        temp = [C]*B
        for t in temp:
            if t>A[index]:
                A[index] = t
            else:
                return A
            index+=1
    
if __name__ == '__main__':
    A=main()
    print(sum(A))


### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    N,M = map(int,input().split())
    A= list(map(int,input().split()))
    A = sorted(A)

    BC=[list(map(int,input().split())) for i in range(M)]
    BC = sorted(BC, key=lambda x: x[1],reverse=True)
    index=0
    max_index=len(A)
    
    for B,C in BC:
        temp = [C]*B
        for t in temp:
            if max_index>index and  t>A[index]:
                A[index] = t
            else:
                return A
            index+=1
    return A
    
if __name__ == '__main__':
    A=main()
    print(sum(A))
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from math import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
t = [ int(input()) for _ in range(n) ]
# print(t)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

ans = lcm_list(t)
print(ans)

### FIXED CODE ###

from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
t = [ int(input()) for _ in range(n) ]
# print(t)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

ans = lcm_list(t)
print(ans)
import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(A))
else:
  print(sum(A[1 :] - A[0]))

### FIXED CODE ###

import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(B))
else:
  print(sum(B[1 :]) - B[0])
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(N):
    while a[i] % 2==0:
        a[i] /= 2
        cnt += 1
print(cnt)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    while a[i] % 2==0:
        a[i] /= 2
        cnt += 1
print(cnt)
A,B = (int(x) for x in input().split())
a=A//2
d=1
s=0
d=int(d)
for i in range(a): 
  if A%d==0 and B%d==0:
    s=d
  d+=1
if s==1:
  print(int(A*B))
else:
  print(int(A*(B/s)))

### FIXED CODE ###

A,B = (int(x) for x in input().split())
if A%2==0:
  a=A//2
else:
  a=(A+1)//2  

d=1
s=0
d=int(d)
for i in range(a): 
  if A%d==0 and B%d==0:
    s=d
  d+=1
if s==1 :
  print(int(A*B))
elif B%A==0:
  print(B)
elif A%B==0:
  print(A)

else:
  print(int(A*(B/s)))
S = input() 

if len(S) == 0:
    print(0)

else:
    # 見つけ次第消していく
    c = 0 # 消したキューブの数
    i = 1
    while i < len(S):
        if int(S[i-1]) + int(S[i]) == 1:
            S = S[:i-1] + S[i+1:]
            i -= 1
            c += 2
        else:
            i += 1

    print(c)


### FIXED CODE ###

S = input()

if len(S) == 0:
    print(0)

else:
    # 1の数
    s = 0
    for i in range(len(S)):
        s += int(S[i])

    print(min(s, len(S)-s)*2)
import math
import numpy as np

L = int(input())
#print(L)

a0 = math.floor(L/2)
#print(a0)

cand = []

if a0==1:
  b0 = -2*a0 + L
  cand.append(a0*b0*a0)
else:
  x = np.arange(0.1, a0, 0.001)
  for i in x:
    b0 = -2*i + L
    cand.append(i*b0*i)

cand_np = np.array(cand)
print(cand_np.max())


### FIXED CODE ###

import math
import numpy as np

L = int(input())
a0 = L/3

print(a0*a0*a0)
import sys

def debug(*args):
    print(*args, file=sys.stderr)


x_diff_of_5th_factor = int(input())


for a in range(-119, 118):
    for a in range(-118, 119):
        if a ** 5 - b ** 5 == x_diff_of_5th_factor:
            print('{} {}'.format(a, b))
            sys.exit(0)

sys.exit(1)


### FIXED CODE ###

print('ABC' if input() == 'ARC' else 'ARC')
s=input()
if s='Sunny':
  print('Cloudy')
elif s='Cloudy':
  print('Rainy')
else:
  print('Sunny')

### FIXED CODE ###

s=input()
if s=='Sunny':
  print('Cloudy')
elif s=='Cloudy':
  print('Rainy')
else:
  print('Sunny')
# coding: utf-8
# Here your code !

def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])

    for exponent in (1, 2, 3, float("inf")):
        print(minkowski_distance(*data, exponent))
#        print("{0:.8f}".format(minkowski_distance(*data, exponent)))

def minkowski_distance(vector_x, vector_y, exponent):
#    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]
    abs_xy = [abs(vector_x[i] - vector_y[i]) for i in range(len(vector_x))]
    
    m_dis = 0
    if exponent == float("inf") :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = ( sum([ elem**exponent for elem in abs_xy ])**(1/exponent) )
    
    return m_dis

if __name__ == "__main__" :
    calculate_minkowski_distances()
    
    

### FIXED CODE ###

# coding: utf-8
# Here your code !

def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])

    for exponent in (1, 2, 3, float("inf")):
        print(minkowski_distance(data[0],data[1], exponent))
#        print("{0:.8f}".format(minkowski_distance(*data, exponent)))

def minkowski_distance(vector_x, vector_y, exponent):
#    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]
    abs_xy = [abs(vector_x[i] - vector_y[i]) for i in range(len(vector_x))]
    
    m_dis = 0
    if exponent == float("inf") :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = sum([ elem**exponent for elem in abs_xy ])**(1/exponent)
    
    return m_dis

if __name__ == "__main__" :
    calculate_minkowski_distances()
import math
while True:
    l = 0; r = []
    try:
        inp = map(int, raw_input().split())
        l = inp[0]
        r = inp[1:]
    except EOFError:
        break
    n = len(r)
    if 2*sum(r) <= l:
        print "OK"
    else:
        r.sort()
        s = []
        for i in xrange(n/2):
            s = [r[i]] + s[::-1] + [r[-i-1]]
        if n&1:
            if abs(s[0]-r[n/2]) < abs(s[-1]-r[n/2]):
                s.append(r[n/2])
            else:
                s = [r[n/2]] + s
        ans = s[0] + s[-1]
        for i in xrange(n-1):
            ans += 2*math.sqrt(s[i]*s[i+1])
        print "OK" if ans < 0.000000001+l else "NA"

### FIXED CODE ###

import math
while True:
    l = 0; r = []
    try:
        inp = map(int, raw_input().split())
        l = inp[0]
        r = inp[1:]
    except EOFError:
        break
    n = len(r)
    if 2*sum(r) <= l:
        print "OK"
    else:
        s = []
        if n>1:
            r.sort()
            for i in xrange(n/2):
                s = [r[i]] + s[::-1] + [r[-i-1]]
            if n&1:
                if abs(s[0]-r[n/2]) < abs(s[-1]-r[n/2]):
                    s.append(r[n/2])
                else:
                    s = [r[n/2]] + s
        else:
            s = r
        ans = s[0] + s[-1]
        for i in xrange(n-1):
            ans += 2*math.sqrt(s[i]*s[i+1])
        print "OK" if ans < 0.000000001+l else "NA"
_input = [i for i in open(0).read().split('\n') if i]
n, k = [int(i) for i in _input[0].split()]
edge = [[int(p) for p in i.split()] for i in _input[1:n]]

import collections

colored  = {}
edge_map = collections.defaultdict(list)
for e in edge:
    edge_map[e[0]].append(e[1])
    edge_map[e[1]].append(e[0])

root = edge[0][0]
colored[root] = k


### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)

_input = [i for i in open(0).read().split('\n') if i]
n, k = [int(i) for i in _input[0].split()]
edge = tuple([tuple([int(p) for p in i.split()]) for i in _input[1:n]])

factorial = [0] * (k + 1)
inverse = [0] * (k + 1)
MOD = 1000000007

# Ref: http://keita-matsushita.hatenablog.com/entry/2016/12/05/175024
def mod_pow1(n, k, mod):
    a = 1
    while k:
        if (k & 1) == 1:
            a = (a * n) % mod
        n = (n * n) % mod
        k >>= 1
    return a

# Ref: https://www.smartbowwow.com/2018/10/mod1097.html
def mod_pow2(n, k, mod):
    if k == 0:
        return 1
    if k % 2 == 0:
        a = mod_pow2(n, k // 2, mod)
        return (a * a) % mod
    else:
        return (n * mod_pow2(n, k - 1, mod)) % mod

#mod_pow = mod_pow1
# It's better to use built-in function for speed.
mod_pow = pow

def mod_factorial_inverse(k, mod):
    factorial[0] = 1
    inverse[0] = 1

    # Ref: http://keita-matsushita.hatenablog.com/entry/2016/12/05/184011
    for i in range(1, k + 1):
        factorial[i] = ((i * factorial[i - 1]) % mod) # factrial[i]
        inverse[i] = mod_pow(factorial[i], mod - 2, mod) # inverse[i]
 
total = 1

if not edge:
    print(k)
else:
    all_edge = tuple([[] for _ in range(n + 1)])
    for e in edge:
        all_edge[e[0]].append(e[1])
        all_edge[e[1]].append(e[0])
    all_edge = [set(v) for v in all_edge]

    if [v for v in all_edge if len(v) >= k]:
        print(0)
    else:
        mod_factorial_inverse(k, MOD)

        root = edge[0]
        total = (factorial[k] * inverse[k - len(all_edge[root[0]]) - 1]) % MOD

        def dfs(current, from_):
            global total
            child = all_edge[current]
            if len(child) - 1 > 0:
                total = (total * factorial[k - 2] * inverse[k - 2 - (len(child) - 1)]) % MOD
            for c in child:
                if c != from_:
                    dfs(c, current)
        for c in all_edge[root[0]]:
            dfs(c, root[0])
        print(total)
N, K, *H = map(int, input().split())
count = 0
for i in range(H):
  if i >= K:
    count += 1
print(count)


### FIXED CODE ###

N, K, *H = map(int, open(0).read().split())
li = [i for i in H if i >= K]
print(len(li))
n,d=list(map(int, input().split()))
 
d1=d*2+1
print((n+d1-1)/d1)

### FIXED CODE ###

n=int(input())
print(3*n*n)
n,a,b=map(int,inout().split())

if (b-a)%2==0:
  ans=(b-a)/2
else:
  ans=(a+b)//2
  
print(ans)

### FIXED CODE ###

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

if (b-a)%2==0:
  ans=(b-a)//2
else:
  ans=min((a+b)//2,(2*(n+1)-(a+b))//2)
  
print(ans)
A,B = map(int,input().split())
ans = -1

for i in range(1,10**4+1):
    if int(i * 0.08) == A and int(i * 0.10) == B:
        ans = i
        break
print(ans)



### FIXED CODE ###

S = str(input())
if S == 'AAA' or S == 'BBB':
    print('No')
else:
    print('Yes')
import decimal
n = int(input())
a = list(map(int, input().split()))
ans = decimal.Decimal(1)
if 0 in a:
    print(-1)
else:
    for i in a:
        ans *= i
    if ans < (10 ** 18 + 1):
        print(ans)
    else:
        print(-1)

### FIXED CODE ###

def main():
  n = int(input())
  a = list(map(int, input().split()))
  if 0 in a:
    print(0)
    return
  
  ans = 1
  for i in a:
    ans *= i
    if ans > (10 ** 18):
      print(-1)
      return
  print(ans)
  
main()
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in (a+1):
    for j in (b+1):
        for k in (c+1):
            if i*500 + j*100 + k*50 == x:
                ans += 1
print(ans)

### FIXED CODE ###

a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)
A,B,C,D = map(int, input().split())
cnt = 0
for i in range(A, B+1):
    if not i % C == 0:
        if not i % D == 0:
            cnt = cnt + 1
print(cnt)

### FIXED CODE ###

S = input()

S1 = S[0]
S2 = S[1]
S3 = S[2]
S4 = S[3]

flg = "Good"

if S1 == S2:
  flg = "Bad"
elif S2 == S3:
  flg = "Bad"
elif S3 == S4:
  flg = "Bad"

print(flg)
n,k,q=map(int,input().split())
a=[(input()) for l in range(q)]
if q-k<0:
    for i in range(n):
        print('Yes')
else:
    c = collections.Counter(a)
    for i in range(n):
        if c[str(i+1)]>q-k:
            print('Yes')
        else:
            print('No')

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[(input()) for l in range(q)]
#if q-k<0:
 #   for i in range(n):
  #      print('Yes')
#else:
import collections
c = collections.Counter(a)
for i in range(n):
    #print(k-c[str(i+1)])
    if q-c[str(i+1)]<k:
        print('Yes')
    else:
        print('No')
from statistics import mode
N = int(input())
if N == 1:
  print(1)
else:
  arr = [list(map(int,input().split())) for _ in range(N)]
  arr = sorted(arr,key=lambda x:(x[0],x[1]))
  diff_arr = [str(arr[i+1][0]-arr[i][0])+'_'+str(arr[i+1][1]-arr[i][1]) for i in range(N-1)]
  mode = mode(diff_arr)
  print(N - diff_arr.count(mode))

### FIXED CODE ###

import collections

N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
if N==1:
  print(1)
else:
  arr = sorted(arr,key=lambda x:(x[0],x[1]))
  diff_arr = []
  for j in range(N):
    for k in range(1,N-j):
      diff_arr.append(str(arr[j+k][0]-arr[j][0])+'_'+str(arr[j+k][1]-arr[j][1]))
  c = collections.Counter(diff_arr)
  print(N-max(c.values()))
from itertools import product
from math import log2

N = int(input())
X = input()
f = [0]*(N+1)
m = sum(list(map(int, X)))+1
n = int(log2(m)+1)

i = 0
for p in product([0,1], repeat=n):
    if i>0:
        a = sum(p)
        f[i] = f[i%a]+1
    i += 1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
        a = m-2
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
        a = m
    print(f[x%a]+1)

### FIXED CODE ###

N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)
import fraction

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

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)

### FIXED CODE ###

from fractions import gcd

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

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)
n = int(input())

if n != 2:
    if n % 2 == 0:
        n += 1
    for p in range(n, 10**5, 2):
        if is_prime(p):
            print(p)
            break
else:
    print(n)

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

### FIXED CODE ###

def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

if __name__ == '__main__':
    n = int(input())
    while not is_prime(n):
        n += 1
    print(n)
import sys
input = lambda: sys.stdin.readline().rstrip()
 
h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(map(int,input().split())))
ans = []
flag = 1
for i in range(h):
    if flag:
        for j in range(w):
            if j == w - 1 and i != h:
                flag ^= 1
                if a[i][j] % 2 == 1: 
                    ans.append([i + 1, j + 1, i + 2, j + 1])
                    a[i + 1][j] += 1
            elif a[i][j] % 2 == 1:
                ans.append([i + 1, j + 1, i + 1, j + 2])
                a[i][j + 1] += 1
    else:
        for j in range(w - 1, -1, -1):
            if j == 0 and i != h:
                flag ^= 1
                if a[i][j] % 2 == 1:
                    ans.append([i + 1, j + 1, i + 2, j + 1])
                    a[i + 1][j] += 1
            elif a[i][j] % 2 == 1:
                ans.append([i + 1, j + 1, i + 1, j])
                a[i][j - 1] += 1
print(len(ans))
for i in ans:
    print(*i)


### FIXED CODE ###

import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().split()]
a = []
for _ in range(H):
    a.append([int(x) for x in input().split()])

place = [0, 0]
ans = []
flag = 1

for i in range(H * W - 1):
    x, y = place
    if flag:
        new_x, new_y = x, y + 1
        if new_y >= W:
            new_x, new_y = x + 1, y
            flag = 0
    else:
        new_x, new_y = x, y - 1
        if new_y < 0:
            new_x, new_y = x + 1, y
            flag = 1
    if a[x][y] % 2 == 1:
        ans.append([x + 1, y + 1, new_x + 1, new_y + 1])
        a[new_x][new_y] += 1
    place = [new_x, new_y]

print(len(ans))
for j in ans:
    print(*j)
k=int(input())
x,y=map(int,input().split())
d=abs(x)+abs(y)
if k%2==0 and d%2!=0:
  print(-1)
else:
  ans=[]
  if d<k and d%2==1:
    n=3
    td=k-d
    ans.append((x,y+td))
    ans.append((x+(k-td//2),y+td//2))
    ans.append((x,y))
  print(n)
  for tx,ty in ans:
    print(tx,ty)

### FIXED CODE ###

def editarr(x,y,arr):
  if abs(x)>=abs(y):
    for i in range(len(arr)):
      arr[i][0],arr[i][1]=arr[i][1],arr[i][0]
  if x<0:
    for i in range(len(arr)):
      arr[i][0]*=-1
  if y<0:
    for i in range(len(arr)):
      arr[i][1]*=-1

k=int(input())
x,y=map(int,input().split())
ans=[]
tx=abs(x)
ty=abs(y)
if tx>=ty:
  tx,ty=ty,tx
if k%2==0 and (tx+ty)%2!=0:
  print(-1)
else:
  if tx+ty<k:
    if (tx+ty)%2==0:
      m=(ty-tx)//2
      ans.append([k-m,m])
    else:
      td=k-(tx+ty)
      ans.append([tx,ty+td])
      ans.append([tx+(k-td//2),ty+td//2])
    ans.append([tx,ty])
    n=len(ans)
  elif ty-(k-tx%k)<k and (ty-(k-tx%k))%2!=0:
    if tx<k and ty<k:
      if (2*k-(tx+ty))%2==0:
        td=2*k-(tx+ty)
        ans.append([tx+td//2,k-(tx+td//2)])
        ans.append([tx,ty])
      else:
        ans.append([tx,k-tx])
        td=ty-(k-tx)
        ans.append([tx+(k-td//2),ans[-1][1]+td//2])
        ans.append([tx,ty])
      n=len(ans)
    else:
      if tx+ty<2*k:
        if (2*k-(tx+ty))%2==0:
          td=2*k-(tx+ty)
          ans.append([tx+td//2,k-(tx+td//2)])
          ans.append([tx,ty])
        else:
          ans.append([tx,k-tx])
          td=ty-(k-tx)
          ans.append([tx+(k-td//2),ans[-1][1]+td//2])
          ans.append([tx,ty])
        n=len(ans)
      else:
        ans.append([0,0])  
  else:
    ans.append([0,0])
    for i in range(tx//k):
      ans.append([ans[-1][0]+k,0])
    if ans[-1][0]!=tx:
      ans.append([tx,k-abs(tx-ans[-1][0])])
    td=ty-ans[-1][1]
    if td%k==0:
      flag=True
    else:
      flag=False
    for i in range(td//k):
      if flag==False and (ty-ans[-1][1])%2==0 and (ty-ans[-1][1])<=2*k:
          break
      ans.append([tx,ans[-1][1]+k])
    if ans[-1][1]!=ty:
      td=ty-ans[-1][1]
      ans.append([tx+(k-td//2),ans[-1][1]+td//2])
      ans.append([tx,ty])
    ans.pop(0)
    n=len(ans)
  editarr(x,y,ans)
  print(n)
  for a,b in ans:
    print(a,b)
from collections import deque

def process_command(dll, commands):
    for cmd, num_str in commands:
        if cmd == 'insert':
            dll.appendleft(int(num_str))
        elif cmd == 'delete':
            temp = []
            result = dll.popleft()
            while result != int(num_str):
                temp.append(result)
                result = dll.popleft()
            dll.extendleft(temp)
        elif cmd == 'deleteFirst':
            dll.popleft()
        elif cmd == 'deleteLast':
            dll.pop()


if __name__ == '__main__':
    # ??????????????\???
    commands = []
    num = int(input())
    for i in range(num):
        commands.append([x for x in input().split(' ')])
    #commands.append(('insert', '5'))
    #commands.append(('insert', '2'))
    #commands.append(('insert', '3'))
    #commands.append(('insert', '1'))
    #commands.append(('delete', '3'))
    #commands.append(('insert', '6'))
    #commands.append(('delete', '5'))

    # ??????
    dll = deque()
    process_command(dll, commands)

    # ???????????????
    dll.reverse()
    print('{0}'.format(' '.join(map(str, dll))))

### FIXED CODE ###

from collections import deque

def process_command(dll, commands):
    # line_count = 1
    for cmd in commands:
        # print('processing line: {0}'.format(line_count))
        # line_count += 1
        # print(cmd)
        try:
            cmd, num_str = cmd.split()
        except ValueError:
            pass
        # if cmd.startswith('insert') or cmd.startswith('delete '):
        #     t = cmd.split(' ')
        #     cmd = t[0]
        #     num_str = t[1]
        if cmd == 'insert':
            dll.appendleft(int(num_str))
        elif cmd == 'delete':
            # deque.index() ????????¨??§???????????? python3.5??\???????????§???????????§??¢???
            if int(num_str) in dll:  # ?????????????????????????????¨???????????´?????????????????????????????????
                temp = []
                result = dll.popleft()
                while result != int(num_str):
                    temp.append(result)
                    result = dll.popleft()
                temp = temp[::-1]
                dll.extendleft(temp)
        elif cmd == 'deleteFirst':
            dll.popleft()
        elif cmd == 'deleteLast':
            dll.pop()
        # print(dll)
        # print('=' * 64)


if __name__ == '__main__':
    # ??????????????\???
    commands = []
    num = int(input())
    commands = [input() for i in range(num)]

    # ??????
    dll = deque()
    process_command(dll, commands)

    # ???????????????
    print('{0}'.format(' '.join(map(str, dll))))