#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node* next;
};
struct Node* createNode(int data){
    struct Node*node = (struct Node*)malloc(sizeof(struct Node));
    node->data = data;
    node->next = NULL;
    return node;
}
voidinsertEnd(struct Node** head,int data){
    struct Node* node=createNode(data);
    if(*head==NULL){
        *head=node;
        node->next=*head;
    }else{
        struct Node* temp=*head;
        while(tep->next!=*head)
        temp=temp->next;
        node->next=*head;
    }
}
void printlist(struct Node* head){
    if (head == NULL) {
        printf("-1");
        return;
    }
    struct Node* temp = head;
    do {
        printf("%d", temp->data);
        temp = temp->next;
    }while (temp != head);
    printf(" ");
}
void splitEvenOdd(struct Node* head, struct Node**evenHead, struct Node** oddHead) {
    if (!head) return;
    struct Node* temp = head;
    do {
        if (temp->data % 2 == 0)
        insertEnd(evenHead, temp->data);
        else
        insertEnd(oddHead, temp->data);
        temp = temp->next;
    }while (temp != head);
}
int main() {
    int n, val;
    struct Node* head = NULL;
    struct Node* evenhead = NULL;
    struct Node* oddhead = NULL;
    scanf("%d", &n);
    for (int i =0; i < n; i++) {
        scanf("%d", &val);
        insertEnd(&head, val);
    }
    splitEvenOdd(head, &evenHead, &oddHead);
    printList(evenHead);
    printList(oddHead);
    
    return 0;
}