#include <stdio.h>
#include <stdio.h>

typedef struct Node{
    int data;
    struct Node* next;
} Node;
Node* createNode(int data){
    Node* newNode = (Node*)malloc(sizeof(Node));
    if(!newNode){
        printf("Memory error\n");
        return NULL;
    }
    newNode->data = data;
    newNode->next = newNode;
    return newNode;
}
void insert(Node**head_ref,int data){
    Node* newNode = createNode(data);
    if (*head_ref == NULL){
        *head_ref = newNode;
    } else {
        Node* last = (*head_ref);
        while (last->next != *head_ref){
            last = last->next;
        }
        last->next = newNode;
        newNode->next = *head_ref;
    }
}
void splitCircularList(Node* head,Node** even_head, Node** odd_head){
    if(head == NULL) return;
    
    Node*even = NULL;
    Node* odd = NULL;
    Node* current = head;
    
    do {
        if current->data % 2 == 0){
            insert(even_head, current->data);
            
        } else {
            insert(odd_head, current->data);
        }
        current = current->next;
    }while(current !=head);
    
}
void printCircularList(Node* head) {
    if(head == NULL)return;
    Node* temp = head;
    do{
        printf("%d ",temp->data);
        temp = temp->next;
    } while(temp !=head);
    printf("\n");
}
int main(){
    int n;
    scanf("%d ",&n);
    if(n < 0){
        printf("Invalid input\n");
        return 0;
    }
    Node* head = NULL;
    Node* even_head = NULL;
    Node* odd_head = NULL;
    
    int val;
    for (int i = 0; i < n; i++){
        scanf("%d ",&val);
        if(val < 0){
            printf("Invalid input\n");
            return 0;
        }
        insert(&head,val);
    }
    splitCircularList(head, &even_head, &odd_head);
    
    printCircularList(even_head);
    printCircularList(odd_head);
}