#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pdd = pair; using pll = pair; using pli = pair; using pil = pair; template using Graph = vector>; const int MOD = 1e9 + 7; const ld PI = acos(-1); int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i].first; A[i].second = i; } sort(A.rbegin(), A.rend()); if (N == 2) { cout << "1 2 1" << endl; return 0; } Graph G(N); for (int i = 0; i < N; ++i) { if (i == 0) { G[A[i].second].emplace_back(A[i + 1].second); G[A[i + 1].second].emplace_back(A[i].second); G[A[i].second].emplace_back(A[i + 2].second); G[A[i + 2].second].emplace_back(A[i].second); continue; } if (i + 2 < N) { G[A[i].second].emplace_back(A[i + 2].second); G[A[i + 2].second].emplace_back(A[i].second); continue; } if (i + 1 < N) { G[A[i].second].emplace_back(A[i + 1].second); G[A[i + 1].second].emplace_back(A[i].second); } } vector seen(N); int now = 0; seen[now] = true; for (int i = 0; i < N; ++i) { cout << now + 1 << " "; for (auto ni : G[now]) { if (seen[ni]) continue; now = ni; seen[now] = true; break; } } cout << 1 << endl; return 0; }