Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B
# Binary Search
# Result:
import sys

NO_ANSWER = -1

def binary_sarch(target, ary, start, end):
    if start == end:
        if target == ary[start]:
            return start
        else:
            return NO_ANSWER

    mid = (start + end) / 2
    if target < ary[mid]:
        return binary_sarch(target, ary, start, mid - 1)
    elif target > ary[mid]:
        return binary_sarch(target, ary, mid + 1, end)
    else: # target == ary[mid]
        return mid


### main
ary_s_len = int(sys.stdin.readline().rstrip())
ary_s = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
ary_t_len = int(sys.stdin.readline().rstrip())
ary_t = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert len(ary_s) == ary_s_len
assert len(ary_t) == ary_t_len

count = 0
for e in ary_t:
    idx = binary_sarch(e, ary_s, 0, ary_s_len - 1)
    if idx >= 0:
        count += 1
print count

Fixed submission:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B
# Binary Search
# Result:
import sys

NO_ANSWER = -1

def binary_sarch(target, ary, start, end):
    if start == end:
        if target == ary[start]:
            return start
        else:
            return NO_ANSWER

    mid = (start + end) / 2
    if target < ary[mid]:
        return binary_sarch(target, ary, start, mid)
    elif target > ary[mid]:
        return binary_sarch(target, ary, mid + 1, end)
    else: # target == ary[mid]
        return mid


### main
ary_s_len = int(sys.stdin.readline().rstrip())
ary_s = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
ary_t_len = int(sys.stdin.readline().rstrip())
ary_t = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert len(ary_s) == ary_s_len
assert len(ary_t) == ary_t_len

count = 0
for e in ary_t:
    idx = binary_sarch(e, ary_s, 0, ary_s_len - 1)
    if idx >= 0:
        count += 1
print count
Buggy python submission (verdict: Runtime Error):
class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = float('inf')
        self.p = -1
        self.state = -1
        # -1 -> undiscovered
        #  1 -> finished
        #  0 -> found(not finished)


M = [float('inf')] * 5
for i in range(5):
    M[i] = [float('inf')] * 5

n = int(input())
nodes = [0] * 100
for i in range(n):
    V = [int(x) for x in input().split()] 
    for (j,m) in enumerate(V):
        M[i][j] = m if not m == -1 else float('inf') 
    nodes[i] = Node([])

nodes[0].d = 0
while True:
    mincost = float('inf')
    u = -1
    for i in range(n):
        node = nodes[i]
        if (mincost > node.d) and (node.state != 1):
            u = i
            mincost = node.d

    if u == -1:
        break

    nodes[u].state = 1
    for v in range(n):
        node = nodes[v]
        if (node.state != 1) and (M[u][v] != float('inf')):
            if node.d > M[u][v]:
                node.d = M[u][v]
                node.p = u
                node.state = 0

sum = 0
for i in range(n):
    if nodes[i].p != -1:
        sum += M[i][nodes[i].p]

print(sum)

Fixed submission:
class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = float('inf')
        self.p = -1
        self.state = -1
        # -1 -> undiscovered
        #  1 -> finished
        #  0 -> found(not finished)


M = [float('inf')] * 100
for i in range(100):
    M[i] = [float('inf')] * 100

n = int(input())
nodes = [0] * 100
for i in range(n):
    V = [int(x) for x in input().split()] 
    for (j,m) in enumerate(V):
        M[i][j] = m if not m == -1 else float('inf') 
    nodes[i] = Node([])

nodes[0].d = 0
while True:
    mincost = float('inf')
    u = -1
    for i in range(n):
        node = nodes[i]
        if (mincost > node.d) and (node.state != 1):
            u = i
            mincost = node.d

    if u == -1:
        break

    nodes[u].state = 1
    for v in range(n):
        node = nodes[v]
        if (node.state != 1) and (M[u][v] != float('inf')):
            if node.d > M[u][v]:
                node.d = M[u][v]
                node.p = u
                node.state = 0

sum = 0
for i in range(n):
    if nodes[i].p != -1:
        sum += M[i][nodes[i].p]

print(sum)
Buggy python submission (verdict: Runtime Error):
s = input()
x,y = map(int,s)

while(x != y or x!=1 or y != 1)
    if(x < y):
        tmp = x
        x = y
        y = tmp

    x %= y
print(x)

Fixed submission:
s = input()
x,y = map(int,s.split())

while(x != y or x>1 or y > 1):
    if(x < y):
        tmp = x
        x = y
        y = tmp
    if( y == 0):
        break

    x %= y
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
num = n = int(input())
price = []
max_profit = -999999999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
for i in range(1,num):
    for n in range(0,i):
        pro = price[i] - price[n]
        if pro > max_profit:
            max_profit = pro

print("{0}".format(max_profit))

Fixed submission:
num= n = int(input())

price = []
max_pro = -999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
min = price[0]
for i in range(1,num):
    pro = price[i]-min

    if(max_pro < pro):
        max_pro = pro
    if(min > price[i]):
        min = price[i]
print ("{0}".format(max_pro))

Buggy python submission (verdict: Runtime Error):
n = int(input())
num = n - 1
price = []
date = 0
max_pro = -999999999

while(n>0):
    x = int(input())
    dataset = [date,x]
    price.append(dataset)
    n -= 1
    date += 1

price.sort(key=lambda price: price[1])

for i in range(0,num):
    j = num
    while(j > i):
        if(price[i][0]<price[j][0]):
            pro = price[j][1] - price[i][1]
            break
        j -= 1
    if (max_pro < pro):
        max_pro = pro
print ("{0}".format(max_pro))

Fixed submission:
num= n = int(input())

price = []
max_pro = -999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
min = price[0]
for i in range(1,num):
    pro = price[i]-min

    if(max_pro < pro):
        max_pro = pro
    if(min > price[i]):
        min = price[i]
print ("{0}".format(max_pro))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0

while(flag == 1):
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1

for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt))

Fixed submission:
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0

while(flag == 1):
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1

for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt)
Buggy python submission (verdict: Runtime Error):
def check(T, p, n, k):
    i = 0
    
    for j in range(k):
        s = 0
       
       while(s+T[i] <= p):
            s += T[i]
            i += 1
            if i == n:
                return n
    
    return i

n, k = [int(x) for x in input().split()]
T = []
for i in range(n):
    T.append(int(input()))

left, right = 0, 100000 * 10000

while(right - left > 1):
    mid = (left + right) / 2
    if (check(mid) >= n):
        right = mid
    else:
        left = mid

print right

Fixed submission:
def check(T, p, n, k):
    i = 0
    
    for j in range(k):
        s = 0
       
        while(s+T[i] <= p):
            s += T[i]
            i += 1
            if i == n:
                return n
    
    return i

n, k = [int(x) for x in input().split()]
T = []
for i in range(n):
    T.append(int(input()))

left, right = 0, 100000 * 10000

while(right - left > 1):
    mid = int((left + right) / 2)
    if (check(T, mid, n, k) >= n):
        right = mid
    else:
        left = mid

print(right)

Buggy python submission (verdict: Runtime Error):
def check(T, p, n, k):
    i = 0
    
    for j in range(k):
        s = 0
       
       while(s+T[i] <= p):
            s += T[i]
            i += 1
            if i == n:
                return n
    
    return i

n, k = [int(x) for x in input().split()]
T = []
for i in range(n):
    T.append(int(input()))

left, right = 0, 100000 * 10000

while(right - left > 1):
    mid = (left + right) / 2
    if (check(T, mid, n, k) >= n):
        right = mid
    else:
        left = mid

print right

Fixed submission:
def check(T, p, n, k):
    i = 0
    
    for j in range(k):
        s = 0
       
        while(s+T[i] <= p):
            s += T[i]
            i += 1
            if i == n:
                return n
    
    return i

n, k = [int(x) for x in input().split()]
T = []
for i in range(n):
    T.append(int(input()))

left, right = 0, 100000 * 10000

while(right - left > 1):
    mid = int((left + right) / 2)
    if (check(T, mid, n, k) >= n):
        right = mid
    else:
        left = mid

print(right)
Buggy python submission (verdict: Runtime Error):
import math
class point:
    def __init__(self):
        self.x = 0.0
        self.y = 0.0
 
def koch(n,a,b):
    if n == 0 :
        return
 
    rad = 1.0471975511965976 ???# 60 deg
    s = point()
    t = point()
    u = point()
    tmp = point()
 
    s.x = (2 * a.x + b.x) / 3.0
    s.y = (2 * a.y + b.y) / 3.0
 
    t.x = (2 * b.x + a.x) / 3.0
    t.y = (2 * b.y + a.y) / 3.0
 
    tmp.x, tmp.y = s.x-t.x ,s.y-t.y
    u.x = (tmp.x * math.cos(rad) + tmp.y * math.sin(rad)) + t.x
    u.y = (-tmp.x * math.sin(rad) + tmp.y * math.cos(rad)) + t.y
 
 
    koch(n-1, a, s)
    print(s.x, s.y)
 
    koch(n-1, s, u)
    print(u.x, u.y)
 
    koch(n-1, u, t)
    print(t.x, t.y)
 
    koch(n-1, t, b)
 
    return
 
a = point()
b = point()
a.x, a.y =   0.0, 0.0
b.x, b.y = 100.0, 0.0
n = int(input())

print(a.x, a.y)
koch(n, a, b)
print(b.x, b.y)

Fixed submission:
import math
class point:
    def __init__(self):
        self.x = 0.0
        self.y = 0.0
 
def koch(n,a,b):
    if n == 0 :
        return
 
    rad = 1.0471975511965976
    s = point()
    t = point()
    u = point()
    tmp = point()
 
    s.x = (2 * a.x + b.x) / 3.0
    s.y = (2 * a.y + b.y) / 3.0
 
    t.x = (2 * b.x + a.x) / 3.0
    t.y = (2 * b.y + a.y) / 3.0
 
    tmp.x, tmp.y = s.x-t.x ,s.y-t.y
    u.x = (tmp.x * math.cos(rad) + tmp.y * math.sin(rad)) + t.x
    u.y = (-tmp.x * math.sin(rad) + tmp.y * math.cos(rad)) + t.y
 
 
    koch(n-1, a, s)
    print(s.x, s.y)
 
    koch(n-1, s, u)
    print(u.x, u.y)
 
    koch(n-1, u, t)
    print(t.x, t.y)
 
    koch(n-1, t, b)
 
    return
 
a = point()
b = point()
a.x, a.y =   0.0, 0.0
b.x, b.y = 100.0, 0.0
n = int(input())

print(a.x, a.y)
koch(n, a, b)
print(b.x, b.y)
Buggy python submission (verdict: Runtime Error):
def Partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if (A[j] <= x):
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

n = int(input())
st = input()
data = list(map(int,st.split()))

mid = Partition(data,0,len(data)-1)

for i in range(0,mid):
    print(data[i],end=" ")
print("[{0}] ".format(data[mid])))
for i in range(mid+1,len(data)-2):
    print(data[i],end=" ")
print(data[len(data)-1])

Fixed submission:
def Partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if (A[j] <= x):
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

n = int(input())
st = input()
data = list(map(int,st.split()))

mid = Partition(data,0,len(data)-1)
for i in range(0,mid):
    print(data[i],end=" ")
print("[{0}] ".format(data[mid]),end="")
for i in range(mid+1,len(data)-1):
    print(data[i],end=" ")
print(data[len(data)-1])
Buggy python submission (verdict: Runtime Error):
data = input()
len = data.split()
ans = int(data[0]) * int(data[1])
print('{0}'.format(ans))

Fixed submission:
data = input()
len = data.split()
ans0 = int(len[0]) * int(len[1])
ans1 = int(len[0]) *2 + int(len[1])*2
print('{0} {1}'.format(ans0, ans1))
Buggy python submission (verdict: Runtime Error):
data = input()
sec = int(data)

h = sec %= 3600
sec -= h*3600

m = sec %= 60
sec -= m*60

print('{0}:{1}:{2}'.format(h, m, s))

Fixed submission:
data = input()
sec = int(data)

h = int(sec / 3600)
sec -= h*3600

m = int(sec / 60)
sec -= m*60

print('{0}:{1}:{2}'.format(h, m, sec))

Buggy python submission (verdict: Runtime Error):
data = input()
sec = int(data)

h = sec %= 3600
sec -= h*3600

m = sec %= 60
sec -= m*60

print('{0}:{1}:{2}'.format(h, m, s))

Fixed submission:
data = input()
sec = int(data)

h = int(sec / 3600)
sec -= h*3600

m = int(sec / 60)
sec -= m*60

print('{0}:{1}:{2}'.format(h, m, sec))
Buggy python submission (verdict: Runtime Error):
data = input()
x = []
x = data.split()
a = int(x[0])
b = int(x[1])
c = int(x[2])


if(a < b < c):
    print('Yes')
elif:
    print("No")

Fixed submission:
data = input()
x = []
x = data.split()
a = int(x[0])
b = int(x[1])
c = int(x[2])


if(a < b < c):
    print('Yes')
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
W, H, x, y, r = [int(x) for x in input().split()]
if (0 <= x-r <= W) and (0 <= x+r <= w):
    if(0 <= y-r <= H) and (0 <= y+r <= H):
        print("Yes")
else:
    print("No")

Fixed submission:
W, H, x, y, r = [int(x) for x in input().split()]
if (0 <= x-r <= W) and (0 <= x+r <= W):
    if(0 <= y-r <= H) and (0 <= y+r <= H):
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
i=1
while((x = input()) != 0):
   print("Case {0}: {1}".format(i, x)) 
   i += 1

Fixed submission:
i=1
x = input()
while(x != "0"):
   print("Case {0}: {1}".format(i, x)) 
   i += 1
   x = input()

Buggy python submission (verdict: Runtime Error):
i=1
x = input()
while(x != 0):
   print("Case {0}: {1}".format(i, x)) 
   i += 1
   x = input()

Fixed submission:
i=1
x = input()
while(x != "0"):
   print("Case {0}: {1}".format(i, x)) 
   i += 1
   x = input()
Buggy python submission (verdict: Runtime Error):
y,x = [int(x) for x in input().split()]
if(not y*x  == 0):
    for i in range(y):
        print('#'*x)    print('#'*x)

Fixed submission:
y,x = [int(x) for x in input().split()]
while(x > 0 or y > 0):
    for i in range(y):
        print('#'*x)
    print()
    y,x = [int(x) for x in input().split()]
Buggy python submission (verdict: Runtime Error):
S = []
H = []
C = []
D = []

n = int(input())
for i in range(n):
    mark, num = [x for x in input().split()]
    if mark == 'S':
        S.append(int(num))

    elif mark == 'H':
        H.append(int(num))

    elif mark == "C":
        C.append(int(num))

    else: #D
        D.append(int(num))


for i in range(1,14):
    if not i in S:
        print("S", i)
for i in range(1,14):
    if not i in H:
        print("H", i)for i in range(1,14):
for i in range(1,14):
    if not i in C:
        print("C", i)for i in range(1,14):
for i in range(1,14):
    if not i in D:
        print("D", i)

Fixed submission:
S = []
H = []
C = []
D = []

n = int(input())
for i in range(n):
    mark, num = [x for x in input().split()]
    if mark == 'S':
        S.append(int(num))

    elif mark == 'H':
        H.append(int(num))

    elif mark == "C":
        C.append(int(num))

    else: #D
        D.append(int(num))


for i in range(1,14):
    if not i in S:
        print("S", i)
for i in range(1,14):
    if not i in H:
        print("H", i)
for i in range(1,14):
    if not i in C:
        print("C", i)
for i in range(1,14):
    if not i in D:
        print("D", i)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

# main
q = int(input())
for a in range(q):
    X = input()
    Y = input()
    m = len(X)
    n = len(Y)
    c = [[0 for j in range(n + 1)] for i in range(m + 1)]
    for i in range(m + 1):
        c[i][0] = 0
    for j in range(n + 1):
        c[0][j] = 0
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if X[i - 1] == Y[j - 1]:
                c[i][j] = c[i - 1][j - 1] + 1
            else:
                c[i][j] = max(c[i][j - 1], c[i - 1][j])
    print(c[m][n])

Fixed submission:
#!/usr/bin/python3
import itertools
# main
q = int(input())
for a in range(q):
    X = input()
    Y = input()
    cost = [0]
    for c in Y:
        for i in range(len(cost) - 1, -1, -1):
            index = X.find(c, cost[i]) + 1
            if index:
                if i + 1 < len(cost):
                    cost[i + 1] = min(cost[i + 1], index)
                else:
                    cost.append(index)
    print(len(cost) - 1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3

def find(id, V, d, dist):
    i = id - 1
    dist[i] = d
    for v in V[i]:
        find(v, V, d + 1, dist)
    
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:])

find(1, V, 0, dist)

for u in U:
    print(u, dist[u - 1])

Fixed submission:
#!/usr/bin/python3

def find(id, V, d, dist):
    i = id - 1
    dist[i] = d
    for v in V[i]:
        if dist[v - 1] == -1 or dist[v - 1] > d + 1:
            find(v, V, d + 1, dist)
    
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
    l = list(map(int, input().split()))
    U.append(l[0])
    V.append(l[2:])

find(1, V, 0, dist)

for u in U:
    print(u, dist[u - 1])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
n = int(input())
inf = 100 * 100000

M = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    L = list(map(int, input().split()))
    u = L[0]
    k = L[1]
    v = L[2::2]
    c = L[3::2]
    for j in range(k):
        M[u][v[j]] = c[j]

S = set()
V = set(range(n))
S.add(0)
d = [inf for i in range(n)]
d[0] = 0
count = 0
while len(V - S) != 0:
    T = V - S
    nd = [inf for i in range(n)]
    for s in S:
        for m, c in enumerate(M[s]):
            if d[s] + c < nd[m] and m in T:
                nd[m] = d[s] + c

    min_nd = min(nd)
    u = nd.index(min_nd)
    S.add(u)
    d[u] = min_nd


for i, v in enumerate(d):
    print(i, v)

Fixed submission:
#!/usr/bin/python3
from heapq import heappop, heappush
n = int(input())
inf = 100 * 100000

M = [[] for i in range(n)]

for i in range(n):
    L = list(map(int, input().split()))
    u = L[0]
    k = L[1]
    v = L[2::2]
    c = L[3::2]
    for j in range(k):
        M[u].append((v[j], c[j]))
result = [0] * n
S = set()
V = set(range(n))
S.add(0)
d = []
for m in M[0]:
    heappush(d, (m[1], m[0]))
T = V - S

while len(T) != 0:
    c, v = heappop(d)
    while v in S:
        c, v = heappop(d)
    result[v] = c
    S.add(v)
    T.remove(v)
    for m in M[v]:
        if m[0] in T:
            heappush(d, (result[v] + m[1], m[0]))

for i, v in enumerate(result):
    print(i, v)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
L = [max(map(lambda n:n-x, R[i+1:])) for i, x in enumerate(R) if i < n-1]
print max(L)

Fixed submission:
import sys
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
minimum = sys.maxint
maximum = -sys.maxint - 1
for x in R:
    p = x - minimum
    if maximum < p:
        maximum = p

    if minimum > x:
        minimum = x
print maximum

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
L = [max(R[i+1:])-x for i, x in enumerate(R) if i < n-1]
print max(L)

Fixed submission:
import sys
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
minimum = sys.maxint
maximum = -sys.maxint - 1
for x in R:
    p = x - minimum
    if maximum < p:
        maximum = p

    if minimum > x:
        minimum = x
print maximum
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
R = []
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = int(L[1])
    if order == 'insert':
        R.insert(0, value)
    if order == 'delete':
        R.remove(value)
    if order == 'deleteFirst':
        R.pop()
    if order == 'deleteLast':
        R.pop(len(R)-1)
print ' '.join(map(str, R))

Fixed submission:
from collections import deque
n = int(raw_input())
R = deque()
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = 0
    if len(L) > 1:
        value = int(L[1])
    if order == 'insert':
        R.appendleft(value)
    if order == 'delete' and value in R:
        R.remove(value)
    if order == 'deleteFirst':
        R.popleft()
    if order == 'deleteLast':
        R.pop()
print ' '.join(map(str, R))

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
R = []
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = 0
    if len(L) > 1:
        value = int(L[1])
    if order == 'insert':
        R.insert(0, value)
    if order == 'delete':
        R.remove(value)
    if order == 'deleteFirst':
        R.pop(0)
    if order == 'deleteLast':
        R.pop()
print ' '.join(map(str, R))

Fixed submission:
from collections import deque
n = int(raw_input())
R = deque()
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = 0
    if len(L) > 1:
        value = int(L[1])
    if order == 'insert':
        R.appendleft(value)
    if order == 'delete' and value in R:
        R.remove(value)
    if order == 'deleteFirst':
        R.popleft()
    if order == 'deleteLast':
        R.pop()
print ' '.join(map(str, R))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
R = []
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = 0
    if len(L) > 1:
        value = int(L[1])
    if order == 'insert':
        R.insert(0, value)
    if order == 'delete' and value in R:
        R.remove(value)
    if order == 'deleteFirst':
        R.pop(0)
    if order == 'deleteLast':
        R.pop()
print ' '.join(map(str, R))

Fixed submission:
from collections import deque
n = int(raw_input())
R = deque()
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = 0
    if len(L) > 1:
        value = int(L[1])
    if order == 'insert':
        R.appendleft(value)
    if order == 'delete' and value in R:
        R.remove(value)
    if order == 'deleteFirst':
        R.popleft()
    if order == 'deleteLast':
        R.pop()
print ' '.join(map(str, R))