#include <bits/stdc++.h>
using
namespace
std;
void
mountArray(vector<
int
>& arr)
{
int
N = arr.size();
vector<
int
> left(N, 1), right(N, 1);
for
(
int
i = 0; i < N; ++i) {
for
(
int
j = 0; j <= i; ++j) {
if
(arr[j] < arr[i]) {
left[i] = max(left[j] + 1, left[i]);
}
}
}
for
(
int
i = N - 1; i >= 0; --i) {
for
(
int
j = i; j <= N - 1; ++j) {
if
(arr[j] < arr[i]) {
right[i] = max(right[j] + 1, right[i]);
}
}
}
int
max = 0;
int
index = 0;
for
(
int
i = 1; i < N - 1; ++i) {
if
(left[i] != 1 && right[i] != 1) {
if
(max < (left[i] + right[i]) - 1) {
index = i;
max = (left[i] + right[i]) - 1;
}
}
}
vector<
int
> left1;
left1.push_back(arr[index]);
for
(
int
i = index; i >= 0; --i) {
if
(arr[i] < arr[index]) {
if
(left[i] + 1 == left[index]) {
left1.push_back(arr[i]);
left[index] -= 1;
}
}
}
vector<
int
> right1;
for
(
int
i = index; i < right.size(); ++i) {
if
(arr[index] > arr[i]) {
if
(right[i] + 1 == right[index]) {
right1.push_back(arr[i]);
right[index] -= 1;
}
}
}
if
(max < 3) {
cout << (-1) <<
"\n"
;
}
else
{
for
(
int
i = left1.size() - 1; i >= 0; --i) {
cout << left1[i] <<
" "
;
}
for
(
int
i = 0; i < right1.size(); ++i) {
cout << right1[i] <<
" "
;
}
}
}
int
main()
{
vector<
int
> arr = { 9, 8, 1, 7, 6, 5, 4, 3, 2, 1 };
mountArray(arr);
}