#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <map>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;
#include <vector>
#include <string>
#include <list>
#include <map>
#include <utility>
#include <cmath>
#include <algorithm>
#include <sstream>
#include<iostream>
using namespace std;
int T;
int N;

#define MAXN 9999
#define DLEN 4
int const MaxBits = 900 * 4;
int const Bits = 4;
int const MaxLen = MaxBits / Bits + 1;
int const MaxSingle = 10000;

struct BigInt
{
	int Dig[MaxLen];
	int Digs;
	// void operator = (int n);
	void operator = (char *s);
	void operator = (long long n);
	void Print();
};

void BigInt::Print()
{
	printf("%d",Dig[Digs-1]);
	for(int i = Digs-2,tmp; i >= 0; i--)
	{
		tmp = MaxSingle / 10;
		while(tmp > 1)
		{
			if(Dig[i] < tmp)
				printf("0");
			else
				break;
			tmp /= 10;
		}
		printf("%d",Dig[i]);
	}
}

void BigInt::operator = (long long n)
{
	Digs = 0;
	while(n > 0)
	{
		Dig[Digs++] = n % MaxSingle;
		n /= MaxSingle;
	}
	for(int i = Digs; i < MaxLen; i++)
		Dig[i] = 0;
}

void BigInt::operator = (char *StrNum)
{
	int len = strlen(StrNum), tmp;
	Digs = 0;
	for( ; len >= Bits; len -= Bits)
	{
		tmp = 0;
		for(int i = len - Bits; i < len; i++)
			tmp *= 10, tmp += StrNum[i] - '0';
		Dig[Digs++] = tmp;
	}
	if(len == 0)
		return;
	tmp = 0;
	for(int i = 0; i < len; i++)
		tmp *= 10, tmp += StrNum[i] - '0';
	Dig[Digs++] = tmp;
	for(int i = Digs; i < MaxLen; i++)
		Dig[i] = 0;
}

BigInt operator + (BigInt const &a, BigInt const &b)
{
	BigInt c = a;
	int carry(0);
	c.Digs = c.Digs> b.Digs ? b.Digs : c.Digs;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] += b.Dig[i] + carry;
		if(c.Dig[i] >= MaxSingle)
			c.Dig[i] -= MaxSingle, carry = 1;
		else
			carry = 0;
	}
	if(carry > 0)
		c.Dig[c.Digs++] = carry;
	return c;
}

BigInt operator - (BigInt const &a, BigInt const &b)
{   // assume that a > b,  a and b are positive
	BigInt c = a;
	int dec = 0;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] -= b.Dig[i] + dec;
		if(c.Dig[i] < 0)
			c.Dig[i] += MaxSingle, dec = 1;
		else
			dec = 0;
	}
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator * (BigInt const &a, BigInt const &b)
{
	BigInt c;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = 0;
	int carry;
	for(int i = 0; i < a.Digs; i++)
	{
		carry = 0;
		for(int j = 0; j < b.Digs; j++)
		{
			c.Dig[i+j] += a.Dig[i] * b.Dig[j] + carry;
			carry = c.Dig[i+j] / MaxSingle;
			c.Dig[i+j] -= carry * MaxSingle;
		}
		if(carry != 0)
			c.Dig[i+b.Digs] += carry;
	}
	c.Digs = a.Digs + b.Digs;
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator * (BigInt const &a, int const &b)
{
	BigInt c = a;
	for(int i = 0; i < c.Digs; i++)
		c.Dig[i] *= b;
	int carry = 0;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] += carry;
		carry = c.Dig[i] / MaxSingle;
		c.Dig[i] -= carry * MaxSingle;
	}
	while(carry > 0)
		c.Dig[c.Digs++] = carry % MaxSingle, carry /= MaxSingle;
	return c;
}

BigInt operator + (BigInt const &a, int const &b)
{
	BigInt c = a;
	int carry = b;
	for(int i = 0; carry > 0; i++)
	{
		c.Dig[i] += carry;
		carry = c.Dig[i] / MaxSingle;
		c.Dig[i] -= carry * MaxSingle;
		if(i == c.Digs)
			c.Digs++;
	}
	return c;
}

bool operator < (BigInt const &a, BigInt const &b)
{
	if(a.Digs == b.Digs)
		for(int i = a.Digs - 1; i >= 0; i--)
			if(a.Dig[i] != b.Dig[i])
				return a.Dig[i] < b.Dig[i];
	return a.Digs < b.Digs;
}

bool operator == (BigInt const &a, BigInt const &b)
{
	if(a.Digs != b.Digs)
		return false;
	for(int i = 0; i < a.Digs; i++)
		if(a.Dig[i] != b.Dig[i])
			return false;
	return true;
}

BigInt operator / (BigInt const &a, BigInt const &b)
{
	BigInt c,t,m;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = t.Dig[i] = 0;
	t.Digs = 1;
	for(int i = a.Digs - 1; i >= 0; i--)
	{
		t = t * MaxSingle;
		t = t + a.Dig[i];
		int left = 0, right = MaxSingle, mid;
		while(left < right - 1)
		{
			mid = ((left + right)>> 1);
			m = b * mid;
			if(m < t) // m >= t
				left = mid;
			else
				if(m == t)
					left = right = mid;   // exit
				else
					right = mid;
		}
		m = b * left;
		c.Dig[i] = left;
		t = t - m;
	}
	c.Digs = a.Digs;
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator % (BigInt const &a, BigInt const &b)
{
	return a - (a / b) * b;
}

BigInt pow(BigInt const &a, int n)
{
	BigInt c,t;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = 0;
	c.Dig[0] = 1;
	c.Digs = 1;
	t = a;
	while(n > 0)
	{
		if(n & 1)
			c = c * t;
		t = t * t;
		n = (n>>1);
	}
	return c;
}
typedef struct
{
	bool isSell;
	int x;
}MSticks;
typedef struct
{
	int x;
	int p;
}Sell;

vector<int> res;
int n;
MSticks allMS[5010];
Sell allSell[5010];

bool isVisit[5010];
int index[5010];

bool cmp(const Sell &a, const Sell &b)
{
	return a.x > b.x;
}

int main()
{
	//freopen("..\\case.in","r",stdin);
	scanf("%d", &n);
	string t_s;
	int x;
	int num_s = 0;
	for(int i = 0;i < n;i++)
	{
		cin>>t_s>>allMS[i].x;
		if(t_s == "win")
			allMS[i].isSell = false;
		else
		{
			allMS[i].isSell = true;
			allSell[num_s].p = i;
			allSell[num_s++].x = allMS[i].x;
		}
		index[i] = i;
	}

	memset(isVisit, false, sizeof(isVisit));

	sort(allSell, allSell + n, cmp);

	for(int i = 0;i < num_s;i++)
	{
		if(!isVisit[allSell[i].p])
		{
			for(int j = allSell[i].p;j >= 0;j--)
			{
				if(!allMS[j].isSell && !isVisit[j] && allMS[j].x == allMS[allSell[i].p].x)
				{
					for(int k = j;k <= allSell[i].p;k++)
						isVisit[k] = true;
					res.push_back(allMS[j].x);
					break;
				}
			}
		}
	}

	if(res.size() == 0) printf("0\n");
	else
	{
		int all = 0;
		BigInt numRes;
		BigInt numTwo;
		numTwo = 2ll;
		numRes = pow(numTwo, res[0]);

		for(int i = 1;i < res.size();i++)
		{
			numRes = numRes + pow(numTwo, res[i]);
		}
		numRes.Print();
		printf("\n");
	}
	//system("Pause");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <map>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;
#include <vector>
#include <string>
#include <list>
#include <map>
#include <utility>
#include <cmath>
#include <algorithm>
#include <sstream>
#include<iostream>
using namespace std;
int T;
int N;

#define MAXN 9999
#define DLEN 4
int const MaxBits = 900;
int const Bits = 4;
int const MaxLen = MaxBits / Bits + 1;
int const MaxSingle = 10000;

struct BigInt
{
	int Dig[MaxLen];
	int Digs;
	// void operator = (int n);
	void operator = (char *s);
	void operator = (long long n);
	void Print();
};

void BigInt::Print()
{
	printf("%d",Dig[Digs-1]);
	for(int i = Digs-2,tmp; i >= 0; i--)
	{
		tmp = MaxSingle / 10;
		while(tmp > 1)
		{
			if(Dig[i] < tmp)
				printf("0");
			else
				break;
			tmp /= 10;
		}
		printf("%d",Dig[i]);
	}
}

void BigInt::operator = (long long n)
{
	Digs = 0;
	while(n > 0)
	{
		Dig[Digs++] = n % MaxSingle;
		n /= MaxSingle;
	}
	for(int i = Digs; i < MaxLen; i++)
		Dig[i] = 0;
}

void BigInt::operator = (char *StrNum)
{
	int len = strlen(StrNum), tmp;
	Digs = 0;
	for( ; len >= Bits; len -= Bits)
	{
		tmp = 0;
		for(int i = len - Bits; i < len; i++)
			tmp *= 10, tmp += StrNum[i] - '0';
		Dig[Digs++] = tmp;
	}
	if(len == 0)
		return;
	tmp = 0;
	for(int i = 0; i < len; i++)
		tmp *= 10, tmp += StrNum[i] - '0';
	Dig[Digs++] = tmp;
	for(int i = Digs; i < MaxLen; i++)
		Dig[i] = 0;
}

BigInt operator + (BigInt const &a, BigInt const &b)
{
	BigInt c = a;
	int carry(0);
	c.Digs = c.Digs> b.Digs ? b.Digs : c.Digs;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] += b.Dig[i] + carry;
		if(c.Dig[i] >= MaxSingle)
			c.Dig[i] -= MaxSingle, carry = 1;
		else
			carry = 0;
	}
	if(carry > 0)
		c.Dig[c.Digs++] = carry;
	return c;
}

BigInt operator - (BigInt const &a, BigInt const &b)
{   // assume that a > b,  a and b are positive
	BigInt c = a;
	int dec = 0;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] -= b.Dig[i] + dec;
		if(c.Dig[i] < 0)
			c.Dig[i] += MaxSingle, dec = 1;
		else
			dec = 0;
	}
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator * (BigInt const &a, BigInt const &b)
{
	BigInt c;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = 0;
	int carry;
	for(int i = 0; i < a.Digs; i++)
	{
		carry = 0;
		for(int j = 0; j < b.Digs; j++)
		{
			c.Dig[i+j] += a.Dig[i] * b.Dig[j] + carry;
			carry = c.Dig[i+j] / MaxSingle;
			c.Dig[i+j] -= carry * MaxSingle;
		}
		if(carry != 0)
			c.Dig[i+b.Digs] += carry;
	}
	c.Digs = a.Digs + b.Digs;
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator * (BigInt const &a, int const &b)
{
	BigInt c = a;
	for(int i = 0; i < c.Digs; i++)
		c.Dig[i] *= b;
	int carry = 0;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] += carry;
		carry = c.Dig[i] / MaxSingle;
		c.Dig[i] -= carry * MaxSingle;
	}
	while(carry > 0)
		c.Dig[c.Digs++] = carry % MaxSingle, carry /= MaxSingle;
	return c;
}

BigInt operator + (BigInt const &a, int const &b)
{
	BigInt c = a;
	int carry = b;
	for(int i = 0; carry > 0; i++)
	{
		c.Dig[i] += carry;
		carry = c.Dig[i] / MaxSingle;
		c.Dig[i] -= carry * MaxSingle;
		if(i == c.Digs)
			c.Digs++;
	}
	return c;
}

bool operator < (BigInt const &a, BigInt const &b)
{
	if(a.Digs == b.Digs)
		for(int i = a.Digs - 1; i >= 0; i--)
			if(a.Dig[i] != b.Dig[i])
				return a.Dig[i] < b.Dig[i];
	return a.Digs < b.Digs;
}

bool operator == (BigInt const &a, BigInt const &b)
{
	if(a.Digs != b.Digs)
		return false;
	for(int i = 0; i < a.Digs; i++)
		if(a.Dig[i] != b.Dig[i])
			return false;
	return true;
}

BigInt operator / (BigInt const &a, BigInt const &b)
{
	BigInt c,t,m;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = t.Dig[i] = 0;
	t.Digs = 1;
	for(int i = a.Digs - 1; i >= 0; i--)
	{
		t = t * MaxSingle;
		t = t + a.Dig[i];
		int left = 0, right = MaxSingle, mid;
		while(left < right - 1)
		{
			mid = ((left + right)>> 1);
			m = b * mid;
			if(m < t) // m >= t
				left = mid;
			else
				if(m == t)
					left = right = mid;   // exit
				else
					right = mid;
		}
		m = b * left;
		c.Dig[i] = left;
		t = t - m;
	}
	c.Digs = a.Digs;
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator % (BigInt const &a, BigInt const &b)
{
	return a - (a / b) * b;
}

BigInt pow(BigInt const &a, int n)
{
	BigInt c,t;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = 0;
	c.Dig[0] = 1;
	c.Digs = 1;
	t = a;
	while(n > 0)
	{
		if(n & 1)
			c = c * t;
		t = t * t;
		n = (n>>1);
	}
	return c;
}
typedef struct
{
	bool isSell;
	int x;
}MSticks;
typedef struct
{
	int x;
	int p;
}Sell;

vector<int> res;
int n;
MSticks allMS[5010];
Sell allSell[5010];

bool isVisit[5010];
int index[5010];

bool cmp(const Sell &a, const Sell &b)
{
	return a.x > b.x;
}

int main()
{
	//freopen("..\\case.in","r",stdin);
	scanf("%d", &n);
	string t_s;
	int x;
	int num_s = 0;
	for(int i = 0;i < n;i++)
	{
		cin>>t_s>>allMS[i].x;
		if(t_s == "win")
			allMS[i].isSell = false;
		else
		{
			allMS[i].isSell = true;
			allSell[num_s].p = i;
			allSell[num_s++].x = allMS[i].x;
		}
		index[i] = i;
	}

	memset(isVisit, false, sizeof(isVisit));

	sort(allSell, allSell + n, cmp);

	for(int i = 0;i < num_s;i++)
	{
		if(!isVisit[allSell[i].p])
		{
			for(int j = allSell[i].p;j >= 0;j--)
			{
				if(!allMS[j].isSell && !isVisit[j] && allMS[j].x == allMS[allSell[i].p].x)
				{
					for(int k = j;k <= allSell[i].p;k++)
						isVisit[k] = true;
					res.push_back(allMS[j].x);
					break;
				}
			}
		}
	}

	if(res.size() == 0) printf("0\n");
	else
	{
		int all = 0;
		BigInt numRes;
		numRes = 1ll;
		numRes = numRes - numRes;
		BigInt numTwo;
		numTwo = 2ll;
		for(int i = 0;i < res.size();i++)
		{
			numRes = numRes + pow(numTwo, res[i]);
		}
		numRes.Print();
		printf("\n");
	}
	//system("Pause");
	return 0;
}


#include <cstdio>
#include <cstring>

#include <vector>
#include <string>
#include <algorithm>

using namespace std;

string dp[5001];
int win[2001];
int n;

string pow2[2001];

void multi2( string &ress , const string &p ){

	int flag = 0;
	ress = "";
	for( int i = 0 ; i < p.size() ; i ++ ){
		ress += ( ( p[i] - '0' ) * 2 + flag ) % 10 + '0';
		flag = ( ( p[i] - '0' ) * 2 + flag ) / 10;
	}

	if( flag )
		ress += '1';

	int pos = ress.size() - 1;
	for( ; pos >= 0 && ress[pos] == '0' ; pos -- );
	ress = ress.substr( 0 , pos + 1 );

	if( ress == "" )
		ress = "0";

	return;
}

void initPow2( void ){

	pow2[0] = "1";
	for( int i = 1; i <= 2000 ; i ++ )
		multi2( pow2[i] , pow2[i-1] );

	return;
}

void add( string &ress , string num ){

	while( ress.size() < num.size() )
		ress += '0';

	while( num.size() < ress.size() )
		num += '0';

	int flag = 0;
	for( int i = 0 ; i < ress.size() ; i ++ ){
		ress[i] = ( ress[i] - '0' + num[i] - '0' + flag ) % 10 + '0';
		flag = ( ress[i] - '0' + num[i] - '0' + flag ) / 10;
	}

	if( flag )
		ress += '1';

	int pos = ress.size() - 1;
	for( ; pos >= 0 && ress[pos] == '0' ; pos -- );
	ress = ress.substr( 0 , pos + 1 );

	if( ress == "" )
		ress = "0";

	return;
}

bool larger( const string &str1 , const string &str2 ){

	if( str1.size() > str2.size() )
		return true;

	if( str1.size() < str2.size() )
		return false;

	for( int i = str1.size() - 1 ; i >= 0 ; i -- )
		if( str1[i] > str2[i] )
			return true;

	return false;
}

int main( void ){

	char enter;
	char input[10];
	int t;

	dp[0] = "0";
	initPow2();
	memset( win , -1 ,sizeof( win ) );

	scanf("%d%c",&n,&enter);
	for( int i = 1 ; i <= n ; i ++ ){
		scanf("%s%c%d%c",input,&enter,&t,&enter);

		if( input[0] == 'w' ){
			win[ t ] = i;
			dp[i] = dp[i-1];
		}
		else{

			if( win[t] != -1 ){
				string temp = pow2[ t ];
				add( temp , dp[ win[t]-1 ] );

				if( larger( temp , dp[i] ) )
					dp[i] = temp;
				else
					dp[i] = dp[i-1];
			}
			else
				dp[i] = dp[i-1];
		}
	}

	reverse( dp[n].begin() , dp[n].end() );
	printf("%s\n",dp[n].c_str());

	//system("pause");

	return 0;
}


#include <cstdio>
#include <cstring>

#include <vector>
#include <string>
#include <algorithm>

using namespace std;

string dp[5010];
int win[2010];
int n;

string pow2[2010];

void multi2( string &ress , const string &p ){

	int flag = 0;
	ress = "";
	for( int i = 0 ; i < p.size() ; i ++ ){
		ress += ( ( p[i] - '0' ) * 2 + flag ) % 10 + '0';
		flag = ( ( p[i] - '0' ) * 2 + flag ) / 10;
	}

	if( flag )
		ress += '1';

	int pos = ress.size() - 1;
	for( ; pos >= 0 && ress[pos] == '0' ; pos -- );
	ress = ress.substr( 0 , pos + 1 );

	if( ress == "" )
		ress = "0";

	return;
}

void initPow2( void ){

	pow2[0] = "1";
	for( int i = 1; i <= 2000 ; i ++ )
		multi2( pow2[i] , pow2[i-1] );

	return;
}

void add( string &ress , string num ){

	while( ress.size() < num.size() )
		ress += '0';

	while( num.size() < ress.size() )
		num += '0';

	int flag = 0;
	for( int i = 0 ; i < ress.size() ; i ++ ){
		ress[i] = ( ress[i] - '0' + num[i] - '0' + flag ) % 10 + '0';
		flag = ( ress[i] - '0' + num[i] - '0' + flag ) / 10;
	}

	if( flag )
		ress += '1';

	int pos = ress.size() - 1;
	for( ; pos >= 0 && ress[pos] == '0' ; pos -- );
	ress = ress.substr( 0 , pos + 1 );

	if( ress == "" )
		ress = "0";

	return;
}

bool larger( const string &str1 , const string &str2 ){

	if( str1.size() > str2.size() )
		return true;

	if( str1.size() < str2.size() )
		return false;

	for( int i = str1.size() - 1 ; i >= 0 ; i -- )
		if( str1[i] > str2[i] )
			return true;

	return false;
}

int main( void ){

	char enter;
	char input[10];
	int t;

	dp[0] = "0";
	initPow2();
	memset( win , -1 ,sizeof( win ) );

	scanf("%d%c",&n,&enter);
	for( int i = 1 ; i <= n ; i ++ ){
		scanf("%s%c%d%c",input,&enter,&t,&enter);

		if( input[0] == 'w' ){
			win[ t ] = i;
			dp[i] = dp[i-1];
		}
		else{

			if( win[t] != -1 ){
				string temp = pow2[ t ];
				add( temp , dp[ win[t]-1 ] );

				if( larger( temp , dp[i-1] ) )
					dp[i] = temp;
				else
					dp[i] = dp[i-1];
			}
			else
				dp[i] = dp[i-1];
		}
	}

	reverse( dp[n].begin() , dp[n].end() );
	printf("%s\n",dp[n].c_str());

	//system("pause");

	return 0;
}


#include <cstdio>
#include <cstring>

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

string dp[5010];
int win[2010];
int n;

string pow2[2010];

void multi2( string &ress , const string &p ){

	int flag = 0;
	ress = "";
	for( int i = 0 ; i < p.size() ; i ++ ){
		ress += ( ( p[i] - '0' ) * 2 + flag ) % 10 + '0';
		flag = ( ( p[i] - '0' ) * 2 + flag ) / 10;
	}

	if( flag )
		ress += '1';

	int pos = ress.size() - 1;
	for( ; pos >= 0 && ress[pos] == '0' ; pos -- );
	ress = ress.substr( 0 , pos + 1 );

	if( ress == "" )
		ress = "0";

	return;
}
void add( string &ress , string num ){

	while( ress.size() < num.size() )
		ress += '0';

	while( num.size() < ress.size() )
		num += '0';

	int flag = 0;
	for( int i = 0 ; i < ress.size() ; i ++ ){
		char tRes = ( ress[i] - '0' + num[i] - '0' + flag ) % 10 + '0';
		flag = ( ress[i] - '0' + num[i] - '0' + flag ) / 10;

		ress[i] = tRes;

	}

	if( flag )
		ress += '1';

	int pos = ress.size() - 1;
	for( ; pos >= 0 && ress[pos] == '0' ; pos -- );
	ress = ress.substr( 0 , pos + 1 );

	if( ress == "" )
		ress = "0";

	return;
}
void initPow2( void ){

	pow2[0] = "1";
	for( int i = 1; i <= 2000 ; i ++ )
		multi2( pow2[i] , pow2[i-1] );
	return;
}

bool larger( const string &str1 , const string &str2 ){

	if( str1.size() > str2.size() )
		return true;

	if( str1.size() < str2.size() )
		return false;

	for( int i = str1.size() - 1 ; i >= 0 ; i -- )
	{
		if( str1[i] > str2[i] )
			return true;
		if( str1[i] < str2[i] )
			return false;
	}

	return false;
}

int main( void ){

	//freopen("..\\case.in","r",stdin);
	char enter;
	char input[10];
	int t;

	dp[0] = "0";
	initPow2();
	memset( win , -1 ,sizeof( win ) );

	scanf("%d%c",&n,&enter);
	for( int i = 1 ; i <= n ; i ++ ){
		scanf("%s%c%d%c",input,&enter,&t,&enter);

		if( input[0] == 'w' ){
			win[ t ] = i;
			dp[i] = dp[i-1];
		}
		else{
			if( win[t] != -1 ){
				string temp = pow2[ t ];
				add( temp , dp[ win[t]-1 ] );

				if( larger( temp , dp[i-1] ) )
					dp[i] = temp;
				else
					dp[i] = dp[i-1];
			}
			else
				dp[i] = dp[i-1];

		}
		//cout<<i<<"##"<<dp[i]<<endl;
	}

	reverse( dp[n].begin() , dp[n].end() );
	printf("%s\n",dp[n].c_str());

	//system("pause");

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <map>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;
#include <vector>
#include <string>
#include <list>
#include <map>
#include <utility>
#include <cmath>
#include <algorithm>
#include <sstream>
#include<iostream>
using namespace std;
int T;
int N;

#define MAXN 9999
#define DLEN 4
int const MaxBits = 900 * 4;
int const Bits = 4;
int const MaxLen = MaxBits / Bits + 1;
int const MaxSingle = 10000;

struct BigInt
{
	int Dig[MaxLen];
	int Digs;
	// void operator = (int n);
	void operator = (char *s);
	void operator = (long long n);
	void Print();
};

void BigInt::Print()
{
	printf("%d",Dig[Digs-1]);
	for(int i = Digs-2,tmp; i >= 0; i--)
	{
		tmp = MaxSingle / 10;
		while(tmp > 1)
		{
			if(Dig[i] < tmp)
				printf("0");
			else
				break;
			tmp /= 10;
		}
		printf("%d",Dig[i]);
	}
}

void BigInt::operator = (long long n)
{
	Digs = 0;
	while(n > 0)
	{
		Dig[Digs++] = n % MaxSingle;
		n /= MaxSingle;
	}
	for(int i = Digs; i < MaxLen; i++)
		Dig[i] = 0;
}

void BigInt::operator = (char *StrNum)
{
	int len = strlen(StrNum), tmp;
	Digs = 0;
	for( ; len >= Bits; len -= Bits)
	{
		tmp = 0;
		for(int i = len - Bits; i < len; i++)
			tmp *= 10, tmp += StrNum[i] - '0';
		Dig[Digs++] = tmp;
	}
	if(len == 0)
		return;
	tmp = 0;
	for(int i = 0; i < len; i++)
		tmp *= 10, tmp += StrNum[i] - '0';
	Dig[Digs++] = tmp;
	for(int i = Digs; i < MaxLen; i++)
		Dig[i] = 0;
}

BigInt operator + (BigInt const &a, BigInt const &b)
{
	BigInt c = a;
	int carry(0);
	c.Digs = c.Digs> b.Digs ? b.Digs : c.Digs;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] += b.Dig[i] + carry;
		if(c.Dig[i] >= MaxSingle)
			c.Dig[i] -= MaxSingle, carry = 1;
		else
			carry = 0;
	}
	if(carry > 0)
		c.Dig[c.Digs++] = carry;
	return c;
}

BigInt operator - (BigInt const &a, BigInt const &b)
{   // assume that a > b,  a and b are positive
	BigInt c = a;
	int dec = 0;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] -= b.Dig[i] + dec;
		if(c.Dig[i] < 0)
			c.Dig[i] += MaxSingle, dec = 1;
		else
			dec = 0;
	}
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator * (BigInt const &a, BigInt const &b)
{
	BigInt c;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = 0;
	int carry;
	for(int i = 0; i < a.Digs; i++)
	{
		carry = 0;
		for(int j = 0; j < b.Digs; j++)
		{
			c.Dig[i+j] += a.Dig[i] * b.Dig[j] + carry;
			carry = c.Dig[i+j] / MaxSingle;
			c.Dig[i+j] -= carry * MaxSingle;
		}
		if(carry != 0)
			c.Dig[i+b.Digs] += carry;
	}
	c.Digs = a.Digs + b.Digs;
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator * (BigInt const &a, int const &b)
{
	BigInt c = a;
	for(int i = 0; i < c.Digs; i++)
		c.Dig[i] *= b;
	int carry = 0;
	for(int i = 0; i < c.Digs; i++)
	{
		c.Dig[i] += carry;
		carry = c.Dig[i] / MaxSingle;
		c.Dig[i] -= carry * MaxSingle;
	}
	while(carry > 0)
		c.Dig[c.Digs++] = carry % MaxSingle, carry /= MaxSingle;
	return c;
}

BigInt operator + (BigInt const &a, int const &b)
{
	BigInt c = a;
	int carry = b;
	for(int i = 0; carry > 0; i++)
	{
		c.Dig[i] += carry;
		carry = c.Dig[i] / MaxSingle;
		c.Dig[i] -= carry * MaxSingle;
		if(i == c.Digs)
			c.Digs++;
	}
	return c;
}

bool operator < (BigInt const &a, BigInt const &b)
{
	if(a.Digs == b.Digs)
		for(int i = a.Digs - 1; i >= 0; i--)
			if(a.Dig[i] != b.Dig[i])
				return a.Dig[i] < b.Dig[i];
	return a.Digs < b.Digs;
}

bool operator == (BigInt const &a, BigInt const &b)
{
	if(a.Digs != b.Digs)
		return false;
	for(int i = 0; i < a.Digs; i++)
		if(a.Dig[i] != b.Dig[i])
			return false;
	return true;
}

BigInt operator / (BigInt const &a, BigInt const &b)
{
	BigInt c,t,m;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = t.Dig[i] = 0;
	t.Digs = 1;
	for(int i = a.Digs - 1; i >= 0; i--)
	{
		t = t * MaxSingle;
		t = t + a.Dig[i];
		int left = 0, right = MaxSingle, mid;
		while(left < right - 1)
		{
			mid = ((left + right)>> 1);
			m = b * mid;
			if(m < t) // m >= t
				left = mid;
			else
				if(m == t)
					left = right = mid;   // exit
				else
					right = mid;
		}
		m = b * left;
		c.Dig[i] = left;
		t = t - m;
	}
	c.Digs = a.Digs;
	while(c.Digs > 1 && c.Dig[c.Digs-1] == 0)
		c.Digs--;
	return c;
}

BigInt operator % (BigInt const &a, BigInt const &b)
{
	return a - (a / b) * b;
}

BigInt pow(BigInt const &a, int n)
{
	BigInt c,t;
	for(int i = 0; i < MaxLen; i++)
		c.Dig[i] = 0;
	c.Dig[0] = 1;
	c.Digs = 1;
	t = a;
	while(n > 0)
	{
		if(n & 1)
			c = c * t;
		t = t * t;
		n = (n>>1);
	}
	return c;
}
typedef struct
{
	bool isSell;
	int x;
}MSticks;
typedef struct
{
	int x;
	int p;
}Sell;

vector<int> res;
int n;
MSticks allMS[5010];
Sell allSell[5010];

bool isVisit[5010];
int index[5010];
int dp[5010];
vector< vector<int> > everyRes;

bool cmp(const Sell &a, const Sell &b)
{
	return a.x > b.x;
}

int main()
{
	//freopen("..\\case.in","r",stdin);
	scanf("%d", &n);
	string t_s;
	int x;
	int num_s = 0;
	for(int i = 0;i < n;i++)
	{
		cin>>t_s>>allMS[i].x;
		if(t_s == "win")
			allMS[i].isSell = false;
		else
		{
			allMS[i].isSell = true;
		}
		//index[i] = i;
	}

	/*memset(isVisit, false, sizeof(isVisit));

	sort(allSell, allSell + n, cmp);

	for(int i = 0;i < num_s;i++)
	{
		if(!isVisit[allSell[i].p])
		{
			for(int j = allSell[i].p;j >= 0;j--)
			{
				if(!allMS[j].isSell && !isVisit[j] && allMS[j].x == allMS[allSell[i].p].x)
				{
					for(int k = j;k <= allSell[i].p;k++)
						isVisit[k] = true;
					res.push_back(allMS[j].x);
					break;
				}
			}
		}
	}*/
	for(int i = 0;i < n;i++)
	{
		vector<int> t;
		everyRes.push_back(t);
	}
	dp[0] = 0;
	for(int i = 1;i < n;i++)
	{
		dp[i] = dp[i - 1];
		everyRes[i] = everyRes[i - 1];
		for(int j = 0;j < i;j++)
		{
			if(allMS[i].isSell && !allMS[j].isSell && allMS[i].x == allMS[j].x)
			{
				if(dp[j] + allMS[j].x > dp[i])
				{
					dp[i] = dp[j] + allMS[j].x;
					everyRes[i] = everyRes[j];
					everyRes[i].push_back(allMS[j].x);
				}
			}
		}
	}

	if(everyRes[n - 1].size() == 0) printf("0\n");
	else
	{
		int all = 0;
		BigInt numRes;
		BigInt numTwo;
		numTwo = 2ll;
		numRes = pow(numTwo, everyRes[n - 1][0]);

		for(int i = 1;i < everyRes[n - 1].size();i++)
		{
			numRes = numRes + pow(numTwo, everyRes[n - 1][i]);
		}
		numRes.Print();
		printf("\n");
	}
	//system("Pause");
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
#define pb push_back
#define ppb pop_back
#define pi 3.1415926535897932384626433832795028841971
#define mp make_pair
#define x first
#define y second
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pii pair<int,int>
#define pdd pair<double,double>
#define INF 1000000000
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define VI vector <int>
#define ll long long
int a,b,c,d,i,j,n,m,k;
vector <pii> act;
char str[101];
bool u[5001];
vector<pii> s(0);
bool bit[2001];
const int LN=2000;
class lng
{
public:
	int n[LN+1];
	inline void tol(int a)
	{
		C(n); n[0]=1; n[LN]=a;
	}
};
inline lng operator +(const lng &a,const lng &b)
{
	lng res; C(res.n);
	int len=max(a.n[0],b.n[0]);
	FORD(i,LN,LN-len+1)
	{
		int m=res.n[i]+a.n[i]+b.n[i];
		res.n[i]=m%10000; res.n[i-1]=m/10000;
	}
	(res.n[LN-len]!=0)?res.n[0]=len+1:res.n[0]=len;
	return res;
}
lng ans,cur;
inline void out(const lng &a)
{
	FOR(i,LN-a.n[0]+1,LN)
	{
		if (i==LN-a.n[0]+1) printf("%d",a.n[i]); else
		if (a.n[i]<10) printf("000%d",a.n[i]); else
		if (a.n[i]<100) printf("00%d",a.n[i]); else
		if (a.n[i]<1000) printf("0%d",a.n[i]); else
		printf("%d",a.n[i]);
	}
	printf("\n");
}
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	scanf("%d",&n);
	rept(i,n)
	{
		scanf("%s%d",str,&a);
		if (str[0]=='w') act.pb(mp(1,a)); else
		act.pb(mp(-1,a));
		if (str[0]=='s') s.pb(mp(a,i));
	}
	SORT(s); reverse(all(s));
	rept(i,L(s))
	{
		a=INF;
		FORD(j,s[i].y,0)
		{
			if (u[j]) continue;
			if (act[j].x==1 && act[j].y==s[i].x)
			{
				a=j;
				break;
			}
		}
		if (a==INF) continue;
		FOR(z,a,s[i].y) u[z]=1;
		bit[s[i].x]=1;
	}
	ans.tol(0);
	cur.tol(1);
	rept(i,2001)
	{
		if (bit[i]) ans=ans+cur;
		cur=cur+cur;
	}
	out(ans);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
#define pb push_back
#define ppb pop_back
#define pi 3.1415926535897932384626433832795028841971
#define mp make_pair
#define x first
#define y second
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pii pair<int,int>
#define pdd pair<double,double>
#define INF 1000000000
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define VI vector <int>
#define ll long long
int a,b,c,d,i,j,n,m,k;
vector <pii> act;
char str[101];
bool u[5001];
vector<pii> s(0);
bool bit[2001];
const int LN=2000;
class lng
{
public:
	int n[LN+1];
	inline void tol(int a)
	{
		C(n); n[0]=1; n[LN]=a;
	}
};
inline lng operator +(const lng &a,const lng &b)
{
	lng res; C(res.n);
	int len=max(a.n[0],b.n[0]);
	FORD(i,LN,LN-len+1)
	{
		int m=res.n[i]+a.n[i]+b.n[i];
		res.n[i]=m%10000; res.n[i-1]=m/10000;
	}
	(res.n[LN-len]!=0)?res.n[0]=len+1:res.n[0]=len;
	return res;
}
lng ans,cur;
inline void out(const lng &a)
{
	FOR(i,LN-a.n[0]+1,LN)
	{
		if (i==LN-a.n[0]+1) printf("%d",a.n[i]); else
		if (a.n[i]<10) printf("000%d",a.n[i]); else
		if (a.n[i]<100) printf("00%d",a.n[i]); else
		if (a.n[i]<1000) printf("0%d",a.n[i]); else
		printf("%d",a.n[i]);
	}
	printf("\n");
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d",&n);
	rept(i,n)
	{
		scanf("%s%d",str,&a);
		if (str[0]=='w') act.pb(mp(1,a)); else
		act.pb(mp(-1,a));
		if (str[0]=='s') s.pb(mp(a,i));
	}
	SORT(s); reverse(all(s));
	rept(i,L(s))
	{
		a=INF;
		FORD(j,s[i].y,0)
		{
			if (u[j]) break;
			if (act[j].x==1 && act[j].y==s[i].x)
			{
				a=j;
				break;
			}
		}
		if (a==INF) continue;
		FOR(z,a,s[i].y) u[z]=1;
		bit[s[i].x]=1;
	}
	ans.tol(0);
	cur.tol(1);
	rept(i,2001)
	{
		if (bit[i]) ans=ans+cur;
		cur=cur+cur;
	}
	out(ans);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
#define pb push_back
#define ppb pop_back
#define pi 3.1415926535897932384626433832795028841971
#define mp make_pair
#define x first
#define y second
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pii pair<int,int>
#define pdd pair<double,double>
#define INF 1000000000
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define VI vector <int>
#define ll long long
int a,b,c,d,i,j,n,m,k;
vector <pii> act;
char str[101];
bool u[5001];
vector<pii> s(0);
bool bit[2001];
const int LN=2000;
class lng
{
public:
	int n[LN+1];
	inline void tol(int a)
	{
		C(n); n[0]=1; n[LN]=a;
	}
};
inline lng operator +(const lng &a,const lng &b)
{
	lng res; C(res.n);
	int len=max(a.n[0],b.n[0]);
	FORD(i,LN,LN-len+1)
	{
		int m=res.n[i]+a.n[i]+b.n[i];
		res.n[i]=m%10000; res.n[i-1]=m/10000;
	}
	(res.n[LN-len]!=0)?res.n[0]=len+1:res.n[0]=len;
	return res;
}
lng ans,cur;
inline void out(const lng &a)
{
	FOR(i,LN-a.n[0]+1,LN)
	{
		if (i==LN-a.n[0]+1) printf("%d",a.n[i]); else
		if (a.n[i]<10) printf("000%d",a.n[i]); else
		if (a.n[i]<100) printf("00%d",a.n[i]); else
		if (a.n[i]<1000) printf("0%d",a.n[i]); else
		printf("%d",a.n[i]);
	}
	printf("\n");
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d",&n);
	rept(i,n)
	{
		scanf("%s%d",str,&a);
		if (str[0]=='w') act.pb(mp(1,a)); else
		act.pb(mp(-1,a));
		if (str[0]=='s') s.pb(mp(a,i));
	}
	SORT(s); reverse(all(s));
	rept(i,L(s))
	{
		a=INF;
		if (u[s[i].y]) continue;
		FORD(j,s[i].y,0)
		{
			if (u[j]) continue;
			if (act[j].x==1 && act[j].y==s[i].x)
			{
				a=j;
				break;
			}
		}
		if (a==INF) continue;
		FOR(z,a,s[i].y) u[z]=1;
		bit[s[i].x]=1;
	}
	ans.tol(0);
	cur.tol(1);
	rept(i,2001)
	{
		if (bit[i]) ans=ans+cur;
		cur=cur+cur;
	}
	out(ans);
}


#include <iostream>

using namespace std;

#define ll long long

int n;
int w[5001];

ll dp(int *w, int begin, int end)
{
	if (begin < 0 || end >= n)
	{
		return 0;
	}
	ll res = 0;
	int L, R;
	for (int i = begin; i <= end; i++)
	{
		ll tmp = 0;
		if (w[i] < 0)
		{
			bool flag = 0;
			int k = i - 1;
			while (k >= 0)
			{
				if (w[k] + w[i] == 0)
				{
					tmp += (ll)pow(2, w[k]);
					flag = 1;
					break;
				}
				k--;
			}

			if (flag) R = k - 1; else R = i - 1;
			L = i + 1;

			if (res < dp(w, begin, R) + dp(w, L, end) + tmp)
				res = dp(w, begin, R) + dp(w, L, end) + tmp;
		}
	}
	return res;
}

int main()
{
	cin >> n;
	char s[10];

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> s >> a;
		if (!strcmp(s, "win"))
			w[i] = a;
		else
			w[i] = -a;
	}
	ll res = dp(w, 0, n - 1);
	cout << res << endl;
}


#include <iostream>

using namespace std;

int n;
int w[5001];

#define ll long long

ll dp(int *w, int begin, int end)
{
	if (begin < 0 || end >= n)
	{
		return 0;
	}
	ll res = 0;
	int L, R;
	for (int i = begin; i <= end; i++)
	{
		ll tmp = 0;
		if (w[i] < 0)
		{
			bool flag = 0;
			int k = i - 1;
			while (k >= 0)
			{
				if (w[k] + w[i] == 0)
				{
					tmp += pow(2, w[k]);
					flag = 1;
					break;
				}
				k--;
			}

			if (flag) R = k - 1; else R = i - 1;
			L = i + 1;

			if (res < dp(w, begin, R) + dp(w, L, end) + tmp)
				res = dp(w, begin, R) + dp(w, L, end) + tmp;
		}
	}
	return res;
}

int main()
{

	cin >> n;
	char s[10];

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> s >> a;
		if (!strcmp(s, "win"))
			w[i] = a;
		else
			w[i] = -a;
	}

	//for (int i = 0; i < n; i++)
	//cout << w[i]<<" ";
	cout << endl;
	ll res = dp(w, 0, n - 1);
	cout << res << endl;
}


#include <iostream>

using namespace std;

const int N = 666;

int f[N];
int pri[5001];
int sign[5001] = {0};
int h[2001];

int main()
{

	char str[5];
	int n;
	cin >> n;
	int p;
	memset(h, 0, sizeof(0));
	for (int i = 0; i < n; i++)
	{
		cin >> str >> p;
		if (str[0] == 'w') pri[i] = p;
		else  pri[i] = 0 - p;
	}

	while (1)
	{
		int tmp = 1;
		int tp;
		for (int i = 0; i < n; i++)
		{
			if ( !sign[i] && pri[i]<0 && tmp > pri[i])
			{
				tmp = pri[i];
				tp = i;
			}
		}
		if (tmp > 0)
			break;
		int j;
		for (j = tp - 1; j >= 0; j--)
		{
			if (pri[j] + tmp == 0 || pri[j] == 0) break;
		}
		if (pri[j] == 0 || j < 0 )
		{
			//pri[tp] = 0;
			sign[tp] = 1;
			continue;
		}
		h[0-tmp] = 1;
		for (int k = j; k <= tp; k++)
			pri[k] = 0;
	}
	int w,e;
	for (w = 2000; w >= 0; w--)
	{
		for (e = 1; e<N; e++){
			f[e] <<= 1;
			if (f[e - 1]>9){
				f[e - 1] -= 10;
				f[e]++;
			}
		}
		f[1] += h[w];
	}
	for (w = N - 1; (w>1) && (!f[w]); w--);
	for (; w; w--)
		printf("%d", f[w]);
	return 0;
}

/*#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
using namespace std;
const int i = 610;
int main(){
int q, w, e, r, t, s[5000], d[5000], h[2001], f[i];
char a[5];
for (w = 0; w<2001; w++)
h[w] = 0;
scanf("%d", &q);
for (w = 0; w<q; w++){
scanf("%s%d", a, &d[w]);
if (a[0] == 'w')
s[w] = 0;
else
s[w] = 1;
}
while (1){
t = -1;
for (w = 0; w<q; w++)
if ((s[w] == 1) && (t<d[w])){
t = d[w];
r = w;
}
if (t<0)
break;
for (w = r - 1; (w >= 0) && (s[w] >= 0); w--)
if ((s[w] == 0) && (d[w] == t))
break;
if ((w<0) || (s[w]<0)){
s[r] = 2;
continue;
}
h[t] = 1;
for (; w <= r; w++)
s[w] = -1;
}
for (w = 0; w<i; w++)
f[w] = 0;
for (w = 2000; w >= 0; w--)
{
for (e = 1; e<i; e++){
f[e] <<= 1;
if (f[e - 1]>9){
f[e - 1] -= 10;
f[e]++;
}
}
f[1] += h[w];
}
for (w = i - 1; (w>1) && (!f[w]); w--);
for (; w; w--)
printf("%d", f[w]);
return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

#define ll long long

int n;
int w[5001];

ll dp(int *w, int begin, int end)
{
if (begin < 0 || end >= n)
{
return 0;
}
ll res = 0;
int L, R;
for (int i = begin; i <= end; i++)
{
ll tmp = 0;
if (w[i] < 0)
{
bool flag = 0;
int k = i - 1;
while (k >= 0)
{
if (w[k] + w[i] == 0)
{
tmp += (ll)pow(2, w[k]);
flag = 1;
break;
}
k--;
}

if (flag) R = k - 1; else R = i - 1;
L = i + 1;

if (res < dp(w, begin, R) + dp(w, L, end) + tmp)
res = dp(w, begin, R) + dp(w, L, end) + tmp;
}
}
return res;
}

int main()
{
cin >> n;
char s[10];

for (int i = 0; i < n; i++)
{
int a;
cin >> s >> a;
if (!strcmp(s, "win"))
w[i] = a;
else
w[i] = -a;
}
ll res = dp(w, 0, n - 1);
cout << res << endl;
}*/


#include <iostream>

using namespace std;
#define ll long long

int n;
int w[5001];

ll dp(int *w, int begin, int end)
{
	if (begin < 0 || end >= n)
	{
		return 0;
	}
	ll res = 0;
	int L, R;
	for (int i = begin; i <= end; i++)
	{
		ll tmp = 0;
		if (w[i] < 0)
		{
			bool flag = 0;
			int k = i - 1;
			while (k >= 0)
			{
				if (w[k] + w[i] == 0)
				{
					tmp += (ll)pow(2, w[k]);
					flag = 1;
					break;
				}
				k--;
			}

			if (flag) R = k - 1; else R = i - 1;
			L = i + 1;

			if (res < dp(w, begin, R) + dp(w, L, end) + tmp)
				res = dp(w, begin, R) + dp(w, L, end) + tmp;
		}
	}
	return res;
}

int main()
{

	cin >> n;
	char s[10];

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> s >> a;
		if (!strcmp(s, "win"))
			w[i] = a;
		else
			w[i] = -a;
	}

	//for (int i = 0; i < n; i++)
	//cout << w[i]<<" ";
	//cout << endl;
	ll res = dp(w, 0, n - 1);
	cout << res << endl;
}


#include <iostream>

using namespace std;

int sign[5001];
int pri[5001];
int h[20001];
const int N =666;
int f[N];

int main()
{
	int n;
	cin >> n;
	char str[5];

	for (int i = 0; i < n; i++)
	{
		cin >> str >> pri[i];
		if (str[0] == 'w')
			sign[i] = 0;
		else sign[i] = 1;
	}

	memset(h, 0, sizeof(0));
	int w;
	while (1)
	{
		int tn, tp;
		tn = -1;

		for (w = 0; w < n; w++)
		{
			if (sign[w] == 1 && tn < pri[w])
			{
				tn = pri[w];
				tp = w;
			}
		}
		if (tn < 0)
			break;

		for (w = tp - 1; w >= 0; w--)
		{
			if (sign[w] == - 1 || (sign[w] == 0 && tn == pri[w]))
				break;
		}
		if (w < 0 || sign[w] == -1)
		{
			sign[tp] = 2;
			continue;
		}
		h[tn] = 1;
		for (; w <= tp; w++)
		{
			sign[w] = -1;
		}
	}
	//for (int i = 10; i >= 0; i--)
	//	cout << h[i] << " ";
	//cout << endl;
	memset(f, 0, sizeof(0));

	for (int w = 2000; w >= 0; w--)
	{
		for (int e = 1; e < N; e++)
		{
			f[e] <<= 1;
			if (f[e - 1] > 9)
			{
				f[e - 1] -= 10;
				f[e]++;
			}
		}
		f[1] += h[w];
	}
	int p;
	for (p = N-1; p > 1; p--)
	{
		if (f[p])
			break;
	}
	for (; p; p--)
	{
		cout << f[p];
	}
	cout << endl;
	return 0;
}

/*#include <iostream>

using namespace std;

const int N = 666;

int f[N];
int pri[5001];
int sign[5001] = {0};
int h[2001];

int main()
{

	char str[5];
	int n;
	cin >> n;
	int p;
	memset(h, 0, sizeof(h));
	for (int i = 0; i < n; i++)
	{
		cin >> str >> p;
		if (str[0] == 'w') pri[i] = p;
		else  pri[i] = 0 - p;
	}

	while (1)
	{
		int tmp = 1;
		int tp;
		for (int i = 0; i < n; i++)
		{
			if (pri[i]<0 && tmp > pri[i])
			{
				tmp = pri[i];
				tp = i;
			}
		}
		if (tmp > 0)
			break;
		int j;
		for (j = tp - 1; j >= 0  &&  pri[j] !=0 ; j--)
		{
			//if (pri[j] + tmp == 0 || pri[j] == 0) break;
		}
		if ( j < 0 || pri[j] == 0 )  // pri[j] == 0 ||j < 0  �����Ǵ��������ġ�
		{
			pri[tp] = 10000000;
			//sign[tp] = 1;
			continue;
		}
		h[0-tmp] = 1;
		for (int k = j; k <= tp; k++)
			pri[k] = 0;
	}
	int w,e;
	for (w = 2000; w >= 0; w--)
	{
		for (e = 1; e<N; e++){
			f[e] <<= 1;
			if (f[e - 1]>9){
				f[e - 1] -= 10;
				f[e]++;
			}
		}
		f[1] += h[w];
	}
	for (w = N - 1; (w>1) && (!f[w]); w--);
	for (; w; w--)
		printf("%d", f[w]);
	cout << endl;
	return 0;
}
*/

/*#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
using namespace std;
const int i = 610;
int main(){
int q, w, e, r, t, s[5000], d[5000], h[2001], f[i];
char a[5];
for (w = 0; w<2001; w++)
h[w] = 0;
scanf("%d", &q);
for (w = 0; w<q; w++){
scanf("%s%d", a, &d[w]);
if (a[0] == 'w')
s[w] = 0;
else
s[w] = 1;
}
while (1){
t = -1;
for (w = 0; w<q; w++)
if ((s[w] == 1) && (t<d[w])){
t = d[w];
r = w;
}
if (t<0)
break;
for (w = r - 1; (w >= 0) && (s[w] >= 0); w--)
if ((s[w] == 0) && (d[w] == t))
break;
if ((w<0) || (s[w]<0)){
s[r] = 2;
continue;
}
h[t] = 1;
for (; w <= r; w++)
s[w] = -1;
}
for (w = 0; w<i; w++)
f[w] = 0;
for (w = 2000; w >= 0; w--)
{
for (e = 1; e<i; e++){
f[e] <<= 1;
if (f[e - 1]>9){
f[e - 1] -= 10;
f[e]++;
}
}
f[1] += h[w];
}
for (w = i - 1; (w>1) && (!f[w]); w--);
for (; w; w--)
printf("%d", f[w]);
return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

#define ll long long

int n;
int w[5001];

ll dp(int *w, int begin, int end)
{
if (begin < 0 || end >= n)
{
return 0;
}
ll res = 0;
int L, R;
for (int i = begin; i <= end; i++)
{
ll tmp = 0;
if (w[i] < 0)
{
bool flag = 0;
int k = i - 1;
while (k >= 0)
{
if (w[k] + w[i] == 0)
{
tmp += (ll)pow(2, w[k]);
flag = 1;
break;
}
k--;
}

if (flag) R = k - 1; else R = i - 1;
L = i + 1;

if (res < dp(w, begin, R) + dp(w, L, end) + tmp)
res = dp(w, begin, R) + dp(w, L, end) + tmp;
}
}
return res;
}

int main()
{
cin >> n;
char s[10];

for (int i = 0; i < n; i++)
{
int a;
cin >> s >> a;
if (!strcmp(s, "win"))
w[i] = a;
else
w[i] = -a;
}
ll res = dp(w, 0, n - 1);
cout << res << endl;
}*/


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin() , x.end()
#define all_mas(mas) copy(mas.begin(),mas.end(), ostream_iterator<int>(cout, " "))
#define fast_io ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)

int main(){
    fast_io;
    int n;
    cin >> n;
    vector <int> mas(n);
    for (int i = 0; i < n; i++){
        cin >> mas[i];
    }
    for (int i = 0; i < n; i++){
        if (mas[i]%2==0)
        for (int j = 0; j < n; j++){
            if ((mas[i]+mas[j]%2)!=0){
                if (i < j && mas[j] < mas[i]){
                    swap(mas[i],mas[j]);
                }
                else if (j < i && mas[i] < mas[j]){
                    swap(mas[i], mas[j]);
                }
            }
        }
    }
all_mas(mas);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin() , x.end()
#define all_mas(mas) copy(mas.begin(),mas.end(), ostream_iterator<int>(cout, " "))
#define fast_io ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
vector <int> a, b;
int main(){
    fast_io;
    int n;
    cin >> n;
    vector <int> mas(n);
    for (int i = 0; i < n; i++){
        cin >> mas[i];
        if (mas[i]%2 == 0) b.push_back(mas[i]);
        else a.push_back(mas[i]);
    }
    sort (all(a), greater<int>());
    sort (all(b), greater<int>());
    for (int i = 0; i < n; i++){
        if (mas[i]%2 == 0){
            if (!a.empty()){
            int t = a.back();
            if (t < mas[i]){
                for(int j = i+1; j < n; j++){
                    if (t == mas[j]){
                       a.pop_back();
                       swap(mas[i], mas[j]);
                       break;
                    }
                }
            }
            }
        }
        else {
            if (!b.empty()){
            int t = b.back();
            if (t < mas[i]){
                for(int j = i+1; j < n; j++){
                    if (t == mas[j]){
                       b.pop_back();
                       swap(mas[i], mas[j]);
                       break;
                    }
                }
            }
            }
        }
    }
    for (int i = 0; i < n-1; i++){
        if ((mas[i] + mas[i+1])%2!= 0 && mas[i] > mas[i+1]){
            swap(mas[i], mas[i+1]);
        }
    }
    all_mas(mas);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin() , x.end()
#define all_mas(mas) copy(mas.begin(),mas.end(), ostream_iterator<int>(cout, " "))
#define fast_io ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)

int main(){
    fast_io;
    int n;
    cin >> n;
    vector <int> mas(n);
    for (int i = 0; i < n; i++){
        cin >> mas[i];
    }
    for (int i = 0; i < n; i++){
        if (mas[i]%2==0)
        for (int j = 0; j < n; j++){
            if ((mas[i]+mas[j]%2)!=0){
                if (i < j && mas[j] < mas[i]){
                    swap(mas[i],mas[j]);
                }
                else if (j < i && mas[i] < mas[j]){
                    swap(mas[i], mas[j]);
                }
            }
        }
    }
all_mas(mas);2

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin() , x.end()
#define all_mas(mas) copy(mas.begin(),mas.end(), ostream_iterator<int>(cout, " "))
#define fast_io ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
vector <int> a, b;
int main(){
    fast_io;
    int n;
    cin >> n;
    vector <int> mas(n);
    for (int i = 0; i < n; i++){
        cin >> mas[i];
        if (mas[i]%2 == 0) b.push_back(mas[i]);
        else a.push_back(mas[i]);
    }
    if (!a.empty() && !b.empty()){
        sort(all(mas));
        all_mas(mas);
    }
    else{
        all_mas(mas);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin() , x.end()
#define all_mas(mas) copy(mas.begin(),mas.end(), ostream_iterator<int>(cout, " "))
#define fast_io ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)

int main(){
    fast_io;
    int n;
    cin >> n;
    vector <int> mas(n);
    for (int i = 0; i < n; i++){
        cin >> mas[i];
    }
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j++){
            if ((mas[i]+mas[j]%2)!=0){
                if (i < j && mas[j] < mas[i]){
                    swap(mas[i],mas[j]);
                }
            }
        }
    }
    all_mas(mas);

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++) cout<<a[i]<<" ";
    return 0;
}


/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;

#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11;
const ld PI = 4*atan((ld)1);

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair<int,int> >even,odd;
    int n;
    cin>>n;
     vector<pair<int, int>> a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i].first;
    	a[i].second = i;
    	if(a[i].first%2==0) even.insert({a[i].first, i});
    	else odd.insert({a[i].first, i});
    }
    for(int i=0;i<n;i++){
    	if(a[i].first%2 == 0){
    	//	cout<<"vikram singh";
    		if(odd.size() != 0){
    		 auto it = odd.begin();
    			if(it->first < a[i].first){
    				swap(a[i], a[it->second]);
    				odd.erase(it);
    			}
    			else{
    			    even.erase(a[i]);
    			}

    		}
    		else{
    			even.erase(a[i]);
    		}
    		// cout<<"array :";
    		// 	for(int i=0;i<n;i++) cout<<a[i].first<<" ";
    		// 	cout<<"\n";
    	}
    	else{
    		//cout<<"vedraj";
    		if(even.size() != 0){
    		//	cout<<"True : ";
    		 	auto it = even.begin();
    			if(it->first < a[i].first){
    				swap(a[i],a[it->second]);
    				even.erase(it);
    			}
    			else{
    				odd.erase(a[i]);
    			}
    		}
    		else{
    			odd.erase(a[i]);
    		}
    		// cout<<"array :";
    		// 	for(int i=0;i<n;i++) cout<<a[i].first<<" ";
    		// 	cout<<"\n";
    	}
    }
    for(int i=0;i<n;i++){
    	cout<<a[i].first<<" ";
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n;
	cin>>n;
	int a[n];
	bool even=false,odd = false;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2 == 0) even = true;
		else odd = true;
	}
	if(even && odd){
		sort(a,a+n);
		for(auto i : a){
			cout<<i<<" ";
		}
	}
	else{
		for(auto i : a){
			cout<<i<<" ";
		}
	}
	return 0;
}


/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;

#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11;
const ld PI = 4*atan((ld)1);

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair<int,int> >even,odd;
    int n;
    cin>>n;
    vector<pair<int, int>> a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i].first;
    	a[i].second = i;
    	if(a[i].first%2==0) even.insert({a[i].first, i});
    	else odd.insert({a[i].first, i});
    }
    for(int i=0;i<n;i++){
    	if(a[i].first%2 == 0){
    	//	cout<<"vikram singh";
    		if(odd.size() != 0){
    		 auto it = odd.begin();
    		 pair<int, int> p = a[i];
    			if(it->first < a[i].first && it->second > a[i].second){
                    a[i].second = it->second;
    				swap(a[i], a[it->second]);
    				odd.erase(it);
    				even.erase(p);
    				even.insert(a[it->second]);
    			}
    			else{
    			    even.erase(a[i]);
    			}

    		}
    		else{
    			even.erase(a[i]);
    		}

    	}
    	else{
    		//cout<<"vedraj";
    		if(even.size() != 0){
    		//	cout<<"True : ";
    		 	auto it = even.begin();
    		 	pair<int, int> p = a[i];
    			if(it->first < a[i].first && it->second > a[i].second){
                    a[i].second = it->second;
    				swap(a[i],a[it->second]);
    				even.erase(it);
    				odd.erase(p);
    				odd.insert(a[it->second]);
    			}
    			else{
    				odd.erase(a[i]);
    			}

    		}
    		else{
    			odd.erase(a[i]);
    		}

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


/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;

#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11;
const ld PI = 4*atan((ld)1);

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair<int,int> >even,odd;
    int n;
    cin>>n;
    vector<pair<int, int>> a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i].first;
    	a[i].second = i;
    	if(a[i].first%2==0) even.insert({a[i].first, i});
    	else odd.insert({a[i].first, i});
    }
    for(int i=0;i<n;i++){
    	if(a[i].first%2 == 0){
    	//	cout<<"vikram singh";
    		if(odd.size() != 0){
    		 auto it = odd.begin();
    			if(it->first < a[i].first){
    				swap(a[i], a[it->second]);
    				odd.erase(it);
    			}
    			else{
    			    even.erase(a[i]);
    			}
    		    continue;
    		}
    		else{
    			even.erase(a[i]);
    		}
    		// cout<<"array :";
    		// 	for(int i=0;i<n;i++) cout<<a[i].first<<" ";
    		// 	cout<<"\n";
    	}
    	else{
    		//cout<<"vedraj";
    		if(even.size() != 0){
    		//	cout<<"True : ";
    		 	auto it = even.begin();
    			if(it->first < a[i].first){
    				swap(a[i],a[it->second]);
    				even.erase(it);
    			}
    			else{
    				odd.erase(a[i]);
    			}
    			continue;
    		}
    		else{
    			odd.erase(a[i]);
    		}
    		// cout<<"array :";
    		// 	for(int i=0;i<n;i++) cout<<a[i].first<<" ";
    		// 	cout<<"\n";
    	}
    }
    for(int i=0;i<n;i++){
    	cout<<a[i].first<<" ";
    }
	return 0;
}


/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;

#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11;
const ld PI = 4*atan((ld)1);

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair<int,int> >even,odd;
    int n;
    cin>>n;
    vector<pair<int, int>> a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i].first;
    	a[i].second = i;
    	if(a[i].first%2==0) even.insert({a[i].first, i});
    	else odd.insert({a[i].first, i});
    }
    for(int i=0;i<n;i++){
    	if(a[i].first%2 == 0){
    	//	cout<<"vikram singh";
    		if(odd.size() != 0){
    		 auto it = odd.begin();
    		 pair<int, int> p = a[i];
    			if(it->first < a[i].first && it->second > a[i].second){
                    a[i].second = it->second;
    				swap(a[i], a[it->second]);
    				odd.erase(it);
    				even.erase(p);
    				even.insert(a[it->second]);
                    i--;
    			}
    			else{
    			    even.erase(a[i]);
    			}

    		}
    		else{
    			even.erase(a[i]);
    		}

    	}
    	else{
    		//cout<<"vedraj";
    		if(even.size() != 0){
    		//	cout<<"True : ";
    		 	auto it = even.begin();
    		 	pair<int, int> p = a[i];
    			if(it->first < a[i].first && it->second > a[i].second){
                    a[i].second = it->second;
    				swap(a[i],a[it->second]);
    				even.erase(it);
    				odd.erase(p);
    				odd.insert(a[it->second]);
    				i--;
    			}
    			else{
    				odd.erase(a[i]);
    			}

    		}
    		else{
    			odd.erase(a[i]);
    		}

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


/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;

#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11;
const ld PI = 4*atan((ld)1);

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair<int,int> >even,odd;
    int n;
    cin>>n;
    vector<pair<int, int>> a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i].first;
    	a[i].second = i;
    	if(a[i].first%2==0) even.insert({a[i].first, i});
    	else odd.insert({a[i].first, i});
    }
    for(int i=0;i<n;i++){
    	if(a[i].first%2 == 0){
    	//	cout<<"vikram singh";
    		if(odd.size() != 0){
    		 auto it = odd.begin();
    		 pair<int, int> p = a[i];
    			if(it->first < a[i].first && it->second > a[i].first){
                    a[i].second = it->second;
    				swap(a[i], a[it->second]);
    				odd.erase(it);
    				even.erase(p);
    				even.insert(a[it->second]);
    			}
    			else{
    			    even.erase(a[i]);
    			}

    		}
    		else{
    			even.erase(a[i]);
    		}

    	}
    	else{
    		//cout<<"vedraj";
    		if(even.size() != 0){
    		//	cout<<"True : ";
    		 	auto it = even.begin();
    		 	pair<int, int> p = a[i];
    			if(it->first < a[i].first && it->second > a[i].second){
                    a[i].second = it->second;
    				swap(a[i],a[it->second]);
    				even.erase(it);
    				odd.erase(p);
    				odd.insert(a[it->second]);
    			}
    			else{
    				odd.erase(a[i]);
    			}

    		}
    		else{
    			odd.erase(a[i]);
    		}

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


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n;
	cin>>n;
	int a[n];
	bool even,odd;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2 == 0) even = true;
		else odd = true;
	}
	if(even && odd){
		sort(a,a+n);
		for(auto i : a){
			cout<<i<<" ";
		}
	}
	else{
		for(auto i : a){
			cout<<i<<" ";
		}
	}
	return 0;
}


/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;

#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11;
const ld PI = 4*atan((ld)1);

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair<int,int> >even,odd;
    int n;
    cin>>n;
    vector<pair<int, int>> a(n);
    for(int i=0;i<n;i++){
    	cin>>a[i].first;
    	a[i].second = i;
    	if(a[i].first%2==0) even.insert({a[i].first, i});
    	else odd.insert({a[i].first, i});
    }
    for(int i=0;i<n;i++){
    	if(a[i].first%2 == 0){
    	//	cout<<"vikram singh";
    		if(odd.size() != 0){
    		 auto it = odd.begin();
    		 pair<int, int> p = a[i];
    			if(it->first < a[i].first){
                    a[i].second = it->second;
    				swap(a[i], a[it->second]);
    				odd.erase(it);
    				even.erase(p);
    				even.insert(a[it->second]);
    			}
    			else{
    			    even.erase(a[i]);
    			}

    		}
    		else{
    			even.erase(a[i]);
    		}

    	}
    	else{
    		//cout<<"vedraj";
    		if(even.size() != 0){
    		//	cout<<"True : ";
    		 	auto it = even.begin();
    		 	pair<int, int> p = a[i];
    			if(it->first < a[i].first){
                    a[i].second = it->second;
    				swap(a[i],a[it->second]);
    				even.erase(it);
    				odd.erase(p);
    				odd.insert(a[it->second]);
    			}
    			else{
    				odd.erase(a[i]);
    			}

    		}
    		else{
    			odd.erase(a[i]);
    		}

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


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(long long n)
{
	long long c;
    // Corner case
    if (n <= 1)
        return false;
	c=sqrt(n);
    // Check from 2 to n-1
    for (int i = 2; i <= c; i++)
        if (n % i == 0)
            return false;

    return true;
}

const long long N=1e5+7;
long long l,k,d,tr,n,m,sum,mini,maxi,a,b,c,x,y;
long long t[N];
set <int> vis;
vector<int> v;
string s1;
string s2;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t[i];
	}
	for(int j=0; j<1000; j++){
		for(int i=n-1; i>=1; i--){
			if(t[i]<t[i-1] && (t[i]+t[i-1])%2){
				c=t[i];t[i]=t[i-1];t[i-1]=c;
			}
		}
	}
	for(int i=0; i<n; i++){
		cout<<t[i]<<" ";
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(long long n)
{
	long long c;
    // Corner case
    if (n <= 1)
        return false;
	c=sqrt(n);
    // Check from 2 to n-1
    for (int i = 2; i <= c; i++)
        if (n % i == 0)
            return false;

    return true;
}

const long long N=1e5+7;
long long l,k,d,tr,n,m,sum,mini,maxi,a,b,c,x,y;
long long t[N],t1[N],t2[N];
set <int> vis;
vector<int> v;
string s1;
string s2;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t[i];
		if(t[i]%2){
			t1[a]=t[i];a++;
		}else{
			t2[b]=t[i];b++;
		}
	}
	sort(t1,t1+a);sort(t2,t2+b);

	for(int i=0; i<n; i++){
		if(t[i]%2){
			if(t2[y]<t[i]){
				for(int j=i+1; j<n; j++){
					if(t[j]==t2[y]){
						c=t[j];t[j]=t[i];t[i]=c;
						break;
					}
					y++;
				}
			}
		}else{
			if(t1[x]<t[i]){
				for(int j=i+1; j<n; j++){
					if(t[j]==t1[x]){
						//cout<<"hi";
						c=t[j];t[j]=t[i];t[i]=c;
						break;
					}
					x++;
				}
			}
		}
	}
	for(int i=0; i<n; i++){
		cout<<t[i]<<" ";
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(long long n)
{
	long long c;
    // Corner case
    if (n <= 1)
        return false;
	c=sqrt(n);
    // Check from 2 to n-1
    for (int i = 2; i <= c; i++)
        if (n % i == 0)
            return false;

    return true;
}

const long long N=1e5+7;
long long l,k,d,tr,n,m,sum,mini,maxi,a,b,c,x,y;
long long t[N];
set <int> vis;
vector<int> v;
string s1;
string s2;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t[i];
	}
	for(int j=0; j<1000; j++){
		for(int i=0; i<n-1; i++){
			if(t[i]>t[i+1] && (t[i]+t[i+1])%2){
				c=t[i];t[i]=t[i+1];t[i+1]=c;
			}
		}
	}
	for(int i=0; i<n; i++){
		cout<<t[i]<<" ";
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(long long n)
{
	long long c;
    // Corner case
    if (n <= 1)
        return false;
	c=sqrt(n);
    // Check from 2 to n-1
    for (int i = 2; i <= c; i++)
        if (n % i == 0)
            return false;

    return true;
}

const long long N=1e5+7;
long long l,k,d,tr,n,m,sum,mini,maxi,a,b,c,x,y;
long long t[N],t1[N],t2[N];
set <int> vis;
vector<int> v;
string s1;
string s2;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t[i];
		if(t[i]%2){
			t1[a]=t[i];a++;
		}else{
			t2[b]=t[i];b++;
		}
	}
	sort(t1,t1+a);sort(t2,t2+b);

	for(int i=0; i<n; i++){
		if(t[i]%2){
			if(t2[y]<t[i]){
				for(int j=i+1; j<n; j++){
					if(t[j]==t2[y]){
						c=t[j];t[j]=t[i];t[i]=c;
						break;
					}

				}
				y++;
			}
		}else{
			if(t1[x]<t[i]){
				for(int j=i+1; j<n; j++){
					if(t[j]==t1[x]){
						//cout<<"hi";
						c=t[j];t[j]=t[i];t[i]=c;
						break;
					}

				}
				x++;
			}
		}
	}
	for(int i=0; i<n; i++){
		cout<<t[i]<<" ";
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(long long n)
{
	long long c;
    // Corner case
    if (n <= 1)
        return false;
	c=sqrt(n);
    // Check from 2 to n-1
    for (int i = 2; i <= c; i++)
        if (n % i == 0)
            return false;

    return true;
}

const long long N=1e5+7;
long long l,k,d,tr,n,m,sum,mini,maxi,a,b,c,x,y;
long long t[N],t1[N],t2[N];
set <int> vis;
vector<int> v;
string s1;
string s2;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t[i];
		if(t[i]%2){
			t1[a]=t[i];a++;
		}else{
			t2[b]=t[i];b++;
		}
	}
	sort(t1,t1+a);sort(t2,t2+b);

	for(int i=0; i<n; i++){
		if(t[i]%2){
			if(t2[y]<t[i]){
				for(int j=0; j<n; j++){
					if(t[j]==t2[y]){
						c=t[j];t[j]=t[i];t[i]=c;
						break;
					}

				}
				y++;
			}
		}else{
			if(t1[x]<t[i]){
				for(int j=0; j<n; j++){
					if(t[j]==t1[x]){
						//cout<<"hi";
						c=t[j];t[j]=t[i];t[i]=c;
						break;
					}

				}
				x++;
			}
		}
	}
	for(int i=0; i<n; i++){
		cout<<t[i]<<" ";
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
bool isPrime(long long n)
{
	long long c;
    // Corner case
    if (n <= 1)
        return false;
	c=sqrt(n);
    // Check from 2 to n-1
    for (int i = 2; i <= c; i++)
        if (n % i == 0)
            return false;

    return true;
}

const long long N=1e5+7;
long long l,k,d,tr,n,m,sum,mini,maxi,a,b,c,x,y;
long long t[N],t1[N],t2[N];
set <int> vis;
vector<int> v;
string s1;
string s2;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>t[i];
		if(t[i]%2){
			a++;
		}else{
			b++;
		}
	}
	if(a && b){
		sort(t,t+n);
		for(int i=0; i<n; i++){
			cout<<t[i]<<" ";
		}
	}else{
		for(int i=0; i<n; i++){
			cout<<t[i]<<" ";
		}
	}

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

	}
*/


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[100005];
	int i;
	for (i = 0; i < n; i++)
		cin >> a[i];
	bool flag=true;

	if (a[0] % 2 == 0)
	{
		for (i = 1; i < n; i++)
		{
			if (a[i] % 2 != 0)
				flag = false;
		}
	}
	else
	{
		for (i = 1; i < n; i++)
		{
			if (a[i] % 2 == 0)
				flag = false;
		}
	}

	if (flag == false)
		sort(a, a + n);

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


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[10005];
	int i;
	for (i = 0; i < n; i++)
		cin >> a[i];
	bool flag=true;

	if (a[0] % 2 == 0)
	{
		for (i = 1; i < n; i++)
		{
			if (a[i] % 2 != 0)
				flag = false;
		}
	}
	else
	{
		for (i = 1; i < n; i++)
		{
			if (a[i] % 2 == 0)
				flag = false;
		}
	}

	if (flag == false)
		sort(a, a + n);

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


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const maxn = 3e5 + 5;
ll k[2];
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) cin >> a[i], k[a[i]%2]++;
	if (k[0] && k[1]) {
		sort(begin(a), end(a));
		for (auto now : a) {
			cout << now << " ";
		}
	}
	else {
		for (auto now : a) {
			cout << now << " ";
		}
	}
	return 0;
}

/*

*/


#define _USE_MATH_DEFINES
#include <iostream>
#include <bitset>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <set>
#include <time.h>
#include <stack>
#include <queue>
#include <sstream>

#define forn(i, n1, n2) for (int i = n1; i < n2; i++)
#define pii pair<int, int>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpii vector<vpii>
#define allR(a) a.begin(), a.end()
#define mt make_tuple

using namespace std;

const ll N = 300100, MOD = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vi arr(n);
	forn(i, 0, n) {
		cin >> arr[i];
	}
	sort(allR(arr), [&](auto a, auto b) {
		return a < b && (a + b) % 2 == 1;
	});
	for (auto& a : arr) {
		cout << a << " ";
	}
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <bitset>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <set>
#include <time.h>
#include <stack>
#include <queue>
#include <sstream>

#define forn(i, n1, n2) for (int i = n1; i < n2; i++)
#define pii pair<int, int>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpii vector<vpii>
#define allR(a) a.begin(), a.end()
#define mt make_tuple

using namespace std;

const ll N = 300100, MOD = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vi arr(n);
	int odd = 0, even = 0;
	forn(i, 0, n) {
		cin >> arr[i];
		if (arr[i] % 2 == 0)
			even++;
		else
			odd++;
	}
	if (odd > 0 && even > 0)
		sort(allR(arr));
	for (auto& a : arr) {
		cout << a << " ";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <map>
#include <set>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <random>
#include <chrono>

using namespace std;

#define mp make_pair
#define pb push_back
#define super_power_ON ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pii pair <int, int>
#define all(a) a.begin(), a.end()
#define BigPair pair <pair <long long, long long>, pair <long long, long long>>
#define rt return
#define ll long long
#define pii pair<ll, ll>

const long long SuperINF = 1e9;
const ll  MOD = 1e9 + 7, INF = 1e9;
const double eps = 1e-2;
const int A_SIZE = 2e6 + 100;
using namespace std;

void files() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}
int n;
vector<ll> a;
int cnt0 = 0, cnt1 = 0;
int main() {
	//files();
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ll t;
		cin >> t;
		a.push_back(t);
		if (t % 2 == 0)cnt0++;
		else cnt1++;
	}
	if (cnt0 == 0 || cnt1 == 0) {
		for (int i = 0; i < a.size(); i++) {
			cout << a[i] << " ";
		}
	}
	else {
		sort(all(a));
		for (int i = 0; i < a.size(); i++) {
			cout << a[i] << " ";
		}
	}
}


#include <cassert>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <chrono>
#include <algorithm>
#include <numeric>
#include <atomic>
#include <tuple>
#include <fstream>
#include <random>
#include <future>
#include <iterator>
#include <functional>
#include <thread>
#include <bitset>
#include <cstddef>
#include <utility>
#include <type_traits>
#include <complex>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
auto _fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return cout.tie(nullptr); }();

template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        in >> v[i];
    }
    return in;
}

template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    if (!v.empty()) {
        out << v.front();
        for (size_t i = 1; i < v.size(); ++i) {
            out << " " << v[i];
        }
    }
    return out;
}

template <typename T, size_t Size>
istream& operator>>(istream& in, array<T, Size>& v) {
    for (size_t i = 0; i < Size; ++i) {
        in >> v[i];
    }
    return in;
}

bool operator<(const pi& l, const pi& r) {
    return l.first < r.first || (l.first == r.first && l.second < r.second);
}

int n, m;
vi a;

int main() {
    cin >> n;
    a.resize(n);
    cin >> a;
    bool add[2] = { false, false };
    for (int i = 0; i < n; ++i) add[a[i] % 2] = true;
    if (add[0] && add[1]) sort(a.begin(), a.end());
    cout << a << endl;
}


#include<iostream>
#include<algorithm>

using namespace std;

int arr[100005];

int main()
{
	int n, i, sign1, sign2;
	cin >> n;
	for (i = 0; i < n; ++i) cin >> arr[i];

	for (i = 0, sign1 = 0, sign2 = 0; i < n; ++i)
	{
		if (arr[i] % 2 == 1) sign1 = 1;
		if (arr[i] % 2 == 0) sign2 = 1;
		if (sign1&&sign2) break;
	}

	if (sign1&&sign2) sort(arr, arr + n);

	for (i = 0; i < n; ++i) cout << arr[i] << " ";
}


#include<iostream>
#include<algorithm>

using namespace std;

int arr[100005];

int main()
{
	int n, i, j, k, flag;
	cin >> n;
	for (i = 1; i <= n; ++i) cin >> arr[i];

	for (i = 1; i <= n; ++i)
	{
		k = -1;
		flag = 1;

		for (j = i + 1; j <= n; ++j)
		{
			if (arr[i] % 2 == 0)
			{
				if (arr[j] == 1)
				{
					swap(arr[i], arr[j]);
					flag = 0;
					break;
				}
				if (arr[j] % 2 == 1 && arr[j] < arr[i] && (k == -1 || arr[j] < arr[k]))k = j;
			}
			else
			{
				if (arr[i] == 1)
				{
					flag = 0;
					break;
				}

				if (arr[j] == 2)
				{
					swap(arr[i], arr[j]);
					flag = 0;
					break;
				}

				if (arr[j] % 2 == 0 && arr[j] < arr[i] && (k == -1 || arr[j] < arr[k]))k = j;
			}
		}

		if (flag&&k != -1) swap(arr[i], arr[k]);
	}

	for (i = 1; i <= n; ++i) cout << arr[i] << " ";

}


#include			  <algorithm>
#include			   <iostream>
#include				<cstring>
#include				<stdio.h>
#include				 <string>
#include			     <vector>
#include				 <time.h>
#include				  <queue>
#include				  <cmath>
#include				    <map>
#include				    <set>
using	namespace	    	 std;
typedef	long long    		  vt;
typedef unsigned long long   vt2;
typedef	pair<vt,vt>		     PVV;
typedef	pair<char,vt>	     PCV;
typedef	pair<string, vt>     PSV;
typedef	map<vt,vt>			 MVV;
typedef map<char,vt>	     MCV;
typedef map<string,vt>	     MSV;
#define	T true;
#define F false;
#define fi(x,y) for(int i=x;i<y;i++)
#define fj(x,y) for(int j=x;j<y;j++)
#define fk(x,y) for(int k=x;k<y;k++)
#define MAXP 2000010
#define LL __int64
const int MAXN = 1e6 + 99, INF = 0x3f3f3f3f;
vt HASHprime = 13331;//7,97,997,9973,99991,999983,131,13331
////////////////////////////////////////////////////////////
int main()
{
	int n;
	int a[MAXN];
	bool flag1 = false;
	bool flag2 = false;
	scanf("%d", &n);
	fi(0, n)
	{
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0)
			flag1 = true;
		else
			flag2 = T;
	}
	if (flag1 && flag2)
		sort(a, a + n);
	fi(0, n)
		printf("%d ", a[i]);
	return 0;
}
/*

							. .........
							..,OOOO]]..... .. .
						  ...O@O/OOO@@@@].......
						  ...@@^/\\]o][@@@@\.....
						   ..@@O//oooooo\/OOOO`......
						   ..@@@//ooooooo`oo/OOO\.....
						   ..=@@^ooooooooooo/o/\OOO]....
							..@@O\oooooooooooooo[/OOO\....
							..=@@ooooooooooooooooo\\oOOO`...
							...O@Ooooooooooooooooooo/o[OOO\.....
							...=@@^]ooooooooooooooooo/o\/\OO^... . .
							 ...\@O=ooooooooooooooooooooooooOO\.....
							 . ..@@Ooooooooooooooooooooooo/o/\OOO`....
							   ..=@@O\/\ooooooooooooooooooooo]/\OOO\.....
				..  ......... ....\@@/]/ooooooooooooooooooooooo///\OO\......
		  .... .....,]]OO]O\`......O@@/oooooooooooooooooooooooooooo^OOO\......
		  ....,@@@@@@@@OO/[O@@@]....O@O/o=ooooooooooooooooooooooooooo\OOO`......
		  ...=@@@Oooo\/\/OOO]/O@@@\`.@@\oooooooooooooooooooooooooooooo/oOOO^....
		  ...=@@/\oo/@@@@@O@@@@O][@@@@@@\\ooooooooooooooooooooooooooooooooOOO`... ..
		  ...@@Oooooo=@@OOOOOOO@@@@OOO@@@\\/oooooooooooooooooooooooooo\o\oo\O@O].... .  ..
		  ..,@@ooooo//@@OOOOOOOOOOO@@@@@@@O`oooooooooooooooooooooooooooooo/ooO@@@@@]...... ...
		  ..=@@/ooooooO@@OOOOOOOOOOO@@@@@@@\ooooooooooooooooooooooooooooooooooO@@@@@@@@\`..... .
		 ...=@@ooooooo/@@OOOOOOOO@@@@@@@@@@@O/\/oooooooooooooooooooooooooooooo//@@@@@@@@@@@\`.......   .
		  ..@@O\ooooooo\@@OOOOO@@@@@@@OOOOOO@@OO/\/ooooooooooooooooooooooooooo/o=@@@@@@@@@@@@@@]....   ..
		  ..@@\ooooooo\o=@@OO@@@@@@OOOOOOOOOOO@@@O\\oooooooooooooooooooooooooo/oooO@@@@@@@@@@@@@@@]......
		  .,@@^ooooooooo\O@@@@@OOOOOOOOOOOOOOOOOO@@@O/o/oooooooooooooooooooooooooo/O@@@@@@@@@@@@@@@@@`...   ..
		 ..=@@ooooooo/o/@@@@OOOOOOOOOOOOOOOOOOOOOOO@@@O/\/ooooooooooooooooooooooooo^O@@@@@@@@@@@@@@@@@@`......
		  .=@@o\oo/o//@@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@O/\oooooooooooooooooooooooo^O@@@@@@@@@@@@@@@@@@@@`.....
		  .=@@oooo^/O@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@\\//o\oooooooooooooooOOoOoO@@@@@@@@@@@@@@@@@@@@@`.....
		  .=@@oo\=O@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@O/o/oooooooooooOoooOOooOO@@@@@@@@@@@@@@@@@@@@@@@`....
		  .=@@/\oO@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@O/ooooooOoOOOOOoOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...
		  .=@@\O@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@\ooooOoOoOO@@@@@@@@@O@@@@@@@@@@@@@@@@@@@@@@@@@@`....
		  .=@@@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@OoO@@@@@@@@OOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@\....
		  .,@@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@@@OOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\....
		  .=@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@@OOOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`..
	   ...=OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@OOOOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`..
	  .../O@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@OOOOOOOOOOOOOO@@@@@@OOOOOOOOOOOO@@@@@@@@@@@@@@@@@@`...
	....=O@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@@@@@@@@@@@@^..
	.../OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@OOO@@@@@@@@@@@@@@^.
	..=O@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@OOoOOOOOOO@@@@@@@@@@@`..
	..OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@OOO@@OoOOOOOOOOoooO@@@@@@@@..
  ...O@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@OOOOOOOOOOOOOOOOOOOOOOOOOO@@@@OoooOOO@@OOoOoOOOOOooooO@@@@@@O... .
  ..=O@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@OOOOOOOOOOOOOOOOOOOOOOOOO@@@@OoooOOOOO@@OooOOOOOOoOoOOOoO@@@@@\.. .
  ..O@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@OOOOOOOOOOOOOOOOOOOOOOOO@@@OOooOOoOOooo@@@oOOOOOOOoOoOOoOoO@@@@@\...
  .,@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@OOOOOOOOOOOOOOOOOOOOOOO@@@OOoOOOooOOoOoOO@@OoOOOOOOoOoOOOOOOO@@@@@\ .
.../@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@OOOOOOOOOOOOOOOOOOOOOO@@@OooOOOOooooooOoOO@@@oOOOOOOOoooOOOOooO@@@@@^...
...O@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@OOOOOOOOOOOOOOOOOOOOO@@@OooOoOOOOooooooOOOo@@@OOoOOOOOOOOOOOOOOoO@@@@@`..
  =O@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@OOOOOOOOOOOOOOOOOOOO@@@OooOOoOOOOOOOOOoOOooOO@@OOoOOooOOooOooOOOoOO@@@@@`.kgj
..=@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@oOoOOOOOoooOOOOOooOOOO@@Oooooooo/\/\//oooooO@@@@@@...
..O@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@OoOoooOoooOOooOOOOOOo@@@/oooo/oooooooooooo/@@@@@@@..
..O@OOOOOOOOOOOO@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@ooO@@@OOoOOOOoooooooOOOOoo@@@\/oooooooooooooooo\O@@@@@@\.
..@@OOOOOOOO@@O@@@@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@OOooo=@@@OoOOOOoooooooOOo\//O@O@@@\/\\oooooooooo\oO@@@@@@@^..
.=@@OOOOOOO@@@OO@@@@@@OOOOOOOOOOOOOOOOOOOO@OOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@Oooo/@@@@@OoOoooOoooooooo\O@@@OOOO@@@\\ooooooooooo=/@@@@@@@O..
.=O@OOOOOOO@@@OO@@@@@@@OOOOOOOOOOOOOOO@@@@@OOOOOOOOOOOOOOOOOOOOOOOOOO@@@OoooO@@@@O@@@@@@Oooooooo\oO@@@O/ooOOOO@@O/ooooooooo=ooO@@@@@@@^..
.=O@OOOOOOO@@@OO@@@@@@@OOOOOOOOOOOO@@@@@@@@OOOOOOOOOOOOOOOOOOOOOOOOO@@OoOOO@@@OOOOOOO@@@@@@@@@O]O@@@@ooo/..,OOO@@@\\ooooooooooO@@@@@@@O...
.=OOOOOOOO@@@@OOO@@@@@@OOOOOOOOOO@@@@@@@@@@OOOOOOOOOOOOOOOOOOOOOOO@@@OOOO@@@@OOOOOOOOOOOOOOO@@@@@@@oooooo`...OOO@@@/ooooooooooO@@@@@@@O^..
..@@OOOOOOO@@@@@O@@@@@@@OOOOOOOO@@@@@@@@@@@OOOOOOOOOOOOOOOOOOOOOO@@OOOOO@@@OOOOOOOOOOOOOoooooooooooooooooo\../OOO@@\^^ooooooooO@@@@@@@@^..
..@@@OOOOOOO@@@@@@@@@@@@OOOOOOOO@@@@@@@@@@@OOOOOOOOOOOOOOOOOOOOO@@OoooO@@@OOOOOOOOOOOOooooooooooooooooooooOOOOOOO@@@=oooooooo\O@@@@@@@@\..
..O@@OOOOO@@@@@@@@@@@@@OOOOOOOO@@@@@@@@@@@@OOOOOOOOOOOOOOOOOOOO@@OOooO@@@OOOOOOOOOOOoooooooooooooooooooooooOOOOOO@@@^oooooooo=@@@@@@@@@@....
..O@@OOO@@@@@@@@@@@@@@@@OOOOO@@@@@@@@@@@@@OOOOOOOOOOOOOOOOOOO@@@OOOOoO@@@OOOOOOOOOoooooooooooooooooooooooooOOOOOOO@@oooooooo^O@@@@@@@@@@^...
.,@@@OOOOOOOOOOOO@@@@@@@OOOO@@@@@@@@@@@@@@OOOOOOOOOOOOOOOOOO@@OoOOOOo@@@OOOOOOOOoooooooooooooooooooooooooooOOOOOO@@@\/ooooo/\O@@@@@@@@@@@\....
.@@@OO@OOOOOOOOOOOO@@@@@@O@@@@@@@@@@@@@@@@OOOOOOOOOOOOOOOOO@@OooOOoOo@@@OOOOOOoooooooooooooooooooooooooooooOOOOOO@@O\ooooo\//@@@@@@@@@@@@@@`....
=@@@@@OOOOOOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOOOOOOO@@OooOOOOOO@@@OOOOOOoooooooooooooooooooooooooooooOOOOO@@@\\/ooooo^O@@@@@@@@@@@@@@@@`......
=@@@@OOOOOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOOOOO@@@OOOOoOoooO@@@OOOOOOOooooooooooooooooooooooooooOOOOOOO@@//oooooo\O@@@@@@@@@@@@@@OOOOO]....
=@@@@OOOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOOO@@@oooOOooooooO@@OOOOOOOoooooooooooooooooooooooooOOOOOOO@@O\oooooo/O@@@@@@@@@@@@@@@@@@OOO@^....
,@@@@OOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOO@@@oOooooooooooo@@@OOOOOOOOooooooooooooooooooooOOOOOOOO@@@/\\\ooooo/@@@@@@@@@@@@@@@@@@@@@OO@O...
.=@@@@OOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOO@@@ooOOooooooooooo@@@OOOOOOOOOOooooooooooooooOOOOOOOOO@@@@/o/oooooooO@@@@@@@@@@@@@@@@@@@@@@@OOO`.......
..@@@@@OOOO@@@@@@@OOOO@@@OO@@@@@@@@@@@@@@@@OOOOOOOOO@@OoooOOoooooooooooo@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@/\\o\ooooo/@@@@@@@@@@@@@@@@@@@@@@@@@@@OO\........ ..  .
..=@@@@@@@@@@@@@@OOOO@@@@@@@@@@@@@@@@@@@@@@OOOOOOOO@@@ooOoOOOOoooooooooo/O@OOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@`/,o/ooooo\O@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O]]............... .
  .\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOO@@@oOoOoooOoOooooooooo\o/O@@@@@@OOOOOOOOOOOO@@@@@@@@@O/\\\o/oooo//\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOO@@@@@]]]`........    ..
  ..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOO@@@ooooOOOoOOOooooooooo\/\/\o][O@@@@@@@@@@@@@@@@@O/\\\/ooooooooo/O@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOOOO@@@@@@]]............
  ..,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOO@@OoOOOOOOOoooooooooooooooooooo\ooo]/o/[[o\\=oo\/o]ooooooooooo/O@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Oo\\/O@OOOOOOOOOOOOOOOOOOOOO@@@@]].....
  ...=@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OO@@@OOOooOOoooooooooooooooooooooooo\ooooooooooooooooooooooooo\/@@@@@@@@@@@@@@@@O[]@@/[\OO@@@@@@@@@@OOOOOO@O*..,[[[\OOOOOOOOOOOOOOOOOO@@@@
	..=@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OoOooooooooooooooooooooooooooooooooooooooooooooooo\@@@@@@@@@@@@@@/\/@@@[.]@@@@OOOO`...**[[[[[[/[*****..****,oooOOOOOOO/*..*\OOO
	...,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Ooooooooooooooooooooooooooooooooooooooooooo/\O@@@@@@@@@@@@@O@@@/`.]@@@OOOOOOOOOOO\]*****,[*.*..*...*******oooOOOOOO\*.../OOO
	 ....\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\\ooooooooooooooooooooooooooooooooooo/]O@@@@@@@@@@@@@@@/`..]@@@OOOOOOOOOOOOOOOOO/*****..*********]]/o/oooOOOOOOOOOOOOOOO@
	  ....,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OO@@@@@@OO\]ooooooooooooooooooooo/o[o/O@@@@@@@@@@@@@@@[..,]@@@OOOOOOOOOOOOOOOOOOOOO/*********]]oooooooOOOOOOOOOOOOOOOOO@@@@@
		  ..,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOO@@@@@@@@@O/\]o[\/\ooo[\ooOO@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOOOOOOOOOOOOOOooooooo/ooooOOOOOOOOOOOOOOOOOOOOO@@@@@@@`..
		  .....[@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOooooooOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@[......
			  .....,[\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O[[O@@@@OOOOOOOOOOOOOOOOOOOOOO@@@@@@@@@@@@@@OOOOOO/[[oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@/.......
					........[[[O@@@@@@@@@@@@@@@@@@@@@OO\/\ooo/o\@@@@@@@@@@@@@@@@@@@@@@@@@@@O@@@@OOOOOOOO[**.*.......,[\OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@/`......  .
						 .  ..............,[\@@@@@@@OOO]/\ooooo/oO@\.................,]OO@OOOOOOOOOO/*......**.............**[[\OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO@@@@@@@@[\@@@@\]`.........
									  ..........,....,@@@@@@OOOOOOO@@O@\............,@[\@@@@OOOOOOOOO]`**........................*[\OOOOOOOOOOOOOOOOOOOOOO@@@@@@@@/`...........[[O@O\]...
												.....@@OOOOOOOOO@@OO@@OO@\..     ...[[\@@@@O/[OO@@@OOOOOOOOO\]`*.........*.*.........,OOOOOOOOOOOOOOO@@@@@@@@@/`......       ..........,[
												.....@@OOOOOOO@@OOOOOO@OO@\....    ........,[\@@@]].[\@@@@@OOOOOOOOO\]]`*..........*,/OOOOOOOOOOO@@@@@@@@@[.....                        .
													.=@@OOOOOO@OOOOOOOO@OO@^..        ....  ......[\@@@\]]*[\@@@@@@@OOOOOOOOOO\]/OOOOOOOOOOOO@@@@@@@@/`........
												   ....,\@@@OO@OOOOOOOO@@@/...              .............,[@@@@O]/[\@@@@@@@@@OOOOOOOOOOOO@@@@@@@@[.......
													  ......,\@@@@@@@@O\@\..                             ........,[\@@@O]/[[O@@@@@@@O@@@@@@@@`......

*/


														//"بسم الله الرحمن الرحيم"

							//"وأما من امن وعمل صالحا فله جزاء الحسنى وسنقول له من امرنا يسرا"

													 //"tomorrow never will be like today........"

										//"Go and try to hack me you are a loooooooser anyway huh *_*........"

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

#define loop(n) for(int i=0;i<n;i++)
#define cinarr(arr,n) for(int i=0;i<n;i++){cin>>arr[i];}
#define PII pair<int , int>
#define PLL pair<long long,long long>
#define PIS pair<int , string>
#define pb(a) push_back(a)
#define veci vector<int>
#define vecl vector<long long>
#define vecs vector<string>
#define sz(s) int(s.size())
#define p(a) push(a)

using namespace std;

typedef long long ll;
typedef string str;
typedef double db;
typedef float fl;
typedef int i;

int Notprime[1000000];

void gemeratePrimes()
{
	Notprime[1]++;
	for (int i = 2; i*i < 1000000; i++)
	{
		if (!Notprime[i])
		{

			for (int j = i * 2; j < 1000000; j *= 2)
				Notprime[j]++;
		}
	}

}

ll arr[1000000];

int main()
{
	int n;
	cin >> n;
	int e = 0;
	int o = 0;
	loop(n)
	{
		cin >> arr[i];
		if (arr[i] & 1)
			o++;
		else
			e++;
	}

	if (e != 0 && o != 0)
		sort(arr, arr + n);

	loop(n)
		cout << arr[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <cstring>
#include <sstream>
#include <string>
#include <bitset>
#include <cstdio>
#include <vector>
#include <ctime>
#include <queue>
#include <cmath>
#include <regex>
#include <stack>
#include <set>
#include <map>

#define re return
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int) (x).size())
#define rep(i, n) for(int i =0;i<(n); i++)
#define rrep(i, n) for(int i =(n)-1;i>=0; i--)
#define y0 = y32479
#define y1 = y93587
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x))- x.begin()))
#define spc(i, n) " \n"[i == n-1]
#define prev prev304
#define next next304

#pragma comment(linker, "/STACK:10000000")

using namespace std;

#define INF 1000000009

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int > ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
template<class T> T abs(T x) { return x > 0 ? x : -x; }

int n;
vi a;
bool even = false; //четный
bool odd = false; // нечетный

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);

	rep(i, n) {
		int b;
		cin >> a[i];
		if (a[i] % 2 == 0) even = true;
		else odd = true;
	}

	if (even && odd) {
		sort(a.begin(), a.end());
	}

	rep(i, n) {
		cout << a[i];
		if (i != n - 1) cout << " ";
	}

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	return a1.zhi<a2.zhi;
}

void go(){
	for(int i=0;i<n;i++){
		int t=0;
		if(a[i]%2==0){
			while(lin2<k2&&ji[lin2].tai==1){
				lin2++;
				if(lin2==k2){
					break;
				}
			}
			if(lin2<k2){
				if(a[i]>ji[lin2].zhi){
					t=a[i];
					a[i]=ji[lin2].zhi;
					a[ji[lin2].pos]=t;
					lin2++;
				}
				else{
					for(int j=lin1;j<k1;j++){
						if(o[j].zhi==a[i]){
							o[j].tai=1;
							break;
						}
					}
				}
			}
		}
		else{
			while(lin1<k1&&o[lin1].tai==1){
				lin1++;
				if(lin1==k1)break;
			}
			if(lin1<k1){
				if(a[i]>o[lin1].zhi){
					t=a[i];
					a[i]=o[lin1].zhi;
					a[o[lin1].pos]=t;
					lin1++;
				}
				else{
					for(int j=lin2;j<k2;j++){
						if(ji[j].zhi==a[i]){
							ji[j].tai=1;
							break;
						}
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	if(a1.zhi<a2.zhi)return 1;
	else if(a1.zhi==a2.zhi)return a1.pos<a2.pos;
	else return 0;
}

void go(){
	for(int i=0;i<n;i++){
		int t=0;
		if(a[i]%2==0){
			while(lin2<k2&&ji[lin2].tai==1){
				lin2++;
				if(lin2==k2){
					break;
				}
			}
			if(lin2<k2){
				if(a[i]>ji[lin2].zhi){
					t=a[i];
					a[i]=ji[lin2].zhi;
					a[ji[lin2].pos]=t;
					lin2++;
				}
				else{
					for(int j=lin1;j<k1;j++){
						if(o[j].zhi==a[i]){
							o[j].tai=1;
							break;
						}
					}
				}
			}
		}
		else{
			while(lin1<k1&&o[lin1].tai==1){
				lin1++;
				if(lin1==k1)break;
			}
			if(lin1<k1){
				if(a[i]>o[lin1].zhi){
					t=a[i];
					a[i]=o[lin1].zhi;
					a[o[lin1].pos]=t;
					lin1++;
				}
				else{
					for(int j=lin2;j<k2;j++){
						if(ji[j].zhi==a[i]){
							ji[j].tai=1;
							break;
						}
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	printf("\n");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	return a1.zhi<a2.zhi;
}

void go(){
	int t;
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			while(ji[lin2].tai==1&&lin2<k2){
				lin2++;
			}
			if(a[i]>ji[lin2].zhi&&lin2<k2){
				t=a[i];
				a[i]=ji[lin2].zhi;
				a[ji[lin2].pos]=t;
				lin2++;
			}
			else{
				for(int j=lin1;j<k1;j++){
					if(o[j].zhi==a[i]){
						o[j].tai=1;
						break;
					}
				}

			}
		}
		else if(a[i]%2==1&&lin1<k1){
			while(o[lin1].tai==1&&lin1<k1){
				lin1++;
			}
			if(a[i]>o[lin1].zhi&&lin1<k1){
				t=a[i];
				a[i]=o[lin1].zhi;
				a[o[lin1].pos]=t;
				lin1++;
			}
			else{
				for(int j=lin2;j<k2;j++){
					if(ji[j].zhi==a[i]){
						ji[j].tai=1;
						break;
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	return a1.zhi<a2.zhi;
}

void go(){
	int t;
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			while(ji[lin2].tai==1&&lin2<k2){
				lin2++;
			}
			if(lin2<k2){
				if(a[i]>ji[lin2].zhi){
					t=a[i];
					a[i]=ji[lin2].zhi;
					a[ji[lin2].pos]=t;
					lin2++;
				}
			}

			else{
				for(int j=lin1;j<k1;j++){
					if(o[j].zhi==a[i]){
						o[j].tai=1;
						break;
					}
				}
			}
		}
		else{
			while(o[lin1].tai==1&&lin1<k1){
				lin1++;
			}
			if(lin1<k1){
				if(a[i]>o[lin1].zhi){
					t=a[i];
					a[i]=o[lin1].zhi;
					a[o[lin1].pos]=t;
					lin1++;
				}
			}
			else{
				for(int j=lin2;j<k2;j++){
					if(ji[j].zhi==a[i]){
						ji[j].tai=1;
						break;
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	return a1.zhi<a2.zhi;
}

void go(){
	int t;
	for(int i=0;i<n;i++){
		if(a[i]%2==0&&lin2<k2){
			if(a[i]>ji[lin2].zhi){
				t=a[i];
				a[i]=ji[lin2].zhi;
				a[ji[lin2].pos]=t;
				lin2++;
			}
			else{
				for(int j=lin1;j<k1;j++){
					lin1=j;
					if(o[j].zhi==a[i]){
						lin1++;
						break;
					}
				}
			}
		}
		else if(a[i]%2==1&&lin1<k1){
			if(a[i]>o[lin1].zhi){
				t=a[i];
				a[i]=o[lin1].zhi;
				a[o[lin1].pos]=t;
				lin1++;
			}
			else{
				for(int j=lin2;j<k2;j++){
					lin2=j;
					if(ji[j].zhi==a[i]){
						lin2++;
						break;
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	return a1.zhi<a2.zhi;
}

void go(){
	for(int i=0;i<n;i++){
		int t=0;
		if(a[i]%2==0){
			while(lin2<k2&&ji[lin2].tai==1){
				lin2++;
			}
			if(lin2<k2){
				if(a[i]>ji[lin2].zhi){
					t=a[i];
					a[i]=ji[lin2].zhi;
					a[ji[lin2].pos]=t;
					lin2++;
				}
				else{
					for(int j=lin1;j<k1;j++){
						if(o[j].zhi==a[i]){
							o[j].tai=1;
							break;
						}
					}
				}
			}
		}
		else{
			while(lin1<k1&&o[lin1].tai==1){
				lin1++;
			}
			if(lin1<k1){
				if(a[i]>o[lin1].zhi){
					t=a[i];
					a[i]=o[lin1].zhi;
					a[o[lin1].pos]=t;
					lin1++;
				}
				else{
					for(int j=lin2;j<k2;j++){
						if(ji[j].zhi==a[i]){
							ji[j].tai=1;
							break;
						}
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100005],ji,ou;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==1)ji=1;
		if(a[i]%2==0)ou=1;
	}
	if(ji==1&&ou==1){
		sort(a,a+n);
	}
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];

bool cmp(madoka a1,madoka a2){
	return a1.zhi<a2.zhi;
}

void go(){
	int t;
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			while(ji[lin2].tai==1&&lin2<k2){
				lin2++;
			}
			if(lin2<k2){
				if(a[i]>ji[lin2].zhi){
					t=a[i];
					a[i]=ji[lin2].zhi;
					a[ji[lin2].pos]=t;
					lin2++;
				}
				else{
					for(int j=lin1;j<k1;j++){
						if(o[j].zhi==a[i]){
							o[j].tai=1;
							break;
						}
					}
				}
			}
		}
		else{
			while(o[lin1].tai==1&&lin1<k1){
				lin1++;
			}
			if(lin1<k1){
				if(a[i]>o[lin1].zhi){
					t=a[i];
					a[i]=o[lin1].zhi;
					a[o[lin1].pos]=t;
					lin1++;
				}
				else{
					for(int j=lin2;j<k2;j++){
						if(ji[j].zhi==a[i]){
							ji[j].tai=1;
							break;
						}
					}
				}
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	sort(o,o+k1,cmp);
	sort(ji,ji+k2,cmp);
	go();
	for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000000],k1,k2,lin1,lin2;

struct madoka{
	int zhi;
	int pos;
	int tai;
}o[1000000],ji[1000000];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			o[k1].zhi=a[i];
			o[k1].pos=i;
			k1++;
		}
		else{
			ji[k2].zhi=a[i];
			ji[k2].pos=i;
			k2++;
		}
	}
	while(1){
		n++;
		n--;
	}
}