Logo
(追記) (追記ここまで)

19064번 - Readability 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB116654.545%

문제

The Martian alphabet consists of 10ドル^9$ integers from 1ドル$ to 10ドル^9$. Odd integers are vowels, and even integers are consonants. A word is a sequence of such integers.

Why do Martians have such a big alphabet? It gives the language an interesting property: changing the order of the integers in a word does not change its meaning. But, it does change its pronunciation. If each pair of adjacent integers in a word contains one vowel and one consonant, such word is called readable.

Vasya Pupkin decided to open a restaurant of Earthern cuisine on Mars. He bought $n$ wooden integers for its name and placed them in a row on $n$ pedestals, numbered from 1ドル$ to $n$. The integer placed on $i$-th pedestal is denoted as $a_i$.

Now Vasya wants to reorder the integers, because he wants the name of the restaurant to be readable. But moving an integer from pedestal $i$ to pedestal $j$ costs $|i - j|$ Martian rubles. Integers are flat, so two or more of them can be placed on one pedestal while reordering, but in the end, each pedestal must have exactly one integer on it.

Help Vasya to find a readable word formed by reordering the integers that requires him to pay as little Martian rubles as possible. If there are several such words, choose one that is the smallest lexicographically, because that will put the name of the restaurant earlier in the telephone directory.

A sequence of integers $b_i$ is lexicographically smaller than a sequence of the same length $c_i$ if there exists such index $j$ that $b_i = c_i$ for all $i < j,ドル but $b_j < c_j$.

입력

The first line contains an integer $n,ドル the number of Martian letters in the word (1ドル \leq n \leq 10^5$).

The second line contains $n$ space-separated integers $a_i$: the letters themselves (1ドル \leq a_i \leq 10^9$).

It is guaranteed that the solution exists.

출력

Output one line. It must contain $n$ space-separated integers: the required readable word.

제한

예제 입력 1

5
5 3 1 4 2

예제 출력 1

5 2 1 4 3

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2017 > Day 3: Ural Contest J번

Contest > Open Cup > 2017/2018 Season > Stage 2: Grand Prix of Ural J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /