# your code goes here
class Node(object):
def __init__(self):
self.data = 0
self.next = None
self.prev = None
def __init__(self,data):
self.data = data
self.next = None
self.prev = None
def setData(self,data):
self.data = data
def getData(self):
return self.data
def setNext(self,next):
self.next = next
def getNext(self):
return self.next
def setPrev(self,prev):
self.prev = prev
def getPrev(self):
return self.prev
class Stack(object):
def __init__(self):
self.top = None
def setTop(self,top):
self.top = top
def getTop(self):
return self.top
def isEmpty(self):
return self.top == None
def push(self,data):
newnode = Node(data)
if not self.isEmpty():
self.getTop().setPrev(newnode)
newnode.setNext(self.getTop())
self.setTop(newnode)
def pop(self):
if not self.isEmpty():
temp = self.getTop()
if not self.getTop().getNext() == None:
self.getTop().getNext().setPrev(None)
self.setTop(self.getTop().getNext())
del temp
class Queue(object):
def __init__(self):
self.front = None
self.rear = None
def setFront(self,front):
self.front = front
def getFront(self):
return self.front
def setRear(self,rear):
self.rear = rear
def getRear(self):
return self.rear
def isEmpty(self):
return self.getFront() == None
def enqueue(self,data):
newnode = Node(data)
if self.isEmpty():
self.setFront(newnode)
else:
self.getRear().setNext(newnode)
newnode.setPrev(self.getRear())
self.setRear(newnode)
def dequeue(self):
if not self.isEmpty():
temp = self.getFront()
if self.getFront().getNext() == None:
self.setRear(None)
else:
self.getFront().getNext().setPrev(None)
self.setFront(self.getFront().getNext())
del temp
def bubbleSort(A):
n = len(A)
i = 1
while i < n:
j = n - 1
while j >= 1:
if A[j] < A[j-1]:
temp = A[j - 1]
A[j - 1] = A[j]
A[j] = temp
j-=1
i+=1
from random import randint
n = int(input())
m = int(input());
S = Stack()
counter = 1
while(counter <= n):
S.push(randint(0,m))
counter += 1
A = []
while not S.isEmpty():
if S.getTop().getData()%2==0:
A.append(S.getTop().getData())
S.pop()
bubbleSort(A)
Q = Queue()
counter = 1
while(counter <= len(A)):
Q.enqueue(A[counter-1])
counter+=1
while not Q.isEmpty():
print(Q.getFront().getData())
Q.dequeue()
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCmNsYXNzIE5vZGU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