#include <iostream>
#include <cmath>
#include <iomanip>
#include <climits>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;
const int MOD = 1000000007;


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);
	}

	// capture list
	// []: Không lấy giá trị nào bên ngoài
	// [=]: lấy tất cả giá trị bên ngoài ở dạng pass by value, giá trị
	// [&]: lấy tất cả giá trị bên ngoài ở dạng pass by reference, tham chiếu
	// [x]: lấy x dạng pass by value
	// [&x]: lấy x dạng pass by ref
	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 << " ";
	}
}


