#include<iostream>
#include<algorithm>
using namespace std;

int num[100005];

int main() {
	int n;
	cin >> n;
	int odd = 0, even = 0;
	for (int i = 0; i < n; i++) {
		cin >> num[i];
		if (num[i] % 2 == 0)even = 1;
		else odd = 1;
	}
	if (even && odd) {
		sort(num, num + n);
	}
	for (int i = 0; i < n; i++) {
		cout << num[i];
		if (i != n - 1)cout << " ";
		else cout << endl;
	}
	//system("pause");
	return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

typedef long long ll;
ll n, a[100005], odd, even;
int main() {
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		if (a[i] % 2) odd++;
		else even++;
	}
	if (!even || !odd || even == n || odd == n) {
		for (int i = 0; i < n; i++) printf("%lld ", a[i]);
	}
	else {
		sort(a, a + n);
		for (int i = 0; i < n; i++) printf("%lld ", a[i]);
	}
	return 0;
}


#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<list>
#include<cstring>
#include<string>
#include<vector>
#include <set>
#include <sstream>
#include <stack>
#include<bitset>
#include <iostream>
#include<algorithm>
#include<queue>
#include <cmath>
#include <map>
#include <limits>
#include <iomanip>
#include <assert.h>
#define ll unsigned long long
using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int64_t INF = 1<<29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

void cf630()
{
    int n;
    int arr[100001];
    cin>>n;
    REP(i,n)
    {
        cin>>arr[i];
    }
    int minOdd[100001],minEven[100001];
    int minE=INF,minO=INF;
    for(int i=n-1;i>=0;i--)
    {
        if(minE>arr[i] && arr[i]%2==0)
        {
            minE=arr[i];
        }
        minEven[i]=minE;
        if(minO>arr[i] && arr[i]%2==1)
        {
            minO=arr[i];
        }
        minOdd[i]=minO;
    }
    int i;
    bool flag=0;
    int ans;
    for(i=0;i<n;i++)
    {
        if(arr[i]%2==0)
        {
            if(minOdd[i]<arr[i])
                cout<<minOdd[i],flag=1,ans=minOdd[i];
            else
                cout<<arr[i];
        }
        else
        {
            int x=min(minEven[i],minOdd[i]);
            if(x<arr[i])
                cout<<minEven[i],flag=1,ans=x;
            else
                cout<<arr[i];
        }
        if(i!=n-1)
            cout<<" ";
        if(flag)
            break;
    }
    for(int j=i+1;j<n;j++)
    {
        if(flag && ans==arr[j])
        {
            cout<<arr[i];
            flag=0;
        }
        else
            cout<<arr[j];
        if(j!=n-1)
            cout<<" ";
    }
    cout<<endl;
}
int main()
{
    cf630();
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
#define maxn 2147483648+30
using namespace std;
int main(){
	 std::ios::sync_with_stdio(false);
	 ll x,y,i,j,k,a,b,v[100030];
	 while(cin>>x){
	 	a=0;b=0;
	 	for(i=0;i<x;i++){
	 		cin>>v[i];
	 		if(v[i]%2==0)a++;
	 		else b++;
		 }
		 if(a!=0&&b!=0){
		 	sort(v,v+x);
		 }
		  for(i=0;i<x;i++)cout<<v[i]<<" ";cout<<endl;
	 }
}


#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<list>
#include<cstring>
#include<string>
#include<vector>
#include <set>
#include <sstream>
#include <stack>
#include<bitset>
#include <iostream>
#include<algorithm>
#include<queue>
#include <cmath>
#include <map>
#include <limits>
#include <iomanip>
#include <assert.h>
#define ll unsigned long long
using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int64_t INF = 1<<29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

void cf630()
{
    int n;
    int arr[100001];
    cin>>n;
    REP(i,n)
    {
        cin>>arr[i];
    }
    int minOdd[100001],minEven[100001];
    int minE=INF,minO=INF;
    for(int i=n-1;i>=0;i--)
    {
        if(minE>arr[i] && arr[i]%2==0)
        {
            minE=arr[i];
        }
        minEven[i]=minE;
        if(minO>arr[i] && arr[i]%2==1)
        {
            minO=arr[i];
        }
        minOdd[i]=minO;
    }
    int i;
    bool flag=0;
    int ans;
    for(i=0;i<n;i++)
    {
        if(arr[i]%2==0)
        {
            if(minOdd[i]<arr[i])
                cout<<minOdd[i],flag=1,ans=minOdd[i];
            else
                cout<<arr[i];
        }
        else
        {
            if(minEven[i]<arr[i])
                cout<<minEven[i],flag=1,ans=minEven[i];
            else
                cout<<arr[i];
        }
        if(i!=n-1)
            cout<<" ";
        if(flag)
            break;
    }
    for(int j=i+1;j<n;j++)
    {
        if(flag && ans==arr[j])
        {
            cout<<arr[i];
            flag=0;
        }
        else
            cout<<arr[j];
        if(j!=n-1)
            cout<<" ";
    }
    cout<<endl;
}
int main()
{
    cf630();
}


#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<list>
#include<cstring>
#include<string>
#include<vector>
#include <set>
#include <sstream>
#include <stack>
#include<bitset>
#include <iostream>
#include<algorithm>
#include<queue>
#include <cmath>
#include <map>
#include <limits>
#include <iomanip>
#include <assert.h>
#define ll unsigned long long
using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int64_t INF = 1<<29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

void cf630()
{
    int n;
    int arr[100001];
    cin>>n;
    REP(i,n)
    {
        cin>>arr[i];
    }
    int minOdd[100001],minEven[100001];
    int minE=INF,minO=INF;
    for(int i=n-1;i>=0;i--)
    {
        if(minE>arr[i] && arr[i]%2==0)
        {
            minE=arr[i];
        }
        minEven[i]=minE;
        if(minO>arr[i] && arr[i]%2==1)
        {
            minO=arr[i];
        }
        minOdd[i]=minO;
    }
    int i;
    bool flag=0;
    int ans;
    for(i=0;i<n;i++)
    {
        if(arr[i]%2==0)
        {
            if(minOdd[i]<arr[i])
                cout<<minOdd[i],flag=1,ans=minOdd[i];
            else
                cout<<arr[i];
        }
        else
        {
            int x=min(minEven[i],minOdd[i]);
            if(x<arr[i])
                cout<<x,flag=1,ans=x;
            else
                cout<<arr[i];
        }
        if(i!=n-1)
            cout<<" ";
        if(flag)
            break;
    }
    for(int j=i+1;j<n;j++)
    {
        if(flag && ans==arr[j])
        {
            cout<<arr[i];
            flag=0;
        }
        else
            cout<<arr[j];
        if(j!=n-1)
            cout<<" ";
    }
    cout<<endl;
}
int main()
{
    cf630();
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, s1 = 0, s2 = 0;;
	vector<int> a;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int temp;
		cin >> temp;
		if (temp % 2 == 0) { ++s1; }
		else { ++s2; }
		a.push_back(temp);
	}
	if ((s1 != 0) && (s2 != 0)) { sort(a.begin(), a.end()); }
	for (int i = 0; i < n; ++i) { cout << a[i] << ' '; }
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=100005;
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	int cn1=0,cn2=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0)
			cn2++;
		else
			cn1++;
	}
	if(cn1==n||cn2==n){
		for(int i=0;i<n;i++){
			printf("%d",a[i]);
			if(i!=n-1)
				printf(" ");
		}
		printf("\n");
	}
	else{
		sort(a,a+n);
		for(int i=0;i<n;i++){
			printf("%d",a[i]);
			if(i!=n-1)
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <deque>
#include <numeric>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< LL > vl;
typedef vector< vl > vvl;
typedef pair <int, int> ii;
#define tr(c,it) for(decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define in(a,b) ( (b).find(a) != (b).end())

int main() {
	ios::sync_with_stdio(false);

	int n, aa;
	vi a;
	bool o, e;
	o = e = false;

	cin >> n;
	rep(i, n) {
		cin >> aa;
		o |= aa % 2 == 0;
		e |= aa % 2 == 1;
		a.pb(aa);
	}

	if (e && o)
		sort(all(a));

	rep(i, n)
		cout << a[i] << ' ';

}


#include<queue>
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<limits.h>
#include<cstdlib>
#include<algorithm>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int main()
{
	int n,i,x=0,y=0;
	int a[100005];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]%2==0)
			x=1;
		else
			y=1;
	}
	if(x+y==2)
	{
		sort(a,a+n);
		for(i=0;i<n;i++)
			cout<<a[i]<<' ';
		cout<<endl;
	}
	else
	{
		for(i=0;i<n;i++)
			cout<<a[i]<<' ';
		cout<<endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[200005];
int main()
{
    int i,j,m,n,s,w,k,u,v;
    while(~scanf("%d",&n))
    {
        u=0;
        v=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]%2==1)
                u++;
            else
                v++;
        }
        s=min(u,v);
        if(s>=1)
        {
            sort(a,a+n);
            for(i=0;i<n-1;i++)
                printf("%d ",a[i]);
            printf("%d\n",a[n-1]);
        }
        else if(s==0)
        {
            for(i=0;i<n-1;i++)
                printf("%d ",a[i]);
            printf("%d\n",a[n-1]);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[200005];
int main()
{
    int i,j,m,n,s,w,k,u,v;
    while(~scanf("%d",&n))
    {
        u=0;
        v=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]%2==1)
                u++;
            else
                v++;
        }
        s=min(u,v);
        if(s>=2)
        {
            sort(a,a+n);
            for(i=0;i<n-1;i++)
                printf("%d ",a[i]);
            printf("%d\n",a[n-1]);
        }
        else if(s==0)
        {
            for(i=0;i<n-1;i++)
                printf("%d ",a[i]);
            printf("%d\n",a[n-1]);
        }
        else if(s==1)
        {
            if(u==1)
            {
                for(i=0;i<n;i++)
                {
                    if(a[i]%2==1)
                    {
                        w=a[i];
                        k=i;
                        break;
                    }
                }
                for(i=0;i<n;i++)
                {
                    if(a[i]>w&&i<k)
                    {
                        a[k]=a[i];
                        a[i]=w;
                        break;
                    }
                    else if(i>k&&a[i]<w)
                    {
                        a[k]=a[i];
                        a[i]=w;
                        break;
                    }
                }
            }
            else if(v==1)
            {
                for(i=0;i<n;i++)
                {
                    if(a[i]%2==0)
                    {
                        w=a[i];
                        k=i;
                        break;
                    }
                }
                for(i=0;i<n;i++)
                {
                    if(a[i]>w)
                    {
                        a[k]=a[i];
                        a[i]=w;
                        break;
                    }
                     else if(i>k&&a[i]<w)
                    {
                        a[k]=a[i];
                        a[i]=w;
                        break;
                    }
                }
            }
            for(i=0;i<n-1;i++)
                printf("%d ",a[i]);
            printf("%d\n",a[n-1]);
        }
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;
long long a[300000];
long long n;
int main(){
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	bool odd = false, even = false;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0)
			even = true;
		else odd = true;
	}
	if (even && odd) {
		sort(a, a + n);
	}
	for (int i = 0; i < n; i ++)
		cout << a[i] << " ";
	}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;
long long a[300000];
long long n;
int main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	bool odd = false, even = false;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) even = true;
		else odd = true;
		sort(a, a + n);
		cout << a[i] << " ";
	}
	}


#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int *Mas = new int[n];
	for (int i = 0; i < n; i++)
		cin >> Mas[i];
	int mod = Mas[0] % 2;
	bool equal_mod = true;
	for (int i = 1; i < n; i++) {
		if (mod != (Mas[i] % 2)) {
			equal_mod = false;
			break;
		}
	}
	if (equal_mod == false)
		sort(Mas, Mas + n);
	for (int i = 0; i < n; i++)
		cout << Mas[i] << ' ';
	delete[]Mas;
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>

#define ll long long

using namespace std;

int main(void)
{
	int n;

	int i;

	scanf("%d", &n);
	int even = 0;
	int odd = 0;
	vector<int> v;
	for (i = 0; i < n; i++)
	{
		int val;
		scanf("%d", &val);
		if (val % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
		v.push_back(val);
	}

	if (even == 0 || odd == 0 ){
		for (i = 0; i < n; i++)
		{
			printf("%d ", v[i]);
		}
		printf("\n");
		return 0;
	}

	sort(v.begin(), v.end());
	for (i = 0; i < n; i++)
	{
		printf("%d ", v[i]);
	}
	printf("\n");
	return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int Temp;
	int Sum1 = 0, Sum2 = 0;
	int n;
	vector <int> T_Vec;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> Temp;
		T_Vec.push_back(Temp);
	}
	sort(T_Vec.begin(), T_Vec.end());

	for (int i = 0; i < n; i++)
	{
		//if (i != n-1)
		//{
		//	//if ((T_Vec[i] + T_Vec[i + 1]) % 2 != 0)
		//	//	swap(T_Vec[i], T_Vec[i + 1]);
		//}
		//else
		//{
		//	if ((T_Vec[i] + T_Vec[i + 1]) % 2 != 0)
		//		swap(T_Vec[i], T_Vec[i + 1]);
		//}

		cout << T_Vec[i] << " ";
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int Temp;
	int Sum1 = 0, Sum2 = 0;
	int n;
	vector <int> T_Vec;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> Temp;
		T_Vec.push_back(Temp);
		if (Temp % 2 == 0)
			Sum1++;//偶数
	}
	if (Sum1 == n || Sum1 == 0)
	{
		for (int i = 0; i < n; i++)
		{
			cout << T_Vec[i] << " ";
		}
	}
	else
	{
		sort(T_Vec.begin(), T_Vec.end());
		for (int i = 0; i < n; i++)
		{
			cout << T_Vec[i] << " ";
		}
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int Temp;
	int Sum1 = 0, Sum2 = 0;
	int n;
	vector <int> T_Vec;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> Temp;
		T_Vec.push_back(Temp);
	}
	sort(T_Vec.begin(), T_Vec.end());

	for (int i = 0; i < n; i++)
	{
		if ((T_Vec[i] + T_Vec[i + 1]) % 2 != 0)
		//
		//	int p1 = t_array[i + 1];
		//	int p2 = t_array[i];
		//	t_array[i] = p1;
		//	t_array[i + 1] = p2;
		//
		//
			swap(T_Vec[i], T_Vec[i+1]);
		cout << T_Vec[i] << " ";
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	int a[10005];
	while (cin>>n)
	{
		int odd = 0, even = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			if (a[i] % 2 == 0)even = 1;
			else odd = 1;
		}
		if (odd == 1&& even == 1)
		{
			sort(a, a + n);
		}
		for (int i = 0; i < n - 1; i++)
			cout<<a[i]<<" ";
		cout<<a[n-1]<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	int a[10005];
	while (scanf("%d",&n))
	{
		int odd = 0, even = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
			if (a[i] % 2 == 0)even = 1;
			else odd = 1;
		}
		if (odd == 1&& even == 1)
		{
			sort(a, a + n);
		}
		for (int i = 0; i < n - 1; i++)
			printf("%d ",a[i]);
		printf("%d\n",a[n-1]);
	}
	return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	int a[10005];
	while (cin >> n)
	{
		int odd = 0, even = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			if (a[i] % 2 == 0)even = 1;
			else odd = 1;
		}
		if (odd == 0 || even == 0)continue;
		else
		{
			sort(a, a + n);
		}
		for (int i = 0; i < n - 1; i++)
			cout << a[i] << " ";
		cout << a[n - 1] << endl;
	}
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	int a[10005];
	while (scanf("%d",&n))
	{
		int odd = 0, even = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
			if (a[i] % 2 == 0)even = 1;
			else odd = 1;
		}
		if (odd == 0 || even == 0)
		{

		}
		else
		{
			sort(a, a + n);
		}
		for (int i = 0; i < n - 1; i++)
			printf("%d ",a[i]);
		printf("%d\n",a[n-1]);
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[10010], pri[10010], cnt;
bool bok[10010];
int main()
{
	ios::sync_with_stdio(false);
	int n;
	int a[100005];
	while (cin>>n)
	{
		int odd = 0, even = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			if (a[i] % 2 == 0)even = 1;
			else odd = 1;
		}
		if (odd == 1&& even == 1)
		{
			sort(a, a + n);
		}
		for (int i = 0; i < n - 1; i++)
			cout<<a[i]<<" ";
		cout<<a[n-1]<<endl;
	}
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	int a[10005];
	while (cin >> n)
	{
		int odd = 0, even = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			if (a[i] % 2 == 0)even = 1;
			else odd = 1;
		}
		if (odd == 0 || even == 0)
		{

		}
		else
		{
			sort(a, a + n);
		}
		for (int i = 0; i < n - 1; i++)
			cout << a[i] << " ";
		cout << a[n - 1] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

// int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2)) % mod;
		return b * b % mod;
	}
	else
		return (binpow(a, n - 1) * a) % mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int>a(n);
	int cnt = 0;
	bool fl1 = false, fl2 = false;
	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		a[i] = c;
		if (c % 2 == 0 && !fl1)
		{
			cnt++;
			fl1 = true;
		}
		else
			if (!fl2 &&c%2!=0)
			{
				cnt++;
				fl2 = true;
			}
	}
	if(fl1 && fl2)
		sort(a.begin(), a.end());

	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

// int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2)) % mod;
		return b * b % mod;
	}
	else
		return (binpow(a, n - 1) * a) % mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int>a(n);
	int cnt = 0;
	bool fl1 = false, fl2 = false;
	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		a[i] = c;
		if (c % 2 == 0 && !fl1)
		{
			cnt++;
			fl1 = true;
		}
		else
			if (!fl2)
			{
				cnt++;
				fl2 = true;
			}
	}
	if(fl1 && fl2)
		sort(a.begin(), a.end());

	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

// int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2)) % mod;
		return b * b % mod;
	}
	else
		return (binpow(a, n - 1) * a) % mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int>a(n);
	vector<pair<int, int>>b;
	int cnt = 0;
	bool fl1 = false, fl2 = false;
	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		a[i] = c;
		if (c % 2 == 0 && !fl1)
		{
			cnt++;
			fl1 = true;
		}
		else
			if (!fl2)
			{
				cnt++;
				fl2 = true;
			}
	}
	if(cnt==2)
		sort(a.begin(), a.end());

	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

// int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2)) % mod;
		return b * b % mod;
	}
	else
		return (binpow(a, n - 1) * a) % mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

// int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2)) % mod;
		return b * b % mod;
	}
	else
		return (binpow(a, n - 1) * a) % mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int>a(n);
	vector<pair<int, int>>b;
	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		if(c%2==0)
			a[i]=c;
		else
			b.push_back({ c, i});
	}
	sort(b.begin(), b.end());
	int j = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != 0 && a[i]%2==0)
		{
			if (j<b.size() &&a[i] > b[j].first && b[j].second>i)
			{
				a[b[j].second] = a[i];
				a[i] = b[j].first;
				j++;
			}
		}
	}
	for (int i = j; i < b.size(); i++)
	{
		a[b[i].second] = b[i].first;
	}
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

// int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2)) % mod;
		return b * b % mod;
	}
	else
		return (binpow(a, n - 1) * a) % mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int>a(n);
	vector<pair<int, int>>b;
	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		if(c%2==0)
			a[i]=c;
		else
			b.push_back({ c, i});
	}
	sort(b.begin(), b.end());
	int j = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != 0 && a[i]%2==0)
		{
			if (j<b.size() &&a[i] > b[j].first)
			{
				a[b[j].second] = a[i];
				a[i] = b[j].first;
				j++;
			}
		}
	}
	for (int i = j; i < b.size(); i++)
	{
		a[b[i].second] = b[i].first;
	}
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,k;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%2==0)
        ans++;
    }
    if(ans==n)
    {
     for(int i=1;i<=n;i++)
    {
        if(i!=n)
        printf("%d ",a[i]);
        else
        printf("%d\n",a[i]);

    }
    return 0;
    }
     ans=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%2!=0)
        ans++;
    }
    if(ans==n)
    {
         for(int i=1;i<=n;i++)
    {
        if(i!=n)
        printf("%d ",a[i]);
        else
        printf("%d\n",a[i]);

    }
    return 0;
    }
 sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        if(i!=n)
        printf("%d ",a[i]);
        else
        printf("%d\n",a[i]);

    }

    /*for(int i=1;i<n;i++)
    {
        //if(a[i]<a[])
    }*/
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int>a(n);
	bool f1 = false, f2 = false;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		f1 |= (a[i] % 2 == 0);
		f2 |= (a[i] % 2 == 1);
	}
	if (f1 && f2)  sort(a.begin(), a.end());
	for (auto x : a) cout << x << " ";
	return 0;
}


#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	int i;
	long long input;
	vector<long long> arr;
	bool flag[2] = { 0, };

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%lld", &input);

		flag[input % 2] = true;

		arr.push_back(input);
	}

	if (!flag[0] || !flag[1])
	{
		for (i = 0; i < n; i++)
		{
			printf("%lld ", arr[i]);
		}
	}

	else
	{
		sort(arr.begin(), arr.end());

		for (i = 0; i < n; i++)
		{
			printf("%lld ", arr[i]);
		}
	}

	return 0;
}


#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <deque>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>
#include <algorithm>
#include <stdio.h>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

FILE * out = stdout;
FILE * in = stdin;

// Solution

const int MAXN = 100005;

int n, A[MAXN], odds, evens;

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);

        if (A[i] % 2 == 0) {
            evens++;
        } else {
            odds++;
        }
    }

    if (odds * evens == 0) {
        for (int i = 0; i < n; i++) {
            printf("%d ", A[i]);
        }

        printf("\n");

        return 0;
    }

    sort(A, A + n);

    for (int i = 0; i < n; i++) {
        printf("%d ", A[i]);
    }

    printf("\n");

    return 0;
}


#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <deque>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>
#include <algorithm>
#include <stdio.h>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

FILE * out = stdout;
FILE * in = stdin;

// Solution

const int MAXN = 100005;

int n, A[MAXN];

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    sort(A, A + n);

    for (int i = 0; i < n; i++) {
        printf("%d ", A[i]);
    }

    printf("\n");

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> v;

int main() {
	int n; cin >> n;
	bool even = false, odd = false;
	for (int i = 0; i < n; i++) {
		int a; cin >> a; v.push_back(a);
		if (a % 2 == 0) { even = true; continue; }
		odd = true;
	}
	if (even && odd) { sort(v.begin(), v.end()); }
	for (int i = 0; i < n; i++) {
		cout << v[i];
		if (i + 1 != n) { cout << " "; }
		else { cout << endl; }
	}
	cin.ignore(2); return 0;
}


#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int odd = 0;
	int even = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
	}
	if (odd * even == 0) {
		for (int i = 0; i < n; i++) {
			cout << a[i] << " ";
		}
	}
	else {
		sort(a.begin(), a.end());
		for (int i = 0; i < n; i++) {
			cout << a[i] << " ";
		}
	}

}


#include<iostream>
#include<algorithm>

using namespace std;

int A[1000050];

int main() {
	int i, n;
	int F1, F2;
	F1 = F2 = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		if (A[i] % 2) F1 = 1;
		else F2 = 1;
	}
	if (F1 && F2) {
		sort(A, A + n);
	}
	for (i = 0; i < n; i++) {
		printf("%d ", A[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;
#pragma warning(disable:4996)

int A[100050];

int main() {
	int i, n;
	int Min;
	int Min_size;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < n; i++) {
		Min = 1000000050;
		Min_size = -1;
		if (A[i] % 2) {
			for (int j = i + 1; j < n; j++) {
				if (A[j] % 2 == 0 && A[j] < Min && A[j] < A[i]) {
					Min = A[j];
					Min_size = j;
				}
			}
			if (Min_size != -1) {
				swap(A[i], A[Min_size]);
			}
		}
		if (A[i] % 2 == 0) {
			for (int j = i + 1; j < n; j++) {
				if (A[j] % 2 && A[j] < Min && A[j] < A[i]) {
					Min = A[j];
					Min_size = j;
				}
			}
			if (Min_size != -1) {
				swap(A[i], A[Min_size]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d ", A[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int A[1000050];

int main() {
	int i, n;
	int F1, F2;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		if (A[i] % 2) F1 = 1;
		else F2 = 1;
	}
	if (F1 && F2) {
		sort(A, A + n);
	}
	for (i = 0; i < n; i++) {
		printf("%d", A[i]);
	}
	return 0;
}


#include <iostream>

using namespace std;

void print(int* a, int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
}

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    bool ex[2];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        ex[a[i] % 2] = 1;
    }

    if (ex[0] && ex[1]) {
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (a[i] > a[j]) {
                    swap(a[i], a[j]);
                }
            }
        }
    }
    print(a, n);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

void print(vector<ll> a, int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i == n - 1){
            cout << a[i];
        } else {
            cout << a[i] << " ";
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    bool k[2];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        k[a[i] % 2] = 1;
    }

    if (k[0] && k[1]){
        sort(a.begin(), a.end());
    }

    print(a, n);

    return 0;
}


#include <iostream>

using namespace std;

void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void print(int* a, int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
}

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (a[i] > a[j] && (a[i] + a[j]) % 2 != 0)
            {
                swap(a[i], a[j]);
            }
        }
    }
    print(a, n);

    return 0;
}


#include <iostream>

using namespace std;

void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;

}

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int i = 0;
    bool t = true;
    while (t)
    {
        t = false;
        for (int j = 0; j < n - i - 1; j++)
        {
            if (a[j] > a[j + 1] && (a[j] + a[j + 1]) % 2 != 0)
            {
                swap(a[j], a[j+1]);
                t = true;
            }
        }
        i++;
    }

    for (int k = 0; k < n; k++)
    {
        cout << a[k] << " ";
    }

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

void print(int* a, int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
}

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    bool ex[2];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        ex[a[i] % 2] = 1;
    }

    if (ex[0] && ex[1]) {
        sort(a, a + n);
//        for (int i = 0; i < n - 1; i++) {
//            for (int j = i + 1; j < n; j++) {
//                if (a[i] > a[j]) {
//                    swap(a[i], a[j]);
//                }
//            }
//        }
    }
    print(a, n);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<chrono>
#include<random>
#include<cerrno>
#include<cfenv>

typedef long long int lli;
typedef double long dl;
using namespace std;

const int mod = 998244353;
const dl pi = std::acos(-1);

int gcd(int a, int b) {
	if (!b) {
		return a;
	}
	return gcd(b, a % b);
}

int gcdE(int a, int b, int* x, int* y) {
	if (!a) {
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int _gcd = gcdE(b % a, a, &x1, &y1);
	*x = y1 - (b / a) * x1;
	*y = x1;
	return _gcd;
}

lli power(lli x, lli y) {
	lli res = 1;
	while (y) {
		if (y & 1) {
			res = (res * x) % mod;
		}
		y >>= 1;
		x = (x * x) % mod;
	}
	return res;
}

lli inverse(lli x) {
	return power(x, mod - 2);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(16);
	int t;
	t = 1;
	while (t--) {
		int n;
		cin >> n;
		vector<int>a(n);
		int c1 = 0, c2 = 0;
		for (int i = 0; i < n; i += 1) {
			cin >> a[i];
			if (a[i] % 2) {
				c1 = 1;
			}
			else {
				c2 = 1;
			}
		}
		if (c1 & c2) {
			sort(a.begin(), a.end());
		}
		for (int i = 0; i < n; i += 1) {
			cout << a[i] << " ";
		}
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll a[100001],n,odd=0,even=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] & 1) {
			odd++;
		}
		else {
			even++;
		}
	}
	if (odd && even) {
		sort(a, a + n);
	}
		for (int i = 0; i < n; i++) {
			cout << a[i] << ' ';
		}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <iomanip>
#include <map>
#include <fstream>
#include <iterator>
#include <math.h>
#include <queue>
#include <unordered_map>
#define N 100008
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
struct lyrics {
	string line1;
	string line2;
};
struct myp
{
	int end;
	ll val;
};
struct edges {
	int v;
	bool check1;
};
struct mypair {
	string f;
	string s;
};
int dx[5] = { -1,0,0,1,0 };
int dy[5] = { 0,1,-1,0,0 };
int countvowel[100007];
bool used1[100008];
myp storingval[100008];
int cursor[6];
int pow2[20];
int convert(int x)
{
	if (x == 4) return 0;
	if (x == 8) return 1;
	if (x == 15) return 2;
	if (x == 16) return 3;
	if (x == 23) return 4;
	if (x == 42) return 5;
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
ll mypow2(ll n)
{
	ll ans = 1;
	REP(i, 0, n)
		ans *= 2;
	return ans;
}
//bool sorting(myp a, myp b) { return a.f < b.f; };
bool isok(int n, int m, int x, int y, char** a)
{
	if (x >= 0 && x < n && y >= 0 && y < m)
	{
		//if (check1[x][y] == false && a[x][y] != '#')
			return true;
		return false;
	}
	return false;
}
int logbase2(int n)
{
	int ans = n;
	int count = 0;
	while (ans != 1)
	{
		ans /= 2;
		count += 1;
	}
	return count;
}
int gcd(int num, int denum)
{
	if (num == 0)
		return denum;
	else
		return gcd(denum % num, num);
}
int myabs(int a)
{
	if (a >= 0)
		return a;
	else
		return -a;
}
int main()
{
	int n;
	cin >> n;
	int* a;
	a = new int[n];
	bool checkodd = false;
	bool checkeven = false;
	REP(i, 0, n)
	{
		cin >> a[i];
		if (a[i] % 2 == 0)
			checkeven = true;
		else
			checkodd = true;
	}
	if (checkeven == true && checkodd == true)
	{
		sort(a, a + n);
	}
	REP(i, 0, n)
		cout << a[i] << " ";
}


#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long n; cin >> n; int* p; p = new int[n]; long long i = 0, j = 0, k = 0; for (int i = 0; i < n; i++) {
		cin >> p[i]; if (p[i] % 2 == 0) { j++; }if (p[i] % 2 != 0) { k++; }
	}
	if(j==n || k==n){
		for (int i = 0; i < n; i++) { cout << p[i] << " "; }
	}
	else {
		sort(p, p + n);
		for (int i = 0; i < n; i++) { cout << p[i] << " "; }
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long n; cin >> n; int* p; p = new int[n]; long long i = 0, j = 0, k = 0; for (int i = 0; i < n; i++) {
		cin >> p[i]; if (p[i] % 2 == 0) { j++; }if (p[i] % 2 != 0) { k++; }
	}
	if(j==n-1 || k==n-1){
		for (int i = 0; i < n; i++) { cout << p[i] << " "; }
	}
	else {
		sort(p, p + n);
		for (int i = 0; i < n; i++) { cout << p[i] << " "; }
	}
	return 0;
}


//#include "C:\Users\Mohammad\Desktop\97c39f35dab0c45a5d924dd9e50c445f-47ecad34033f986b0972cdbf4636e22f838a1313/stdc++.h"
#include <cstdio>
#include <iostream>
#include<algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <fstream>
#include <stack>
#include<deque>
#include <vector>
#include <set>
#include <map>
#include <iterator>
using namespace std;

//ostream_iterator<int>output(cout, " | ");
//copy(v.begin(), v.end(), output);

/*
#inclue <fstream>

	ifstream infile;
	ofstream outfile;
	infile.open("TextFile1.txt");
	outfile.open("outputFile.txt");
	if (infile.fail() || outfile.fail()) {
		cerr << "Error Opening File" << endl;
		exit(1);
	}
	string s;
	infile >> s;
	outfile << s<< endl;

	freeopen
	*/
	/*
				ifstream infile;
				ofstream outfile;
				infile.open("TextFile1.txt");
				outfile.open("outputFile.txt");
				if (infile.fail() || outfile.fail()) {
					cerr << "Error Opening File" << endl;
					exit(1);
				}
				string s;
				infile >> s;
				outfile << s<< endl;

				*/

#ifndef ONLINE_JUDGE
ofstream fout("output.txt");
#define cout fout
ifstream fin("input.txt");
#define cin fin
#endif // !ONLINE_JUDGE
typedef long long ll;

int main()
{
	ll n;
	cin >> n;
	vector<ll>v;
	for (ll i = 0; i < n; i++)
	{
		ll a;
		cin >> a;
		v.push_back(a);
	}

	for (ll i = 0; i < n; i++)
	{
		for (ll j = i+1; j < n; j++)
		{
			if (v[i] > v[j] &&(v[i] + v[j]) % 2 == 1) {
				ll temp;
				temp = v[i];
				v[i] = v[j];
				v[j] = temp;
			}
		}
	}
	for (ll i = 0; i < n; i++)
	{
		cout<<v[i]<<" ";
	}

	return 0;
}


//#include "C:\Users\Mohammad\Desktop\97c39f35dab0c45a5d924dd9e50c445f-47ecad34033f986b0972cdbf4636e22f838a1313/stdc++.h"
#include <cstdio>
#include <iostream>
#include<algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <fstream>
#include <stack>
#include<deque>
#include <vector>
#include <set>
#include <map>
#include <iterator>
using namespace std;

//ostream_iterator<int>output(cout, " | ");
//copy(v.begin(), v.end(), output);

/*
#inclue <fstream>

	ifstream infile;
	ofstream outfile;
	infile.open("TextFile1.txt");
	outfile.open("outputFile.txt");
	if (infile.fail() || outfile.fail()) {
		cerr << "Error Opening File" << endl;
		exit(1);
	}
	string s;
	infile >> s;
	outfile << s<< endl;

	freeopen
	*/
	/*
				ifstream infile;
				ofstream outfile;
				infile.open("TextFile1.txt");
				outfile.open("outputFile.txt");
				if (infile.fail() || outfile.fail()) {
					cerr << "Error Opening File" << endl;
					exit(1);
				}
				string s;
				infile >> s;
				outfile << s<< endl;

				*/

#ifndef ONLINE_JUDGE
ofstream fout("output.txt");
#define cout fout
ifstream fin("input.txt");
#define cin fin
#endif // !ONLINE_JUDGE
typedef long long ll;

int main()
{
	int n; cin >> n;
	vector<int>v;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		int a; cin >> a;
		v.push_back(a);
		if (a % 2 == 0) {
			count++;
		}
	}
	if (count == n || count == 0) {
		for (int i = 0; i < v.size(); i++)
		{
			cout << v[i] << " ";
		}
	}
	else {
		sort(v.begin(), v.end());
		for (int i = 0; i < v.size(); i++)
		{
			cout << v[i] << " ";
		}
	}

	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<string>
using namespace std;
int main(){
	long long n;
	while(cin>>n){
		long long i,j=0,h=0,g;
		long long a[100005];
		for(i=0;i<n;i++){
			scanf("%lld",&a[i]);
			//cin>>a[i];
			if(a[i]%2==1){
				h++;
			}
			else{
				j++;
			}
		}
		if(h!=0&&j!=0){
			sort(a,a+n);
		}
		for(i=0;i<n;i++){
			cout<<a[i];
			if(i!=n-1){
				cout<<" ";
			}
			else{
				cout<<endl;
			}
		}

	}
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<string>
using namespace std;
int main(){
	long long n;
	while(cin>>n){
		long long i,j=0,h=0,g;
		long long a[2005];
		for(i=0;i<n;i++){
			cin>>a[i];
			if(a[i]%2==1){
				h++;
			}
			else{
				j++;
			}
		}
		if(h!=0&&j!=0){
			sort(a,a+n);
		}
		for(i=0;i<n;i++){
			cout<<a[i];
			if(i!=n-1){
				cout<<" ";
			}
			else{
				cout<<endl;
			}
		}

	}
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector<int> A;

void input()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        A.push_back(x);
    }
}

void solve()
{
    bool odd = false;
    bool even = false;
    for (auto x : A)
    {
        if (x % 2 == 0)
            even = true;
        else
            odd = true;
    }
    if (odd && even)
    {
        sort(A.begin(), A.end());
    }
    for (int i = 0; i < n; ++i)
    {
        if (i != 0)
            cout << " ";
        cout << A[i];
    }
    cout << "\n";
}

int main()
{
    input();
    solve();
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[100010];
int main()
{
	int n,t;
	scanf("%d",&n);
	int sum1=0,sum2=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0)
		sum1++;
		else
		sum2++;
	}
	if(sum1==0||sum2==0)  ;
    else  sort(a,a+n);

	for(int i=0;i<n;i++){
		if(i!=n-1)
		printf("%d ",a[i]);
		else
		printf("%d\n",a[i]);
	}
	return 0;
 }


n, d1, d2, zero_i = int(input()), [], [], None
def f(i, x, m):
	global zero_i
	if not x:
		zero_i = i
		return 20000
	r = 0
	while not x % m:
		r += 1
		x //= m
	return r
def get_path():
	for i in range(1, n):
		d1[i][0] += d1[i - 1][0]
		d2[i][0] += d2[i - 1][0]
		d1[0][i] += d1[0][i - 1]
		d2[0][i] += d2[0][i - 1]
	for i in range(1, n):
		for j in range(1, n):
			d1[i][j] += min(d1[i - 1][j], d1[i][j - 1])
			d2[i][j] += min(d2[i - 1][j], d2[i][j - 1])
	if d1[-1][-1] < d2[-1][-1]:
		return d1[-1][-1], build_path(d1)
	else:
		return d2[-1][-1], build_path(d2)
def build_path(d):
	path = []
	i = j = n - 1
	while i + j:
		if not i or j and d[i][j - 1] < d[i - 1][j]:
			path.append('R')
			j -= 1
		else:
			path.append('D')
			i -= 1
	path.reverse()
	return ''.join(path)
def solve():
	ans, path = get_path()
	if ans < 2 or not zero_i:
		return ans, path
	else:
		return 1, 'D' * zero_i +'R' * (n - 1) +'D' * (n - 1 - zero_i)
def main():
	for i in range(n):
		a = [int(x) for x in input().split()]
		d1.append([f(i,el,2) for el in a])
		d2.append([f(i,el,5) for el in a])

	ans, path=solve()
	print(ans)
	print(path)
if __name__=='__main__':
	main()


n=int(input())
lis2=[]
lis5=[]
liss=[lis2,lis5]
zero_i=None
def flis(i,val,m):
	global zero_i
	if val==0:
		zero_i=i
		return 20000
	r=0
	while val % m==0:
		r+=1
		val//=m
	return r

def get_path():
	for i in range(1,n):
		lis2[i][0]+=lis2[i-1][0]
		lis5[i][0]+=lis5[i-1][0]
	for j in range(1,n):
		lis2[0][j]+=lis2[0][j-1]
		lis5[0][j]+=lis5[0][j-1]

	for i in range(1,n):
		for j in range(1,n):
			lis2[i][j]+=min(lis2[i-1][j],lis2[i][j-1])
			lis5[i][j]+=min(lis5[i-1][j],lis5[i][j-1])
	if lis2[-1][-1] < lis5[-1][-1]:
		return lis2[-1][-1],build_path(lis2)
	else:
		return lis5[-1][-1] , build_path(lis5)
def build_path(lis):
	path=[]
	i=j=n-1
	while i+j:
		if i==0 or not j==0 and lis[i][j-1] < lis[i-1][j]:
			path.append('R')
			j-=1
		else:
			path.append('D')
			i-=1
	path.reverse()
	return ''.join(path)
def solve():
	zero,path=get_path()
	if zero < 2:
		return zero,path
	if zero_i is None:
		return zero,path
	else:
		return 1,'D'*zero_i +'R'*(n-1) +'D'*(n-1-zero_i)
def main():
	for i in range(n):
		l=[int(x) for x in input().split()]
		lis2.append([flis(i,e,2) for e in l])
		lis5.append([flis(i,e,5) for e in l])

	zero,path=solve()
	print(zero)
	print(path)
if __name__=='__main__':
	main()


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1], y = zero_spot[0]
		path += 'R'*x + 'D'*y + 'R'*(n-x) + 'D'*(m-y)
		print(path); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1]; y = zero_spot[0]
		print('R'*x + 'D'*y + 'R'*(n-x) + 'D'*(m-y))
	 	return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(n):
	if n != 0:
		b = (n%2 == 0) or (n%5 == 0); ori_n = n; num_2s = 0; num_5s = 0
		while b:
			if n%2 == 0: num_2s += 1; n = n//2;
			if n%5 == 0: num_5s += 1; n = n//5;
			b = (n%2 == 0) or (n%5 == 0)
		return (num_2s, num_5s, ori_n, ori_n)
	else:
		return (1, 1, n, n)

def grim_reaper(r, d, add):
	res0 = res1 = res2 = res3= 0;
	if r[0] < d[0]:
		res0 = r[0] + add[0]
		res2 = r[2] * add[2]
	elif r[0] == d[0]:
		if r[2] <= d[2]:
			res0 = r[0] + add[0]
			res2 = r[2] * add[2]
		else:
			res0 = d[0] + add[0]
			res2 = d[2] * add[2]
	else:
		res0 = d[0] + add[0]
		res2 = d[2] * add[3]
	if r[1] < d[1]:
		res1 = r[1] + add[1]
		res3 = r[3] * add[3]
	elif r[1] == d[1]:
		if r[2] <= d[2]:
			res1 = r[1] + add[1]
			res3 = r[3] * add[3]
		else:
			res1 = d[1] + add[1]
			res3 = d[3] * add[3]
	else:
		res1 = d[1] + add[1]
		res3 = d[3] * add[3]
	return (res0, res1, res2,res3)

def backtracker(mode, path, m, n):
	if m == 0 or n == 0:
		if m == 0 and n == 0: print(path); return;
		elif m == 0: print('R'*n + path); return;
		else:	print('D'*m + path); return;
	else: # 0 for 2 and 1 for 5
		if arr[m-1][n][mode] <= arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
		else: backtracker(mode, 'R' + path, m-1,n);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero_ex = False
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2]*arr[j][k][2], arr[j][k-1][3]*arr[j][k][3])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2]*arr[j][k][2], arr[j-1][k][3]*arr[j][k][3])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
zero = arr[n-1][n-1][2] * arr[n-1][n-1][3] == 0
if zero:
	print(1)
	if arr[n-1][n-1][2] == 0: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(n):
	if n != 0:
		b = (n%2 == 0) or (n%5 == 0); ori_n = n; num_2s = 0; num_5s = 0
		while b:
			if n%2 == 0: num_2s += 1; n = n//2;
			if n%5 == 0: num_5s += 1; n = n//5;
			b = (n%2 == 0) or (n%5 == 0)
		return (num_2s, num_5s, ori_n, ori_n)
	else:
		return (1, 1, n, n)

def grim_reaper(r, d, add):
	res0 = res1 = res2 = res3= 0;
	if r[0] < d[0]:
		res0 = r[0] + add[0]
		res2 = r[2] * add[2]
	elif r[0] == d[0]:
		if r[2] <= d[2]:
			res0 = r[0] + add[0]
			res2 = r[2] * add[2]
		else:
			res0 = d[0] + add[0]
			res2 = d[2] * add[2]
	else:
		res0 = d[0] + add[0]
		res2 = d[2] * add[3]
	if r[1] < d[1]:
		res1 = r[1] + add[1]
		res3 = r[3] * add[3]
	elif r[1] == d[1]:
		if r[2] <= d[2]:
			res1 = r[1] + add[1]
			res3 = r[3] * add[3]
		else:
			res1 = d[1] + add[1]
			res3 = d[3] * add[3]
	else:
		res1 = d[1] + add[1]
		res3 = d[3] * add[3]
	return (res0, res1, res2,res3)

def backtracker(mode, path, m, n):
	if m == 0 or n == 0:
		if m == 0 and n == 0: print(path); return;
		elif m == 0: print('R'*n + path); return;
		else:	print('D'*m + path); return;
	else: # 0 for 2 and 1 for 5
		if arr[m-1][n][mode] <= arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
		else: backtracker(mode, 'R' + path, m-1,n);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero_ex = False
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2]*arr[j][k][2], arr[j][k-1][3]*arr[j][k][3])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2]*arr[j][k][2], arr[j][k-1][3]*arr[j][k][3])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
zero = arr[n-1][n-1][2] * arr[n-1][n-1][3] == 0
if zero:
	print(1)
	if arr[n-1][n-1][2] == 0: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1], y = zero_spot[0]
		print(('R'*x) + ('D' *y) + ('R'* (n - x)) + ('D'* (n - y))); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(n):
	if n != 0:
		b = (n%2 == 0) or (n%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if n%2 == 0: num_2s += 1; n = n//2;
			if n%5 == 0: num_5s += 1; n = n//5;
			b = (n%2 == 0) or (n%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		zero = True
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n):
	if m == 0 or n == 0:
		if m == 0 and n == 0: print(path); return;
		elif m == 0: print('R'*n + path); return;
		else:	print('D'*m + path); return;
	else: # 0 for 2 and 1 for 5
		if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
		elif arr[m-1][n][mode] == arr[m][n-1][mode]:
			if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
			else: backtracker(mode, 'R' + path, m,n-1);
		else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(0,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[0], y = zero_spot[1]
		path_from_0 = 'R'* (n - x) + 'D'* (n - y)
		path_to_0 = 'R'*(x - 1) + 'D' * (y - 1)
		print(path_to_0 + path_from_0)
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(n):
	if n != 0:
		b = (n%2 == 0) or (n%5 == 0); fac_tup = (0, 0, n); ori_n = n
		while b:
			if n%2 == 0: fac_tup = (fac_tup[0] + 1, fac_tup[1], ori_n); n = n//2;
			if n%5 == 0: fac_tup = (fac_tup[0], fac_tup[1] + 1, ori_n); n = n//5;
			b = (n%2 == 0) or (n%5 == 0)
		return fac_tup
	else:
		return (1, 1, n)

n = int(input())
arr = [[1]]*n
zero_ex = False
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: arr[j][k] = (arr[0][0][0], arr[0][0][1], arr[0][0][2])
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2] * arr[j][k][2])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2] * arr[j][k][2])
		else:
			can_a = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2] * arr[j][k][2])
			can_b = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2] * arr[j][k][2])
			num_pair_a = min(can_a[0], can_a[1]); num_pair_b = min(can_b[0], can_b[1])
			if not zero_ex and (can_a[2] == 0 or can_b[2] == 0): zero_ex = True;
			if num_pair_a == num_pair_b:
				num_unpair_a = max(can_a[0], can_a[1]); num_unpair_b = max(can_b[0], can_b[1])
				if num_unpair_a >= num_unpair_b: arr[j][k] = can_b
				else: arr[j][k] = can_a
			else:
				if num_pair_a > num_pair_b: arr[j][k] = can_b
				else: arr[j][k] = can_a
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if val >= 2: print(1)
else: print(val)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		print(zero_spot)
		x = zero_spot[1]; y = zero_spot[0]
		print(x); print(y)
		path += 'R'*x + 'D'*y + 'R'*(n-x) + 'D'*(m-y)
		print(path); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1], y = zero_spot[0]
		path += 'R'*(n-x) + 'D'*(m-y)
		backtracker(1, path, y,x);
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1]; y = zero_spot[0]
		path += 'R'*x + 'D'*y + 'R'*(n-x) + 'D'*(m-y)
		print(path); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1], y = zero_spot[0]
		print(('R'*x) + ('D' *y) + ('R'* (n - x)) + ('D'* (n - y)) + path); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[0], y = zero_spot[1]
		path_from_0 = 'R'* (n - x) + 'D'* (n - y)
		path_to_0 = 'R'*(x - 1) + 'D' * (y - 1)
		print(path_to_0 + path_from_0); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(n):
	if n != 0:
		b = (n%2 == 0) or (n%5 == 0); fac_tup = (0, 0, n); ori_n = n
		while b:
			if n%2 == 0: fac_tup = (fac_tup[0] + 1, fac_tup[1], ori_n); n = n//2;
			if n%5 == 0: fac_tup = (fac_tup[0], fac_tup[1] + 1, ori_n); n = n//5;
			b = (n%2 == 0) or (n%5 == 0)
		return fac_tup
	else:
		return (1, 1, n)

n = int(input())
arr = [[1]]*n
zero_ex = False
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: arr[j][k] = (arr[0][0][0], arr[0][0][1], '', arr[0][0][2])
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2] + 'R', arr[j][k-1][3] * arr[j][k][2])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2] + 'D', arr[j-1][k][3] * arr[j][k][2])
		else:
			can_a = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2] + 'D', arr[j-1][k][3] * arr[j][k][2]); can_b = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2] + 'R', arr[j][k-1][3] * arr[j][k][2])
			num_pair_a = min(can_a[0], can_a[1]); num_pair_b = min(can_b[0], can_b[1])
			if not zero_ex and (can_a[3] == 0 or can_b[3] == 0): zero_ex = True;
			if num_pair_a == num_pair_b:
				num_unpair_a = max(can_a[0], can_a[1]); num_unpair_b = max(can_b[0], can_b[1])
				if num_unpair_a >= num_unpair_b: arr[j][k] = can_b
				else: arr[j][k] = can_a
			else:
				if num_pair_a > num_pair_b: arr[j][k] = can_b
				else: arr[j][k] = can_a
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if val >= 1 and zero_ex: print(1)
else: print(val)
print(arr[n-1][n-1][2])


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			global n
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		global n
		x = zero_spot[0], y = zero_spot[1]
		path_from_0 = 'R'* (n - 1 - x) + 'D'* (n - 1 - y)
		path_to_0 = 'R'*(x - 1) + 'D' * (y - 1)
		print(path_to_0 + path_from_0)
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(i):
	global num_called
	num_called += 1
	if i != 0:
		b = (i%2 == 0) or (i%5 == 0); num_2s = 0; num_5s = 0
		while b:
			if i%2 == 0: num_2s += 1; i = i//2;
			if i%5 == 0: num_5s += 1; i = i//5;
			b = (i%2 == 0) or (i%5 == 0)
		return (num_2s, num_5s)
	else:
		global zero
		if not zero:
			zero = True
			global zero_spot
			rem = num_called%n
			quot = num_called//n
			if num_called%n == 0:
				zero_spot = (quot - 1, n - 1)
			else:
				zero_spot = (quot, rem - 1)
		return (1, 1)

#needs to choose the one with less 0's.
def grim_reaper(r, d, add):
	if r[0] < d[0]:
		if r[1] < d[1]: return (r[0] + add[0], r[1] + add[1])
		else: return (r[0] + add[0], d[1] + add[1])
	else:
		if r[1] < d[1]: return (d[0] + add[0], r[1] + add[1])
		else: return (d[0] + add[0], d[1] + add[1])

def backtracker(mode, path, m, n): # backtracker now needs to follow the zero in case of zero
	if mode == 2:
		global zero_spot
		x = zero_spot[1]; y = zero_spot[0]
		print('R'*x + 'D'*y + 'R'*(n-x) + 'D'*(m-y)); return;
	else:
		if m == 0 or n == 0:
			if m == 0 and n == 0: print(path); return;
			elif m == 0: print('R'*n + path); return;
			else:	print('D'*m + path); return;
		else: # 0 for 2 and 1 for 5
			if arr[m-1][n][mode] < arr[m][n-1][mode]: backtracker(mode, 'D' + path, m-1,n);
			elif arr[m-1][n][mode] == arr[m][n-1][mode]:
				if arr[m-1][n][(mode + 1)%2] <= arr[m][n-1][(mode + 1)%2]: backtracker(mode, 'D' + path, m-1,n)
				else: backtracker(mode, 'R' + path, m,n-1);
			else: backtracker(mode, 'R' + path, m,n-1);

#first route is for the 2s and second is for the 5s
n = int(input())
arr = [[1]]*n
zero = False
zero_spot = (0, 0)
num_called = 0
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: continue
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1])
		else:
			arr[j][k] = grim_reaper(arr[j][k-1], arr[j-1][k], arr[j][k])
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if zero and val >= 1:
	print(1)
	backtracker(2,'',n-1,n-1)
else:
	print(val)
	if arr[n-1][n-1][0] < arr[n-1][n-1][1]: backtracker(0,'',n-1,n-1)
	else: backtracker(1,'',n-1,n-1)


def sqr_5_converter(n):
	if n != 0:
		b = (n%2 == 0) or (n%5 == 0); fac_tup = (0, 0, n); ori_n = n
		while b:
			if n%2 == 0: fac_tup = (fac_tup[0] + 1, fac_tup[1], ori_n); n = n//2;
			if n%5 == 0: fac_tup = (fac_tup[0], fac_tup[1] + 1, ori_n); n = n//5;
			b = (n%2 == 0) or (n%5 == 0)
		return fac_tup
	else:
		return (1, 1, n)

n = int(input())
arr = [[1]]*n
zero_ex = False
for i in range(n):
	a = list(map(sqr_5_converter, (map(int, input().split()))))
	arr[i] = a
for j in range(n):
	for k in range(n):
		if j == 0 or k == 0:
			if j == 0 and k == 0: arr[j][k] = (arr[0][0][0], arr[0][0][1], arr[0][0][2])
			elif j == 0: arr[j][k] = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2] * arr[j][k][2])
			else: arr[j][k] = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2] * arr[j][k][2])
		else:
			can_a = (arr[j-1][k][0] + arr[j][k][0], arr[j-1][k][1] + arr[j][k][1], arr[j-1][k][2] * arr[j][k][2])
			can_b = (arr[j][k-1][0] + arr[j][k][0], arr[j][k-1][1] + arr[j][k][1], arr[j][k-1][2] * arr[j][k][2])
			num_pair_a = min(can_a[0], can_a[1]); num_pair_b = min(can_b[0], can_b[1])
			if not zero_ex and (can_a[3] == 0 or can_b[3] == 0): zero_ex = True;
			if num_pair_a == num_pair_b:
				num_unpair_a = max(can_a[0], can_a[1]); num_unpair_b = max(can_b[0], can_b[1])
				if num_unpair_a >= num_unpair_b: arr[j][k] = can_b
				else: arr[j][k] = can_a
			else:
				if num_pair_a > num_pair_b: arr[j][k] = can_b
				else: arr[j][k] = can_a
val = min(arr[n-1][n-1][0], arr[n-1][n-1][1])
if val >= 2: print(1)
else: print(val)