아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Catchy Tunes

시간 제한3초메모리 제한1024 MB

요약
적어도 절반의 노래가 고유한 아티스트를 가질 때, 연속한 두 노래의 아티스트가 겹치지 않도록 재생 목록을 배열한다.
난이도

보통10점 중 6점

유형
그리디, 힙, 해시맵
정답자
아직 제출이 없습니다

문제

Summer holidays are approaching, and Kate has to decide how to spend her time for two months. She was walking on the university campus, listening to music on her headphones, when suddenly she had an idea. When listening to her favourite playlist on shuffle, Kate noticed that sometimes the songs were not as shuffled as she would like them to be. She suddenly realised why this was happening: sometimes two songs from the same artist would be played in a row. "This is unacceptable," she thought, and asks you to write a program that would shuffle the songs in a way that consecutive songs played are from different artists.

Kate is not like any other listener: she likes diverse music. It is guaranteed that at least half of the songs in her playlist are from a unique artist (in other words, the artist of such a song has no other songs in the playlist).

Output the names of the songs in a well-shuffled playlist, where no two songs from the same artist are played in a row.

입력

The input consists of:

  • One line with integer nn (1≤n≤1051\leq n\leq 10^5), the number of songs in Kate's playlist.
  • nn lines, each with two space-separated strings aa and ss, the artist and the name of the song.

The artist and song names have length between 11 and 2020 characters, and only consist of English lowercase letters (a-z) and numbers (0-9).

The names of the songs are globally unique.

출력

Output nn strings, the names of the songs in a well-shuffled playlist.

If there are multiple valid solutions, you may output any one of them.

예제2

  1. 예제 1

    입력
    5
    greenbiscuits hard2catch
    greenbiscuits born2run
    thebakers baking1000breads
    2fast2fail flyinghigh
    rock2thetop goingout
    
    예상 출력
    hard2catch
    baking1000breads
    flyinghigh
    goingout
    born2run
    
  2. 예제 2

    입력
    10
    a a1
    a a2
    a a3
    a a4
    a a5
    b b1
    c c1
    d d1
    e e1
    f f1
    
    예상 출력
    a1
    b1
    a2
    c1
    a3
    d1
    e1
    a4
    f1
    a5