#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node* next;
};
void insert(struct Node** head, int value){
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    if(*head == NULL){
        newNode->next = newNode;
        Node*= newNode;
    }else{
        struct Node* temp =*head;
        while (temp->next != *head)
        temp = temp->next;
        temp->next = newNode;
        newNode->next = *head;
    }
}
void splitList(struct Node* head, struct Node** even, struct Node** odd){
    if(!head) return;
    struct Node* temp = head;
    do{
        if(temp->data % 2 == 0)
        insert(even, temp->data);
        else
        insert(odd, temp->data);
        temp = temp->next;
    }while (temp != head);
}
void printList(struct Node* head){
    if(!head) return;
    struct Node* temp = head;
    do{
      printf("%d ", temp->data);
      temp = temp->next;
    }while (temp != head);
    printf("\n");
}
 int main(){
     int n, val;
     scanf("%d", &n);
     if(n <= 0){
         printf("Invalid input.\n");
         return 0;
     }
     struct Node* head = NULL;
     for(int i = 0; i < n; i++){
         scanf("%d", &val);
         if(val < 0){
              printf("Invalid input.\n");
         return 0;
     }
     insert(&head, val);
         }
         struct Node *even = NULL, *odd = NULL;
         splitList(head, &even, &odd);
         printList(even);
          printList(odd);
     
     return 0;
 }
    
    
    
    
    
    
    
    
    
    
    
    
         
        
        
}