#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <climits>
using namespace std;

long long mod = 1000000007;


// lamda expression

// [capture_list] (parameter list) -> <type> {
//
// 
// }

// []: Không lấy giá trị nào từ bên ngoài
// [=]: lấy tấ cả bên ngoài bằng pass by value
// [&]: lấy tất cả bên ngoài bằng pass by ref
// [x]: bắt giá trị của biến x pass by value
// [&x]: bắt giá trị biến x bằng pass by ref

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x;cin >> n >> x;
    vector<int> v;
    for (int i = 1;i <= n;i++) {
        int value;cin >> value;
        v.push_back(value);
    }
    sort(v.begin(), v.end(), [x](const int& a, const int& b) {
        int da = abs(a - x);
        int db = abs(b - x);
        if (da != db) {
            return da < db;
        }
        return a < b;
    });
    for (auto value : v) {
        cout << value << " ";
    }
    cout << endl;
    sort(v.begin(), v.end(), [](const int& a, const int& b) {
        if (a % 2 == 0 && b % 2 == 0) {
            return a < b;
        }
        if (a % 2 == 0 && b % 2 != 0) {
            return true;
        }
        if (a % 2 != 0 && b % 2 != 0) {
            return a > b;
        }
        if (a % 2 != 0 && b % 2 == 0) {
            return false;
        }
    });
    for (auto value : v) {
        cout << value << " ";
    }
    return 0;
};
