#include<stdio.h>
#include<stdlib.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;
    naewnode->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 (lasr->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 printCircukarList(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){
                print("Invalid input\n");
                return 0;
            }
            insert(&head,val);
        }
        splitCircularList(head, &even_head, &odd_head);
        
        printCirccularList(even_head);
        printCircularList(odd_head);
        
    }
}