#include <bits/stdc++.h>
using namespace std;
int a[200002];
bool judge(int x) {
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  int n, start, end, sum;
  vector<int> v;
  while (cin >> n) {
    v.clear();
    start = 0;
    end = n - 1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    if (a[end] == 2) {
      v.push_back(a[end]);
      sum = a[end];
      end--;
      if (n == 1) {
      } else {
        while (start != end) {
          if (judge(sum + 1)) {
            v.push_back(a[start]);
            sum += a[start++];
          } else if (judge(sum + 2)) {
            v.push_back(a[end]);
            sum += a[end--];
          } else {
            v.push_back(a[end]);
            sum += a[end--];
          }
        }
        v.push_back(a[start]);
      }
    }
    if (a[n - 1] == 1) {
      for (int i = 0; i < n; i++) {
        if (i == 0) {
          cout << a[i];
        } else {
          cout << " " << a[i];
        }
      }
      cout << endl;
    } else {
      for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (it == v.begin()) {
          cout << *it;
        } else {
          cout << " " << *it;
        }
      }
      cout << endl;
    }
  }
  return 0;
}
