Process First In First OutEasy

Process First In First Out

EasyPractice library · +10 XPqueuesimulationbeginner

You are given a sequence of distinct integers. Process these integers using a queue. When an integer arrives, add it to the back of the queue. If the queue is not empty, take the integer from the front of the queue and print it. Repeat this for all incoming integers.

For example, if the input sequence is [10, 20, 30], the steps are:

  1. 10 arrives: enqueue 10. Queue: [10].
  2. 20 arrives: enqueue 20. Queue: [10, 20]. Dequeue 10, print 10. Queue: [20].
  3. 30 arrives: enqueue 30. Queue: [20, 30]. Dequeue 20, print 20. Queue: [30].
  4. End of input. Dequeue 30, print 30. Queue: [].

Input

The first line contains a single integer N, the number of integers. The second line contains N distinct integers, separated by spaces.

Output

Print the integers dequeued, each on a new line, in the order they are dequeued.

Constraints

1 <= N <= 1000. Each integer is between -10^9 and 10^9.

Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests

Example 1

Input
3
10 20 30
Output
10
20
30

Processes 10, then 20, then 30. Remaining 30 is processed at the end.

Example 2

Input
5
5 15 25 35 45
Output
5
15
25
35
45

Processes 5, 15, 25, 35. Remaining 45 is processed at the end.

Hints