/*内存泄露*/
#include<iostream>
using namespace std;
class item
{
public:
friend class List;
item(){data=0; pre=0; }
item(int x){data=x;pre=0;}
private:
int data;
item *pre;
};
class List
{
public:
List(){len=0;ed=0;}
~List()
{
item *temp=ed->pre;
while (temp)
{
delete[] ed;
ed=temp;
temp=ed->pre;
}
}
void Print()
{
item *temp=ed;
while (ed)
{
cout<<ed->data<<" ";
ed=ed->pre;
}
cout<<endl;
}
int Length(){return len;}
bool IsEmpty()
{
if (len) return false;
return true;
}
void Add(int x)
{
item *temp= new item(x);
temp->pre=ed;
ed=temp;
len++;
}
void Del()
{
if ( !len )
{
cout<<"There is nothing to delete!"<<endl;
return;
}
item *temp=ed->pre;
delete[] ed;
ed=temp;
}
private:
int len;
item *ed;
};
int main()
{
List list;
int n;
while (1)
{
cin>>n;
if (n==-1) break;
list.Add(n);
}
cout<<list.Length()<<endl;
list.Print();
return 0;
}