#include <iostream>
#include <cstring>
#include <stack>
#include <cstdio>
using namespace std;
struct Queue
{
stack<int> st1,st2;
} q1;
void deq()
{
while(!q1.st1.empty())
{
q1.st2.push(q1.st1.top());
q1.st1.pop();
}
if(!q1.st2.empty())
cout<<q1.st2.top()<<endl;
q1.st2.pop();
}
void enq(int x)
{
q1.st1.push(x);
}
int main()
{
int n,x;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>x;
enq(x);
}
for(int i=0; i<n; i++)
{
deq();
}
return 0;
}