#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;const int N = (int)3e5 + 5;
int n;
int a[N * 2];int main() {cin >> n;for (int i = 0; i < n; i++) {cin >> a[i];a[i + n] = a[i]; // 构造成链}int l = 0, r = 1; // 一开始 r 不能等于 lint k = 0;while (l <= n - 1 && r <= n - 1)//再大就重复了{for (k = 0; k < n && a[l + k] == a[r + k]; k++); // 找到第一个不同的a[l + k] > a[r + k] ? l = l + k + 1 : r = r + k + 1;if (l == r) r++;}int p = min(l, r);for (int i = p; i <= (p + n - 1); i++) {cout << a[i] << " ";}
}