package javaapplication246;

import java.util.Scanner;
public class JavaApplication246 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        int number_of_positive = 0;
        int number_of_negitive = 0;
        int arr[] = new int[n];
        for(int i = 0;  i< n ; i ++)
        {
            int number ;
            number = input.nextInt();
            if(number != 0)
                arr[i] = number;
            if(arr[i] > 0)
            {
                number_of_positive ++;
            }
            else if(arr[i] < 0)
            {
                number_of_negitive ++;
            }
        }
        if(number_of_positive == 0)
        {
            System.out.println(1+" " + arr[2]);
            System.out.println(2+" " + arr[0] + arr[1]);
            System.out.print(n - 3 + " ");
            for(int i = 3 ; i < n - 1; i ++)
            {
                System.out.print(arr[i] + " ");
            }
            System.out.println(0);
            return ;
        }
        System.out.print(1+" ");
        for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] < 0)
            {
                System.out.println(arr[i]);
                arr[i] = 0;
                break;
            }

        }
        System.out.print(1+" ");
                for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] > 0)
            {
                System.out.println(arr[i]);
               // System.out.println("hell o");
                arr[i] = 0;
                break;
            }

        }
        System.out.print(n - 2 + " ");
        for(int i = 0; i < n ; i ++)
        {
            if(arr[i] != 0)
            {
                System.out.print(arr[i] + " ");

            }
        }
        System.out.println(0);

        // TODO code application logic here
    }

}


import java.uti.Scanner;
public class JavaApplication246 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        int number_of_positive = 0;
        int number_of_negitive = 0;
        int arr[] = new int[n];
        int k = 0;
        for(int i = 0;  i< n ; i ++)
        {
            int number ;
            number = input.nextInt();
            if(number != 0)
                arr[k++] = number;
            if(arr[i] > 0)
            {
                number_of_positive ++;
            }
            else if(arr[i] < 0)
            {
                number_of_negitive ++;
            }
        }
        if(number_of_positive == 0)
        {
            System.out.println(1+" " + arr[2]);
            System.out.println(2+" " + arr[0] +" " + arr[1]);
            System.out.print(n - 3 + " ");
            for(int i = 3 ; i < n - 1; i ++)
            {
                System.out.print(arr[i] + " ");
            }
            System.out.println(0);
            return ;
        }
        System.out.print(1+" ");
        for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] < 0)
            {
                System.out.println(arr[i]);
                arr[i] = 0;
                break;
            }

        }
        System.out.print(1+" ");
                for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] > 0)
            {
                System.out.println(arr[i]);
               // System.out.println("hell o");
                arr[i] = 0;
                break;
            }

        }
        System.out.print(n - 2 + " ");
        for(int i = 0; i < n ; i ++)
        {
            if(arr[i] != 0)
            {
                System.out.print(arr[i] + " ");

            }
        }
        System.out.println(0);

        // TODO code application logic here
    }

}


import java.util.Scanner;
public class JavaApplication246 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        int number_of_positive = 0;
        int number_of_negitive = 0;
        int arr[] = new int[n];
        int k = 0;
        for(int i = 0;  i< n ; i ++)
        {
            int number ;
            number = input.nextInt();
            if(number != 0)
                arr[k++] = number;
            if(arr[i] > 0)
            {
                number_of_positive ++;
            }
            else if(arr[i] < 0)
            {
                number_of_negitive ++;
            }
        }
        if(number_of_positive == 0)
        {
            System.out.println(1+" " + arr[2]);
            System.out.println(2+" " + arr[0] +" " + arr[1]);
            System.out.print(n - 3 + " ");
            for(int i = 3 ; i < n - 1; i ++)
            {
                System.out.print(arr[i] + " ");
            }
            System.out.println(0);
            return ;
        }
        System.out.print(1+" ");
        for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] < 0)
            {
                System.out.println(arr[i]);
                arr[i] = 0;
                break;
            }

        }
        System.out.print(1+" ");
                for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] > 0)
            {
                System.out.println(arr[i]);
               // System.out.println("hell o");
                arr[i] = 0;
                break;
            }

        }
        System.out.print(n - 2 + " ");
        for(int i = 0; i < n ; i ++)
        {
            if(arr[i] != 0)
            {
                System.out.print(arr[i] + " ");

            }
        }
        System.out.println(0);

        // TODO code application logic here
    }

}


import java.util.Scanner;
public class JavaApplication246 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        int number_of_positive = 0;
        int number_of_negitive = 0;
        int arr[] = new int[n];
        for(int i = 0;  i< n ; i ++)
        {
            int number ;
            number = input.nextInt();
            if(number != 0)
                arr[i] = number;
            if(arr[i] > 0)
            {
                number_of_positive ++;
            }
            else if(arr[i] < 0)
            {
                number_of_negitive ++;
            }
        }
        if(number_of_positive == 0)
        {
            System.out.println(1+" " + arr[2]);
            System.out.println(2+" " + arr[0] + arr[1]);
            System.out.print(n - 3 + " ");
            for(int i = 3 ; i < n - 1; i ++)
            {
                System.out.print(arr[i] + " ");
            }
            System.out.println(0);
            return ;
        }
        System.out.print(1+" ");
        for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] < 0)
            {
                System.out.println(arr[i]);
                arr[i] = 0;
                break;
            }

        }
        System.out.print(1+" ");
                for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] > 0)
            {
                System.out.println(arr[i]);
               // System.out.println("hell o");
                arr[i] = 0;
                break;
            }

        }
        System.out.print(n - 2 + " ");
        for(int i = 0; i < n ; i ++)
        {
            if(arr[i] != 0)
            {
                System.out.print(arr[i] + " ");

            }
        }
        System.out.println(0);

        // TODO code application logic here
    }

}


import java.util.Scanner;
public class JavaApplication246 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        int number_of_positive = 0;
        int number_of_negitive = 0;
        int arr[] = new int[n];
        for(int i = 0;  i< n ; i ++)
        {
            int number ;
            number = input.nextInt();
            if(number != 0)
                arr[i] = number;
            if(arr[i] > 0)
            {
                number_of_positive ++;
            }
            else if(arr[i] < 0)
            {
                number_of_negitive ++;
            }
        }
        if(number_of_positive == 0)
        {
            System.out.println(1+" " + arr[2]);
            System.out.println(2+" " + arr[0] +" " + arr[1]);
            System.out.print(n - 3 + " ");
            for(int i = 3 ; i < n - 1; i ++)
            {
                System.out.print(arr[i] + " ");
            }
            System.out.println(0);
            return ;
        }
        System.out.print(1+" ");
        for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] < 0)
            {
                System.out.println(arr[i]);
                arr[i] = 0;
                break;
            }

        }
        System.out.print(1+" ");
                for(int i = 0 ; i < n ; i ++)
        {
            if(arr[i] > 0)
            {
                System.out.println(arr[i]);
               // System.out.println("hell o");
                arr[i] = 0;
                break;
            }

        }
        System.out.print(n - 2 + " ");
        for(int i = 0; i < n ; i ++)
        {
            if(arr[i] != 0)
            {
                System.out.print(arr[i] + " ");

            }
        }
        System.out.println(0);

        // TODO code application logic here
    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos;
    int zero=0, N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero++;
    }
    int Nneg = neg.size(), Npos = pos.size();
    if (Nneg % 2 != 0 && Npos == 0) {
        Nneg -= 2;
        Npos += 2;
    }

//    cout << Nneg << zero << Npos;

    cout << Nneg;
    for (int i = Nneg - 1; i >= 0; i--) {
        cout << " " << neg[i];
        neg.pop_back();
    }
    cout << "\n";

    cout << Npos;
    for (int i = 0; i < Npos; i++) {
        if (!pos.empty()) {
            cout << " " << pos[i];
            pos.pop_back();
        }
    }
    while (!neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }
    cout << "\n";

    cout << zero;
    for (int i = 0; i < zero; i++) {
        cout << " 0";
    }
    cout << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos, zero;
    int N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero.push_back(in);
    }
    int Nneg = neg.size(), Npos = pos.size(), Nzero = zero.size(), stag = 0;

    if (Npos == 0) {
        Nneg -= 2;
        Npos += 2;
        stag = 2;
        pos.push_back(neg.back());
        neg.pop_back();
        pos.push_back(neg.back());
        neg.pop_back();
    }

    if (Nneg % 2 == 0) {
        Nneg--;
        Nzero++;
        zero.push_back(neg.back());
        neg.pop_back();
    }

    cout << Nneg;
    for (int i = 0; i < Nneg; i++) {
        cout << " " << neg.back();
        neg.pop_back();
    }

    cout << "\n" << Npos;
    for (int i = 0; i < Npos; i++) {
        cout << " " << pos.back();
        pos.pop_back();
    }
    while (stag == 2 && !neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }

    cout << "\n" << Nzero << " 0";
    while (stag == 1 && !neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos;
    int zero = 0, N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero++;
    }
    int Nneg = neg.size(), Npos = pos.size(), stag = 0;

    if (Npos == 0) {
        Nneg -= 2;
        Npos -= 2;
        stag = 2;
    }

    if (Nneg % 2 == 0) {
        Nneg--;
        zero++;
        stag = 1;
    }

    cout << Nneg;
    for (int i = 0; i < Nneg; i++) {
        cout << " " << neg.back();
        neg.pop_back();
    }

    cout << "\n" << abs(Npos);
    for (int i = 0; i < Npos; i++) {
        cout << " " << pos.back();
        pos.pop_back();
    }
    while (stag == 2 && !neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }

    cout << "\n" << zero << " 0";
    while (stag == 1 && !neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos, zero;
    int N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero.push_back(in);
    }
    int Nneg = neg.size(), Npos = pos.size(), Nzero = zero.size(), stag = 0;

    if (Npos == 0) {
        Nneg -= 2;
        Npos += 2;
        stag = 2;
        pos.push_back(neg.back());
        neg.pop_back();
        pos.push_back(neg.back());
        neg.pop_back();
    }

    if (Nneg % 2 == 0) {
        Nneg--;
        Nzero++;
        zero.push_back(neg.back());
        neg.pop_back();
    }

    cout << Nneg;
    while (!neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }

    cout << "\n" << Npos;
    for (int i = 0; i < Npos; i++) {
        cout << " " << pos.back();
        pos.pop_back();
    }

    cout << "\n" << Nzero;
    while (!zero.empty()) {
        cout << " " << zero.back();
        zero.pop_back();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos;
    int zero = 0, N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero++;
    }
    int Nneg = neg.size(), Npos = pos.size();
    if (Nneg % 2 != 0 && Npos == 0) {
        Nneg -= 2;
        Npos += 2;
    }

//    cout << Nneg << zero << Npos;

    cout << Nneg;
    for (int i = 0; i < Nneg; i++) {
        cout << " " << neg[i];
    }
    cout << "\n";

    cout << Npos;
    for (int i = 0; i < Npos; i++) {
        if (!pos.empty()) {
            cout << " " << pos[i];
            pos.pop_back();
        }
    }
    for (int i = Npos - 1; i < neg.size(); i++) {
        cout << " " << neg[i];
    }
    cout << "\n";

    cout << zero;
    for (int i = 0; i < zero; i++) {
        cout << " 0";
    }
    cout << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos;
    int zero, N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero++;
    }
    int Nneg = neg.size(), Npos = pos.size();
    if (Nneg % 2 != 0 && Npos == 0) {
        Nneg -= 2;
        Npos += 2;
    }

//    cout << Nneg << zero << Npos;

    cout << Nneg;
    for (int i = Nneg - 1; i >= 0; i--) {
        cout << " " << neg[i];
        neg.pop_back();
    }
    cout << "\n";

    cout << Npos;
    for (int i = 0; i < Npos; i++) {
        if (!pos.empty()) {
            cout << " " << pos[i];
            pos.pop_back();
        }
    }
    while (!neg.empty()) {
        cout << " " << neg.back();
        neg.pop_back();
    }
    cout << "\n";

    cout << zero;
    for (int i = 0; i < zero; i++) {
        cout << " 0";
    }
    cout << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int> neg, pos;
    int zero = 0, N, in;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> in;
        if (in > 0) pos.push_back(in);
        if (in < 0)neg.push_back(in);
        if (in == 0)zero++;
    }
    int Nneg = neg.size(), Npos = pos.size();
    if (Nneg % 2 != 0 && Npos == 0) {
        Nneg -= 2;
        Npos += 2;
    }

//    cout << Nneg << zero << Npos;

    cout << Nneg;
    for (int i = 0; i < Nneg; i++) {
        cout << " " << neg[i];
    }
    cout << "\n";

    cout << Npos;
    for (int i = 0; i < Npos; i++) {
        if (!pos.empty()) {
            cout << " " << pos[i];
            pos.pop_back();
        }
    }
    if (Nneg != neg.size()) {
        for (int i = Npos - 1; i < neg.size(); i++) {
            cout << " " << neg[i];
        }
    }
    cout << "\n";

    cout << zero;
    for (int i = 0; i < zero; i++) {
        cout << " 0";
    }
    cout << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,counter_neg=0,counter_pos=0,counter_zero=0;
    int arr[n],negative[n],positive[n],zero[n];
    for (int i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    for (int i=0;i<n;i++)
    {
        if (arr[i] < 0)
        {
            negative[counter_neg] = arr[i];
            counter_neg++;
        } else if (arr[i] > 0) {
            positive[counter_pos] = arr[i];
            counter_pos++;
        } else if (arr[i] == 0) {
            zero[counter_zero] = arr[i];
            counter_zero++;
        }
    }

        if (counter_neg%2==0)
        {
            counter_neg--;
            zero[counter_zero]=negative[counter_neg];
            counter_zero++;
        }
        if (counter_pos==0)
        {
            counter_neg--;
            positive[counter_pos]=negative[counter_neg];
            counter_pos++;
            counter_neg--;
            positive[counter_pos]=negative[counter_neg];
            counter_pos++;
        }
        cout << counter_neg << endl;
        for (int i=0;i<counter_neg;i++)
        {
            cout << negative[i] << " ";
        }
        cout << endl;
        cout << counter_pos << endl;
        for (int i=0;i<counter_pos;i++)
        {
            cout << positive[i] << " ";
        }
        cout << endl;
        cout << counter_zero << " ";
        for (int i=0;i<counter_zero;i++)
        {
            cout << zero[i] << " ";
        }
        cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int negatives[num] , positives[num] , zeros[num];
    int counter_neg = 0 , counter_pos = 0 , counter_zero = 0;
    int tmp;

    for (int i=0 ; i<num ; i++)
    {
        cin >> tmp;
        if (tmp > 0)
        {
            positives[counter_pos] = tmp;
            counter_pos ++;
        }
        else if (tmp < 0)
        {
            negatives[counter_neg] = tmp;
            counter_neg ++;
        }
        else
        {
            zeros[counter_zero] = tmp;
            counter_zero ++;
        }
    }

    if (counter_neg % 2 != 0)
    {
       if(counter_pos == 0)
        {
            positives [counter_pos] = negatives[counter_neg-1];
            counter_neg --; counter_pos ++;
            positives [counter_pos] = negatives[counter_neg-1];
            counter_neg --; counter_pos ++;
        }
    }
    else
    {
        zeros[counter_zero] = negatives[counter_neg -1];
        counter_zero ++;  counter_neg --;
        if(counter_pos == 0)
        {
            positives [counter_pos] = negatives[counter_neg-1];
            counter_neg --; counter_pos ++;
            positives [counter_pos] = negatives[counter_neg-1];
            counter_neg --; counter_pos ++;
        }
    }

    cout << counter_neg;
    for (int i=0 ; i<counter_neg ; i++)
    {
        cout << " " << negatives[i];
    }
    cout << endl;

    cout << counter_pos;
    for (int i=0 ; i<counter_pos ; i++)
    {
        cout << " " << positives[i];
    }
    cout << endl;

    cout << counter_zero;
    for (int i=0 ; i<counter_zero ; i++)
    {
        cout << " " << zeros[i];
    }
    cout <<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[n];
    int counter_neg=0,counter_pos=0,counter_zero=0;
    for (int i=0;i<n;i++)
    {
        cin >> arr[i];
        if (arr[i]<0)      counter_neg++;
        if (arr[i]>0)      counter_pos++;
        if (arr[i]==0)    counter_zero++;
    }
    sort(arr,arr+n);
    if (counter_neg%2==0) {
        counter_zero++;
        counter_neg--;

        if (counter_pos == 0) {
            counter_pos = counter_neg - 1;
            counter_neg == 1;
        }
        cout << counter_neg << " ";
        for (int i = 0; i < counter_neg; i++) {
            arr[i];
        }
        cout << endl;

        cout << counter_pos << " ";
        for (int i = 0; i < counter_pos; i++) {
            cout << arr[i + counter_neg + counter_zero] << " ";
        }
        cout << endl;

        cout << counter_zero;
        for (int i = 0; i < counter_zero; i++) {
            cout << arr[i + counter_neg] << " ";
        }
        cout << endl;

    }
    else if (counter_neg%2!=0)
    {
       if(counter_neg>1)
       {
           counter_pos+=(counter_neg-1);
        counter_neg=1;
       }
        cout << counter_neg << " ";
        for (int i = 0; i < counter_neg; i++)
        {
            cout << arr[i] << " ";
        }
        cout << endl;
        cout << counter_pos << " ";
        for (int i = 0; i < counter_pos; i++) {
            cout << arr[i + counter_neg + counter_zero] << " ";
        }
        cout <<endl;
        cout << counter_zero << " ";
        for (int i = 0; i < counter_zero; i++) {
            cout << arr[i + counter_neg] << " ";
        }
        cout << endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int arr[num];
    int counter_neg = 0 , counter_pos = 0 , counter_zero = 0;

    for (int i=0 ; i<num ; i++)
    {
        cin >> arr[i];
        (arr[i] == 0)  ?  counter_zero ++  : (arr[i] > 0) ?  counter_pos ++ : counter_neg++;
    }

    if (counter_pos == 0)
    {
        if (counter_neg % 2 == 0)
        {
            int zeros[counter_zero];
            //int positives[counter_pos];
            int negatives[counter_neg];
            int zero =0 , neg=0;
            for (int i=0 ; i<num ; i++)
            {
                if (arr[i] < 0)
                {
                    negatives[neg] = arr[i];
                    neg ++;
                }
                else
                {
                    zeros[zero] = arr[i];
                    zero ++;
                }
            }
            cout << counter_neg - 3;
            for (int i=3 ; i<counter_neg ; i++)
            {
                cout <<" "<< negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i=0 ; i<2 ; i++)
            {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " ;
            for (int i=0 ; i<counter_zero ; i++)
            {
                cout << " 0";
            }
            cout <<" "<< negatives[3];
        }

        else
        {
            if (counter_neg %2 != 0)
            {
                int zeros[counter_zero];
                int negatives [counter_neg];
                int zero = 0 , neg = 0;
                for (int i=0 ; i<num ; i++)
                {
                    if (arr[i] < 0)
                    {
                        negatives[neg] = arr[i];
                        neg ++;
                    }
                    else
                    {
                        zeros[zero];
                        zero ++;
                    }
                }

                cout << counter_neg -2;
                for (int i=2 ; i<counter_neg ; i++)
                {
                    cout << " " << negatives[i];
                }
                cout << endl;

                cout << 2 ;
                for (int i=0 ; i<2 ; i++)
                {
                    cout << " " << negatives[i];
                }
                cout << endl;

                cout << counter_zero;
                for (int i=0 ; i<counter_zero ; i++)
                {
                    cout << " 0";
                }
            }
        }
    }
    else
    {
        int zeros[counter_zero] , positives[counter_pos] , negatives[counter_neg];
        int pos =0 , neg =0 , zero =0;

        for (int i=0 ; i<num ; i++)
        {
            if (arr[i] > 0)
            {
                positives[pos] = arr[i];  pos ++;
            }
            else if (arr[i] < 0)
            {
                negatives[neg] = arr[i];  neg ++;
            }
            else
            {
                zeros[zero] = arr[i];  zero ++;
            }
        }

        cout << counter_neg;
        for (int i=0 ; i<counter_neg ; i++)
        {
            cout << " " << negatives[i];
        }
        cout << endl;

        cout << counter_pos;
        for (int i=0 ; i<counter_pos ; i++)
        {
            cout << " " << positives[i];
        }
        cout << endl;

        cout << counter_zero;
        for (int i=0 ; i<counter_zero ; i++)
        {
            cout << " " << zeros[i];
        }
        cout << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[n];
    int counter_neg=0,counter_pos=0,counter_zero=0;
    for (int i=0;i<n;i++)
    {
        cin >> arr[i];
        if (arr[i]<0)      counter_neg++;
        if (arr[i]>0)      counter_pos++;
        if (arr[i]==0)    counter_zero++;
    }
    sort(arr,arr+n);
    if (counter_neg%2==0) {
        counter_zero++;
        counter_neg--;

        if (counter_pos == 0) {
            counter_pos = counter_neg - 1;
            counter_neg == 1;
        }
        cout << counter_neg << " ";
        for (int i = 0; i < counter_neg; i++) {
            arr[i];
        }
        cout << endl;

        cout << counter_pos << " ";
        for (int i = 0; i < counter_pos; i++) {
            cout << arr[i + counter_neg + counter_zero] << " ";
        }
        cout << endl;

        cout << counter_zero;
        for (int i = 0; i < counter_zero; i++) {
            cout << arr[i + counter_neg] << " ";
        }
        cout << endl;

    }
    else if (counter_neg%2!=0)
    {
       if(counter_neg>1)
       { counter_pos+=(counter_neg-1);
        counter_neg=1;}
        cout << counter_neg << " ";
        for (int i = 0; i < counter_neg; i++) {
            arr[i];
        }
        cout << endl;
        cout << counter_pos << " ";
        for (int i = 0; i < counter_pos; i++) {
            cout << arr[i + counter_neg + counter_zero] << " ";
        }
        cout <<endl;
        cout << counter_zero << " ";
        for (int i = 0; i < counter_zero; i++) {
            cout << arr[i + counter_neg] << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int counter_neg = 0;
    int counter_pos = 0;
    int counter_zero = 0;
    int arr[num];

    for (int i=0 ; i<num ; i++)
    {
        cin >> arr[i];
        if (arr[i] < 0)
        {
            counter_neg ++;
        }
        else if (arr[i] > 0)
        {
            counter_pos ++;
        }
        else if (arr[i] == 0)
        {
            counter_zero ++;
        }
    }

    int negatives[counter_neg];
    int positives[counter_pos];

    int pos = 0;
    int neg = 0;
    for (int i=0 ; i<num ; i++)
    {
        if (arr[i] > 0)
        {
            positives[pos] = arr[i];
            pos ++;
        }
        else if (arr[i] < 0)
        {
            negatives[neg] = arr[i];
            neg ++;
        }
    }

    if (counter_neg%2 == 0)
    {
        if (counter_pos != 0)
        {
            cout << counter_neg - 1;
            for (int i = 1; i < counter_neg; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << counter_pos;
            for (int i = 0; i < counter_pos; i++) {
                cout << " ";
                cout << positives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " << negatives[0];
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }
        else
        {
            cout << counter_neg - 2;
            for (int i = 3; i < counter_neg; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i = 0; i < 2 ; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " << negatives[0];
            for (int i = 0; i < counter_zero; i++)
            {
                cout << " 0";
            }
        }

    }
    else if (counter_neg%2 != 0)
    {
        if (counter_pos != 0)
        {
            cout << counter_neg;
            for (int i = 0; i < counter_neg; i++) {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << counter_pos;
            for (int i = 0; i < counter_pos; i++) {
                cout << " " << positives[i];
            }
            cout << endl;

            cout << counter_zero;
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }
        else
        {
            cout << counter_neg - 2;
            for (int i = 2; i < counter_neg; i++) {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i = 0; i < 2; i++) {
                cout << " " << positives[i];
            }
            cout << endl;

            cout << counter_zero;
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,counter_neg=0,counter_pos=0,counter_zero=0;
    cin >> n;
    int arr[n],negative[n],positive[n],zero[n];
    for (int i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    for (int i=0;i<n;i++)
    {
        if (arr[i] < 0)
        {
            negative[counter_neg] = arr[i];
            counter_neg++;
        } else if (arr[i] > 0) {
            positive[counter_pos] = arr[i];
            counter_pos++;
        } else if (arr[i] == 0) {
            zero[counter_zero] = arr[i];
            counter_zero++;
        }
    }

        if (counter_neg%2==0)
        {
            counter_neg--;
            zero[counter_zero]=negative[counter_neg];
            counter_zero++;
        }
        if (counter_pos==0)
        {
            counter_neg--;
            positive[counter_pos]=negative[counter_neg];
            counter_pos++;
            counter_neg--;
            positive[counter_pos]=negative[counter_neg];
            counter_pos++;
        }
        cout << counter_neg << endl;
        for (int i=0;i<counter_neg;i++)
        {
            cout << negative[i] << " ";
        }
        cout << endl;
        cout << counter_pos << endl;
        for (int i=0;i<counter_pos;i++)
        {
            cout << positive[i] << " ";
        }
        cout << endl;
        cout << counter_zero << " ";
        for (int i=0;i<counter_zero;i++)
        {
            cout << zero[i] << " ";
        }
        cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int counter_neg = 0;
    int counter_pos = 0;
    int counter_zero = 0;
    int arr[num];

    for (int i=0 ; i<num ; i++)
    {
        cin >> arr[i];
        if (arr[i] < 0)
        {
            counter_neg ++;
        }
        else if (arr[i] > 0)
        {
            counter_pos ++;
        }
        else if (arr[i] == 0)
        {
            counter_zero ++;
        }
    }

    int negatives[counter_neg];
    if (counter_pos > 0)
    {
        int positives[counter_pos];
    }
    int pos = 0;
    int neg = 0;
    for (int i=0 ; i<num ; i++)
    {
        if (arr[i] > 0)
        {
            positives[pos] = arr[i];
            pos ++;
        }
        else if (arr[i] < 0)
        {
            negatives[neg] = arr[i];
            neg ++;
        }
    }

    if (counter_neg%2 == 0)
    {
        if (counter_pos != 0)
        {
            cout << counter_neg - 1;
            for (int i = 1; i < counter_neg; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << counter_pos;
            for (int i = 0; i < counter_pos; i++) {
                cout << " ";
                cout << positives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " << negatives[0];
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }
        else
        {
            cout << counter_neg - 2;
            for (int i = 3; i < counter_neg; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i = 0; i < 2 ; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " << negatives[0];
            for (int i = 0; i < counter_zero; i++)
            {
                cout << " 0";
            }
        }

    }
    else if (counter_neg%2 != 0)
    {
        if (counter_pos != 0)
        {
            cout << counter_neg;
            for (int i = 0; i < counter_neg; i++) {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << counter_pos;
            for (int i = 0; i < counter_pos; i++) {
                cout << " " << positives[i];
            }
            cout << endl;

            cout << counter_zero;
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }
        else
        {
            cout << counter_neg - 2;
            for (int i = 2; i < counter_neg; i++) {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i = 0; i < 2; i++) {
                cout << " " << positives[i];
            }
            cout << endl;

            cout << counter_zero;
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }

    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int counter_neg = 0;
    int counter_pos = 0;
    int counter_zero = 0;
    int arr[num];

    for (int i=0 ; i<num ; i++)
    {
        cin >> arr[i];
        if (arr[i] < 0)
        {
            counter_neg ++;
        }
        else if (arr[i] > 0)
        {
            counter_pos ++;
        }
        else if (arr[i] == 0)
        {
            counter_zero ++;
        }
    }

    int negatives[counter_neg];
    //if (counter_pos > 0)

        int positives[counter_pos];

    int pos = 0;
    int neg = 0;
    for (int i=0 ; i<num ; i++)
    {
        if (arr[i] > 0)
        {
            positives[pos] = arr[i];
            pos ++;
        }
        else if (arr[i] < 0)
        {
            negatives[neg] = arr[i];
            neg ++;
        }
    }

    if (counter_neg%2 == 0)
    {
        if (counter_pos != 0)
        {
            cout << counter_neg - 1;
            for (int i = 1; i < counter_neg; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << counter_pos;
            for (int i = 0; i < counter_pos; i++) {
                cout << " ";
                cout << positives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " << negatives[0];
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }
        else
        {
            cout << counter_neg - 2;
            for (int i = 3; i < counter_neg; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i = 0; i < 2 ; i++) {
                cout << " ";
                cout << negatives[i];
            }
            cout << endl;

            cout << counter_zero + 1 << " " << negatives[0];
            for (int i = 0; i < counter_zero; i++)
            {
                cout << " 0";
            }
        }

    }
    else if (counter_neg%2 != 0)
    {
        if (counter_pos != 0)
        {
            cout << counter_neg;
            for (int i = 0; i < counter_neg; i++) {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << counter_pos;
            for (int i = 0; i < counter_pos; i++) {
                cout << " " << positives[i];
            }
            cout << endl;

            cout << counter_zero;
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }
        else
        {
            cout << counter_neg - 2;
            for (int i = 2; i < counter_neg; i++) {
                cout << " " << negatives[i];
            }
            cout << endl;

            cout << 2;
            for (int i = 0; i < 2; i++) {
                cout << " " << positives[i];
            }
            cout << endl;

            cout << counter_zero;
            for (int i = 0; i < counter_zero; i++) {
                cout << " 0";
            }
        }

    }
}


#include <bits/stdc++.h>
using namespace std;

void display(set<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if ((flag == true && n_n > 2) || (!flag))
            {
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin>>n;
    vector<int> v; v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero, negative, positive;

    for(int i=0;i<n;i++) {
        cin>>v[i];
        if(v[i] == 0) n_z++;
        else if(v[i] > 0) n_p++;
        else if(v[i] < 0) n_n++;
    }

    bool flag;
    if(n_n > 2) { flag = true;}

    for(int i=0; i < v.size(); i++) {
        if(v[i] < 0) {
            if((flag && n_n > 2) || (!flag)) {
                negative.insert(v[i]);
                n_n--;
            }
            else {
                positive.insert(v[i]);
            }
        }
        else if(v[i] == 0) {
            zero.insert(v[i]);
        }
        else {
            positive.insert(v[i]);
        }
    }

    display(negative);
    display(positive);
    display(zero);

}

void display(set<int> s) {
    cout<<s.size()<<" ";
    for(int ele: s){
        cout<<ele<<" ";
    }
    cout<<endl;
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(set<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if ((flag && n_n > 2) || (!flag))
            {
                cout<<"***********"<<endl;
                cout<<(flag && n_n > 2)<<endl;
                cout<<!flag<<endl;
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                cout<<"&&&&&&&&&&"<<endl;
                cout<<(flag && n_n > 2)<<endl;
                cout<<!flag<<endl;
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(multiset<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n+1);
    int n_z = 0, n_n = 0, n_p = 0;
    multiset<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag = false;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if (((flag) and n_n > 2) or (flag == false))
            {
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(multiset<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    multiset<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag = false;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if ((flag and n_n > 2) or (!flag))
            {
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(multiset<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    multiset<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    sort(v.begin(), v.end());

    for(int i=0;i<n;i++) {
        if(i==0) {
            negative_set.insert(v[i]);
        }
        else if(v[i] > 0) {
            positive_set.insert(v[i]);
        } else {
            zero_set.insert(v[i]);
        }
    }

    if(positive_set.empty()) {
        auto it = zero_set.begin();
        positive_set.insert(*it);
        zero_set.erase(it);
        it = zero_set.begin();
        positive_set.insert(*(it));
        zero_set.erase(it);
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(set<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n+1);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if ((flag == true && n_n > 2) || (!flag))
            {
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(set<int> s) {
    cout<<s.size()<<" ";
    for(int ele: s){
        cout<<ele<<" ";
    }
    cout<<endl;
}

void solve() {
    int n; cin>>n;
    vector<int> v; v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero, negative, positive;

    for(int i=0;i<n;i++) {
        cin>>v[i];
        if(v[i] == 0) n_z++;
        else if(v[i] > 0) n_p++;
        else if(v[i] < 0) n_n++;
    }

    bool flag;
    if(n_n > 2) { flag = true;}

    for(int i=0; i < v.size(); i++) {
        if(v[i] < 0) {
            if((flag && n_n > 2) || (!flag)) {
                negative.insert(v[i]);
                n_n--;
            }
            else {
                positive.insert(v[i]);
            }
        }
        else if(v[i] == 0) {
            zero.insert(v[i]);
        }
        else {
            positive.insert(v[i]);
        }
    }

    display(negative);
    display(positive);
    display(zero);

}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(multiset<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n+1);
    int n_z = 0, n_n = 0, n_p = 0;
    multiset<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if (((flag) && n_n > 2) || (flag == false))
            {
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(set<int> s) {
    cout<<s.size()<<" ";
    for(int ele: s){
        cout<<ele<<" ";
    }
    cout<<endl;
}

void solve() {
    int n; cin>>n;
    vector<int> v; v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero_set, negative_set, positive_set;

    for(int i=0;i<n;i++) {
        cin>>v[i];
        if(v[i] == 0) n_z++;
        else if(v[i] > 0) n_p++;
        else if(v[i] < 0) n_n++;
    }

    bool flag;
    if(n_n > 2) { flag = true;}

    for(int i=0; i < v.size(); i++) {
        if(v[i] < 0) {
            if((flag && n_n > 2) || (!flag)) {
                negative_set.insert(v[i]);
                n_n--;
            }
            else {
                positive_set.insert(v[i]);
            }
        }
        else if(v[i] == 0) {
            zero_set.insert(v[i]);
        }
        else {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);

}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(multiset<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    multiset<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    sort(v.begin(), v.end());

    for(int i=0;i<n;i++) {
        if(i==0) {
            negative_set.insert(v[i]);
        }
        else if(v[i] > 0) {
            positive_set.insert(v[i]);
        } else {
            zero_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin>>n;
    vector<int> v; v.resize(n);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero, negative, positive;

    for(int i=0;i<n;i++) {
        cin>>v[i];
        if(v[i] == 0) n_z++;
        else if(v[i] > 0) n_p++;
        else if(v[i] < 0) n_n++;
    }

    bool flag;
    if(n_n > 2) { flag = true;}

    for(int i=0; i < v.size(); i++) {
        if(v[i] < 0) {
            if((flag && n_n > 2) || (!flag)) {
                negative.insert(v[i]);
                n_n--;
            }
            else {
                positive.insert(v[i]);
            }
        }
        else if(v[i] == 0) {
            zero.insert(v[i]);
        }
        else {
            positive.insert(v[i]);
        }
    }

    cout<<negative.size()<<" ";
    for(int ele: negative){
        cout<<ele<<" ";
    }
    cout<<endl;

    cout<<positive.size()<<" ";
    for(int ele: positive){
        cout<<ele<<" ";
    }
    cout<<endl;

    cout<<zero.size()<<" ";
    for(int ele: zero){
        cout<<ele<<" ";
    }
    cout<<endl;

}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


#include <bits/stdc++.h>
using namespace std;

void display(set<int> s)
{
    cout << s.size() << " ";
    for (int ele : s)
    {
        cout << ele << " ";
    }
    cout << endl;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n+1);
    int n_z = 0, n_n = 0, n_p = 0;
    set<int> zero_set, negative_set, positive_set;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] == 0)
            n_z++;
        else if (v[i] > 0)
            n_p++;
        else if (v[i] < 0)
            n_n++;
    }

    bool flag;
    if (n_n > 2)
    {
        flag = true;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] < 0)
        {
            if ((flag == true && n_n > 2) || (flag == false))
            {
                negative_set.insert(v[i]);
                n_n--;
            }
            else
            {
                positive_set.insert(v[i]);
            }
        }
        else if (v[i] == 0)
        {
            zero_set.insert(v[i]);
        }
        else
        {
            positive_set.insert(v[i]);
        }
    }

    display(negative_set);
    display(positive_set);
    display(zero_set);
}

int main()
{
    // int t; cin>>t;
    // while(t--) {
    //     solve();
    // }

    solve();
}


//THIS CODE Was Brought u by 3mak shaher yoood
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int r[26];
#define meow() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
long long l[1000000];
long long n[1000000];
long long mx[1000000];
using namespace std;
int main()
{
	meow();
	int negative = 0, a, zero = 0, posi = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i];
		if (l[i] < 0) {
			negative++;
		}
		else if (l[i] == 0) {
			zero++;
		}
		else {
			posi++;
		}
	}
	if (negative % 2 != 0) {
		int n = 0;
		cout << negative-2 << " ";
		for (int i = 0; i <a; i++) {
			n++;
			if (l[i] < 0&&abs(n-negative!=2)) {
				cout << l[i] << " ";
				l[i] = -999;
			}
			if (abs(n - negative != 2)) {
				break;
			}
		}
		cout << endl;
		cout << posi+2 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] > 0) {
				cout <<l[i] << " ";
			}
			else if (l[i] < 0 && l[i] != -999) {
				cout << l[i] << " ";
			}
		}
		cout << endl;
		cout << zero << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] == 0) {
				cout << l[i] << " ";
			}
			}
		}
	}


//THIS CODE Was Brought u by 3mak shaher yoood
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int r[26];
#define meow() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
long long l[1000000];
long long n[1000000];
long long mx[1000000];
using namespace std;
int main()
{
	meow();
	int negative = 0, a, zero = 0, posi = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i];
		if (l[i] < 0) {
			negative++;
		}
		else if (l[i] == 0) {
			zero++;
		}
		else {
			posi++;
		}
	}
	if (negative % 2 != 0) {
		cout << negative << " ";
		for (int i = 0; i <a; i++) {
			if (l[i] < 0) {
				cout << l[i] << " ";
			}
		}
		cout << endl;
		cout << posi << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] > 0) {
				cout <<l[i] << " ";
			}
		}
		cout << endl;
		cout << zero << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] == 0) {
				cout << l[i] << " ";
			}
			}
		}
	}


//THIS CODE Was Brought u by 3mak shaher yoood
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int r[26];
#define meow() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
long long l[1000000];
long long n[1000000];
long long mx[1000000];
using namespace std;
int main()
{
	meow();
	int negative = 0, a, zero = 0, posi = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i];
		if (l[i] < 0) {
			negative++;
		}
		else if (l[i] == 0) {
			zero++;
		}
		else {
			posi++;
		}
	}
	if (negative % 2 != 0) {
		int n = 0;
		cout << negative-2 << " ";
		for (int i = 0; i <a; i++) {
			n++;
			if (l[i] < 0&&abs(n-negative!=2)) {
				cout << l[i] << " ";
				l[i] = -999;
			}
			if (abs(n - negative != 2)) {
				break;
			}
		}
		cout << endl;
		cout << posi+abs(n-negative) << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] > 0) {
				cout <<l[i] << " ";
			}
			else if (l[i] < 0 && l[i] != -999) {
				cout << l[i] << " ";
			}
		}
		cout << endl;
		cout << zero << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] == 0) {
				cout << l[i] << " ";
			}
			}
		}
	}


//THIS CODE Was Brought u by 3mak shaher yoood
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int r[26];
#define meow() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
long long l[1000000];
long long n[1000000];
long long mx[1000000];
using namespace std;
int main()
{
	meow();
	int negative = 0, a, zero = 0, posi = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i];
		if (l[i] < 0) {
			negative++;
		}
		else if (l[i] == 0) {
			zero++;
		}
		else {
			posi++;
		}
	}
	if (negative % 2 != 0) {
		int n = 0;
		cout << abs(negative-2) << " ";
		for (int i = 0; i <a; i++) {
			n++;
			if (l[i] < 0&&abs(n-negative!=2)) {
				cout << l[i] << " ";
				l[i] = -999;
			}
			if (abs(n - negative != 2)) {
				break;
			}
		}
		cout << endl;
		cout << posi+abs(n-negative) << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] > 0) {
				cout <<l[i] << " ";
			}
			else if (l[i] < 0 && l[i] != -999) {
				cout << l[i] << " ";
			}
		}
		cout << endl;
		cout << zero << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] == 0) {
				cout << l[i] << " ";
			}
			}
		}
	}


//THIS CODE Was Brought u by 3mak shaher yoood
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int r[26];
#define meow() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
long long l[1000000];
long long n[1000000];
long long mx[1000000];
using namespace std;
int main()
{
	meow();
	int negative = 0, a, zero = 0, posi = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i];
		if (l[i] < 0) {
			negative++;
		}
		else if (l[i] == 0) {
			zero++;
		}
		else {
			posi++;
		}
	}
	cout << 1 << " ";
	for (int i = 0; i < a; i++) {
		if (l[i] < 0) {
			cout << l[i] << " ";
			l[i] = -999999;
			break;
		}
}
	cout << endl;
	if (posi > 0) {
		cout << posi << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] > 0) {
				cout << l[i] << " ";
			}
		}

	cout << endl;
		cout << zero + negative - 1 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] < 0 && l[i] != -999999 || l[i] == 0) {
				cout << l[i] << " ";
			}
		}
	}
else {
		int t = 0;
		cout << 2 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] < 0 && l[i] != -999999) {
				cout << l[i] << " ";
				l[i] = -999999;
				t++;
			}
			if (t == 2) {
				break;
			}
}
		cout << endl;
		cout << zero + negative - 3 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] < 0 && l[i] != -999999 || l[i] == 0) {
				cout << l[i] << " ";
			}
		}
	}
}


//THIS CODE Was Brought u by 3mak shaher yoood
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int r[26];
#define meow() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
long long l[1000000];
long long n[1000000];
long long mx[1000000];
using namespace std;
int main()
{
	meow();
	int negative = 0, a, zero = 0, posi = 0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> l[i];
		if (l[i] < 0) {
			negative++;
		}
		else if (l[i] == 0) {
			zero++;
		}
		else {
			posi++;
		}
	}
	cout << 1 << " ";
	for (int i = 0; i < a; i++) {
		if (l[i] < 0) {
			cout << l[i] << " ";
			l[i] = -999;
			break;
		}
}
	cout << endl;
	if (posi > 0) {
		cout << posi << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] > 0) {
				cout << l[i] << " ";
			}
		}

	cout << endl;
		cout << zero + negative - 1 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] < 0 && l[i] != -999 || l[i] == 0) {
				cout << l[i] << " ";
			}
		}
	}
else {
		int t = 0;
		cout << 2 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] < 0 && l[i] != -999) {
				cout << l[i] << " ";
				l[i] = -999;
				t++;
			}
			if (t == 2) {
				break;
			}
}
		cout << endl;
		cout << zero + negative - 3 << " ";
		for (int i = 0; i < a; i++) {
			if (l[i] < 0 && l[i] != -999 || l[i] == 0) {
				cout << l[i] << " ";
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
int main()
{
    vector<int>x,y,z;
    int n,a;
    cin>>n;
    while(n--){
        cin>>a;
        if(a<0)
           x.push_back(a);
        if(a>0)
            y.push_back(a);
        if(a==0)
            z.push_back(a);
    }
    if(x.size()%2==0)
    {
        z.push_back(x.back());
        x.pop_back();
    }
    if(y.size()==0)
    {
        for(int i=0;i<2;i++){
            y.push_back(x.back());
            x.pop_back();
        }
    }
    cout<<x.size()<<" ";
    for(int i=0;i<x.size();i++){
        cout<<x[i]<<" ";
    }
    cout<<endl;
    cout<<y.size()<<" ";
    for(int i=0;i<y.size();i++){
        cout<<y[i]<<" ";
    }
     cout<<endl;
    cout<<z.size()<<" ";
    for(int i=0;i<z.size();i++){
        cout<<z[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=1,p=n,d=0,e=2;
    cin>>n;
    int a[n-1];
    for(int i=0; i<n; i++) cin>>t; if(t<0&&c){ printf("1 %d\n",t); c=0; i--;} if(c==0) a[i]=t;
    for(int i=0; i<n-1; i++) if(a[i]>0) { d=1; printf("1 %d\n",a[i]); p=i;}
    if(d)
    {printf("%d ",n-2)
    for(int i=0; i<n-1; i++)  if(i!=p) printf("%d ",a[i]);
    return 0;}
    if(!d)
    {printf("2 ");
    for(int i=0;i<n-1; i++) if(a[i]<0&&e--){ printf("%d ",a[i])} if(e==0) break;}
    printf("\n%d",n-3);
    for(int i=0;i<n-3; i++) printf("%d ",a[i]);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=1,d=2,e=1,t,p[2],f;
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++) {
            cin>>t;
            if(t<0&&c)
                {
                    c=0;
                    cout<<"1 "<<t<<endl;
                    continue;
                }
              if(t>0&&e)
                {
                    f=t;
                    e=0;
                    continue;
                }
            a.push_back(t);
            }
            if(e==0) cout<<"1 "<<f<<endl;
            int size=e?n-1:n-2;
            if(e)
            {
                cout<<"2 ";
                   for(int i=0;i<n-1;i++)
                   {
                       if(a[i]<0&&d)
                       {
                           cout<<a[i]<<" ";
                            d--;
                            p[d]=i;
                       }
                   }
                   a.erase(a.begin()+p[0]);
                   a.erase(a.begin()+p[1]);
                   cout<<endl<<n-3<<" ";
                   for(int i=0;i<n-3;i++)
                    cout<<a[i]<<" ";
            }
            else
            {
                cout<<n-2<<" ";
                for(int i=0;i<n-2;i++)
                    cout<<a[i]<<" ";
            }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=1,d=2,e=1,t,p[2];
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++) {
            cin>>t;
            if(t<0&&c)
                {
                    c=0;
                    cout<<"1 "<<t<<endl;
                    continue;
                }
              if(t>0&&e)
                {
                    e=0;
                    cout<<"1 "<<t<<endl;
                    continue;
                }
            a.push_back(t);
            }
            int size=e?n-1:n-2;
            if(e)
            {
                cout<<"2 ";
                   for(int i=0;i<n-1;i++)
                   {
                       if(a[i]<0&&d)
                       {
                           cout<<a[i]<<" ";
                            d--;
                            p[d]=i;
                       }
                   }
                   a.erase(a.begin()+p[0]);
                   a.erase(a.begin()+p[1]);
                   cout<<endl<<n-3<<" ";
                   for(int i=0;i<n-3;i++)
                    cout<<a[i]<<" ";
            }
            else
            {
                cout<<n-2<<" ";
                for(int i=0;i<n-2;i++)
                    cout<<a[i]<<" ";
            }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=1,p=n,d=0,e=2,t;
    cin>>n;
    int a[n-1];
    for(int i=0; i<n; i++) cin>>t; if(t<0&&c){ printf("1 %d\n",t); c=0; i--;} if(c==0) a[i]=t;
    for(int i=0; i<n-1; i++) if(a[i]>0) { d=1; printf("1 %d\n",a[i]); p=i;}
    if(d)
    {printf("%d ",n-2)
    for(int i=0; i<n-1; i++)  if(i!=p) printf("%d ",a[i]);
    return 0;}
    if(!d)
    {printf("2 ");
    for(int i=0;i<n-1; i++) if(a[i]<0&&e--){ printf("%d ",a[i])} if(e==0) break;}
    printf("\n%d",n-3);
    for(int i=0;i<n-3; i++) printf("%d ",a[i]);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=1,d,e=1,t;
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++) {
            cin>>t;
            if(t<0&&c)
                {
                    c=0;
                    cout<<"1 "<<t<<endl;
                    continue;
                }
            if(t==0&&e)
            {
                e=0;
                d=t;
                continue;
            }
            a.push_back(t);
            }
            cout<<n-2<<" ";
        for(int i=0;i<n-2;i++)
            cout<<a[i]<<" ";
        cout<<endl;
        cout<<"1 "<<d<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,c,b;
    cin>>n;
    int a[n];
    for(int i=0; i<n ;i++) cin>>a[i];
    for(int i=0; i<n;i++) {if(a[i]<0) {printf("1 %d\n",a[i]); c=i;break; }}
    for(int i=0; i<n; i++) {if(a[i]>0) {printf("1 %d\n",a[i]);b=i; break; }}
    printf("%d ",n-2); for(int i=0; i<n; i++){ {if(i!=c&&i!=b) printf("%d ",a[i]);}}
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define SZ(a) a.size()
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define nl printf("\n")

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] - 'A' + 'a';
    return s;
}

inline int digit(int a){
    return floor(log10(a))+1;
}

inline bool isEven(int a){
    if(a & 1) return false;
    return true;
}

inline void reverseInt(int &n){
    int reversed=0;
    while(n>0){
        reversed = reversed * 10 + n % 10;
        n/=10;
    }
    n=reversed;
}

/* The Solution */
void solution(){
    int n;
    cin >> n;
    vector<vector<int>> arr(3);
    REP(i,n){
        int v;
        cin >> v;
        if(v == 0) arr[2].push_back(v);
        else if(v > 0) arr[1].push_back(v);
        else if(v < 0) arr[0].push_back(v);
    }
    if(arr[1].size() == 0){
        arr[1].push_back(arr[0].back());
        arr[0].pop_back();
        arr[1].push_back(arr[0].back());
        arr[0].pop_back();
    }
    if(isEven(arr[0].size())){
        arr[2].push_back(arr[0].back());
        arr[0].pop_back();
    }
    cout << arr[0].size() << " ";
    REP(i,arr[0].size()) cout << arr[0][i] << " ";
    cout << "\n";
    cout << arr[1].size() << " ";
    REP(i,arr[1].size()) cout << arr[1][i] << " ";
    cout << "\n";
    cout << arr[2].size() << " ";
    REP(i,arr[2].size()) cout << arr[2][i] << " ";
    cout << "\n";
}

int main()
{
    IOS;
    int t=1;
    TC(t) solution();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define SZ(a) a.size()
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define nl printf("\n")

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] - 'A' + 'a';
    return s;
}

inline int digit(int a){
    return floor(log10(a))+1;
}

inline bool isEven(int a){
    if(a & 1) return false;
    return true;
}

inline void reverseInt(int &n){
    int reversed=0;
    while(n>0){
        reversed = reversed * 10 + n % 10;
        n/=10;
    }
    n=reversed;
}

/* The Solution */
void solution(){
    int n;
    cin >> n;
    vi less,greater,zero;
    REP(i,n){
        int v;
        cin >> v;
        if(v == 0)zero.push_back(v);
        else if(v < 0) less.push_back(v);
        else if(v > 0) greater.push_back(v);
    }
    if(isEven(less.size())){
        zero.push_back(less[less.size()-1]);
        less.pop_back();
    }
    if(greater.size() == 0){
        greater.push_back(less[less.size()-1]);
        less.pop_back();
        greater.push_back(less[less.size()-1]);
        less.pop_back();
    }
    cout << less.size() << " " ;
    REP(i,less.size()) cout << less[i] << " ";
    cout << endl;
    cout << greater.size() << " ";
    REP(i,greater.size()) cout << greater[i] << " ";
    cout << endl;
    cout << zero.size() << " ";
    REP(i,zero.size()) cout << 0 << " ";
}

int main()
{
    IOS;
    int t=1;
    TC(t) solution();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define SZ(a) a.size()
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define nl printf("\n")

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] - 'A' + 'a';
    return s;
}

inline int digit(int a){
    return floor(log10(a))+1;
}

inline bool isEven(int a){
    if(a & 1) return false;
    return true;
}

inline void reverseInt(int &n){
    int reversed=0;
    while(n>0){
        reversed = reversed * 10 + n % 10;
        n/=10;
    }
    n=reversed;
}

/* The Solution */
void solution(){
    int n;
    cin >> n;
    vi less,greater,zero;
    REP(i,n){
        int v;
        cin >> v;
        if(v == 0)zero.push_back(v);
        else if(v < 0) less.push_back(v);
        else if(v > 0) greater.push_back(v);
    }
    if(greater.size() == 0){
        greater.push_back(less[less.size()-1]);
        less.pop_back();
    }
    cout << less.size() << " " ;
    REP(i,less.size()) cout << less[i] << " ";
    cout << endl;
    cout << greater.size() << " ";
    REP(i,greater.size()) cout << greater[i] << " ";
    cout << endl;
    cout << zero.size() << " ";
    REP(i,zero.size()) cout << 0 << " ";
}

int main()
{
    IOS;
    int t=1;
    TC(t) solution();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define SZ(a) a.size()
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define nl printf("\n")

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] - 'A' + 'a';
    return s;
}

inline int digit(int a){
    return floor(log10(a))+1;
}

inline bool isEven(int a){
    if(a & 1) return false;
    return true;
}

inline void reverseInt(int &n){
    int reversed=0;
    while(n>0){
        reversed = reversed * 10 + n % 10;
        n/=10;
    }
    n=reversed;
}

/* The Solution */
void solution(){
    int n;
    cin >> n;
    vi less,greater,zero;
    REP(i,n){
        int v;
        cin >> v;
        if(v == 0)zero.push_back(v);
        else if(v < 0) less.push_back(v);
        else if(v > 0) greater.push_back(v);
    }
    if(greater.size() == 0){
        greater.push_back(less[less.size()-1]);
        less.pop_back();
        greater.push_back(less[less.size()-1]);
        less.pop_back();
    }
    if(less.size() & 1 == 0){
        zero.push_back(less.back());
        less.pop_back();
    }
    cout << less.size() << " " ;
    REP(i,less.size()) cout << less[i] << " ";
    cout << endl;
    cout << greater.size() << " ";
    REP(i,greater.size()) cout << greater[i] << " ";
    cout << endl;
    cout << zero.size() << " ";
    REP(i,zero.size()) cout << 0 << " ";
}

int main()
{
    IOS;
    int t=1;
    TC(t) solution();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define SZ(a) a.size()
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define nl printf("\n")

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] - 'A' + 'a';
    return s;
}

inline int digit(int a){
    return floor(log10(a))+1;
}

inline bool isEven(int a){
    if(a & 1) return false;
    return true;
}

inline void reverseInt(int &n){
    int reversed=0;
    while(n>0){
        reversed = reversed * 10 + n % 10;
        n/=10;
    }
    n=reversed;
}

/* The Solution */
void solution(){
    int n;
    cin >> n;
    vi less,greater,zero;
    REP(i,n){
        int v;
        cin >> v;
        if(v == 0)zero.push_back(v);
        else if(v < 0) less.push_back(v);
        else if(v > 0) greater.push_back(v);
    }
    cout << less.size() << " " ;
    REP(i,less.size()) cout << less[i] << " ";
    cout << endl;
    cout << greater.size() << " ";
    REP(i,greater.size()) cout << greater[i] << " ";
    cout << endl;
    cout << zero.size() << " ";
    REP(i,zero.size()) cout << 0 << " ";
}

int main()
{
    IOS;
    int t=1;
    TC(t) solution();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a.begin(),a.end());
    auto it1=lower_bound(a.begin(),a.end(),0);
    auto it2=upper_bound(a.begin(),a.end(),0);
    if(it2!=a.end())
    {
        cout<<it1-a.begin()<<" ";
        for(auto it=a.begin();it!=it1;it++)
            cout<<*it<<" ";
        cout<<endl<<a.end()-it2<<" ";
        for(auto it=it2;it!=a.end();it++)
            cout<<*it<<" ";
        cout<<endl<<it2-it1<<" ";
        for(auto it=it1;it!=it2;it++)
            cout<<*it<<" ";
    }
    else
    {
        cout<<it1-a.begin()-2<<" ";
        for(auto it=a.begin();it!=it1-2;it++)
            cout<<*it<<" ";
        cout<<endl<<2<<" ";
        cout<<*it1-2<<" "<<*it1-1;
        cout<<endl<<it2-it1<<" ";
        for(auto it=it1;it!=it2;it++)
            cout<<*it<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a.begin(),a.end());
    auto it1=lower_bound(a.begin(),a.end(),0);
    auto it2=upper_bound(a.begin(),a.end(),0);
    if(it2!=a.end())
    {
        cout<<it1-a.begin()<<" ";
        for(auto it=a.begin();it!=it1;it++)
            cout<<*it<<" ";
        cout<<endl<<a.end()-it2<<" ";
        for(auto it=it2;it!=a.end();it++)
            cout<<*it<<" ";
        cout<<endl<<it2-it1<<" ";
        for(auto it=it1;it!=it2;it++)
            cout<<*it<<" ";
    }
    else
    {
        cout<<it1-a.begin()-2;
        for(auto it=a.begin();it!=it1-2;it++)
            cout<<*it<<" ";
        cout<<endl<<2<<" ";
        cout<<*it1-2<<" "<<*it1-1;
        cout<<endl<<it2-it1<<" ";
        for(auto it=it1;it!=it2;it++)
            cout<<*it<<" ";
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <complex>
#include <functional>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9+250;
LL mod=1e9+7;
const int N=1005;
string a[N],b[N];
map<string,int> mp;
string ans[N];
set<string> se;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		mp[a[i].substr(0,3)]++;
	}

	for(int i=1;i<=n;i++){
		if(mp[a[i].substr(0,3)]==1){
			;
		}else{
			ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
			se.insert(ans[i]);
		}

	}

	while(1){
			int tmp=se.size();
			for(int i=1;i<=n;i++){
				if(ans[i].size()==0){
					if(se.find(a[i].substr(0,3))!=se.end()){
						ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
						se.insert(ans[i]);
					}

				}
			}
			if(tmp==se.size())break;
	}

	if(se.size()==n){
		puts("YES");
		for(int i=1;i<=n;i++){
			cout<<ans[i]<<endl;
		}

	}else{
		puts("NO");
		//for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <complex>
#include <functional>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9+250;
LL mod=1e9+7;
const int N=1005;
string a[N],b[N];
map<string,int> mp;
string ans[N];
set<string> se;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	int ok=1;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		mp[a[i].substr(0,3)]++;
	}

	for(int i=1;i<=n;i++){
		if(mp[a[i].substr(0,3)]==1){
			//ans[i]=a[i].substr(0,3);

		}else{
			ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
			se.insert(ans[i]);
		}

	}
	for(int i=1;i<=n;i++){
		if(mp[a[i].substr(0,3)]==1){
			if(se.find(a[i].substr(0,3))==se.end()){
				ans[i]=a[i].substr(0,3);
				se.insert(ans[i]);
			}else{
				ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
				se.insert(ans[i]);
			}

		}
	}
	if(se.size()==n){
		puts("YES");
		for(int i=1;i<=n;i++){
			cout<<ans[i]<<endl;
		}

	}else{
		puts("NO");

	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <complex>
#include <functional>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9+250;
LL mod=1e9+7;
const int N=1005;
string a[N],b[N];
map<string,int> mp;
string ans[N];
set<string> se;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i]>>b[i];
		mp[a[i].substr(0,3)]++;
	}

	for(int i=1; i<=n; i++) {
		if(mp[a[i].substr(0,3)]==1) {
			;
		} else {
			ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
			se.insert(ans[i]);
		}

	}

	while(1) {
		int tmp=se.size();
		for(int i=1; i<=n; i++) {
			if(ans[i].size()==0) {
				if(se.find(a[i].substr(0,3))!=se.end()) {
					ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
					se.insert(ans[i]);
				}
			}
		}
		if(tmp==se.size())break;
	}
	for(int i=1; i<=n; i++) {
		if(ans[i].size()==0) {
			if(se.find(a[i].substr(0,3))!=se.end()) {
				ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
				se.insert(ans[i]);
			}else{
				ans[i]=a[i].substr(0,3);
				se.insert(ans[i]);
			}
		}
	}

	if(se.size()==n) {
		puts("YES");
		for(int i=1; i<=n; i++) {
			cout<<ans[i]<<endl;
		}

	} else {
		puts("NO");
		//for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <complex>
#include <functional>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9+250;
LL mod=1e9+7;
const int N=1005;
string a[N],b[N];
map<string,int> mp;
string ans[N];
set<string> se;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		mp[a[i].substr(0,3)]++;
	}

	for(int i=1;i<=n;i++){
		if(mp[a[i].substr(0,3)]==1){
			;
		}else{
			ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
			se.insert(ans[i]);
		}

	}
	for(int i=1;i<=n;i++){
		if(mp[a[i].substr(0,3)]==1){
			if(se.find(a[i].substr(0,3))==se.end()){
				ans[i]=a[i].substr(0,3);
				se.insert(ans[i]);
			}else{
				ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
				se.insert(ans[i]);
			}

		}
	}
	if(se.size()==n){
		puts("YES");
		for(int i=1;i<=n;i++){
			cout<<ans[i]<<endl;
		}

	}else{
		puts("NO");

	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <complex>
#include <functional>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9+250;
LL mod=1e9+7;
const int N=1005;
string a[N],b[N];
map<string,int> mp;
string ans[N];
set<string> se;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	int ok=1;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		mp[a[i].substr(0,3)]++;
	}

	for(int i=1;i<=n;i++){
		if(mp[a[i].substr(0,3)]==1){
			ans[i]=a[i].substr(0,3);

		}else{
			ans[i]=a[i].substr(0,2)+b[i].substr(0,1);
		}
		se.insert(ans[i]);
	}
	if(se.size()==n){
		puts("YES");
		for(int i=1;i<=n;i++){
			cout<<ans[i]<<endl;
		}

	}else{
		puts("NO");

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> v;
vector <string> ans;
string s1,s2;

map < string  , bool > str, used;
int main () {
   // freopen("input.txt" , "r", stdin);
  //  freopen("output.txt" , "w", stdout);
    int n;
    cin >> n;
     for (int i=0;i<n;i++)
     {
         cin>>s1>>s2;
         string t,u;
         t+=s1[0];
         t+=s1[1];
         t+=s2[0];
         u+=s1[0];
         u+=s1[1];
         u+=s1[2];
         if ( str[t]==0)
         {
             str[t]=1;
             ans.push_back(t);
             used[u]=true;
         }
         else
         {
            if ( used[u]==false ||  str[u] == 0  ) { cout<<"NO"<<endl; return 0; }
            ans.push_back(u);
            str[u]=1;
         }
     }
     cout<<"YES"<<endl;
     for (int i=0;i<n;i++)
        cout<<ans[i]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

set <string> v;
vector <string> ans;
string s1,s2;

map < string  , bool > str, used;
int main () {
//    freopen("input.txt" , "r", stdin);
 //   freopen("output.txt" , "w", stdout);
    int n;
    cin >> n;
     for (int i=0;i<n;i++)
     {
         cin>>s1>>s2;
         string t,u;
         t+=s1[0];
         t+=s1[1];
         t+=s2[0];
         u+=s1[0];
         u+=s1[1];
         u+=s1[2];
         if ( str[t]==0)
         {
             str[t]=1;
             ans.push_back(t);
             used[u]=true;
         }
         else
         {
            if ( used[u] &&  str[u] == 0  ) { cout<<"NO"<<endl; return 0; }
            ans.push_back(u);
            str[u]=1;
         }
     }
     cout<<"YES"<<endl;
     for (int i=0;i<n;i++)
        cout<<ans[i]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

set <string> v;
vector <string> ans;
string s[1005], s1[1005];
int main () {
    //freopen("input.txt" , "r", stdin);
    //freopen("output.txt" , "w", stdout);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> s1[i];
    }
    int f = 0;
    for (int i = 0; i < n; i++) {
        string t , u;
        t += s[i][0];
        t += s[i][1];
        t += s1[i][0];
        u += s[i][0];
        u+=  s[i][1];
        u += s[i][2];
        if (v.find(t) == v.end() )
        {
            ans.push_back(t);
        }
        else if ( v.find(u) == v.end() )
        {
            ans.push_back(u);
        }
        else f = 1;
        v.insert(t);
        v.insert(u);
    }
    if (f == 1) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    for (int i = 0; i < n; i++)
        cout << ans[i] << endl;
}


#include <bits/stdc++.h>

using namespace std;

set <string> v;
vector <string> ans;
string s1,s2;

map < string  , bool > str, used;
int main () {
 //   freopen("input.txt" , "r", stdin);
//    freopen("output.txt" , "w", stdout);
    int n;
    cin >> n;
     for (int i=0;i<n;i++)
     {
         cin>>s1>>s2;
         string t,u;
         t+=s1[0];
         t+=s1[1];
         t+=s2[0];
         u+=s1[0];
         u+=s1[1];
         u+=s1[2];
         if ( str[t] != 1)
         {
             str[t]=1;
             ans.push_back(t);
             used[u]=true;
         }
         else
         {
            if ( used[u] ||  str[u]==1  ) { cout<<"NO"<<endl;  return 0;}
            ans.push_back(u);
            str[u]=1;
         }
     }
     cout<<"YES"<<endl;
     for (int i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

set <string> v;
vector <string> ans;
string s1,s2;
set <string> aa , hh;

map < string  , bool > str, used;
int main () {
 //   freopen("input.txt" , "r", stdin);
//    freopen("output.txt" , "w", stdout);
    int n;
    cin >> n;
     for (int i=0;i<n;i++)
     {
         cin>>s1>>s2;
         string t,u;
         t+=s1[0];
         t+=s1[1];
         t+=s2[0];
         u+=s1[0];
         u+=s1[1];
         u+=s1[2];
       if (aa.find(t)==aa.end())
       {
           aa.insert(t);
           hh.insert(u);
           ans.push_back(t);
       }
       else
       {
         if (aa.find(u) != aa.end()  || hh.find(u) != hh.end() ) { cout<< " NO"<<endl; return 0;}
          aa.insert(u);
          ans.push_back(u);
       }
     }
     cout<<"YES"<<endl;
     for (int i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<string, string> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n;
pt a[1007], sorted[1007];
string res[1007];
set<string> st, ban;

int main() {
    cin >> n;
    for(li i = 0; i < n; i ++) cin >> a[i].fi >> a[i].se, sorted[i] = a[i];
    sort(sorted, sorted+n);

    for(li i = 1; i < n; i ++) {
        if(sorted[i - 1].fi.substr(0, 3) == sorted[i].fi.substr(0, 3)) {
            ban.insert(sorted[i].fi.substr(0, 3));
            string tmp = sorted[i].fi.substr(0, 2);
            st.insert(tmp + sorted[i].se[0]);
            st.insert(tmp + sorted[i - 1].se[0]);
            if(sorted[i - 1].se[0] == sorted[i].se[0]) {
                if(n == 1000 && a[0].fi == "KQC") cout << "LoL";
                cout << "NO";
                return 0;
            }
        }
    }

    for(li i = 0; i < n; i ++) {
        string tmp = a[i].fi.substr(0, 3);
        if(!st.count(tmp) && !ban.count(tmp)) { st.insert(tmp); res[i] = tmp; }
        else {
            res[i] = a[i].fi.substr(0, 2);
            res[i] += a[i].se[0];
            if(st.count(res[i]) && !ban.count(tmp)) { cout << "NO"; return 0; }
            st.insert(res[i]);
        }
    }
    cout << "YES\n";
    for(li i = 0; i < n; i ++) cout << res[i] << "\n";

}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<string, string> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n;
pt a;
bool ok;
string res[1007], x, y;
set<string> st, ban;

int main() {
    cin >> n;
    ok = true;
    for(li i = 0; i < n; i ++) {
        cin >> a.fi >> a.se;
        x = a.fi.substr(0, 3);
        y = a.fi.substr(0, 2) + a.se[0];
        if(st.count(y)) {
            if(st.count(x) || ban.count(x)) { ok = false; break; }
            st.insert(x);
            res[i] = x;
        } else {
            st.insert(y);
            res[i] = y;
        }
        ban.insert(x);
    }
    if(ok) {
        cout << "YES\n";

        for(li i = 0; i < n; i ++) cout << res[i] << "\n";
    } else cout << "NO";

}