1174B Ehab Is an Odd Person

B. Ehab Is an Odd Person

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given an array aa of length nn. You can perform the following operation on it as many times as you want:

  • Pick two integers ii and jj (1≤i,j≤n)(1≤i,j≤n) such that ai+ajai+aj is odd, then swap aiai and ajaj.

What is lexicographically the smallest array you can obtain?

An array xx is lexicographically smaller than an array yy if there exists an index ii such that xi<yixi<yi, and xj=yjxj=yj for all 1≤j<i1≤j<i. Less formally, at the first index ii in which they differ, xi<yixi<yi

Input

The first line contains an integer nn (1≤n≤1051≤n≤105) — the number of elements in the array aa.

The second line contains nn space-separated integers a1a1, a2a2, ……, anan (1≤ai≤1091≤ai≤109) — the elements of the array aa.

Output

The only line contains nn space-separated integers, the lexicographically smallest array you can obtain.

Examples

input

Copy

3
4 1 7

output

Copy

1 4 7 

input

Copy

2
1 1

output

Copy

1 1 

Note

In the first example, we can swap 11 and 44 since 1+4=51+4=5, which is odd.

题意:给了n个数,如果里面两个数的和是奇数,就能交换他们的位置,能无限次交换不同这种数,输出经过交换后字典序最小的排列,也就是从小到大的顺序。

题解:如果这些数里面有一个奇数和一个偶数,就能直接排序(也就是经过多次交换达到排序的效果),没有的话就原样输出。

c++:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[100010],odd=0,even=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
         cin>>a[i];
         if(a[i]&1) odd=1;
         else even=1;
    }
    if(odd&&even)
        sort(a,a+n);
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    return 0;
}

python:

n=int(input())
a=list(map(int,input().split()))
odd=0;even=0
for i in a:
          if i%2: odd=1
          else:even=1
if odd and even:
          print(*sorted(a))
else:print(*a)

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落凡尘.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值