#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> res;
function<void(int, int)> build1 = [&](int l, int r) {
if (l > r) return;
int tl = l + 1, tr = r;
while (tl <= r && v[tl] < v[l]) tl++;
while (tr > l && v[tr] >= v[l]) tr--;
if (tl - tr != 1) return;
build1(l + 1, tr);
build1(tl, r);
res.push_back(v[l]);
};
function<void(int, int)> build2 = [&](int l, int r) {
if (l > r) return;
int tl = l + 1, tr = r;
while (tl <= r && v[tl] >= v[l]) tl++;
while (tr > l && v[tr] < v[l]) tr--;
if (tl - tr != 1) return;
build2(l + 1, tr);
build2(tl, r);
res.push_back(v[l]);
};
build1(0, n - 1);
if (res.size() == n) {
cout << "YES" << "\n";
for (int i = 0; i < res.size(); i++) {
cout << res[i] << " "[i == res.size() - 1];
}
return 0;
}
res.clear();
build2(0, n - 1);
if (res.size() == n) {
cout << "YES" << "\n";
for (int i = 0; i < res.size(); i++) {
cout << res[i] << " "[i == res.size() - 1];
}
return 0;
}
cout << "NO" << "\n";
return 0;
}