#include<stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node *next;
};
int main()
{
    int n,x;
    scanf("%d",&n);
    if(n <= 0)
    {
        printf("Invalid input");
        return 0;
    }
     struct node *head = NULL,*tail = NULL,*temp;
     for(int i=0;i<n;i++)
     {
         scanf("%d",&x);
         if(x<0)
         {
              printf("Invalid input");
              return 0;
         }
         temp = (struct node*)malloc(sizeof(struct node));
         temp->data = x;
         temp->next = NULL;
         if(head == NULL)
         head = tail = temp;
         else
         {
             tail->next = temp;
             tail = temp;
         }
     }
     tail->next = head;
     
     struct node *curr = head;
     
     do
     {
         if(curr->data % 2 == 0)
         {
             printf("%d ",curr->data);
             curr = curr->next;
         }
         }while(curr != head);
         printf("\n");
         curr = head;
         do
         {
             if(curr->data % 2 != 0)
             {
                printf("%d ",curr->data);
                curr = curr->next; 
             }
         }while(curr != head);
         
         return 0;
     }
}