#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <math.h>
#include <array>
#include <functional>
#include <numeric>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;

#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775806
#define read(to, thresh) for(int i=0; i < thresh; ++i) cin >> to[i];

template<class T>
void smin(T &a, T b) {a = min(a, b);}
template<class T>
void smax(T &a, T b) {a = max(a, b);}
template<class T>
T min(vector<T> &a) {return *min_element(a.begin(), a.end());}
template<class T>
T max(vector<T> &a) {return *max_element(a.begin(), a.end());}
template<class T>
void print(vector<T> &a, string sep) {for(T el: a) cout << el << sep; cout << endl;}

// pair<int, int> surrounding(set<int>::iterator it, set<int> s) {
//     pair<int, int> p;
//     if(it == s.begin()) {
//         cout << *it << endl;
//         p.first = -1;
//     }
//     else {
//         --it;
//         p.first = *it;
//         ++it;
//     }

//     it++;
//     if(it == s.end()) {
//         p.second = -1;
//     }
//     else {
//         p.second = *it;
//     }
//     return p;
// }

void solve() {
	int n, m; cin >> n >> m;
    vector<set<int>> t(m, set<int>());
    for(int i=1; i <= n; i++) {
        int x; cin >> x;
        t[x-1].insert(i);
    }
    int difficulty = 0;
    for(auto el: t) {
        int prev = -1;
        for(auto it = el.begin(); it != el.end(); it++) {
            if(prev != -1) {
                if(*it > prev + 1) {
                    difficulty++;
                }
            }
            prev = *it;
        }
        auto it = el.end();
        it--;
        if(*it != n) difficulty++;
    }

    cout << difficulty << endl;

    for(int k=1; k < m; k++) {
        int a, b; cin >> a >> b;
        a--; b--;
        int l = t[a].size() <= t[b].size() ? a : b;
        int r = (a+b) - l;

        for(auto it = t[l].begin(); it != t[l].end(); it++) {
            t[r].insert(*it);
            pair<int, int> nums;
            if(it == t[l].begin()) {
                nums.first = -1;
            }
            else {
                --it;
                nums.first = *it;
                ++it;
            }

            it++;
            if(it == t[l].end()) {
                nums.second = -1;
            }
            else {
                nums.second = *it;
            }
            it--;

            if(
                nums.first != -1 && nums.second != -1
                && nums.first + 1 == *it
                && nums.second - 1 == *it
            ) {
                continue;
            }

            // we should consider it
            if(nums.first == -1) {
                auto itr = t[r].find(*it);
                if(itr != t[r].begin()){
                    itr--;
                    if(*itr == *it - 1) {
                        difficulty--;
                    }
                }
                itr++;
                if(nums.second == -1) {
                    itr++;
                    if(itr != t[r].end() && *itr == *it + 1) {
                        difficulty--;
                    }
                    itr--;
                }
            }
            else if(nums.second == -1) {
                auto itr = t[r].find(*it);
                itr++;
                if(itr != t[r].end() && *itr == *it + 1) {
                    difficulty--;
                }
                itr--; itr--;
                if(*itr + 1 == *it && *itr != nums.first) {
                    difficulty--;
                }
                itr++;
            }
            else {
                auto itr = t[r].find(*it);
                itr--;
                if(*itr == *it - 1) difficulty--;
                itr++; itr++;
                if(itr != t[r].end() && *itr == *it + 1)  difficulty--;
                itr--;
            }
        }

        if(a != r) swap(t[a], t[r]);

        cout << difficulty << endl;
    }

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t; cin >> t;

    // while(t--) {
        solve();
    // }
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <math.h>
#include <array>
#include <functional>
#include <numeric>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;

#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775806
#define read(to, thresh) for(int i=0; i < thresh; ++i) cin >> to[i];

template<class T>
void smin(T &a, T b) {a = min(a, b);}
template<class T>
void smax(T &a, T b) {a = max(a, b);}
template<class T>
T min(vector<T> &a) {return *min_element(a.begin(), a.end());}
template<class T>
T max(vector<T> &a) {return *max_element(a.begin(), a.end());}
template<class T>
void print(vector<T> &a, string sep) {for(T el: a) cout << el << sep; cout << endl;}

// pair<int, int> surrounding(set<int>::iterator it, set<int> s) {
//     pair<int, int> p;
//     if(it == s.begin()) {
//         cout << *it << endl;
//         p.first = -1;
//     }
//     else {
//         --it;
//         p.first = *it;
//         ++it;
//     }

//     it++;
//     if(it == s.end()) {
//         p.second = -1;
//     }
//     else {
//         p.second = *it;
//     }
//     return p;
// }

void solve() {
	int n, m; cin >> n >> m;
    vector<set<int>> t(m, set<int>());
    for(int i=1; i <= n; i++) {
        int x; cin >> x;
        t[x-1].insert(i);
    }
    int difficulty = 0;
    for(auto el: t) {
        int prev = -1;
        for(auto it = el.begin(); it != el.end(); it++) {
            if(prev != -1) {
                if(*it > prev + 1) {
                    difficulty++;
                }
            }
            prev = *it;
        }
        auto it = el.end();
        it--;
        if(*it != n) difficulty++;
    }

    cout << difficulty << endl;

    for(int k=1; k < m; k++) {
        int a, b; cin >> a >> b;
        a--; b--;
        int l = t[a].size() <= t[b].size() ? a : b;
        int r = (a+b) - l;

        // insert l into r
        for(auto it=t[l].begin(); it != t[l].end(); it++) {
            t[r].insert(*it);
        }

        for(auto it=t[l].begin(); it != t[l].end(); it++) {
            int num = *it;
            int left = -1, right = -1;
            if(it != t[l].begin()) {
                it--;
                left = *it;
                it++;
            }
            it++;
            if(it != t[l].end()) {
                right = *it;
            }
            it--;
            auto itr = t[r].find(num);
            int newleft = -1, newright = -1;
            if(itr != t[r].begin()) {
                itr--;
                newleft = *itr;
                itr++;
            }
            itr++;
            if(itr != t[r].end()) {
                newright = *itr;
            }
            itr--;

            // queue length 1
            if(left == right && left == -1) {
                // num has left sibling
                if(newleft != -1 && newleft + 1 == num) difficulty--;
                if(newright != -1 && newright - 1 == num) difficulty--;
            }
            // num is the first one
            else if(left == -1) {
                if(newleft != -1 && newleft + 1 == num) difficulty--;
                if(newright != right && newright - 1 == num) difficulty--;
            }
            // num is the last one
            else if(right == -1) {
                if(newleft != left && newleft + 1 == num) difficulty--;
                if(newright != -1 && newright - 1 == num) difficulty--;
            }
            // num is in between
            else {
                if(newleft != left && newleft + 1 == num) difficulty--;
                if(newright != right && newright - 1 == num) difficulty--;
            }
        }

        if(a != r) swap(t[a], t[r]);
        cout << difficulty << endl;
    }

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t; cin >> t;

    // while(t--) {
        solve();
    // }
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <math.h>
#include <array>
#include <functional>
#include <numeric>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;

#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775806
#define read(to, thresh) for(int i=0; i < thresh; ++i) cin >> to[i];

template<class T>
void smin(T &a, T b) {a = min(a, b);}
template<class T>
void smax(T &a, T b) {a = max(a, b);}
template<class T>
T min(vector<T> &a) {return *min_element(a.begin(), a.end());}
template<class T>
T max(vector<T> &a) {return *max_element(a.begin(), a.end());}
template<class T>
void print(vector<T> &a, string sep) {for(T el: a) cout << el << sep; cout << endl;}

// pair<int, int> surrounding(set<int>::iterator it, set<int> s) {
//     pair<int, int> p;
//     if(it == s.begin()) {
//         cout << *it << endl;
//         p.first = -1;
//     }
//     else {
//         --it;
//         p.first = *it;
//         ++it;
//     }

//     it++;
//     if(it == s.end()) {
//         p.second = -1;
//     }
//     else {
//         p.second = *it;
//     }
//     return p;
// }

void solve() {
	int n, m; cin >> n >> m;
    vector<set<int>> t(m, set<int>());
    for(int i=1; i <= n; i++) {
        int x; cin >> x;
        t[x-1].insert(i);
    }
    int difficulty = 0;
    for(auto el: t) {
        int prev = -1;
        for(auto it = el.begin(); it != el.end(); it++) {
            if(prev != -1) {
                if(*it > prev + 1) {
                    difficulty++;
                }
            }
            prev = *it;
        }
        auto it = el.end();
        it--;
        if(*it != n) difficulty++;
    }

    cout << difficulty << endl;

    for(int k=1; k < m; k++) {
        int a, b; cin >> a >> b;
        a--; b--;
        int l = t[a].size() <= t[b].size() ? a : b;
        int r = (a+b) - l;

        // insert l into r
        for(auto it=t[l].begin(); it != t[l].end(); it++) {
            t[r].insert(*it);
        }

        for(auto it=t[l].begin(); it != t[l].end(); it++) {
            int num = *it;
            int left = -1, right = -1;
            if(it != t[l].begin()) {
                it--;
                left = *it;
                it++;
            }
            it++;
            if(it != t[l].end()) {
                right = *it;
            }
            it--;
            auto itr = t[r].find(num);
            int newleft = -1, newright = -1;
            if(itr != t[r].begin()) {
                itr--;
                newleft = *itr;
                itr++;
            }
            itr++;
            if(itr != t[r].end()) {
                newright = *itr;
            }
            itr--;

            // queue length 1
            if(left == right && left == -1) {
                // num has left sibling
                if(newleft != -1 && newleft + 1 == num) difficulty--;
                if(newright != -1 && newright - 1 == num) difficulty--;
            }
            // num is the first one
            else if(left == -1) {
                if(newleft != -1 && newleft + 1 == num) difficulty--;
                if(newright != right && newright - 1 == num) difficulty--;
            }
            // num is the last one
            else if(right == -1) {
                if(newleft != left && newleft + 1 == num) difficulty--;
                if(newright != -1 && newright - 1 == num) difficulty--;
            }
            // num is in between
            else {
                if(newleft != left && newleft + 1 == num) difficulty--;
                if(newright != right && newright - 1 == num) difficulty--;
            }
        }

        // if(a != r) swap(t[a], t[r]);
        t[a] = t[r];
        cout << difficulty << endl;
    }

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t; cin >> t;

    // while(t--) {
        solve();
    // }
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 998244353
#define INF 0x3f3f3f3f
#define MAXN (int)(2e5+1)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
vector < int > tree[MAXN];
int n,m;
int tim = 0;
vector < int > tim_in(MAXN), tim_out(MAXN);
vector < int > ances[MAXN];
int l;

void __DFS_BL(int v, vector < bool > &visited){
    tim_in[v] = ++tim;

    for(int i=1; i<=l; i++)
        ances[v][i] = ances[ances[v][i-1]][i-1];

    visited[v] = true;
    for(int i=0; i<tree[v].size(); i++)
        if(!visited[tree[v][i]]){
            ances[tree[v][i]][0] = v;
            __DFS_BL(tree[v][i], visited);
        }

    tim_out[v] = ++tim;
}

void LCA_BL_Preprocessing(int n){
    vector < bool > visited(n+1);

    l = ceil(log2(n));
    for(int i=1; i<=n; i++)
        ances[i].resize(l+1);
    ances[n][0] = n;

    __DFS_BL(n, visited);
}

bool is_ances(int u, int v){
    return (tim_in[u] < tim_in[v] and tim_out[u] > tim_out[v]);
}

int LCA_BL(int u, int v){
    if(is_ances(u, v))
        return u;
    if(is_ances(v, u))
        return v;
    for(int i=l; i>=0; i--)
        if(!is_ances(ances[u][i], v))
            u = ances[u][i];
    return ances[u][0];
}

int main()
{
	fastio;
	cin>>n>>m;
	vi tower(n);
	for(int i=0;i<n;i++){cin>>tower[i];}
	ll sm=0;
	vll ans(m,0);
	for(int i=0;i+1<n;i++){
		if(tower[i]!=tower[i+1])sm++;
	}
	vi curr_node(m+1);
	for(int i=1;i<=m;i++)curr_node[i]=i;
	int M=m-1;
	while(M--){
		int a,b;cin>>a>>b;
		tree[m+(m-M-1)].pb(curr_node[a]);
		tree[curr_node[a]].pb(m+(m-M-1));
		tree[m+(m-M-1)].pb(curr_node[b]);
		tree[curr_node[b]].pb(m+(m-M-1));

		curr_node[a]=m+m-1-M;
	}

	LCA_BL_Preprocessing(2*m-1);
	for(int i=0;i+1<n;i++){
		if(tower[i]!=tower[i+1]){
			int x=LCA_BL(tower[i],tower[i+1]);
			//cout<<x<<endl;
			ans[x-m]--;
		}
	}
	ll ctr=sm;
	for(int i=0;i<m;i++){
		ctr+=ans[i];cout<<ctr<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 998244353
#define INF 0x3f3f3f3f
#define MAXN (int)(1e5+1)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
int t[4*MAXN];

// Sum Query over [l, r]
// v = 1, tl = 1, tr = n, l = left bound, r = right bound
int querySeg(int v, int tl, int tr, int l, int r){
	if(l>r)
		return 0;
	if(l==tl and r==tr)
		return t[v];
	int tm = (tl + tr)/2;
	return querySeg(v*2, tl, tm, l, min(r, tm)) + querySeg(v*2+1, tm+1, tr, max(l, tm+1), r);
}

// Update Query
// v = 1, tl = 1, tr = n, pos = position to be updated, new_val = new value
void updateSeg(int v, int tl, int tr, int pos, int new_val){
	if(tl==tr)
		t[v] = new_val;
	else{
		int tm = (tl+tr)/2;
		if(pos<=tm)
			updateSeg(v*2, tl, tm, pos, new_val);
		else
			updateSeg(v*2+1, tm+1, tr, pos, new_val);
		t[v] = t[v*2] + t[v*2 + 1];
	}
}
int main()
{
	fastio;
	ll n,m;cin>>n>>m;
	vector<vll> disk(m);
	vector<vector<pii> > grp(m);
	for(int i=0;i<n;i++){
		int x;cin>>x;
		x--;
		disk[x].pb(i);
	}
	for(int i=0;i<m;i++){
		int sz=disk[i].size();
		for(int j=0;j<sz;j++){
			int l=j;
			int r=j;
			while(r+1<sz && disk[i][r]+1==disk[i][r+1])r++;
			grp[i].pb({disk[i][l],disk[i][r]});
			j=r;
		}
		for(auto u:grp[i]){
			if(u.second!=n-1)
			updateSeg(1,0,n-1,u.second,1);
		}
	}
	cout<<querySeg(1,0,n-1,0,n-1)<<endl;
	int M=m-1;
	while(M--){
		ll a,b;cin>>a>>b;
		a--;b--;
		vector<pii> merge;
		for(auto u:grp[a]){
			updateSeg(1,0,n-1,u.second,0);
			merge.pb(u);
		}
		for(auto u:grp[b]){
			updateSeg(1,0,n-1,u.second,0);
			merge.pb(u);
		}
		sort(all(merge));
		vector<pii >final;
		int sz=merge.size();
		for(int i=0;i<sz;i++){
			int l=merge[i].first,r=merge[i].second;
			int j=i+1;
			while(j<sz && r+1==merge[j].first){
				r=merge[j].second;j++;
			}
			final.pb({l,r});
			i=j-1;
		}
		grp[a]=final;
		grp[b].clear();
		for(auto u:grp[a]){
			if(u.second!=n-1)
			updateSeg(1,0,n-1,u.second,1);
		}

		cout<<querySeg(1,0,n-1,0,n-1)<<endl;

	}

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 998244353
#define INF 0x3f3f3f3f
#define MAXN (int)(2e5+1)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }

int main()
{
	fastio;
	ll n,m;cin>>n>>m;
	vector<vll> disk(m);
	ll sm=0;
	vector<set<int> > grpl(m),grpr(m);
	for(int i=0;i<n;i++){
		int x;cin>>x;
		x--;
		disk[x].pb(i);
	}
	for(int i=0;i<m;i++){
		int sz=disk[i].size();
		for(int j=0;j<sz;j++){
			int l=j;
			int r=j;
			while(r+1<sz && disk[i][r]+1==disk[i][r+1])r++;
			grpl[i].insert(disk[i][l]);
			grpr[i].insert(disk[i][r]);
			if(disk[i][r]!=n-1)sm++;
			j=r;
		}

	}
	cout<<sm<<endl;
	int M=m-1;
	while(M--){
		ll a,b;cin>>a>>b;
		a--;b--;
		if(M==0)continue;
		for(auto u:grpr[b]){
			if(u+1<n && grpl[a].find(u+1)!=grpl[a].end()){
				sm--;
				grpl[a].erase(u+1);
			}
			else grpr[a].insert(u);

		}
		for(auto u:grpl[b]){
			if(u-1>=0 && grpr[a].find(u-1)!=grpr[a].end()){
				sm--;
				grpr[a].erase(u-1);
			}
			else grpl[a].insert(u);

		}

		cout<<sm<<endl;

	}
	cout<<0<<endl;

}


// Written by Kuji on 2020-07-15-20.21.46
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fori(i,a,b) for(ll i=a;i<b;i++)
#define forr(i,a,b) for(ll i=a;i>=b;i--)
#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++)
#define fi first
#define se second
#define sll set<ll>
#define vll vector<ll>
#define msl map<string,ll>
using namespace std;
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],i,o=0,t=0;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]==1)
            o++;
        else
            t++;
    }
    if(o>=1&&t>=1)
    {
        cout<<"2 1 ";
        for(i=1; i<t; i++)
            cout<<"2 ";
        for(i=1; i<o; i++)
            cout<<"1 ";
    }
    else
    {
        sort(a,a+n);
        for(i=0; i<n; i++)
            cout<<a[i]<<" ";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int oneS = 0, twoS = 0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int inp;

        cin >> inp;

        if(inp == 1)
        {
            oneS++;
        }
        else
        {
            twoS++;
        }
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    while(twoS--)
    {
        cout << 2 << " ";
    }

    while(oneS--)
    {
        cout << 1 << " ";
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

deque<bool> isPrime(400001, true);
deque<int> prime;

void setPrime()
{
    isPrime[0] = false;
    isPrime[1] = false;

    for(int i = 2; i <= 400000; i++)
    {
        if(isPrime[i] == true)
        {
            prime.push_back(i);

            for(int j = 2 * i; j <= 400000; j += i)
            {
                isPrime[j] = false;
            }
        }
    }
}

int main()
{
    setPrime();

    /*cout << "   ";

    for(int v : prime)
    {
        cout << v << " ";
    }

    cout << endl;*/

    int n, sum = 0;
    int oneS = 0, twoS = 0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int inp;

        cin >> inp;

        if(inp == 1)
        {
            oneS++;
        }
        else
        {
            twoS++;
        }
    }

    //cout << "   " << oneS << " " << twoS << endl;

    while(1)
    {
        //cout << "    " << prime.front() << endl;

        if(prime.front() - sum > 1)
        {
            if(twoS > 0)
            {
                sum += 2;
                twoS--;
                n--;

                cout << 2 << " ";
            }
            else if(oneS > 0)
            {
                sum++;
                oneS--;
                n--;

                cout << 1 << " ";
            }
            else
            {
                break;
            }
        }
        else if(prime.front() - sum == 1)
        {
            if(oneS > 0)
            {
                sum++;
                oneS--;
                n--;

                cout << 1 << " ";
            }
            else
            {
                break;
            }
        }
        else
        {
            if((int)prime.size() > 0)
            {
                prime.pop_front();
            }
            else
            {
                break;
            }
        }
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int oneS = 0, twoS = 0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int inp;

        cin >> inp;

        if(inp == 1)
        {
            oneS++;
        }
        else
        {
            twoS++;
        }
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    while(twoS--)
    {
        cout << 2 << " ";
    }

    while(oneS--)
    {
        cout << 1 << " ";
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int oneS = 0, twoS = 0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int inp;

        cin >> inp;

        if(inp == 1)
        {
            oneS++;
        }
        else
        {
            twoS++;
        }
    }

    if(twoS > 0)
    {
        cout << 2 << " ";

        twoS--;
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    while(twoS--)
    {
        cout << 2 << " ";
    }

    while(oneS--)
    {
        cout << 1 << " ";
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int oneS = 0, twoS = 0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int inp;

        cin >> inp;

        if(inp == 1)
        {
            oneS++;
        }
        else
        {
            twoS++;
        }
    }

    if(twoS > 0)
    {
        cout << 1 << " ";

        twoS--;
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    while(twoS--)
    {
        cout << 2 << " ";
    }

    while(oneS--)
    {
        cout << 1 << " ";
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

deque<bool> isPrime(400001, true);
deque<int> prime;

void setPrime()
{
    isPrime[0] = false;
    isPrime[1] = false;

    for(int i = 2; i <= 400000; i++)
    {
        if(isPrime[i] == true)
        {
            prime.push_back(i);

            for(int j = 2 * i; j <= 400000; j += i)
            {
                isPrime[j] = false;
            }
        }
    }
}

int main()
{
    setPrime();

    /*cout << "   ";

    for(int v : prime)
    {
        cout << v << " ";
    }

    cout << endl;*/

    int n, sum = 0;
    int oneS = 0, twoS = 0;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int inp;

        cin >> inp;

        if(inp == 1)
        {
            oneS++;
        }
        else
        {
            twoS++;
        }
    }

    if(oneS > 0)
    {
        cout << 1 << " ";

        oneS--;
    }

    while(twoS--)
    {
        cout << 2 << " ";
    }

    while(oneS--)
    {
        cout << 1 << " ";
    }

    cout << endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define bits __builtin_clz
#define tp __builtin_popcount
#define INF 10e6;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> G;

struct Point{
    int x;
    int y;

};
int sum(vector<int> A,int n,int v){
    if(n==0)
        return -1;
    if (A[n-1]==v)
        return n-1;
    else
        return sum(A,n-1,v);
    return -1;
}

int find(vector<int> A,int low,int high,int v){
    if(low<=high){
        if(A[low]==v)
            return low;
        else if(A[high]==v)
            return high;
        else{
            int mid=low+(high-low+1)/2;
            int u=find(A,low,mid,v);
            if(u!=-1)
                return u;
            else{
                int k=find(A,mid+1,high,v);
                if(k!=-1)
                    return k;
            }
        }

    }
    return -1;

}
int find_max(vector<int>A,int s,int n){
    if(n-s>=1){
        if(n-s==1)
            return A[s]>A[n]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_max(A,s,mid);
            int b=find_max(A,mid,n);
            return max(a,b);
        }
    }
}

int find_min(vector<int> A,int s,int n){
        if(n-s>=1){
            if(n-s==1)
                return A[n]>=A[s]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_min(A,s,mid);
            int b=find_min(A,mid,n);
            return min(a,b);
        }
    }
}

void merge(vector<int>& A,int low,int mid,int high){
    int l1=mid-low+1;
    int l2=high-mid;
    int a[l1];
    int b[l2];
    for(int i=0;i<l1;i++)
        a[i]=A[i+low];
    for(int j=0;j<l2;++j){
        b[j]=A[j+mid+1];
    }
    int i=0;
    int j=0;
    int k=low;
    while(i<l1 && j<l2){
        if(a[i]<=b[j]){
            A[k]=a[i];
            ++i;
        }
        else{
            A[k]=b[j];
            ++j;
        }
        ++k;
    }
    while(i<l1){
        A[k]=a[i];
        k++;
        i++;

    }
    while(j<l2){
        A[k]=b[j];
        k++;
        j++;
    }

}

void sort(vector<int>& A,int low,int high){
    if(low<high){
        int mid=low+(high-low)/2;
        sort(A,low,mid);
        sort(A,mid+1,high);
        merge(A,low,mid,high);
    }

}

int min_dist(vector<int> a,int low,int high,int c=INT_MAX){
    if(high-low>=1){
        if(high-low==1)
            return c=min(c,abs(a[high]-a[low]));
        else{
            int mid=low+(high-low)/2;
            return min(min_dist(a,low,mid,c),min_dist(a,mid+1,high,c));
        }
    }

}

ll rev(ll n){
    ll res=0;
    while(n){
        ll r=n%10;
        res=10*res+r;
        n/=10;
    }
    return res;
}

vector<ll> code(vector<ll>O){
    vector<ll> L;
    L.push_back(O[0]);
    for(int i=1;i<O.size();i++){
        L.push_back(L[i-1]+O[i]);
    }
    return L;
}

ll CC(int  o){
    ll u=(1<<(o-1))-1;
    return u;
}

void ab(ll& x){
    x=floor(x/2)+10;
}
void an(ll& x){
    x-=10;
}
int code(vector<ll> arr,int a,int b,ll sum)
{
    ll n=arr.size();
    unordered_map<ll, ll> m;

    for (int i=0; i<n; i++)
        m[arr[i]]++;

    int twice_count = 0;

    for (int i=0; i<n; i++)
    {

        twice_count += m[sum-arr[i]];

        if (sum-arr[i] == arr[i])
            twice_count--;

        else
            continue;
    }

    return twice_count/2;
}

ll code2(vector<ll>arr)
{
    ll n=arr.size();

    unordered_map<ll, ll> M;

    for (int i = 0; i < n - 1; i++){
        vector<ll> s;
        for (int j = i + 1; j < n; j++){
            if(find(s.begin(),s.end(),arr[i]+arr[j])==s.end()){
            M[(arr[i] + arr[j])]++;
            s.push_back(arr[i]+arr[j]);
            }
        }
    }

    ll max_count = 0;

    for (auto ele : M)
        if (max_count < ele.second)
            max_count = ele.second;

    return max_count;
}

ll  cde3(vector<ll> arr){
   ll n=arr.size();
   ll sum[20]={0};
   ll maxC = 0;

   for (int i = 0; i < n - 1; i++){
        vector<ll> s;
      for (int j = i + 1; j < n; j++){
         ll y=arr[i]+arr[j];
         if(find(arr.begin(),arr.end(),y)==arr.end()){
            sum[arr[i]+arr[j]]++;
            s.push_back(y);
        }

      }
    }
      for(int i=0;i<20;i++)
         if(sum[i]>maxC)
            maxC=sum[i];
   return maxC;
}
ll bs(vector<ll> A,ll k){
    int low=0;
    int high=int(A.size())-1;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==k)
            return mid+1;
        else if(A[mid]>k)
            high=mid-1;
        else
            low=mid+1;

    }
    return -1;
}
bool is_palindrom(string s,int low,int high){
    if(low<high){
        if(s[low]==s[high])
            return is_palindrom(s,low+1,high-1);
        else
            return false;
    }
    return true;

}

void print_pal(vector<vector<string>>& A,vector<string>& C,int low,int high,string s){
    if(low==high){
        A.push_back(C);
        return ;
    }
    for(int i=low;i<high;++i){
        if(is_palindrom(s,low,i)){
            C.push_back(s.substr(low,i-low+1));
            print_pal(A,C,i+1,high,s);
            C.pop_back();
        }
    }

}

void count_consonents(string s,vector<char> A,int& c,int high){
    if(high){
        if(find(A.begin(),A.end(),s[high-1])==A.end())
            ++c;
        count_consonents(s,A,c,high-1);
    }

}
void insert_at_bottom(stack<int>& S,int x){
    if(S.size()==0){
        S.push(x);
        return ;
    }
    int a=S.top();
    S.pop();
    insert_at_bottom(S,x);
    S.push(a);
}

void reverse_stack(stack<int>& S){
    if(S.size()==0)
        return ;
    int a=S.top();
    S.pop();
    reverse_stack(S);
    insert_at_bottom(S,a);

}

int count_subs(string s,int low,int& c,int high){
    if(low<=high){
        if(s[low]==s[high])
            ++c;
        return count_subs(s,low+1,c,high-1)+count_subs(s,low+1,c,high)-count_subs(s,low,c,high-1);
    }

}
bool sum_of_digits(int s,int& c,int n){
    if(s>=2){
        if(s!=n  && n%s==0)
            ++c;
        return sum_of_digits(s-1,c,n);

    }
    if(c==2)
        return true;
    else
        return false;

}

int edit_distance(string s,string m){
    int y=s.length();
    int k=m.length();
    int dp[y][k];
    for(int i=0;i<=y;i++){
        for(int j=0;j<=k;j++){
            if(i==0 && j==0)
                dp[i][j]=0;
            else if(i==0)
                dp[i][j]=j;
            else if(j==0)
                dp[i][j]=i;
            else if(s[i-1]==m[j-1])
                dp[i][j]=dp[i-1][j-1];
            else
                dp[i][j]=1+min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]));
        }
    }
    return dp[y][k];
}

int binary_s(vector<ll> A,ll val){
    int low=0;
    int high=A.size();
    high--;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==mid)
            return mid;
        else if(A[mid]>val)
            high=mid-1;
        else
            low=mid+1;
    }
    return -1;
}

bool is_prime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)
            return false;
    }
    return true;
}

bool is_palin(ll n){
    int r=0;
    ll res=0;
    ll temp=n;
    while(n){
        r=n%10;
        res=res*10+r;
        n/=10;

    }
    return temp==res;
}

int factorial(ll n){
    if(n==1)
        return 1;
    else
        return n*factorial(n-1);
}

vector<ll> test_case(string s,ll x,ll y,ll a,ll b,unordered_map<char,ll> M){

    ll u=abs(a-x)+abs(b-y);
    vector<ll> J;

    bool x_flag=false;
    bool y_flag=false;
    if(a>=x){
        if(a-x<=M['R'])
            x_flag=true;
        else
            x_flag=false;
    }
    else{
        if(x-a<=M['L'])
            x_flag=true;
        else
            x_flag==false;
    }
    if(b>=y){
        if(b-y<=M['U'])
            y_flag=true;
        else
            y_flag=false;
    }
    else{
        if(y-b<=M['D'])
            y_flag=true;
        else
            y_flag==false;
    }
    if(x_flag==true && y_flag==true){
        J.push_back(1);
        J.push_back(u);
    }
    else
        J.push_back(0);

    return J;
}
void convert_binary(int n){
    for(int i=31;i>=0;i--){
        if(n&(1<<i))
            cout<<1;
        else
            cout<<0;
    }
    cout<<"\n";
}
bool collision(string s){
    int i=0;
    int j=s.length()-1;
    while(i<j){
        if(s[i]==s[j])
            return true;

        i++;
        j--;
    }
    return false;
}
ll bin_exp(ll a,ll b){
    ll res=1;
    while(b>=1){
        if(b&1)
            res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

void ex_gcd(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x=1;
        y=0;
        return ;
    }
    ll x1,y1;
    ex_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;
    return ;
}
vector<ll> prime_factor(ll n){
    vector<ll> temp;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            temp.push_back(i);
            n=n/i;

        }
    }
    if(n>1)
        temp.push_back(n);
    return temp;
}

ll LCM(ll a,ll b){
    return (a*b)/(__gcd(a,b));
}
bool Prime(ll a){

    if(a<2)
        return false;
    if(a>2 && a%2==0)
        return false;
    if(a==2)
        return true;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0)
            return false;
    }
    return true;
}

ll good(ll a, ll&c){

    for(int i=a;i>=1;i/=2){
        if(i&1)
            return i;
        ++c;
    }
}
int main(){
    ll n;
    cin>>n;
    vector<int> A(n);
    unordered_map<int,int> M;
    for(auto& x:A){
        cin>>x;
        M[x]++;
    }

    for(int i=0;i<n;i++){
        if(i%3==0 && i!=0){
            if(M[2]){
                cout<<2<<" ";
                M[2]--;
            }
            else{
                cout<<1<<" ";
                M[1]--;
            }
        }
        else{
            if(M[1]){
                cout<<1<<" ";
                M[1]--;
            }
            else{
                cout<<2<<" ";
                M[2]--;
            }
        }
    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define bits __builtin_clz
#define tp __builtin_popcount
#define INF 10e6;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> G;

struct Point{
    int x;
    int y;

};
int sum(vector<int> A,int n,int v){
    if(n==0)
        return -1;
    if (A[n-1]==v)
        return n-1;
    else
        return sum(A,n-1,v);
    return -1;
}

int find(vector<int> A,int low,int high,int v){
    if(low<=high){
        if(A[low]==v)
            return low;
        else if(A[high]==v)
            return high;
        else{
            int mid=low+(high-low+1)/2;
            int u=find(A,low,mid,v);
            if(u!=-1)
                return u;
            else{
                int k=find(A,mid+1,high,v);
                if(k!=-1)
                    return k;
            }
        }

    }
    return -1;

}
int find_max(vector<int>A,int s,int n){
    if(n-s>=1){
        if(n-s==1)
            return A[s]>A[n]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_max(A,s,mid);
            int b=find_max(A,mid,n);
            return max(a,b);
        }
    }
}

int find_min(vector<int> A,int s,int n){
        if(n-s>=1){
            if(n-s==1)
                return A[n]>=A[s]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_min(A,s,mid);
            int b=find_min(A,mid,n);
            return min(a,b);
        }
    }
}

void merge(vector<int>& A,int low,int mid,int high){
    int l1=mid-low+1;
    int l2=high-mid;
    int a[l1];
    int b[l2];
    for(int i=0;i<l1;i++)
        a[i]=A[i+low];
    for(int j=0;j<l2;++j){
        b[j]=A[j+mid+1];
    }
    int i=0;
    int j=0;
    int k=low;
    while(i<l1 && j<l2){
        if(a[i]<=b[j]){
            A[k]=a[i];
            ++i;
        }
        else{
            A[k]=b[j];
            ++j;
        }
        ++k;
    }
    while(i<l1){
        A[k]=a[i];
        k++;
        i++;

    }
    while(j<l2){
        A[k]=b[j];
        k++;
        j++;
    }

}

void sort(vector<int>& A,int low,int high){
    if(low<high){
        int mid=low+(high-low)/2;
        sort(A,low,mid);
        sort(A,mid+1,high);
        merge(A,low,mid,high);
    }

}

int min_dist(vector<int> a,int low,int high,int c=INT_MAX){
    if(high-low>=1){
        if(high-low==1)
            return c=min(c,abs(a[high]-a[low]));
        else{
            int mid=low+(high-low)/2;
            return min(min_dist(a,low,mid,c),min_dist(a,mid+1,high,c));
        }
    }

}

ll rev(ll n){
    ll res=0;
    while(n){
        ll r=n%10;
        res=10*res+r;
        n/=10;
    }
    return res;
}

vector<ll> code(vector<ll>O){
    vector<ll> L;
    L.push_back(O[0]);
    for(int i=1;i<O.size();i++){
        L.push_back(L[i-1]+O[i]);
    }
    return L;
}

ll CC(int  o){
    ll u=(1<<(o-1))-1;
    return u;
}

void ab(ll& x){
    x=floor(x/2)+10;
}
void an(ll& x){
    x-=10;
}
int code(vector<ll> arr,int a,int b,ll sum)
{
    ll n=arr.size();
    unordered_map<ll, ll> m;

    for (int i=0; i<n; i++)
        m[arr[i]]++;

    int twice_count = 0;

    for (int i=0; i<n; i++)
    {

        twice_count += m[sum-arr[i]];

        if (sum-arr[i] == arr[i])
            twice_count--;

        else
            continue;
    }

    return twice_count/2;
}

ll code2(vector<ll>arr)
{
    ll n=arr.size();

    unordered_map<ll, ll> M;

    for (int i = 0; i < n - 1; i++){
        vector<ll> s;
        for (int j = i + 1; j < n; j++){
            if(find(s.begin(),s.end(),arr[i]+arr[j])==s.end()){
            M[(arr[i] + arr[j])]++;
            s.push_back(arr[i]+arr[j]);
            }
        }
    }

    ll max_count = 0;

    for (auto ele : M)
        if (max_count < ele.second)
            max_count = ele.second;

    return max_count;
}

ll  cde3(vector<ll> arr){
   ll n=arr.size();
   ll sum[20]={0};
   ll maxC = 0;

   for (int i = 0; i < n - 1; i++){
        vector<ll> s;
      for (int j = i + 1; j < n; j++){
         ll y=arr[i]+arr[j];
         if(find(arr.begin(),arr.end(),y)==arr.end()){
            sum[arr[i]+arr[j]]++;
            s.push_back(y);
        }

      }
    }
      for(int i=0;i<20;i++)
         if(sum[i]>maxC)
            maxC=sum[i];
   return maxC;
}
ll bs(vector<ll> A,ll k){
    int low=0;
    int high=int(A.size())-1;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==k)
            return mid+1;
        else if(A[mid]>k)
            high=mid-1;
        else
            low=mid+1;

    }
    return -1;
}
bool is_palindrom(string s,int low,int high){
    if(low<high){
        if(s[low]==s[high])
            return is_palindrom(s,low+1,high-1);
        else
            return false;
    }
    return true;

}

void print_pal(vector<vector<string>>& A,vector<string>& C,int low,int high,string s){
    if(low==high){
        A.push_back(C);
        return ;
    }
    for(int i=low;i<high;++i){
        if(is_palindrom(s,low,i)){
            C.push_back(s.substr(low,i-low+1));
            print_pal(A,C,i+1,high,s);
            C.pop_back();
        }
    }

}

void count_consonents(string s,vector<char> A,int& c,int high){
    if(high){
        if(find(A.begin(),A.end(),s[high-1])==A.end())
            ++c;
        count_consonents(s,A,c,high-1);
    }

}
void insert_at_bottom(stack<int>& S,int x){
    if(S.size()==0){
        S.push(x);
        return ;
    }
    int a=S.top();
    S.pop();
    insert_at_bottom(S,x);
    S.push(a);
}

void reverse_stack(stack<int>& S){
    if(S.size()==0)
        return ;
    int a=S.top();
    S.pop();
    reverse_stack(S);
    insert_at_bottom(S,a);

}

int count_subs(string s,int low,int& c,int high){
    if(low<=high){
        if(s[low]==s[high])
            ++c;
        return count_subs(s,low+1,c,high-1)+count_subs(s,low+1,c,high)-count_subs(s,low,c,high-1);
    }

}
bool sum_of_digits(int s,int& c,int n){
    if(s>=2){
        if(s!=n  && n%s==0)
            ++c;
        return sum_of_digits(s-1,c,n);

    }
    if(c==2)
        return true;
    else
        return false;

}

int edit_distance(string s,string m){
    int y=s.length();
    int k=m.length();
    int dp[y][k];
    for(int i=0;i<=y;i++){
        for(int j=0;j<=k;j++){
            if(i==0 && j==0)
                dp[i][j]=0;
            else if(i==0)
                dp[i][j]=j;
            else if(j==0)
                dp[i][j]=i;
            else if(s[i-1]==m[j-1])
                dp[i][j]=dp[i-1][j-1];
            else
                dp[i][j]=1+min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]));
        }
    }
    return dp[y][k];
}

int binary_s(vector<ll> A,ll val){
    int low=0;
    int high=A.size();
    high--;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==mid)
            return mid;
        else if(A[mid]>val)
            high=mid-1;
        else
            low=mid+1;
    }
    return -1;
}

bool is_prime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)
            return false;
    }
    return true;
}

bool is_palin(ll n){
    int r=0;
    ll res=0;
    ll temp=n;
    while(n){
        r=n%10;
        res=res*10+r;
        n/=10;

    }
    return temp==res;
}

int factorial(ll n){
    if(n==1)
        return 1;
    else
        return n*factorial(n-1);
}

vector<ll> test_case(string s,ll x,ll y,ll a,ll b,unordered_map<char,ll> M){

    ll u=abs(a-x)+abs(b-y);
    vector<ll> J;

    bool x_flag=false;
    bool y_flag=false;
    if(a>=x){
        if(a-x<=M['R'])
            x_flag=true;
        else
            x_flag=false;
    }
    else{
        if(x-a<=M['L'])
            x_flag=true;
        else
            x_flag==false;
    }
    if(b>=y){
        if(b-y<=M['U'])
            y_flag=true;
        else
            y_flag=false;
    }
    else{
        if(y-b<=M['D'])
            y_flag=true;
        else
            y_flag==false;
    }
    if(x_flag==true && y_flag==true){
        J.push_back(1);
        J.push_back(u);
    }
    else
        J.push_back(0);

    return J;
}
void convert_binary(int n){
    for(int i=31;i>=0;i--){
        if(n&(1<<i))
            cout<<1;
        else
            cout<<0;
    }
    cout<<"\n";
}
bool collision(string s){
    int i=0;
    int j=s.length()-1;
    while(i<j){
        if(s[i]==s[j])
            return true;

        i++;
        j--;
    }
    return false;
}
ll bin_exp(ll a,ll b){
    ll res=1;
    while(b>=1){
        if(b&1)
            res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

void ex_gcd(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x=1;
        y=0;
        return ;
    }
    ll x1,y1;
    ex_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;
    return ;
}
vector<ll> prime_factor(ll n){
    vector<ll> temp;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            temp.push_back(i);
            n=n/i;

        }
    }
    if(n>1)
        temp.push_back(n);
    return temp;
}

ll LCM(ll a,ll b){
    return (a*b)/(__gcd(a,b));
}
bool Prime(ll a){

    if(a<2)
        return false;
    if(a>2 && a%2==0)
        return false;
    if(a==2)
        return true;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0)
            return false;
    }
    return true;
}

ll good(ll a, ll&c){

    for(int i=a;i>=1;i/=2){
        if(i&1)
            return i;
        ++c;
    }
}
int main(){
    ll n;
    cin>>n;
    vector<int> A(n);
    unordered_map<int,int> M;
    for(auto& x:A){
        cin>>x;
        M[x]++;
    }

    for(int i=0;i<n;i++){
        if(i%2==0)
            cout<<2<<" ";
        else
            cout<<1<<" ";
    }
    cout<<"\n";

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define bits __builtin_clz
#define tp __builtin_popcount
#define INF 10e6;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> G;

struct Point{
    int x;
    int y;

};
int sum(vector<int> A,int n,int v){
    if(n==0)
        return -1;
    if (A[n-1]==v)
        return n-1;
    else
        return sum(A,n-1,v);
    return -1;
}

int find(vector<int> A,int low,int high,int v){
    if(low<=high){
        if(A[low]==v)
            return low;
        else if(A[high]==v)
            return high;
        else{
            int mid=low+(high-low+1)/2;
            int u=find(A,low,mid,v);
            if(u!=-1)
                return u;
            else{
                int k=find(A,mid+1,high,v);
                if(k!=-1)
                    return k;
            }
        }

    }
    return -1;

}
int find_max(vector<int>A,int s,int n){
    if(n-s>=1){
        if(n-s==1)
            return A[s]>A[n]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_max(A,s,mid);
            int b=find_max(A,mid,n);
            return max(a,b);
        }
    }
}

int find_min(vector<int> A,int s,int n){
        if(n-s>=1){
            if(n-s==1)
                return A[n]>=A[s]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_min(A,s,mid);
            int b=find_min(A,mid,n);
            return min(a,b);
        }
    }
}

void merge(vector<int>& A,int low,int mid,int high){
    int l1=mid-low+1;
    int l2=high-mid;
    int a[l1];
    int b[l2];
    for(int i=0;i<l1;i++)
        a[i]=A[i+low];
    for(int j=0;j<l2;++j){
        b[j]=A[j+mid+1];
    }
    int i=0;
    int j=0;
    int k=low;
    while(i<l1 && j<l2){
        if(a[i]<=b[j]){
            A[k]=a[i];
            ++i;
        }
        else{
            A[k]=b[j];
            ++j;
        }
        ++k;
    }
    while(i<l1){
        A[k]=a[i];
        k++;
        i++;

    }
    while(j<l2){
        A[k]=b[j];
        k++;
        j++;
    }

}

void sort(vector<int>& A,int low,int high){
    if(low<high){
        int mid=low+(high-low)/2;
        sort(A,low,mid);
        sort(A,mid+1,high);
        merge(A,low,mid,high);
    }

}

int min_dist(vector<int> a,int low,int high,int c=INT_MAX){
    if(high-low>=1){
        if(high-low==1)
            return c=min(c,abs(a[high]-a[low]));
        else{
            int mid=low+(high-low)/2;
            return min(min_dist(a,low,mid,c),min_dist(a,mid+1,high,c));
        }
    }

}

ll rev(ll n){
    ll res=0;
    while(n){
        ll r=n%10;
        res=10*res+r;
        n/=10;
    }
    return res;
}

vector<ll> code(vector<ll>O){
    vector<ll> L;
    L.push_back(O[0]);
    for(int i=1;i<O.size();i++){
        L.push_back(L[i-1]+O[i]);
    }
    return L;
}

ll CC(int  o){
    ll u=(1<<(o-1))-1;
    return u;
}

void ab(ll& x){
    x=floor(x/2)+10;
}
void an(ll& x){
    x-=10;
}
int code(vector<ll> arr,int a,int b,ll sum)
{
    ll n=arr.size();
    unordered_map<ll, ll> m;

    for (int i=0; i<n; i++)
        m[arr[i]]++;

    int twice_count = 0;

    for (int i=0; i<n; i++)
    {

        twice_count += m[sum-arr[i]];

        if (sum-arr[i] == arr[i])
            twice_count--;

        else
            continue;
    }

    return twice_count/2;
}

ll code2(vector<ll>arr)
{
    ll n=arr.size();

    unordered_map<ll, ll> M;

    for (int i = 0; i < n - 1; i++){
        vector<ll> s;
        for (int j = i + 1; j < n; j++){
            if(find(s.begin(),s.end(),arr[i]+arr[j])==s.end()){
            M[(arr[i] + arr[j])]++;
            s.push_back(arr[i]+arr[j]);
            }
        }
    }

    ll max_count = 0;

    for (auto ele : M)
        if (max_count < ele.second)
            max_count = ele.second;

    return max_count;
}

ll  cde3(vector<ll> arr){
   ll n=arr.size();
   ll sum[20]={0};
   ll maxC = 0;

   for (int i = 0; i < n - 1; i++){
        vector<ll> s;
      for (int j = i + 1; j < n; j++){
         ll y=arr[i]+arr[j];
         if(find(arr.begin(),arr.end(),y)==arr.end()){
            sum[arr[i]+arr[j]]++;
            s.push_back(y);
        }

      }
    }
      for(int i=0;i<20;i++)
         if(sum[i]>maxC)
            maxC=sum[i];
   return maxC;
}
ll bs(vector<ll> A,ll k){
    int low=0;
    int high=int(A.size())-1;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==k)
            return mid+1;
        else if(A[mid]>k)
            high=mid-1;
        else
            low=mid+1;

    }
    return -1;
}
bool is_palindrom(string s,int low,int high){
    if(low<high){
        if(s[low]==s[high])
            return is_palindrom(s,low+1,high-1);
        else
            return false;
    }
    return true;

}

void print_pal(vector<vector<string>>& A,vector<string>& C,int low,int high,string s){
    if(low==high){
        A.push_back(C);
        return ;
    }
    for(int i=low;i<high;++i){
        if(is_palindrom(s,low,i)){
            C.push_back(s.substr(low,i-low+1));
            print_pal(A,C,i+1,high,s);
            C.pop_back();
        }
    }

}

void count_consonents(string s,vector<char> A,int& c,int high){
    if(high){
        if(find(A.begin(),A.end(),s[high-1])==A.end())
            ++c;
        count_consonents(s,A,c,high-1);
    }

}
void insert_at_bottom(stack<int>& S,int x){
    if(S.size()==0){
        S.push(x);
        return ;
    }
    int a=S.top();
    S.pop();
    insert_at_bottom(S,x);
    S.push(a);
}

void reverse_stack(stack<int>& S){
    if(S.size()==0)
        return ;
    int a=S.top();
    S.pop();
    reverse_stack(S);
    insert_at_bottom(S,a);

}

int count_subs(string s,int low,int& c,int high){
    if(low<=high){
        if(s[low]==s[high])
            ++c;
        return count_subs(s,low+1,c,high-1)+count_subs(s,low+1,c,high)-count_subs(s,low,c,high-1);
    }

}
bool sum_of_digits(int s,int& c,int n){
    if(s>=2){
        if(s!=n  && n%s==0)
            ++c;
        return sum_of_digits(s-1,c,n);

    }
    if(c==2)
        return true;
    else
        return false;

}

int edit_distance(string s,string m){
    int y=s.length();
    int k=m.length();
    int dp[y][k];
    for(int i=0;i<=y;i++){
        for(int j=0;j<=k;j++){
            if(i==0 && j==0)
                dp[i][j]=0;
            else if(i==0)
                dp[i][j]=j;
            else if(j==0)
                dp[i][j]=i;
            else if(s[i-1]==m[j-1])
                dp[i][j]=dp[i-1][j-1];
            else
                dp[i][j]=1+min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]));
        }
    }
    return dp[y][k];
}

int binary_s(vector<ll> A,ll val){
    int low=0;
    int high=A.size();
    high--;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==mid)
            return mid;
        else if(A[mid]>val)
            high=mid-1;
        else
            low=mid+1;
    }
    return -1;
}

bool is_prime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)
            return false;
    }
    return true;
}

bool is_palin(ll n){
    int r=0;
    ll res=0;
    ll temp=n;
    while(n){
        r=n%10;
        res=res*10+r;
        n/=10;

    }
    return temp==res;
}

int factorial(ll n){
    if(n==1)
        return 1;
    else
        return n*factorial(n-1);
}

vector<ll> test_case(string s,ll x,ll y,ll a,ll b,unordered_map<char,ll> M){

    ll u=abs(a-x)+abs(b-y);
    vector<ll> J;

    bool x_flag=false;
    bool y_flag=false;
    if(a>=x){
        if(a-x<=M['R'])
            x_flag=true;
        else
            x_flag=false;
    }
    else{
        if(x-a<=M['L'])
            x_flag=true;
        else
            x_flag==false;
    }
    if(b>=y){
        if(b-y<=M['U'])
            y_flag=true;
        else
            y_flag=false;
    }
    else{
        if(y-b<=M['D'])
            y_flag=true;
        else
            y_flag==false;
    }
    if(x_flag==true && y_flag==true){
        J.push_back(1);
        J.push_back(u);
    }
    else
        J.push_back(0);

    return J;
}
void convert_binary(int n){
    for(int i=31;i>=0;i--){
        if(n&(1<<i))
            cout<<1;
        else
            cout<<0;
    }
    cout<<"\n";
}
bool collision(string s){
    int i=0;
    int j=s.length()-1;
    while(i<j){
        if(s[i]==s[j])
            return true;

        i++;
        j--;
    }
    return false;
}
ll bin_exp(ll a,ll b){
    ll res=1;
    while(b>=1){
        if(b&1)
            res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

void ex_gcd(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x=1;
        y=0;
        return ;
    }
    ll x1,y1;
    ex_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;
    return ;
}
vector<ll> prime_factor(ll n){
    vector<ll> temp;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            temp.push_back(i);
            n=n/i;

        }
    }
    if(n>1)
        temp.push_back(n);
    return temp;
}

ll LCM(ll a,ll b){
    return (a*b)/(__gcd(a,b));
}
bool Prime(ll a){

    if(a<2)
        return false;
    if(a>2 && a%2==0)
        return false;
    if(a==2)
        return true;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0)
            return false;
    }
    return true;
}

ll good(ll a, ll&c){

    for(int i=a;i>=1;i/=2){
        if(i&1)
            return i;
        ++c;
    }
}
int main(){
    ll n;
    cin>>n;
    vector<int> A(n);
    unordered_map<int,int> M;
    for(auto& x:A){
        cin>>x;
        M[x]++;
    }
    if(M[1]==0 || M[2]==0){
        for(auto x:A)
            cout<<x<<" ";
        cout<<"\n";

    }
    else{
    cout<<2<<" "<<1<<" ";
    M[2]=M[2]-1;
    M[1]=M[1]-1;
    for(int i=0;i<n;i++){
        if(M[2]){
            cout<<2<<" ";
            M[2]--;
        }
        else if(M[1]){
            M[1]--;
            cout<<1<<" ";
        }

    }
        cout<<"\n";
    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define bits __builtin_clz
#define tp __builtin_popcount
#define INF 10e6;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> G;

struct Point{
    int x;
    int y;

};
int sum(vector<int> A,int n,int v){
    if(n==0)
        return -1;
    if (A[n-1]==v)
        return n-1;
    else
        return sum(A,n-1,v);
    return -1;
}

int find(vector<int> A,int low,int high,int v){
    if(low<=high){
        if(A[low]==v)
            return low;
        else if(A[high]==v)
            return high;
        else{
            int mid=low+(high-low+1)/2;
            int u=find(A,low,mid,v);
            if(u!=-1)
                return u;
            else{
                int k=find(A,mid+1,high,v);
                if(k!=-1)
                    return k;
            }
        }

    }
    return -1;

}
int find_max(vector<int>A,int s,int n){
    if(n-s>=1){
        if(n-s==1)
            return A[s]>A[n]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_max(A,s,mid);
            int b=find_max(A,mid,n);
            return max(a,b);
        }
    }
}

int find_min(vector<int> A,int s,int n){
        if(n-s>=1){
            if(n-s==1)
                return A[n]>=A[s]?A[s]:A[n];
        else{
            int mid=s+(n-s)/2;
            int a=find_min(A,s,mid);
            int b=find_min(A,mid,n);
            return min(a,b);
        }
    }
}

void merge(vector<int>& A,int low,int mid,int high){
    int l1=mid-low+1;
    int l2=high-mid;
    int a[l1];
    int b[l2];
    for(int i=0;i<l1;i++)
        a[i]=A[i+low];
    for(int j=0;j<l2;++j){
        b[j]=A[j+mid+1];
    }
    int i=0;
    int j=0;
    int k=low;
    while(i<l1 && j<l2){
        if(a[i]<=b[j]){
            A[k]=a[i];
            ++i;
        }
        else{
            A[k]=b[j];
            ++j;
        }
        ++k;
    }
    while(i<l1){
        A[k]=a[i];
        k++;
        i++;

    }
    while(j<l2){
        A[k]=b[j];
        k++;
        j++;
    }

}

void sort(vector<int>& A,int low,int high){
    if(low<high){
        int mid=low+(high-low)/2;
        sort(A,low,mid);
        sort(A,mid+1,high);
        merge(A,low,mid,high);
    }

}

int min_dist(vector<int> a,int low,int high,int c=INT_MAX){
    if(high-low>=1){
        if(high-low==1)
            return c=min(c,abs(a[high]-a[low]));
        else{
            int mid=low+(high-low)/2;
            return min(min_dist(a,low,mid,c),min_dist(a,mid+1,high,c));
        }
    }

}

ll rev(ll n){
    ll res=0;
    while(n){
        ll r=n%10;
        res=10*res+r;
        n/=10;
    }
    return res;
}

vector<ll> code(vector<ll>O){
    vector<ll> L;
    L.push_back(O[0]);
    for(int i=1;i<O.size();i++){
        L.push_back(L[i-1]+O[i]);
    }
    return L;
}

ll CC(int  o){
    ll u=(1<<(o-1))-1;
    return u;
}

void ab(ll& x){
    x=floor(x/2)+10;
}
void an(ll& x){
    x-=10;
}
int code(vector<ll> arr,int a,int b,ll sum)
{
    ll n=arr.size();
    unordered_map<ll, ll> m;

    for (int i=0; i<n; i++)
        m[arr[i]]++;

    int twice_count = 0;

    for (int i=0; i<n; i++)
    {

        twice_count += m[sum-arr[i]];

        if (sum-arr[i] == arr[i])
            twice_count--;

        else
            continue;
    }

    return twice_count/2;
}

ll code2(vector<ll>arr)
{
    ll n=arr.size();

    unordered_map<ll, ll> M;

    for (int i = 0; i < n - 1; i++){
        vector<ll> s;
        for (int j = i + 1; j < n; j++){
            if(find(s.begin(),s.end(),arr[i]+arr[j])==s.end()){
            M[(arr[i] + arr[j])]++;
            s.push_back(arr[i]+arr[j]);
            }
        }
    }

    ll max_count = 0;

    for (auto ele : M)
        if (max_count < ele.second)
            max_count = ele.second;

    return max_count;
}

ll  cde3(vector<ll> arr){
   ll n=arr.size();
   ll sum[20]={0};
   ll maxC = 0;

   for (int i = 0; i < n - 1; i++){
        vector<ll> s;
      for (int j = i + 1; j < n; j++){
         ll y=arr[i]+arr[j];
         if(find(arr.begin(),arr.end(),y)==arr.end()){
            sum[arr[i]+arr[j]]++;
            s.push_back(y);
        }

      }
    }
      for(int i=0;i<20;i++)
         if(sum[i]>maxC)
            maxC=sum[i];
   return maxC;
}
ll bs(vector<ll> A,ll k){
    int low=0;
    int high=int(A.size())-1;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==k)
            return mid+1;
        else if(A[mid]>k)
            high=mid-1;
        else
            low=mid+1;

    }
    return -1;
}
bool is_palindrom(string s,int low,int high){
    if(low<high){
        if(s[low]==s[high])
            return is_palindrom(s,low+1,high-1);
        else
            return false;
    }
    return true;

}

void print_pal(vector<vector<string>>& A,vector<string>& C,int low,int high,string s){
    if(low==high){
        A.push_back(C);
        return ;
    }
    for(int i=low;i<high;++i){
        if(is_palindrom(s,low,i)){
            C.push_back(s.substr(low,i-low+1));
            print_pal(A,C,i+1,high,s);
            C.pop_back();
        }
    }

}

void count_consonents(string s,vector<char> A,int& c,int high){
    if(high){
        if(find(A.begin(),A.end(),s[high-1])==A.end())
            ++c;
        count_consonents(s,A,c,high-1);
    }

}
void insert_at_bottom(stack<int>& S,int x){
    if(S.size()==0){
        S.push(x);
        return ;
    }
    int a=S.top();
    S.pop();
    insert_at_bottom(S,x);
    S.push(a);
}

void reverse_stack(stack<int>& S){
    if(S.size()==0)
        return ;
    int a=S.top();
    S.pop();
    reverse_stack(S);
    insert_at_bottom(S,a);

}

int count_subs(string s,int low,int& c,int high){
    if(low<=high){
        if(s[low]==s[high])
            ++c;
        return count_subs(s,low+1,c,high-1)+count_subs(s,low+1,c,high)-count_subs(s,low,c,high-1);
    }

}
bool sum_of_digits(int s,int& c,int n){
    if(s>=2){
        if(s!=n  && n%s==0)
            ++c;
        return sum_of_digits(s-1,c,n);

    }
    if(c==2)
        return true;
    else
        return false;

}

int edit_distance(string s,string m){
    int y=s.length();
    int k=m.length();
    int dp[y][k];
    for(int i=0;i<=y;i++){
        for(int j=0;j<=k;j++){
            if(i==0 && j==0)
                dp[i][j]=0;
            else if(i==0)
                dp[i][j]=j;
            else if(j==0)
                dp[i][j]=i;
            else if(s[i-1]==m[j-1])
                dp[i][j]=dp[i-1][j-1];
            else
                dp[i][j]=1+min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]));
        }
    }
    return dp[y][k];
}

int binary_s(vector<ll> A,ll val){
    int low=0;
    int high=A.size();
    high--;
    while(low<=high){
        int mid=low+(high-low)/2;
        if(A[mid]==mid)
            return mid;
        else if(A[mid]>val)
            high=mid-1;
        else
            low=mid+1;
    }
    return -1;
}

bool is_prime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)
            return false;
    }
    return true;
}

bool is_palin(ll n){
    int r=0;
    ll res=0;
    ll temp=n;
    while(n){
        r=n%10;
        res=res*10+r;
        n/=10;

    }
    return temp==res;
}

int factorial(ll n){
    if(n==1)
        return 1;
    else
        return n*factorial(n-1);
}

vector<ll> test_case(string s,ll x,ll y,ll a,ll b,unordered_map<char,ll> M){

    ll u=abs(a-x)+abs(b-y);
    vector<ll> J;

    bool x_flag=false;
    bool y_flag=false;
    if(a>=x){
        if(a-x<=M['R'])
            x_flag=true;
        else
            x_flag=false;
    }
    else{
        if(x-a<=M['L'])
            x_flag=true;
        else
            x_flag==false;
    }
    if(b>=y){
        if(b-y<=M['U'])
            y_flag=true;
        else
            y_flag=false;
    }
    else{
        if(y-b<=M['D'])
            y_flag=true;
        else
            y_flag==false;
    }
    if(x_flag==true && y_flag==true){
        J.push_back(1);
        J.push_back(u);
    }
    else
        J.push_back(0);

    return J;
}
void convert_binary(int n){
    for(int i=31;i>=0;i--){
        if(n&(1<<i))
            cout<<1;
        else
            cout<<0;
    }
    cout<<"\n";
}
bool collision(string s){
    int i=0;
    int j=s.length()-1;
    while(i<j){
        if(s[i]==s[j])
            return true;

        i++;
        j--;
    }
    return false;
}
ll bin_exp(ll a,ll b){
    ll res=1;
    while(b>=1){
        if(b&1)
            res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

void ex_gcd(ll a,ll b,ll& x,ll& y){
    if(b==0){
        x=1;
        y=0;
        return ;
    }
    ll x1,y1;
    ex_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;
    return ;
}
vector<ll> prime_factor(ll n){
    vector<ll> temp;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            temp.push_back(i);
            n=n/i;

        }
    }
    if(n>1)
        temp.push_back(n);
    return temp;
}

ll LCM(ll a,ll b){
    return (a*b)/(__gcd(a,b));
}
bool Prime(ll a){

    if(a<2)
        return false;
    if(a>2 && a%2==0)
        return false;
    if(a==2)
        return true;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0)
            return false;
    }
    return true;
}

ll good(ll a, ll&c){

    for(int i=a;i>=1;i/=2){
        if(i&1)
            return i;
        ++c;
    }
}
int main(){
    ll n;
    cin>>n;
    vector<ll> A(n);
    for(auto& x:A)
        cin>>x;
    for(int i=0;i<n;i++){
        if(i&1)
            cout<<2<<" ";
        else
            cout<<1<<" ";
    }
    cout<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
int n,low,fl,l[maxn],r[maxn],a[maxn],tot,pos[maxn],cnt[3];
int isprime(int x){
    if(x==1)return 0;
    int len=sqrt(x);
    for(int i=2;i<=len;i++)if(x%i==0)return 0;
    return 1;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];cnt[a[i]]++;
    }
    int now=0;
    for(int i=1;i<=n;i++){
        //cout<<endl<<now<<" "<<isprime(now+1)<<endl;
        if(!cnt[1])putchar('2'),putchar(' '),now+=2,cnt[2]--;
        else if(!cnt[2])putchar('1'),putchar(' '),now++,cnt[1]--;
        else if(isprime(now+1))putchar('1'),putchar(' '),now++,cnt[1]--;
        else putchar('2'),putchar(' '),now+=2,cnt[2]--;
    }

}
/*
你有一堆1和一堆2，把它们排起来跑个前缀和，要求质数最多。
哦朝着质数狂奔就好了
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
int n,low,fl,l[maxn],r[maxn],a[maxn],tot,pos[maxn],cnt[3];
bool isprime(int x){
    if(x==1)return 0;int len=sqrt(x);
    for(int i=1;i<=len;i++)if(!x%i)return 0;
    return 1;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];cnt[a[i]]++;
    }
    int now=1;
    for(int i=1;i<=n;i++){
        if(!cnt[1])putchar('2'),putchar(' '),now+=2,cnt[2]--;
        else if(!cnt[2])putchar('1'),putchar(' '),now++,cnt[1]--;
        else if(isprime(now+1))putchar('1'),putchar(' '),now++,cnt[1]--;
        else putchar('2'),putchar(' '),now+=2,cnt[2]--;

    }

}
/*
你有一堆1和一堆2，把它们排起来跑个前缀和，要求质数最多。
哦朝着质数狂奔就好了
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
int n,low,fl,l[maxn],r[maxn],a[maxn],tot,pos[maxn],cnt[3];
bool isprime(int x){
    if(x==1)return 0;
    int len=sqrt(x);
    for(int i=1;i<=len;i++)if(x%i)return 0;
    return 1;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];cnt[a[i]]++;
    }
    int now=1;
    for(int i=1;i<=n;i++){
        if(!cnt[1])putchar('2'),putchar(' '),now+=2,cnt[2]--;
        else if(!cnt[2])putchar('1'),putchar(' '),now++,cnt[1]--;
        else if(isprime(now+1))putchar('1'),putchar(' '),now++,cnt[1]--;
        else putchar('2'),putchar(' '),now+=2,cnt[2]--;

    }

}
/*
你有一堆1和一堆2，把它们排起来跑个前缀和，要求质数最多。
哦朝着质数狂奔就好了
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
int n,low,fl,l[maxn],r[maxn],a[maxn],tot,pos[maxn],cnt[3];
bool isprime(int x){
    if(x==1)return 0;
    int len=sqrt(x);
    for(int i=1;i<=len;i++)if(x%i)return 0;
    return 1;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];cnt[a[i]]++;
    }
    int now=0;
    for(int i=1;i<=n;i++){
        if(!cnt[1])putchar('2'),putchar(' '),now+=2,cnt[2]--;
        else if(!cnt[2])putchar('1'),putchar(' '),now++,cnt[1]--;
        else if(isprime(now+1))putchar('1'),putchar(' '),now++,cnt[1]--;
        else putchar('2'),putchar(' '),now+=2,cnt[2]--;

    }

}
/*
你有一堆1和一堆2，把它们排起来跑个前缀和，要求质数最多。
哦朝着质数狂奔就好了
*/


#include <bits/stdc++.h>
//By_arshak

using namespace std;

const int MAXX = 2e5 + 10, MAXP = 5e5 + 10;
int n, a[MAXX], l, cnt[3], x;
bool ip[MAXP];
vector <int> v, ans;

void era() {
	ip[1] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			for (int j = 2 * i; j < MAXP; j += i)
				ip[j] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			v.push_back(i - l), l = i;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, era();
	for(int i = 0; i < n; i++)
		cin >> a[i], cnt[a[i]]++;
	for(int i = 0; i < v.size(); i++) {
		if(cnt[1] <= 0 && cnt[2] <= 0)
			break;
		if((v[i] & 1) && cnt[1] > 0)
			cnt[1]--, ans.push_back(1);
		for(int j = 0; j < v[i] / 2; j++) {
			if(cnt[2] > 0)
				ans.push_back(2), cnt[2]--;
			else if(cnt[1] >= 2)
				ans.push_back(1), ans.push_back(1), cnt[1] -= 2;
		}
	}
	for(int i = 0; i < cnt[1]; i++)
		ans.push_back(1);
	for(int i = 0; i < cnt[2]; i++)
		ans.push_back(2);
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
	return cout << endl, 0;
}


#include <bits/stdc++.h>
//By_arshak

using namespace std;

const int MAXX = 2e5 + 10, MAXP = 5e5 + 10;
int n, a[MAXX], l, cnt[3], x;
bool ip[MAXP];
vector <int> v, ans;

void era() {
	ip[1] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			for (int j = 2 * i; j < MAXP; j += i)
				ip[j] = 1;
	for (int i = 2; i <= MAXP; i++)
		if(!ip[i])
			v.push_back(i - l), l = i;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, era();
	for(int i = 0; i < n; i++)
		cin >> a[i], cnt[a[i]]++;
	for(int i = 0; i < v.size(); i++) {
		if(cnt[1] <= 0 && cnt[2] <= 0)
			break;
		if((v[i] & 1))
			cnt[1]--, ans.push_back(1);
		for(int j = 0; j < v[i] / 2; j++) {
			if(cnt[2] > 0)
				ans.push_back(2), cnt[2]--;
			else if(cnt[1] >= 2)
				ans.push_back(1), ans.push_back(1), cnt[1] -= 2;
		}
	}
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
	return cout << endl, 0;
}


#include <bits/stdc++.h>
//By_arshak

using namespace std;

const int MAXX = 2e5 + 10, MAXP = 5e5 + 10;
int n, a[MAXX], l, cnt[3], x;
bool ip[MAXP];
vector <int> v, ans;

void era() {
	ip[1] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			for (int j = 2 * i; j < MAXP; j += i)
				ip[j] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			v.push_back(i - l), l = i;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, era();
	for(int i = 0; i < n; i++)
		cin >> a[i], cnt[a[i]]++;
	for(int i = 0; i < v.size(); i++) {
		if(cnt[1] <= 0 && cnt[2] <= 0)
			break;
		if((v[i] & 1))
			cnt[1]--, ans.push_back(1);
		for(int j = 0; j < v[i] / 2; j++) {
			if(cnt[2] > 0)
				ans.push_back(2), cnt[2]--;
			else if(cnt[1] >= 2)
				ans.push_back(1), ans.push_back(1), cnt[1] -= 2;
		}
	}
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
	return cout << endl, 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXX = 2e5 + 10, MAXP = 4e5 + 10;
int n, a[MAXX], l, cnt[3], x;
bool ip[MAXP];
vector <int> v, ans;

void era() {
	ip[1] = 1;
	for (int i = 2; i <= MAXP; i++)
		if(!ip[i])
			for (int j = 2 * i; j <= MAXP; j += i)
				ip[j] = 1;
	for (int i = 2; i <= MAXP; i++)
		if(!ip[i])
			v.push_back(i - l), l = i;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, era();
	for(int i = 0; i < n; i++)
		cin >> a[i], cnt[a[i]]++;
	for(int i = 0; i < v.size(); i++) {
		if(cnt[1] <= 0 && cnt[2] <= 0)
			break;
		if((v[i] & 1))
			cnt[1]--, ans.push_back(1);
		for(int j = 0; j < v[i] / 2; j++) {
			if(cnt[2] > 0)
				ans.push_back(2), cnt[2]--;
			else if(cnt[1] >= 2)
				ans.push_back(1), ans.push_back(1), cnt[1] -= 2;
		}
	}
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
	return cout << endl, 0;
}


#include <bits/stdc++.h>
//By_arshak

using namespace std;

const int MAXX = 2e5 + 10, MAXP = 5e5 + 10;
int n, a[MAXX], l, cnt[3], x;
bool ip[MAXP];
vector <int> v, ans;

void era() {
	ip[1] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			for (int j = 2 * i; j < MAXP; j += i)
				ip[j] = 1;
	for (int i = 2; i < MAXP; i++)
		if(!ip[i])
			v.push_back(i - l), l = i;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, era();
	for(int i = 0; i < n; i++)
		cin >> a[i], cnt[a[i]]++;
	for(int i = 0; i < v.size(); i++) {
		if(cnt[1] <= 0 && cnt[2] <= 0)
			break;
		if((v[i] & 1) && cnt[1] > 0)
			cnt[1]--, ans.push_back(1);
		for(int j = 0; j < v[i] / 2; j++) {
			if(cnt[2] > 0)
				ans.push_back(2), cnt[2]--;
			else if(cnt[1] >= 2)
				ans.push_back(1), ans.push_back(1), cnt[1] -= 2;
		}
	}
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
	return cout << endl, 0;
}


//author:mel0n

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long int
#define all(x) (x).begin(),(x).end()

signed main()
{
	ll n;
	cin>>n;
	vector <ll> a(n);
	map <ll,ll> mp;
	for(auto &x:a)
		cin>>x;
	for(auto x:a)
		mp[x]++;

	if(mp[2] && mp[1])
	{cout<<2<<" "<<1<<" ";
	mp[2]--;
	mp[1]--;
	}
	else if(mp[1])
	{
		cout<<1<<" "<<1<<" ";
		mp[1]-=2;
	}
	else if(mp[2])
	{

		cout<<2<<" "<<2<<" ";
		mp[2]-=2;
	}

	for(int i=0;i<n-2;i++)
	{
		if(mp[2])
		{
			cout<<2<<" ";
			mp[2]--;
		}
		else if(mp[1])
		{
			cout<<1<<" ";
			mp[1]--;

		}

	}
	cout<<'\n';

}


//author:mel0n

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long int
#define all(x) (x).begin(),(x).end()

signed main()
{
	ll n;
	cin>>n;
	vector <ll> a(n);
	map <ll,ll> mp;
	for(auto &x:a)
		cin>>x;
	for(auto x:a)
		mp[x]++;

	if(n==1)
		cout<<a[0]<<" ";

	else if(mp[2] && mp[1])
	{cout<<2<<" "<<1<<" ";
	mp[2]--;
	mp[1]--;
	}
	else if(mp[1])
	{
		cout<<1<<" "<<1<<" ";
		mp[1]-=2;
	}
	else if(mp[2])
	{

		cout<<2<<" "<<2<<" ";
	}

	for(int i=0;i<n-2;i++)
	{
		if(mp[2])
		{
			cout<<2<<" ";
			mp[2]--;
		}
		else if(mp[1])
		{
			cout<<1<<" ";
			mp[1]--;

		}

	}
	cout<<'\n';

}


//author:mel0n

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long int
#define all(x) (x).begin(),(x).end()

signed main()
{
	ll n;
	cin>>n;
	vector <ll> a(n);
	map <ll,ll> mp;
	for(auto &x:a)
		cin>>x;
	for(auto x:a)
		mp[x]++;

	if(mp[2] && mp[1])
	{cout<<2<<" "<<1<<" ";
	mp[2]--;
	mp[1]--;
	}

	for(int i=0;i<n-2;i++)
	{
		if(mp[2])
		{
			cout<<2<<" ";
			mp[2]--;
		}
		else if(mp[1])
		{
			cout<<1<<" ";
			mp[1]--;

		}

	}
	cout<<'\n';

}


//author:mel0n

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long int
#define all(x) (x).begin(),(x).end()

signed main()
{
	ll n;
	cin>>n;
	vector <ll> a(n);
	map <ll,ll> mp;
	for(auto &x:a)
		cin>>x;
	for(auto x:a)
		mp[x]++;

	if(n==1)
		cout<<mp[a[0]]<<" ";

	else if(mp[2] && mp[1])
	{cout<<2<<" "<<1<<" ";
	mp[2]--;
	mp[1]--;
	}
	else if(mp[1])
	{
		cout<<1<<" "<<1<<" ";
		mp[1]-=2;
	}
	else if(mp[2])
	{

		cout<<2<<" "<<2<<" ";
	}

	for(int i=0;i<n-2;i++)
	{
		if(mp[2])
		{
			cout<<2<<" ";
			mp[2]--;
		}
		else if(mp[1])
		{
			cout<<1<<" ";
			mp[1]--;

		}

	}
	cout<<'\n';

}


#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(const std::vector<unsigned>& v)
{
    const char* separator = "";
    for (const unsigned x : v) {
        std::cout << separator << x;
        separator = " ";
    }
    std::cout << '\n';
}

void solve(std::vector<unsigned>& a)
{
    unsigned f[2] = {};
    for (const unsigned x : a)
        ++f[x-1];

    std::vector<bool> primes(f[0] + 2 * f[1] + 100, true);
    primes[0] = false;
    primes[1] = false;
    for (unsigned x = 2; x < primes.size(); ++x) {
        if (!primes[x])
            continue;

        for (unsigned y = 2 * x; y < primes.size(); y += x)
            primes[y] = false;
    }

    const auto next_prime = [&primes](unsigned x) {
        while (!primes[++x]);
        return x;
    };

    unsigned s = 0;
    for (unsigned& x : a) {
        const unsigned p = next_prime(s);
        if (p - s > 1 && f[1] > 0) {
            x = 2, --f[1];
        } else {
            x = 1, --f[0];
        }

        s += x;
    }

    answer(a);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::cin >> a;

    solve(a);

    return 0;
}


#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(const std::vector<unsigned>& v)
{
    const char* separator = "";
    for (const unsigned x : v) {
        std::cout << separator << x;
        separator = " ";
    }
    std::cout << '\n';
}

void solve(std::vector<unsigned>& a)
{
    const size_t n = a.size();

    unsigned f[2] = {};
    for (const unsigned x : a)
        ++f[x-1];

    unsigned s = 0;
    for (size_t i = 0; i < n; ++i) {
        if (f[0] == 0 || (i % 2 != 0 && f[1] > 0)) {
            a[i] = 2;
            --f[1];
        } else {
            a[i] = 1;
            --f[0];
        }

        s += a[i];
    }

    answer(a);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::cin >> a;

    solve(a);

    return 0;
}


#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(const std::vector<unsigned>& v)
{
    const char* separator = "";
    for (const unsigned x : v) {
        std::cout << separator << x;
        separator = " ";
    }
    std::cout << '\n';
}

void solve(std::vector<unsigned>& a)
{
    unsigned f[2] = {};
    for (const unsigned x : a)
        ++f[x-1];

    size_t i = 0;
    if (f[1] > 0) {
        a[i++] = 2;
        --f[1];
    }
    if (f[0] > 0) {
        a[i++] = 1;
        --f[0];
    }
    for ( ; f[1]-- > 0; a[i++] = 2);
    for ( ; f[0]-- > 0; a[i++] = 1);

    answer(a);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::cin >> a;

    solve(a);

    return 0;
}


#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(const std::vector<unsigned>& v)
{
    const char* separator = "";
    for (const unsigned x : v) {
        std::cout << separator << x;
        separator = " ";
    }
    std::cout << '\n';
}

void solve(std::vector<unsigned>& a)
{
    const size_t n = a.size();

    unsigned f[2] = {};
    for (const unsigned x : a)
        ++f[x-1];

    unsigned s = 0;
    for (size_t i = 0; i < n; ++i) {
        if ((i % 2 == 0 && f[1] > 0) || f[0] == 0) {
            a[i] = 2;
            --f[1];
        } else {
            a[i] = 1;
            --f[0];
        }

        s += a[i];
    }

    answer(a);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::cin >> a;

    solve(a);

    return 0;
}


#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(const std::vector<unsigned>& v)
{
    const char* separator = "";
    for (const unsigned x : v) {
        std::cout << separator << x;
        separator = " ";
    }
    std::cout << '\n';
}

void solve(std::vector<unsigned>& a)
{
    unsigned f[2] = {};
    for (const unsigned x : a)
        ++f[x-1];

    std::vector<bool> primes(f[0] + 2 * f[1] + 100, true);
    primes[0] = false;
    primes[1] = false;
    for (unsigned x = 2; x < primes.size(); ++x) {
        if (!primes[x])
            continue;

        for (unsigned y = 2 * x; y < primes.size(); y += x)
            primes[y] = false;
    }

    const auto next_prime = [&primes](unsigned x) {
        while (!primes[++x]);
        return x;
    };

    unsigned s = 0;
    for (unsigned& x : a) {
        const unsigned p = next_prime(s);
        if ((p - s > 1 && f[1] > 0) || f[0] == 0) {
            x = 2, --f[1];
        } else {
            x = 1, --f[0];
        }

        s += x;
    }

    answer(a);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::cin >> a;

    solve(a);

    return 0;
}


#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(const std::vector<unsigned>& v)
{
    const char* separator = "";
    for (const unsigned x : v) {
        std::cout << separator << x;
        separator = " ";
    }
    std::cout << '\n';
}

void solve(std::vector<unsigned>& a)
{
    const size_t n = a.size();

    unsigned f[2] = {};
    for (const unsigned x : a)
        ++f[x-1];

    unsigned s = 0;
    for (size_t i = 0; i < n; ++i) {
        if (i % 2 == 0 && (f[1] > 0 || f[0] == 0)) {
            a[i] = 2;
            --f[1];
        } else {
            a[i] = 1;
            --f[0];
        }

        s += a[i];
    }

    answer(a);
}

int main()
{
    size_t n;
    std::cin >> n;

    std::vector<unsigned> a(n);
    std::cin >> a;

    solve(a);

    return 0;
}


//I_Love_PNQ
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, input;
    cin >> n;
    int cnt1(0), cnt2(0);
    while (n--)
    {
       cin >> input;
       if (input == 1){++cnt1;}
       if (input == 2){++cnt2;}
    }
    if (cnt2 <= cnt1)
    {
    for (int i = 0; i < cnt2; ++ i)
    {
        cout << 2<<' ' << 1 <<' ';
    }
    cnt1 -= cnt2;
    for (int i = 0; i < cnt1; ++ i)
    {
        cout <<1 <<' ';
    }
    }
    else
    {
        for (int i = 0; i < cnt1; ++ i)
    {
        cout << 2<<' ' << 1 <<' ';
    }
    cnt2 -= cnt1;
    for (int i = 0; i < cnt2; ++ i)
    {
        cout <<2 <<' ';
    }
    }

}


//I_Love_PNQ
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, input;
    cin >> n;
    int cnt1(0), cnt2(0);
    while (n--)
    {
       cin >> input;
       if (input == 1){++cnt1;}
       if (input == 2){++cnt2;}
    }
    if (cnt2 <= cnt1)
    {
    for (int i = 0; i < cnt2; ++ i)
    {
        cout << 2<<' ' << 1 <<' ';
    }
    cnt1 -= cnt2;
    for (int i = 0; i < cnt1; ++ i)
    {
        cout <<1 <<' ';
    }
    }
    else
    {
        for (int i = 0; i < cnt2; ++ i)
    {
        cout << 2<<' ' << 1 <<' ';
    }
    cnt2 -= cnt1;
    for (int i = 0; i < cnt2; ++ i)
    {
        cout <<2 <<' ';
    }
    }

}


//I_Love_PNQ
#include <iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, input;
    cin >> n;
    int cnt1(0), cnt2(0);
    while (n--)
    {
       cin >> input;
       if (input == 1){++cnt1;}
       if (input == 2){++cnt2;}
    }
    if (cnt2 --){cout << 2 <<" ";}
    if (cnt1 --){cout << 1<< " ";}
    while (cnt2 -- > 0 ){cout << 2 <<" ";}
    while (cnt1-- > 0){cout << 1 << " ";}

}


//I_Love_PNQ
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, input;
    cin >> n;
    int cnt1(0), cnt2(0);
    while (n--)
    {
       cin >> input;
       if (input == 1){++cnt1;}
       if (input == 2){++cnt2;}
    }
    for (int i = 0; i < cnt2; ++ i)
    {
        cout << 2<<' ';
    }
    for (int i = 0; i < cnt1; ++ i)
    {
        cout << 1<<' ';
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> findPrimes(ll x)
{
    bool isprime[x + 1];
    fill_n(isprime, x + 1, true);
    vector<int> ans;
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= x; i++)
    {
        if (isprime[i])
        {
            for (ll j = i * i; j <= x; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = 0; i <= x; i++)
    {
        if (isprime[i])
            ans.emplace_back(i);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    int count2 = 0, count1 = 0;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 2)
            count2++;
        else
            count1++;
    }

    vector<int> primes = findPrimes(2*count2+count1);

    int i = 0, sum = 0;
    vector<int> ans;
    while (count1 > 0&&count2 > 0)
    {
        if (count2 > 0 && (primes[i] - sum) >= 2)
        {
            sum += 2;
            count2--;
            ans.emplace_back(2);
            if(sum==primes[i]) i++;
        }
        else if (count1 > 0 && (primes[i] - sum) >= 1)
        {
            sum += 1;
            count1--;
            ans.emplace_back(1);
            if(sum==primes[i]) i++;
        }
    }
    while(count1>0){
        ans.emplace_back(1); count1--;
    }
    while(count2>0){
        ans.emplace_back(2); count2--;
    }
    for (auto v : ans)
        cout << v << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> findPrimes(int x)
{
    bool isprime[x + 1];
    fill_n(isprime, x + 1, true);
    vector<int> ans;
    isprime[0] = false;
    isprime[1] = false;
    for (int i = 2; i <= x; i++)
    {
        if (isprime[i])
        {
            for (int j = i * i; j <= x; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = 0; i <= x; i++)
    {
        if (isprime[i])
            ans.emplace_back(i);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    int count2 = 0, count1 = 0;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 2)
            count2++;
        else
            count1++;
    }

    vector<int> primes = findPrimes(2 * count2 + count1);
    int i = 0, sum = 0;
    vector<int> ans;
    while (count1 > 0&&count2 > 0)
    {
        if (count2 > 0 && (primes[i] - sum) >= 2)
        {
            sum += 2;
            count2--;
            ans.emplace_back(2);
            if(sum==primes[i]) i++;
        }
        else if (count1 > 0 && (primes[i] - sum) >= 1)
        {
            sum += 1;
            count1--;
            ans.emplace_back(1);
            if(sum==primes[i]) i++;
        }
    }
    while(count1>0){
        ans.emplace_back(1); count1--;
    }
    while(count2>0){
        ans.emplace_back(2); count2--;
    }
    for (auto v : ans)
        cout << v << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> findPrimes(ll x)
{
    bool isprime[x + 1];
    fill_n(isprime, x + 1, true);
    vector<int> ans;
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= x; i++)
    {
        if (isprime[i])
        {
            for (ll j = i * i; j <= x; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = 0; i <= x; i++)
    {
        if (isprime[i])
            ans.emplace_back(i);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    int count2 = 0, count1 = 0;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 2)
            count2++;
        else
            count1++;
    }
    vector<int> ans;
    if (count1 != 0 && count2 != 0)
    {
        vector<int> primes = findPrimes(2 * count2 + count1);

        int i = 0, sum = 0;

        while (count1 > 0 && count2 > 0)
        {
            if (count2 > 0 && (primes[i] - sum) >= 2)
            {
                sum += 2;
                count2--;
                ans.emplace_back(2);
                if (sum == primes[i])
                    i++;
            }
            else if (count1 > 0 && (primes[i] - sum) >= 1)
            {
                sum += 1;
                count1--;
                ans.emplace_back(1);
                if (sum == primes[i])
                    i++;
            }
        }
    }

    while (count1 > 0)
    {
        ans.emplace_back(1);
        count1--;
    }
    while (count2 > 0)
    {
        ans.emplace_back(2);
        count2--;
    }
    for (auto v : ans)
        cout << v << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> findPrimes(int x)
{
    bool isprime[x + 1];
    fill_n(isprime, x + 1, true);
    vector<int> ans;
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= x; i++)
    {
        if (isprime[i])
        {
            for (ll j = i * i; j <= x; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = 0; i <= x; i++)
    {
        if (isprime[i])
            ans.emplace_back(i);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    int count2 = 0, count1 = 0;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 2)
            count2++;
        else
            count1++;
    }

    vector<int> primes = findPrimes(2 * count2 + count1);
    int i = 0, sum = 0;
    vector<int> ans;
    while (count1 > 0&&count2 > 0)
    {
        if (count2 > 0 && (primes[i] - sum) >= 2)
        {
            sum += 2;
            count2--;
            ans.emplace_back(2);
            if(sum==primes[i]) i++;
        }
        else if (count1 > 0 && (primes[i] - sum) >= 1)
        {
            sum += 1;
            count1--;
            ans.emplace_back(1);
            if(sum==primes[i]) i++;
        }
    }
    while(count1>0){
        ans.emplace_back(1); count1--;
    }
    while(count2>0){
        ans.emplace_back(2); count2--;
    }
    for (auto v : ans)
        cout << v << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> findPrimes(int x)
{
    bool isprime[x + 1];
    fill_n(isprime, x + 1, true);
    vector<int> ans;
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= x; i++)
    {
        if (isprime[i])
        {
            for (ll j = i * i; j <= x; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = 0; i <= x; i++)
    {
        if (isprime[i])
            ans.emplace_back(i);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    int count2 = 0, count1 = 0;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 2)
            count2++;
        else
            count1++;
    }

    vector<int> primes = findPrimes(2 * count2 + count1);
    int i = 0, sum = 0;
    vector<int> ans;
    while (count1 > 0&&count2 > 0)
    {
        int diff=primes[i]-sum;
        if (count2 > 0 && diff >= 2)
        {
            int p=diff/2;
            sum += 2*p;
            count2-=p;
            for(int k=0;k<p;k++) ans.emplace_back(2);
            if(sum==primes[i]) i++;
        }
        else if (count1 > 0 && diff >= 1)
        {
            int p=diff;
            sum += p;
            count1-=p;
            for(int k=0;k<p;k++)ans.emplace_back(1);
            if(sum==primes[i]) i++;
        }
    }
    while(count1>0){
        ans.emplace_back(1); count1--;
    }
    while(count2>0){
        ans.emplace_back(2); count2--;
    }
    for (auto v : ans)
        cout << v << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> findPrimes(ll x)
{
    bool isprime[x + 1];
    fill_n(isprime, x + 1, true);
    vector<int> ans;
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= x; i++)
    {
        if (isprime[i])
        {
            for (ll j = i * i; j <= x; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = 0; i <= x; i++)
    {
        if (isprime[i])
            ans.emplace_back(i);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    int count2 = 0, count1 = 0;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 2)
            count2++;
        else
            count1++;
    }
    if(count2!=0&&count1!=0){
        cout<<2<<" "<<1<<" ";
        count2--; count1--;
    }
    while(count2>0){
        cout<<2<<" "; count2--;
    }
    while(count1>0){
        cout<<1<<" "; count1--;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int n,cnt = 0 ;
    cin>>n;
    int ar[n];
    for(int i = 0 ; i< n ; i++){
        cin>>ar[i];
        if(ar[i]==1) cnt+=1;
    }
    sort(ar,ar+n);
    if(cnt!=n && n>1) {
        swap(ar[0],ar[cnt]);
        if(cnt%2==0){
           swap(ar[cnt], ar[n-1]);
        }
    }
    for(int i = 0 ; i<n-1 ; i++)
        cout<<ar[i]<<" "; cout<<ar[n-1]<<endl;

return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int n,on=0,t,tm , fg = 0 ;
    cin>>n;
    tm = n;
    while(tm--){
        cin>>t;
        if(t==1) on+=1;
    }
    tm = n - on;
    if(!(on&1)) {
            fg = 1;
            on-=1;
    }
    if(tm>0){
        cout<<"2";
        if(tm!=n) cout<<" "; else cout<<endl;
        tm-=1;
    }
    for(int i = 1 ; i<on ; i++)  cout<<"1 ";
    if(on==n) cout<<"1"<<endl; else cout<<"1 ";

    for(int i = 1 ; i<tm ; i++) cout<<"2 ";
    if(!fg&&n>1) cout<<"2"<<endl;
    if(fg) cout<<"1"<<endl;

return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int n,on=0,t,tm , fg = 0 ;
    cin>>n;
    tm = n;

    while(tm--){
        cin>>t;
        if(t==1) on+=1;
    }
    if(n==1){
        if(on) cout<<"1"<<endl;
        else cout<<"2"<<endl;
        return 0 ;
    }
    tm = n - on;
    if(!(on&1)) { fg = 1; on-=1; }

    if(tm>0){
        cout<<"2";
        if(tm!=n) cout<<" "; else cout<<endl;
        tm-=1;
    }
    for(int i = 1 ; i<on ; i++)  cout<<"1 ";
    if(on==n) cout<<"1"<<endl; else cout<<"1 ";

    for(int i = 1 ; i<tm ; i++) cout<<"2 ";
    if(!fg&&n>1 ) {if(tm) cout<<"2"<<endl; }else cout<<"1"<<endl;

return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int n,on=0,t,tm , fg = 0 ;
    cin>>n;
    tm = n;

    while(tm--){
        cin>>t;
        if(t==1) on+=1;
    }
    if(n==1){
        if(on) cout<<"1"<<endl;
        else cout<<"2"<<endl;
        return 0 ;
    }
    tm = n - on;
    if(!(on&1)) {
            fg = 1;
            on-=1;
    }
    if(tm>0){
        cout<<"2";
        if(tm!=n) cout<<" "; else cout<<endl;
        tm-=1;
    }
    for(int i = 1 ; i<on ; i++)  cout<<"1 ";
    if(on==n) cout<<"1"<<endl; else cout<<"1 ";

    for(int i = 1 ; i<tm ; i++) cout<<"2 ";
    if(!fg&&n>1) cout<<"2"<<endl; else cout<<"1"<<endl;

return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int n,on=0,t,tm , fg = 0 ;
    cin>>n;
    tm = n;
    while(tm--){
        cin>>t;
        if(t==1) on+=1;
    }
    tm = n - on;
    if(!(on&1)) {
            fg = 1;
            on-=1;
    }
    if(tm>0){
        cout<<"2";
        if(tm!=n) cout<<" "; else cout<<endl;
        tm-=1;
    }
    for(int i = 1 ; i<on ; i++)  cout<<"1 ";
    if(on==n) cout<<"1"<<endl; else cout<<"1 ";

    for(int i = 1 ; i<tm ; i++) cout<<"2 ";
    if(!fg) cout<<"2"<<endl; else cout<<"1"<<endl;

return 0;
}


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

void solve() {
    int n;
    cin >> n;

    int a, b;

    while(n--) {
        int x;
        cin >> x;
        if(x == 1) a++;
        else b++;
    }

    if(a > 0) {
        a--;
        cout << 1 << " ";
    }

    while(b--) {
        cout << 2 <<  " ";
    }

    while(a--) {
        cout << 1 << " ";
    }

    cout << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    //int t;
    //cin>>t;

    //while(t--)
        solve();
}


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

void solve() {
    int n;
    cin >> n;

    int a=0, b=0;

    while(n--) {
        int x;
        cin >> x;
        if(x == 1) a++;
        else b++;
    }

    int d = min(a,b);

    while(d--) {
        a--;
        b--;
        cout << 2 << " " << 1 << " ";
    }

    if(a > 0) {
        while(a--) {
            cout << 1 << " ";
        }
    }
    else {
        while(b--) {
            cout << 2 << " ";
        }
    }
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    //int t;
    //cin>>t;

    //while(t--)
        solve();
}


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

void solve() {
    int n;
    cin >> n;

    int a=0, b=0;

    while(n--) {
        int x;
        cin >> x;
        if(x == 1) a++;
        else b++;
    }

    if(a > 0) {
        a--;
        cout << 1 << " ";
    }

    while(b--) {
        cout << 2 <<  " ";
    }

    while(a--) {
        cout << 1 << " ";
    }

    cout << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    //int t;
    //cin>>t;

    //while(t--)
        solve();
}