2022 Azerbaijan Round 1, 8-9-10-11 classes
Lexicographically smallest cyclic shift
A permutation of order n is a sequence of pairwise distinct positive integers
pn, where each 1 ≤
pi ≤ n. We say that the permutation
qn is lexicographically less than the permutation
pn if there is i such that
pi, and for any j < i
A cyclic shift by k of a permutation
pn is the sequence
pk. Note that any cyclic shift of a permutation is also a permutation.
Find the lexicographically smallest cyclic shift of the given permutation.
The first line contains the order n (1 ≤ n ≤
105) of the given permutation. The second line contains numbers
Print the permutation that is the smallest lexicographically cyclic shift of the permutation given in the input. Use the same format as the permutation given in the second line of the input.
3 3 2 1
1 3 2