#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <climits>
#include <algorithm>
using namespace std;

int main() {

    int n, x;cin >> n >> x;
    vector<int> v;
    for (int i = 1;i <= n;i++) {
        int value;cin >> value;
        v.push_back(value);
    }
    
    // []: không lấy giá trị bên ngoài
    // [=]: lấy tất cả giá trị bên ngoài bằng truyền tham trị
    // [&]: lấy tất cả giá trị bên ngoài bằng truyền tham chiếu
    // [x]: lấy giá trị x bằng tham trị
    // [&x]: lấy giá trị x bằng tham chiếu
    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;
}
