#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next;
}Node;
Node *head = NULL;
void insert(int num){
    Node *newnode = (Node*)malloc(1 * sizeof(Node));
    newnode->data = num;
    if(head==NULL){
        newnode->next = newnode;
        head = newnode;
    }
    else{
        newnode->next = head->next;
        head->next = newnode;
        head  = newnode;
    }
}
void display(){
    Node *temp = head->next;
    do{
        if(temp->data %2 ==0)
            printf("%d ",temp->data);
            temp = temp->next;
    }while(temp !=head->next);
        printf("\n");
    do{
        if(temp->data %2 !=0)
        printf("%d ",temp->data);
        temp = temp->next;
    }while(temp != head->next);
}
int main(){
    int size,num,itr,val;
    scanf("%d",&size);
    if(size<=0){
        printf("Invalid input");
        return 0;
    }
    for(itr=1; itr<=size; itr++){
        scanf("%d",&num;
        if(num<0){
            printf("Invalid input");
            return 0;
        }
        insert(num);
    }
    display();
    return 0;
}