#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
struct node *next;
}Snode;
void init(Snode* &s){
s=new Snode;
s=NULL;
}
void push(Snode* &s,int x){
Snode *p=new Snode;
p->data=x;
p->next=s;
s=p;
}
void pop(Snode* &s){
Snode *p;
p=s;
cout<<p->data<<" ";
s=s->next;
delete p;
}
int main()
{
Snode *s;
int x;
init(s);
cin>>x;
while(x){
push(s,x);
cin>>x;
}
while(s!=NULL){
pop(s);
}
//cout << "Hello world!" << endl;
return 0;
}