Black Box

시간 제한1초메모리 제한2048 MB

요약
주어진 셔플 함수 BlackBox의 결과 Z가 나오도록 원래 리스트 I를 역으로 복원한다.
난이도

보통10점 중 7점

유형
구현, 배열, 수학
정답자
아직 제출이 없습니다

문제

The following Python-like pseudo code for function BlackBox() takes a list of positive integers and shuffles the integers in the list in a specific way, and returns the result as a list.

Three list methods are used below; For a list L, len(L) returns the number of items in L. L.append(x) adds the item x to the end of L. L.pop(idx) removes the item at the specified index idx from the list L and returns the removed item.

Given a list Z of positive integers, write a program to reconstruct a list I such that Z = BlackBox(I).

function BlackBox( Banana ):
    if len( Banana ) ≤ 4 :
        exit("Too small Banana")
    Apple = [] # [] is an empty list
    Mango = 0
    Papaya = len( Banana )

    while( Papaya >= 2 ) :
        Kiwi = Banana[ Mango ]
        Apple.append( Kiwi )
        Banana.pop( Mango )
        Papaya = Papaya - 1
        Mango = ( Kiwi + Mango - 1 ) % Papaya
    # end of while

    Apple.append( Banana[ 0 ] )
    Pear = len( Apple ) - 1
    Orange = Apple[ Pear ]
    Lime = Apple[ 0 ]
    Coconut = Orange % Pear
    Melon = Apple[ Coconut ]
    Apple[ 0 ] = Melon
    Apple[ Coconut ] = Lime

    return ( Apple )
# end of function BlackBox

입력

Your program is to read from standard input. The first line contains a positive integer nn representing the number of positive integers of a list Z, where 5≤n≤200,0005 ≤ n ≤ 200\\,000. The following nn lines contain nn positive integers of the list Z returned from BlackBox(I); the ii-th line contains the ii-th integer of the list Z between 11 and 100,000100\\,000, both inclusive.

출력

Your program is to write to standard output. Print nn integers of the list I where Z = BlackBox(I), one per line; the ii-th line should contain the ii-th integer of I.

예제2

  1. 예제 1

    입력
    13
    113
    49
    68
    91
    10
    179
    2
    71
    78
    45
    57
    10
    88
    
    예상 출력
    10
    113
    179
    68
    57
    45
    10
    2
    88
    71
    49
    78
    91
    
  2. 예제 2

    입력
    9
    6
    8
    7
    9
    5
    1
    2
    4
    3
    
    예상 출력
    9
    8
    7
    6
    5
    1
    2
    3
    4