#include
using namespace std;
class node
{
public:
int data;
node *next;
node(int d)
{
data=d;
next=NULL;
}
};
void Display(node *p)
{
while(p!=NULL)
{
cout<data<<" ";
p=p->next;
}
}
void Create(node *&head,int n)
{
int ele;
cin>>ele;
head=new node(ele);
node *last=head;
node *t=NULL;
for(int i=0;i<n-1;i++)
{
cin>>ele;
t=new node(ele);
last->next=t;
last=t;
}
}
node * CreateOdd(node *p)
{
node *h1=new node(p->data);
node *last=h1;
node *t;
if(h1!=NULL)
{
t=new node(p->data);
last->next=t;
last=t;
}
return h1;
}
node * CreateEven(node *p)
{
node *h2=new node(p->data);
node *last=h2;
node *t;
if(h2!=NULL)
{
t=new node(p->data);
last->next=t;
last=t;
}
return h2;
}
node * EvenAfterOdd(node *head)
{
node *p;
node *head1;
node *head2;
while(p!=NULL)
{
if(p->data%2!=0)
{
head1=CreateOdd§;
}
else
{
head2=CreateEven§;
}
p=p->next;
}
p=head1;
while(p->next!=NULL)
{
p=p->next;
}
p->next=head2;
return head1;
}
int main()
{
int n;
cin>>n;
node *head=NULL;
Create(head,n);
head=EvenAfterOdd(head);
Display(head);
}