#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>

using namespace std;

const int M = 100005;
char tmp[2*M], s[M];
int main()
{
    int n;
    scanf("%d", &n);
    char *p = tmp;
    memset(tmp,'\0',sizeof(tmp));
    for(int i = 0; i < n; ++i)
    {
        scanf("%s", p);
        p += (strlen(p)+1);
    }
    scanf("%s", s);
    int len = strlen(s), i, j, flag = 0, to = 1;
    for(i = 0, j = 0; i < len; ++i)
        if(to==1)
        {
            while(s[i++]!='<'&&i<len);
            while(s[i++]!='3'&&i<len);
            --i;
            if(s[i]!='3') flag = 1;
            to = 0;
        }
        else if(to==0&&tmp[j]!='\0')
        {
            while(tmp[j]!='\0'&&i<len) {if(s[i]==tmp[j]) ++j; ++i; }
            ++j;--i;
            to = 1;
        }
    if(tmp[j]=='\0'&&flag==0&&to==0) puts("yes");
    else puts("no");
    return 0;
}


#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>

using namespace std;

const int M = 100005;
char tmp[M], s[M];
int main()
{
    int n;
    scanf("%d", &n);
    char *p = tmp;
    p[0] = '<'; p[1] = '3'; p += 2;
    for(int i = 0; i < n; ++i)
    {
        scanf("%s", p);
        p+=(strlen(p));
        p[0] = '<'; p[1] = '3'; p += 2;
    }
    scanf("%s", s);
    int len = strlen(s);
    int i, j;
    for(i = 0, j = 0; i < len; ++i)
        if(s[i]==tmp[j]) ++j;
    if(tmp[j]=='\0') puts("yes");
    else puts("no");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
int a[200100],book[200100];
int main()
{
	memset(book,0,sizeof(book));
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	int MAX=9999999,MIN=0;
	int flag=0;
	for(i=0;i<n;i++)
	{
		if(a[i]<=MIN&&a[i]>=MAX)
		{
			flag=1;
			break;
		}
		else
		{
			if(a[i]>MIN&&a[i]<MAX)
			{
			if(i==n-1)
			{
				break;
			 }
			if(a[i]<a[i+1])
			{
				MIN=a[i];
			}
			else
			{
				MAX=a[i];
				book[i]=1;
			}
			}
			else
			{
				if(a[i]>MIN)
				{
					MIN=a[i];
					continue;
				}
				if(a[i]<MAX)
				{
					MAX=a[i];
					book[i]=1;
					continue;
				}
			}
		}
	}
	if(flag)
	printf("NO");
	else
	{
		printf("YES\n");
	for(i=0;i<n;i++)
	{
		printf("%d ",book[i]);
	}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
int a[200100],in[200100],de[200100],book[200100];
int main()
{
	memset(book,0,sizeof(book));
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	int MAX=0,MIN=999999;
	j=0;
	if(a[1]>a[0])
	{
		de[j]=a[1];
		in[j++]=a[0];
		book[1]=1;
		MAX=a[1];
		MIN=a[0];
	}
	else
	{
		de[j]=a[0];
		in[j++]=a[1];
		book[0]=1;
		MAX=a[0];
		MIN=a[1];
	}
	int flag=0;
	for(i=2;i<n;i++)
	{
		if(a[i]>=MAX&&a[i]<=MIN)
		{
			flag=1;
			break;
		}
		if(a[i]>MIN&&i==n-1)
		{
			in[j++]=a[i];
			break;
		}
		if(a[i]<MAX)
		{
			de[j++]=a[i];
			MAX=a[i];
			book[i]=1;
		}
		else
		{
			if(a[i]>MIN)
			{
				MIN=a[i];
				in[j++]=a[i];
			}
		}
	}
	if(flag)
	printf("NO");
	else
	{
		printf("YES\n");
	for(i=0;i<n;i++)
	{
		printf("%d ",book[i]);
	}
	}
	return 0;
}


#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM(binsearch)
// --> binsearch
// ---- inserted library file binsearch.cc

template<typename T>
T binsearch(auto check, T yes, T no, T err = (T)1) {
  while (abs(yes - no) > err) {
    T mid = (yes + no) / (T)2;
    if (check(mid)) yes = mid;
    else            no  = mid;
  }
  return yes;
}

// ---- end binsearch.cc
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll n; cin >> n;
  vector<ll> A(n);
  for (ll i = 0; i < n; i++) cin >> A[i];
  ll lim = 2e5;

  auto check = [&](ll bnd) -> bool {
    ll stage = 0;
    ll prev = -1;
    for (ll i = 0; i < n; i++) {
      if (A[i] < bnd) continue;
      if (stage == 0) {
	prev = A[i];
	stage = 1;
      }else if (stage == 1) {
	if (prev <= A[i]) {
	  stage = 2;
	}
	prev = A[i];
      }else if (stage == 2) {
	if (prev >= A[i]) return false;
	prev = A[i];
      }
    }
    return true;
  };

  ll bnd = binsearch<ll>(check, lim, -1);

  ll stage = 0;
  vector<ll> ans(n);
  ll decLast = 1e10;
  ll incLast = -1;
  for (ll i = 0; i < n; i++) {
    if (stage == 0) {
      if (A[i] >= bnd) {
	if (decLast > A[i]) {
	  ans[i] = 1;
	  decLast = A[i];
	}else {
	  stage = 1;
	  ans[i] = 0;
	  incLast = A[i];
	}
      }else {
	if (incLast >= A[i]) {
	  cout << "NO\n";
	  return 0;
	}
	ans[i] = 0;
	incLast = A[i];
      }
    } else if (stage == 1) {
      if (A[i] >= bnd) {
	if (incLast >= A[i]) {
	  cout << "NO\n";
	  return 0;
	}
	ans[i] = 0;
	incLast = A[i];
      }else {
	if (decLast <= A[i]) {
	  cout << "NO\n";
	  return 0;
	}
	ans[i] = 1;
	decLast = A[i];
      }
    }
  }
  cout << "YES\n";
  for (ll i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM(binsearch cmpNaive debug)
// --> binsearch cmpNaive f:<< debug
// ---- inserted library file binsearch.cc

template<typename T>
T binsearch(auto check, T yes, T no, T err = (T)1) {
  while (abs(yes - no) > err) {
    T mid = (yes + no) / (T)2;
    if (check(mid)) yes = mid;
    else            no  = mid;
  }
  return yes;
}

// ---- end binsearch.cc
// ---- inserted library file cmpNaive.cc

const string end_mark("^__=end=__^");
const string end_file_mark("^__=end_file=__^");

int naive(istream& cin, ostream& cout);
int body(istream& cin, ostream& cout);

void cmpNaive() {
  while (true) {
    string s;
    getline(cin, s);
    bool run_body;
    if (s.at(0) == 'Q') {
      return;
    }else if (s.at(0) == 'B') {
      run_body = true;
    }else if (s.at(0) == 'N') {
      run_body = false;
    }else {
      cerr << "Unknown body/naive specifier.\n";
      exit(1);
    }
    string input_s;
    while (true) {
      getline(cin, s);
      if (s == end_mark) break;
      input_s += s;
      input_s += "\n";
    }
    stringstream ss_in(move(input_s));
    stringstream ss_out;
    if (run_body) {
      body(ss_in, ss_out);
    }else {
      naive(ss_in, ss_out);
    }
    cout << ss_out.str() << end_mark << endl;
  }
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

#if CMPNAIVE
  if (argc == 2) {
    if (strcmp(argv[1], "cmpNaive") == 0) {
      cmpNaive();
    }else if (strcmp(argv[1], "naive") == 0) {
      naive(cin, cout);
    }else {
      cerr << "Unknown argument.\n";
      exit(1);
    }
  }else {
#endif
    body(cin, cout);
#if CMPNAIVE
  }
#endif
  return 0;
}

/*
int naive(istream& cin, ostream& cout) {
  return 0;
}
int body(istream& cin, ostream& cout) {
  return 0;
}
*/

// ---- end cmpNaive.cc
// ---- inserted function << from util.cc
template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T1, typename T2, typename T3>
ostream& operator<< (ostream& os, const tuple<T1,T2,T3>& t) {
  os << "(" << get<0>(t) << ", " << get<1>(t)
     << ", " << get<2>(t) << ")";
  return os;
}

template <typename T1, typename T2, typename T3, typename T4>
ostream& operator<< (ostream& os, const tuple<T1,T2,T3,T4>& t) {
  os << "(" << get<0>(t) << ", " << get<1>(t)
     << ", " << get<2>(t) << ", " << get<3>(t) << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename C>
ostream& operator<< (ostream& os, const set<T, C>& v) {
  os << '{';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << '}';

  return os;
}

template <typename T, typename C>
ostream& operator<< (ostream& os, const unordered_set<T, C>& v) {
  os << '{';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << '}';

  return os;
}

template <typename T, typename C>
ostream& operator<< (ostream& os, const multiset<T, C>& v) {
  os << '{';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << '}';

  return os;
}

template <typename T1, typename T2, typename C>
ostream& operator<< (ostream& os, const map<T1, T2, C>& mp) {
  os << '[';
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it != mp.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  os << ']';

  return os;
}

template <typename T1, typename T2, typename C>
ostream& operator<< (ostream& os, const unordered_map<T1, T2, C>& mp) {
  os << '[';
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it != mp.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  os << ']';

  return os;
}

template <typename T, typename T2>
ostream& operator<< (ostream& os, const queue<T, T2>& orig) {
  queue<T, T2> que(orig);
  bool first = true;
  os << '[';
  while (!que.empty()) {
    T x = que.front(); que.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}

template <typename T>
ostream& operator<< (ostream& os, const stack<T>& st) {
  stack<T> tmp(st);
  os << '[';
  bool first = true;
  while (!tmp.empty()) {
    T& t = tmp.top();
    if (first) first = false;
    else os << ", ";
    os << t;
    tmp.pop();
  }
  os << ']';
  return os;
}

#if __cplusplus >= 201703L
template <typename T>
ostream& operator<< (ostream& os, const optional<T>& t) {
  if (t.has_value()) os << "v(" << t.value() << ")";
  else               os << "nullopt";
  return os;
}
#endif

ostream& operator<< (ostream& os, int8_t x) {
  os << (int32_t)x;
  return os;
}

// ---- end <<
// ---- inserted library file debug.cc
template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

#if DEBUG_LIB
  #define DLOG_LIB(...)        dbgLog(__VA_ARGS__)
  #define DFMT_LIB(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL_LIB(func, ...) func(__VA_ARGS__)
#else
  #define DLOG_LIB(...)
  #define DFMT_LIB(...)
  #define DCALL_LIB(func, ...)
#endif

// ---- end debug.cc
// @@ !! LIM  -- end mark --

int naive(istream& cin, ostream& cout) {

  ll n; cin >> n;
  vector<ll> A(n);
  for (ll i = 0; i < n; i++) cin >> A[i];

  auto judge = [&]() -> bool {

    auto sub = [&](const auto& vec) -> bool {
      ll incLast = -1;
      ll decLast = 1e10;
      for (ll i = 0; i < n; i++) {
	if (vec[i] == 1) {
	  if (decLast <= A[i]) return false;
	  decLast = A[i];
	}else {
	  if (incLast >= A[i]) return false;
	  incLast = A[i];
	}
      }
      return true;

    };

    string bans; cin >> bans;
    if (bans == "YES") {
      vector<ll> bvec(n);
      for (ll i = 0; i < n; i++) cin >> bvec[i];
      return sub(bvec);
    }else if (bans == "NO") {

      for (ll x = 0; x < (1LL << n); x++) {
	vector<ll> evec(n);
	for (ll i = 0; i < n; i++) evec[i] = ((x >> i) & 1);
	if (sub(evec)) return false;
      }
      return true;

    }else return false;

  };

  cout << (judge() ? "OK\n" : "NG\n");
  return 0;

  return 0;
}
int body(istream& cin, ostream& cout) {

  ll n; cin >> n;
  vector<ll> A(n);
  for (ll i = 0; i < n; i++) cin >> A[i];
  ll lim = 2e5;

  auto check = [&](ll bnd) -> bool {
    ll stage = 0;
    ll prev = -1;
    for (ll i = 0; i < n; i++) {
      if (A[i] < bnd) continue;
      if (stage == 0) {
	prev = A[i];
	stage = 1;
      }else if (stage == 1) {
	if (prev <= A[i]) {
	  stage = 2;
	}
	prev = A[i];
      }else if (stage == 2) {
	if (prev >= A[i]) return false;
	prev = A[i];
      }
    }
    return true;
  };

  ll bnd = binsearch<ll>(check, lim, -1);
  DLOG("bnd=", bnd);

  ll stage = 0;
  vector<ll> ans(n);
  ll decLast = 1e10;
  ll incLast = -1;
  for (ll i = 0; i < n; i++) {
    if (stage == 0) {
      if (A[i] >= bnd) {
	if (decLast > A[i]) {
	  ans[i] = 1;
	  decLast = A[i];
	}else {
	  stage = 1;
	  ans[i] = 0;
	  incLast = A[i];
	}
      }else {
	if (incLast < A[i]) {
	  ans[i] = 0;
	  incLast = A[i];
	}else {
	  stage = 1;
	  ans[i] = 1;
	  decLast = A[i];
	}
      }
    } else if (stage == 1) {
      if (A[i] >= bnd) {
	if (incLast >= A[i]) {
	  cout << "NO\n";
	  return 0;
	}
	ans[i] = 0;
	incLast = A[i];
      }else {
	if (decLast <= A[i]) {
	  cout << "NO\n";
	  return 0;
	}
	ans[i] = 1;
	decLast = A[i];
      }
    }
  }
  cout << "YES\n";
  for (ll i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


// Author: Sanskar Mani
// date: 2020-11-28 18:52:05

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#if DEBUG && !ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(args...)
#define test
#define print(a,n,k)
#endif
const int mod = 1000000007;
// const int mod = 998244353;
// #define int long long
#define TIME (chrono::steady_clock::now().time_since_epoch().count())
#define ull unsigned long long
#define ok order_of_key
#define fo find_by_order
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repp(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define newl cout<<'\n'
#define inf 1000000000
#define repaa(i,a) for(auto j=a.rbegin(),auto i = *j;j!=a.rend();++j,i=*j)
#define pb push_back
#define tc int tt;cin>>tt;while(tt--)
#define mem(v,i) memset(v,i,sizeof(v))
#define all(x) x.begin(), x.end()
#define inf1 1e18
#define repa(i,a) for (auto i : a)
#define X first
#define Y second
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define in(a,n) repp(jjj,n)cin>>a[jjj];
#define intree(a,m) repp(i,m){int tmp1,tmp2;cin>>tmp1>>tmp2;tmp1--,tmp2--;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define ins insert
#define er erase
#define sz(a) (int)(a.size())
#define mt make_tuple
#define eb emplace_back
#define bpl(i) __builtin_popcountll(i)
#define bp(i) __builtin_popcount(i)
#define precision(x) cout << fixed << setprecision(x);
#define si set<int>
#define usi unordered_set<int>
#define sl set < ll >
#define usl unordered_set < ll >
#define sip set < ip >
#define sil set < il >
#define mi map<int , int >
#define umi unordered_map<int , int >
#define ml map < ll , ll>
#define uml unordered_map < ll , ll>
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vii vector < vi >
#define vip vector<pair<int,int>>
#define vil vector<pair<ll,ll>>
#define vll vector < vl >
#define ip pair<int, int>
#define il pair<ll, ll>
const int dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const char nl = '\n',sp = ' ';
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){static char now[1<<16],*S,*T;if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}return *S++;}
#endif
ll R(ll B) {static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());return (unsigned long long)rng() % B;}
inline ll read(){register ll x=0,f=1;char ch=gc();while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}return (f==1)?x:-x;}
ull mix(ull o){o+=0x9e3779b97f4a7c15;o=(o^(o>>30))*0xbf58476d1ce4e5b9;o=(o^(o>>27))*0x94d049bb133111eb;return o^(o>>31);}
template<typename T>T Min(T v) {return v;}template<typename T, typename... Args>T Min(T first, Args... args) {return min(first , Min(args...));}
template<typename T>T Max(T v) {return v;}template<typename T, typename... Args> T Max(T first, Args... args) {return max(first , Max(args...));}
ll mult(ll v) {return v%mod;}template<typename... Args>ll mult(ll first, Args... args) {return mult((first%mod * mult(args...))%mod);}
template<class T , class U> inline bool remax(T &a, U b) {return a<b?a=b,1:0;}template<class T , class U> inline bool remin(T &a, U b) { return a > b ? a = b, 1 : 0; }
template<class A, class B> void add(A &a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}template<class A, class B> ll addr(A a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;return a;}
template<class T1,class T2>T2 min(T1 a,T2 b){return min((T2)a,b);}template<class T1,class T2>T2 max(T1 a,T2 b){return max((T2)a,b);}
void pnt(char a){if(a == nl || a == sp) cout << a;else cout << a << sp;}void pnt(string &a,int b = 0){cout << a << nl;}
template<class A> void pnt(A &a,int b=0) {cout << A(a + b) << sp;}template<class A ,class B> void pnt(pair<A,B>&a,int b=0){cout << A(a.X+b) << ' ' << B(a.Y+b) << nl;}
template<class A> void pnt(vector<A>&a,int b=0) {repa(i,a) pnt(i,b);}template<class A> void pnt(set<A>&a,int b=0) {repa(i,a) pnt(i,b);}
template<class A> void pnt(unordered_set<A>&a,int b=0) {repa(i,a) pnt(i,b) ;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.X>>v.Y;}
template<class T>struct isChar{bool ch(T a){return false;}};template<>struct isChar<char>{int ch(char s){return s == '`';}};
template<typename T>void W(T v){pnt(v);}template<typename T,typename A>void W(T f,A s) {if(isChar<A>().ch(s)) pnt(f,1);else pnt(f) ,W(s);}
template<typename T,typename A,typename... Args>void W(T f,A s,Args... args) {if(isChar<A>().ch(s)) pnt(f,1), W(args...);else pnt(f),W(s,args...);}
template <class T1>void kill(T1 ans){pnt(ans);exit(0);}ll nc2(ll a){return a * (a - 1) / 2;}
int mylog(ll x , ll y = 2){if(x == 0) return -1;return mylog(x/y,y) + 1;}ll setbit(ll n, ll kk){return 1LL*(n|(1LL<<kk));}
ll unsetbit(ll n, ll kk){return 1LL*(n&~(1LL<<kk));} ll invertbit(ll n, ll kk){return 1LL*(n^(1LL<<kk));}bool kthbit(ll n, ll kk){return n&(1LL<<kk);}
ll mceil(ll a, ll b){return a/b + (ll)(a%b > 0);} ll poww(ll a, ll b,ll m = mod){ll val = 1;a %= m;while (b > 0){if (b & 1) val = (a * val) % m;a = (a * a) % m;b >>= 1;}return val;}
ll inv(ll a,ll m=mod){return poww(a , m - 2);}ll gcdll(ll x, ll y){return y == 0 ? x : gcdll(y, x % y);}

//-------------------------------------------------LEZENDARY------------------------------------------------------------//
//------------------------------------------------------SANDWICH-------------------------------------------------------//

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int a[n]; in(a,n)
    int dp[n][2];
    repp(i,n) dp[i][0] = -inf, dp[i][1] = inf;
    dp[0][0] = inf, dp[0][1] = -inf;
    rep(i,1,n){
        if(a[i] > a[i - 1]) remax(dp[i][0], dp[i - 1][0]);
        if(a[i] > dp[i - 1][1]) remax(dp[i][0], a[i - 1]);
        if(a[i] < a[i - 1]) remin(dp[i][1], dp[i - 1][1]);
        if(a[i] < dp[i - 1][0]) remin(dp[i][1], a[i - 1]);
    }
    print(dp,n,2);
    if(dp[n - 1][0] == -inf && dp[n - 1][1] == inf) kill("NO");
    vi ans(n,-1);
    int cur = dp[n - 1][0] == - inf ? 1 : 0;
    ans[n - 1] = cur;
    ip tmp{inf, -inf};
    repr(i,n - 2){
        if(a[i] < tmp.X && dp[i][0] > tmp.Y) cur = 0;
        else cur = 1;
        ans[i] = cur;
    }
    W("YES", nl, ans);
}


// Author: Sanskar Mani
// date: 2020-11-28 18:52:05

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#if DEBUG && !ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(args...)
#define test
#define print(a,n,k)
#endif
const int mod = 1000000007;
// const int mod = 998244353;
// #define int long long
#define TIME (chrono::steady_clock::now().time_since_epoch().count())
#define ull unsigned long long
#define ok order_of_key
#define fo find_by_order
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repp(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define newl cout<<'\n'
#define inf 1000000000
#define repaa(i,a) for(auto j=a.rbegin(),auto i = *j;j!=a.rend();++j,i=*j)
#define pb push_back
#define tc int tt;cin>>tt;while(tt--)
#define mem(v,i) memset(v,i,sizeof(v))
#define all(x) x.begin(), x.end()
#define inf1 1e18
#define repa(i,a) for (auto i : a)
#define X first
#define Y second
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define in(a,n) repp(jjj,n)cin>>a[jjj];
#define intree(a,m) repp(i,m){int tmp1,tmp2;cin>>tmp1>>tmp2;tmp1--,tmp2--;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define ins insert
#define er erase
#define sz(a) (int)(a.size())
#define mt make_tuple
#define eb emplace_back
#define bpl(i) __builtin_popcountll(i)
#define bp(i) __builtin_popcount(i)
#define precision(x) cout << fixed << setprecision(x);
#define si set<int>
#define usi unordered_set<int>
#define sl set < ll >
#define usl unordered_set < ll >
#define sip set < ip >
#define sil set < il >
#define mi map<int , int >
#define umi unordered_map<int , int >
#define ml map < ll , ll>
#define uml unordered_map < ll , ll>
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vii vector < vi >
#define vip vector<pair<int,int>>
#define vil vector<pair<ll,ll>>
#define vll vector < vl >
#define ip pair<int, int>
#define il pair<ll, ll>
const int dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const char nl = '\n',sp = ' ';
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){static char now[1<<16],*S,*T;if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}return *S++;}
#endif
ll R(ll B) {static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());return (unsigned long long)rng() % B;}
inline ll read(){register ll x=0,f=1;char ch=gc();while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}return (f==1)?x:-x;}
ull mix(ull o){o+=0x9e3779b97f4a7c15;o=(o^(o>>30))*0xbf58476d1ce4e5b9;o=(o^(o>>27))*0x94d049bb133111eb;return o^(o>>31);}
template<typename T>T Min(T v) {return v;}template<typename T, typename... Args>T Min(T first, Args... args) {return min(first , Min(args...));}
template<typename T>T Max(T v) {return v;}template<typename T, typename... Args> T Max(T first, Args... args) {return max(first , Max(args...));}
ll mult(ll v) {return v%mod;}template<typename... Args>ll mult(ll first, Args... args) {return mult((first%mod * mult(args...))%mod);}
template<class T , class U> inline bool remax(T &a, U b) {return a<b?a=b,1:0;}template<class T , class U> inline bool remin(T &a, U b) { return a > b ? a = b, 1 : 0; }
template<class A, class B> void add(A &a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}template<class A, class B> ll addr(A a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;return a;}
template<class T1,class T2>T2 min(T1 a,T2 b){return min((T2)a,b);}template<class T1,class T2>T2 max(T1 a,T2 b){return max((T2)a,b);}
void pnt(char a){if(a == nl || a == sp) cout << a;else cout << a << sp;}void pnt(string &a,int b = 0){cout << a << nl;}
template<class A> void pnt(A &a,int b=0) {cout << A(a + b) << sp;}template<class A ,class B> void pnt(pair<A,B>&a,int b=0){cout << A(a.X+b) << ' ' << B(a.Y+b) << nl;}
template<class A> void pnt(vector<A>&a,int b=0) {repa(i,a) pnt(i,b);}template<class A> void pnt(set<A>&a,int b=0) {repa(i,a) pnt(i,b);}
template<class A> void pnt(unordered_set<A>&a,int b=0) {repa(i,a) pnt(i,b) ;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.X>>v.Y;}
template<class T>struct isChar{bool ch(T a){return false;}};template<>struct isChar<char>{int ch(char s){return s == '`';}};
template<typename T>void W(T v){pnt(v);}template<typename T,typename A>void W(T f,A s) {if(isChar<A>().ch(s)) pnt(f,1);else pnt(f) ,W(s);}
template<typename T,typename A,typename... Args>void W(T f,A s,Args... args) {if(isChar<A>().ch(s)) pnt(f,1), W(args...);else pnt(f),W(s,args...);}
template <class T1>void kill(T1 ans){pnt(ans);exit(0);}ll nc2(ll a){return a * (a - 1) / 2;}
int mylog(ll x , ll y = 2){if(x == 0) return -1;return mylog(x/y,y) + 1;}ll setbit(ll n, ll kk){return 1LL*(n|(1LL<<kk));}
ll unsetbit(ll n, ll kk){return 1LL*(n&~(1LL<<kk));} ll invertbit(ll n, ll kk){return 1LL*(n^(1LL<<kk));}bool kthbit(ll n, ll kk){return n&(1LL<<kk);}
ll mceil(ll a, ll b){return a/b + (ll)(a%b > 0);} ll poww(ll a, ll b,ll m = mod){ll val = 1;a %= m;while (b > 0){if (b & 1) val = (a * val) % m;a = (a * a) % m;b >>= 1;}return val;}
ll inv(ll a,ll m=mod){return poww(a , m - 2);}ll gcdll(ll x, ll y){return y == 0 ? x : gcdll(y, x % y);}

//-------------------------------------------------LEZENDARY------------------------------------------------------------//
//------------------------------------------------------SANDWICH-------------------------------------------------------//

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int a[n]; in(a,n)
    int dp[n][2], prev[n][2];
    repp(i,n) dp[i][0] = -inf, dp[i][1] = inf;
    dp[0][0] = inf, dp[0][1] = -inf;
    prev[0][0] = prev[0][1] = -1;
    rep(i,1,n){
        if(a[i] > a[i - 1]) remax(dp[i][0], dp[i - 1][0]), prev[i][0] = 0;
        if(a[i] > dp[i - 1][1]) remax(dp[i][0], a[i - 1]), prev[i][0] = 1;
        if(a[i] < a[i - 1]) remin(dp[i][1], dp[i - 1][1]), prev[i][1] = 1;
        if(a[i] < dp[i - 1][0]) remin(dp[i][1], a[i - 1]), prev[i][1] = 0;
    }
    print(dp,n,2);
    if(dp[n - 1][0] == -inf && dp[n - 1][1] == inf) kill("NO");
    vi ans(n);
    int cur = dp[n - 1][0] == - inf ? 1 : 0;
    int st = n - 1;
    while(cur != -1){
        ans[st] = cur;
        cur = prev[st --][cur];
    }
    W("YES", nl, ans);
}


// Author: Sanskar Mani
// date: 2020-11-28 18:52:05

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#if DEBUG && !ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(args...)
#define test
#define print(a,n,k)
#endif
const int mod = 1000000007;
// const int mod = 998244353;
// #define int long long
#define TIME (chrono::steady_clock::now().time_since_epoch().count())
#define ull unsigned long long
#define ok order_of_key
#define fo find_by_order
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repp(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define newl cout<<'\n'
#define inf 1000000000
#define repaa(i,a) for(auto j=a.rbegin(),auto i = *j;j!=a.rend();++j,i=*j)
#define pb push_back
#define tc int tt;cin>>tt;while(tt--)
#define mem(v,i) memset(v,i,sizeof(v))
#define all(x) x.begin(), x.end()
#define inf1 1e18
#define repa(i,a) for (auto i : a)
#define X first
#define Y second
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define in(a,n) repp(jjj,n)cin>>a[jjj];
#define intree(a,m) repp(i,m){int tmp1,tmp2;cin>>tmp1>>tmp2;tmp1--,tmp2--;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define ins insert
#define er erase
#define sz(a) (int)(a.size())
#define mt make_tuple
#define eb emplace_back
#define bpl(i) __builtin_popcountll(i)
#define bp(i) __builtin_popcount(i)
#define precision(x) cout << fixed << setprecision(x);
#define si set<int>
#define usi unordered_set<int>
#define sl set < ll >
#define usl unordered_set < ll >
#define sip set < ip >
#define sil set < il >
#define mi map<int , int >
#define umi unordered_map<int , int >
#define ml map < ll , ll>
#define uml unordered_map < ll , ll>
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vii vector < vi >
#define vip vector<pair<int,int>>
#define vil vector<pair<ll,ll>>
#define vll vector < vl >
#define ip pair<int, int>
#define il pair<ll, ll>
const int dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const char nl = '\n',sp = ' ';
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){static char now[1<<16],*S,*T;if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}return *S++;}
#endif
ll R(ll B) {static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());return (unsigned long long)rng() % B;}
inline ll read(){register ll x=0,f=1;char ch=gc();while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}return (f==1)?x:-x;}
ull mix(ull o){o+=0x9e3779b97f4a7c15;o=(o^(o>>30))*0xbf58476d1ce4e5b9;o=(o^(o>>27))*0x94d049bb133111eb;return o^(o>>31);}
template<typename T>T Min(T v) {return v;}template<typename T, typename... Args>T Min(T first, Args... args) {return min(first , Min(args...));}
template<typename T>T Max(T v) {return v;}template<typename T, typename... Args> T Max(T first, Args... args) {return max(first , Max(args...));}
ll mult(ll v) {return v%mod;}template<typename... Args>ll mult(ll first, Args... args) {return mult((first%mod * mult(args...))%mod);}
template<class T , class U> inline bool remax(T &a, U b) {return a<b?a=b,1:0;}template<class T , class U> inline bool remin(T &a, U b) { return a > b ? a = b, 1 : 0; }
template<class A, class B> void add(A &a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}template<class A, class B> ll addr(A a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;return a;}
template<class T1,class T2>T2 min(T1 a,T2 b){return min((T2)a,b);}template<class T1,class T2>T2 max(T1 a,T2 b){return max((T2)a,b);}
void pnt(char a){if(a == nl || a == sp) cout << a;else cout << a << sp;}void pnt(string &a,int b = 0){cout << a << nl;}
template<class A> void pnt(A &a,int b=0) {cout << A(a + b) << sp;}template<class A ,class B> void pnt(pair<A,B>&a,int b=0){cout << A(a.X+b) << ' ' << B(a.Y+b) << nl;}
template<class A> void pnt(vector<A>&a,int b=0) {repa(i,a) pnt(i,b);}template<class A> void pnt(set<A>&a,int b=0) {repa(i,a) pnt(i,b);}
template<class A> void pnt(unordered_set<A>&a,int b=0) {repa(i,a) pnt(i,b) ;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.X>>v.Y;}
template<class T>struct isChar{bool ch(T a){return false;}};template<>struct isChar<char>{int ch(char s){return s == '`';}};
template<typename T>void W(T v){pnt(v);}template<typename T,typename A>void W(T f,A s) {if(isChar<A>().ch(s)) pnt(f,1);else pnt(f) ,W(s);}
template<typename T,typename A,typename... Args>void W(T f,A s,Args... args) {if(isChar<A>().ch(s)) pnt(f,1), W(args...);else pnt(f),W(s,args...);}
template <class T1>void kill(T1 ans){pnt(ans);exit(0);}ll nc2(ll a){return a * (a - 1) / 2;}
int mylog(ll x , ll y = 2){if(x == 0) return -1;return mylog(x/y,y) + 1;}ll setbit(ll n, ll kk){return 1LL*(n|(1LL<<kk));}
ll unsetbit(ll n, ll kk){return 1LL*(n&~(1LL<<kk));} ll invertbit(ll n, ll kk){return 1LL*(n^(1LL<<kk));}bool kthbit(ll n, ll kk){return n&(1LL<<kk);}
ll mceil(ll a, ll b){return a/b + (ll)(a%b > 0);} ll poww(ll a, ll b,ll m = mod){ll val = 1;a %= m;while (b > 0){if (b & 1) val = (a * val) % m;a = (a * a) % m;b >>= 1;}return val;}
ll inv(ll a,ll m=mod){return poww(a , m - 2);}ll gcdll(ll x, ll y){return y == 0 ? x : gcdll(y, x % y);}

//-------------------------------------------------LEZENDARY------------------------------------------------------------//
//------------------------------------------------------SANDWICH-------------------------------------------------------//

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int a[n]; in(a,n)
    int dp[n][2];
    repp(i,n) dp[i][0] = -inf, dp[i][1] = inf;
    dp[0][0] = inf, dp[0][1] = -inf;
    rep(i,1,n){
        if(a[i] > a[i - 1]) remax(dp[i][0], dp[i - 1][0]);
        if(a[i] > dp[i - 1][1]) remax(dp[i][0], a[i - 1]);
        if(a[i] < a[i - 1]) remin(dp[i][1], dp[i - 1][1]);
        if(a[i] < dp[i - 1][0]) remin(dp[i][1], a[i - 1]);
    }
    print(dp,n,2);
    if(dp[n - 1][0] == -inf && dp[n - 1][1] == inf) kill("NO");
    vi ans(n,-1);
    int cur = dp[n - 1][0] == - inf ? 1 : 0;
    ans[n - 1] = cur;
    ip tmp{inf, -inf};
    if(cur == 0) tmp.X = a[n - 1]; else tmp.Y = a[n - 1];
    repr(i,n - 2){
        if(a[i] < tmp.X && dp[i][0] > tmp.Y) cur = 0, tmp.X = a[i];
        else cur = 1, tmp.Y = a[i];
        ans[i] = cur;
    }
    W("YES", nl, ans);
}


// Author: Sanskar Mani
// date: 2020-11-28 18:52:05

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#if DEBUG && !ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(args...)
#define test
#define print(a,n,k)
#endif
const int mod = 1000000007;
// const int mod = 998244353;
// #define int long long
#define TIME (chrono::steady_clock::now().time_since_epoch().count())
#define ull unsigned long long
#define ok order_of_key
#define fo find_by_order
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repp(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define newl cout<<'\n'
#define inf 1000000000
#define repaa(i,a) for(auto j=a.rbegin(),auto i = *j;j!=a.rend();++j,i=*j)
#define pb push_back
#define tc int tt;cin>>tt;while(tt--)
#define mem(v,i) memset(v,i,sizeof(v))
#define all(x) x.begin(), x.end()
#define inf1 1e18
#define repa(i,a) for (auto i : a)
#define X first
#define Y second
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define in(a,n) repp(jjj,n)cin>>a[jjj];
#define intree(a,m) repp(i,m){int tmp1,tmp2;cin>>tmp1>>tmp2;tmp1--,tmp2--;a[tmp1].eb(tmp2);a[tmp2].eb(tmp1);}
#define ins insert
#define er erase
#define sz(a) (int)(a.size())
#define mt make_tuple
#define eb emplace_back
#define bpl(i) __builtin_popcountll(i)
#define bp(i) __builtin_popcount(i)
#define precision(x) cout << fixed << setprecision(x);
#define si set<int>
#define usi unordered_set<int>
#define sl set < ll >
#define usl unordered_set < ll >
#define sip set < ip >
#define sil set < il >
#define mi map<int , int >
#define umi unordered_map<int , int >
#define ml map < ll , ll>
#define uml unordered_map < ll , ll>
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vii vector < vi >
#define vip vector<pair<int,int>>
#define vil vector<pair<ll,ll>>
#define vll vector < vl >
#define ip pair<int, int>
#define il pair<ll, ll>
const int dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const char nl = '\n',sp = ' ';
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){static char now[1<<16],*S,*T;if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}return *S++;}
#endif
ll R(ll B) {static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());return (unsigned long long)rng() % B;}
inline ll read(){register ll x=0,f=1;char ch=gc();while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}return (f==1)?x:-x;}
ull mix(ull o){o+=0x9e3779b97f4a7c15;o=(o^(o>>30))*0xbf58476d1ce4e5b9;o=(o^(o>>27))*0x94d049bb133111eb;return o^(o>>31);}
template<typename T>T Min(T v) {return v;}template<typename T, typename... Args>T Min(T first, Args... args) {return min(first , Min(args...));}
template<typename T>T Max(T v) {return v;}template<typename T, typename... Args> T Max(T first, Args... args) {return max(first , Max(args...));}
ll mult(ll v) {return v%mod;}template<typename... Args>ll mult(ll first, Args... args) {return mult((first%mod * mult(args...))%mod);}
template<class T , class U> inline bool remax(T &a, U b) {return a<b?a=b,1:0;}template<class T , class U> inline bool remin(T &a, U b) { return a > b ? a = b, 1 : 0; }
template<class A, class B> void add(A &a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}template<class A, class B> ll addr(A a, B b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;return a;}
template<class T1,class T2>T2 min(T1 a,T2 b){return min((T2)a,b);}template<class T1,class T2>T2 max(T1 a,T2 b){return max((T2)a,b);}
void pnt(char a){if(a == nl || a == sp) cout << a;else cout << a << sp;}void pnt(string &a,int b = 0){cout << a << nl;}
template<class A> void pnt(A &a,int b=0) {cout << A(a + b) << sp;}template<class A ,class B> void pnt(pair<A,B>&a,int b=0){cout << A(a.X+b) << ' ' << B(a.Y+b) << nl;}
template<class A> void pnt(vector<A>&a,int b=0) {repa(i,a) pnt(i,b);}template<class A> void pnt(set<A>&a,int b=0) {repa(i,a) pnt(i,b);}
template<class A> void pnt(unordered_set<A>&a,int b=0) {repa(i,a) pnt(i,b) ;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.X>>v.Y;}
template<class T>struct isChar{bool ch(T a){return false;}};template<>struct isChar<char>{int ch(char s){return s == '`';}};
template<typename T>void W(T v){pnt(v);}template<typename T,typename A>void W(T f,A s) {if(isChar<A>().ch(s)) pnt(f,1);else pnt(f) ,W(s);}
template<typename T,typename A,typename... Args>void W(T f,A s,Args... args) {if(isChar<A>().ch(s)) pnt(f,1), W(args...);else pnt(f),W(s,args...);}
template <class T1>void kill(T1 ans){pnt(ans);exit(0);}ll nc2(ll a){return a * (a - 1) / 2;}
int mylog(ll x , ll y = 2){if(x == 0) return -1;return mylog(x/y,y) + 1;}ll setbit(ll n, ll kk){return 1LL*(n|(1LL<<kk));}
ll unsetbit(ll n, ll kk){return 1LL*(n&~(1LL<<kk));} ll invertbit(ll n, ll kk){return 1LL*(n^(1LL<<kk));}bool kthbit(ll n, ll kk){return n&(1LL<<kk);}
ll mceil(ll a, ll b){return a/b + (ll)(a%b > 0);} ll poww(ll a, ll b,ll m = mod){ll val = 1;a %= m;while (b > 0){if (b & 1) val = (a * val) % m;a = (a * a) % m;b >>= 1;}return val;}
ll inv(ll a,ll m=mod){return poww(a , m - 2);}ll gcdll(ll x, ll y){return y == 0 ? x : gcdll(y, x % y);}

//-------------------------------------------------LEZENDARY------------------------------------------------------------//
//------------------------------------------------------SANDWICH-------------------------------------------------------//

signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int a[n]; in(a,n)
    int dp[n][2];
    repp(i,n) dp[i][0] = -inf, dp[i][1] = inf;
    dp[0][0] = inf, dp[0][1] = -inf;
    rep(i,1,n){
        if(a[i] > a[i - 1]) remax(dp[i][0], dp[i - 1][0]);
        if(a[i] > dp[i - 1][1]) remax(dp[i][0], a[i - 1]);
        if(a[i] < a[i - 1]) remin(dp[i][1], dp[i - 1][1]);
        if(a[i] < dp[i - 1][0]) remin(dp[i][1], a[i - 1]);
    }
    print(dp,n,2);
    if(dp[n - 1][0] == -inf && dp[n - 1][1] == inf) kill("NO");
    vi ans(n,-1);
    int cur = dp[n - 1][0] == - inf ? 1 : 0;
    ans[n - 1] = cur;
    ip tmp{inf, -inf};
    repr(i,n - 2){
        if(a[i] < tmp.X && dp[i][0] > tmp.Y) cur = 0, tmp.X = a[i];
        else cur = 1, tmp.Y = a[i];
        ans[i] = cur;
    }
    W("YES", nl, ans);
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	scanf("%lld",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%lld",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
		ans[lisite]=0;
		assert(0<=lisite && lisite<n && lisite>bef[lisite]);
		lisite=bef[lisite];
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%lld",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	scanf("%lld",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%lld",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
		ans[lisite]=0;
		lisite=bef[lisite];
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%lld",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//typedef long long ll;
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	/*
	FILE *fp;
	fp=fopen("test.txt","r");
	if(fp==NULL){
		printf("error!\n");
		return -1;
	}
	*/
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
//		assert(0<=lisite && lisite<n && lisite>bef[lisite]);
		ans[lisite]=0;
		lisite=bef[lisite];
//		printf("lisite=%lld\n",lisite);
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
//	fclose(fp);
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5+8,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
		ans[lisite]=0;
		lisite=bef[lisite];
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//typedef long long ll;
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	/*
	FILE *fp;
	fp=fopen("test.txt","r");
	if(fp==NULL){
		printf("error!\n");
		return -1;
	}
	*/
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	assert(n<=10);
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
//		assert(0<=lisite && lisite<n && lisite>bef[lisite]);
		ans[lisite]=0;
		lisite=bef[lisite];
//		printf("lisite=%lld\n",lisite);
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
//	fclose(fp);
}


#include <bits/stdc++.h>
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
typedef pair<ll,ll> P;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
vector<P> lisary,dsary;
int main(){
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
		ans[lisite]=0;
		lisary.push_back(P(a[lisite],lisite));
		lisite=bef[lisite];
	}
	reverse(lisary.begin(),lisary.end());
	ll cnt=0,cinx=-1;
	REP(i,n){
		if(ans[i]==-1){
			if(!dsary.empty() && dsary.back().first<=a[i]){
				cnt++;
				cinx=dsary.size();
			}
			dsary.push_back(P(a[i],i));
			ans[i]=1;
		}
	}
	bool ansf=true;
	if(cnt>=2){
		ansf=false;
	}else if(cnt==1){
		ansf=false;
		REP(i,2){
			ll i2=1-i;
			auto lmd=[](const P &a,const P &b){
				return a.second<b.second;
			};
			if(cinx-2>=0 && dsary[cinx-2].first<=dsary[cinx-i].first){
				continue;
			}
			if(cinx+1<dsary.size() && dsary[cinx-i].first<=dsary[cinx+1].first){
				continue;
			}
			ll ite=lower_bound(lisary.begin(),lisary.end(),dsary[cinx-i2],lmd)-lisary.begin();
			ll ret,c=0;
			if(ite>0 && lisary[ite-1].first>=dsary[cinx-i2].first){
				ret=ite-1;
				c++;
			}
			if(ite<lisary.size() && dsary[cinx-i2].first>=lisary[ite].first){
				ret=ite;
				c++;
			}
			if(ite>1 && lisary[ite-2].first>=dsary[cinx-i2].first){
				c+=2;
			}
			if(ite+1<lisary.size() && dsary[cinx-i2].first>=lisary[ite+1].first){
				c+=2;
			}
			if(c>=2){
				continue;
			}
			ite=lower_bound(dsary.begin(),dsary.end(),lisary[ret],lmd)-dsary.begin();
			if(ite==cinx-i2)ite++;
			if(ite<dsary.size() && lisary[ret].first<=dsary[ite].first){
				continue;
			}
			ite=lower_bound(dsary.begin(),dsary.end(),lisary[ret],lmd)-dsary.begin();
			ite--;
			if(ite==cinx-i2)ite--;
			if(ite>0 && dsary[ite].first<=lisary[ret].first){
				continue;
			}
			ans[lisary[ret].second]=1;
			ans[dsary[cinx-i2].second]=0;
			ansf=true;
			break;
		}
	}

	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
		ans[lisite]=0;
		lisite=bef[lisite];
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//typedef long long ll;
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	/*
	FILE *fp;
	fp=fopen("test.txt","r");
	if(fp==NULL){
		printf("error!\n");
		return -1;
	}
	*/
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
		assert(n<=10);
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
//		assert(0<=lisite && lisite<n && lisite>bef[lisite]);
		ans[lisite]=0;
		lisite=bef[lisite];
//		printf("lisite=%lld\n",lisite);
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
//	fclose(fp);
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		cin>>a[i];
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
		ans[lisite]=0;
		lisite=bef[lisite];
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		cout<<"YES"<<endl;
		REP(i,n){
			if(i)cout<<' ';
			cout<<ans[i];
		}
		cout<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//typedef long long ll;
#define ll int
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e8;
ll n,a[MAX_N],ans[MAX_N],lis[MAX_N],bef[MAX_N],lisinx[MAX_N];
int main(){
	/*
	FILE *fp;
	fp=fopen("test.txt","r");
	if(fp==NULL){
		printf("error!\n");
		return -1;
	}
	*/
	scanf("%d",&n);
	fill(lis,lis+n,INF);
	memset(ans,-1,sizeof(ans));
	REP(i,n){
		scanf("%d",a+i);
		ll inx=lower_bound(lis,lis+n,a[i])-lis;
		lis[inx]=a[i];
		lisinx[inx]=i;
		if(inx==0){
			bef[i]=-1;
		}else{
			bef[i]=lisinx[inx-1];
		}
		assert(i<=1e5);
	}
	ll lislen=lower_bound(lis,lis+n,INF)-lis,lisite=lisinx[lislen-1];
	while(lisite>=0){
//		assert(0<=lisite && lisite<n && lisite>bef[lisite]);
		ans[lisite]=0;
		lisite=bef[lisite];
//		printf("lisite=%lld\n",lisite);
	}
	ll lst=INF;
	bool ansf=true;
	REP(i,n){
		if(ans[i]==-1){
			if(a[i]>=lst){
				ansf=false;
				break;
			}else{
				ans[i]=1;
				lst=a[i];
			}
		}
	}
	if(ansf){
		printf("YES\n");
		REP(i,n){
			if(i)printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}else{
		printf("NO\n");
	}
//	fclose(fp);
}


#include <bits/stdc++.h>
#include<cmath>
#define maxn 100005
#define maxa 1000005
#define MOD 998244353 //100000000  //1000000007 //
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

ll n;
ll ans[maxn*2], a[maxn*2];
ll dp[maxn*2][2];

void sol(ll p, ll pinc, ll pdec, ll f)
{ //cout << p << " " << pinc <<  " " << pdec << " " << f << endl;
    if(p == n-1){
        cout << "YES\n";
        ans[p] = f;
        rep(i, n) cout << ans[i] << " ";
        exit(0);
    }
    if(dp[p][f]) return;
    dp[p][f] = 1;
    ans[p] = f;
    if(a[p+1] > pinc){
        sol(p+1, a[p+1], pdec, 0);
    }
    if(a[p+1] < pdec){
        sol(p+1, pinc, a[p+1], 1);
    }
}
void solve()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    sol(0, a[0], INF, 0);
    sol(0, -1, a[0], 1);
    cout << "NO\n";
}

int main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
#include<cmath>
#define maxn 100005
#define maxa 1000005
#define MOD 998244353 //100000000  //1000000007 //
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }
    vector<pii> inc, dec;
    inc.pb({-1, -1});
    dec.pb({-1, INF});
    for(ll i = 0; i < n-1; i++)
    {
        ll x = a[i], y = a[i+1];
        if(inc.back().sd < x && dec.back().sd > x) {
            if(y > x) inc.pb({i, x});
            else dec.pb({i, x}); //cout << i << " ";
        }
        else if(inc.back().sd < x) inc.pb({i, x});
        else if(dec.back().sd > x) dec.pb({i, x});
        else ANS("NO");
    }
    ll x = a[n-1], i = n-1;
    if(inc.back().sd < x) inc.pb({i, x});
    else if(dec.back().sd > x) dec.pb({i, x});
    else ANS("NO");

    ll ans[n];
    mem(ans, 0);
    //for(auto x: dec) printpii( x)
    for(auto x: dec) ans[x.ft] = 1;
    print(ans, n);
}

int main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
#include<cmath>
#define maxn 100005
#define maxa 1000005
#define MOD 998244353 //100000000  //1000000007 //
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

ll n, f = 0;
ll ans[maxn*2], a[maxn*2];
ll dp[maxn*2][2];

void sol(ll p, ll pinc, ll pdec, ll f)
{ //cout << p << " " << pinc <<  " " << pdec << " " << f << endl;
    if(p == n-1){
        cout << "YES\n";
        ans[p] = f;
        rep(i, n) cout << ans[i] << " ";
        exit(0);
    }
    if(dp[p][f]) return;
    dp[p][f] = 1;
    ans[p] = f;
    if(a[p+1] > pinc){
        sol(p+1, a[p+1], pdec, 0);
    }
    if(a[p+1] < pdec){
        sol(p+1, pinc, a[p+1], 1);
    }
}
void solve()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    sol(0, a[0], INF, 0);
    sol(0, -1, a[0], 1);
    if(!f)cout << "NO\n";
}

int main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
#include<cmath>
#define maxn 100005
#define maxa 1000005
#define MOD 998244353 //100000000  //1000000007 //
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }
    vector<pii> inc, dec;
    inc.pb({-1, -1});
    dec.pb({-1, INF});
    for(ll i = 0; i < n-1; i++)
    {
        ll x = a[i], y = a[i+1];
        if(inc.back().sd < x && dec.back().sd > x) {
            if(y > x) inc.pb({i, x});
            else dec.pb({i, x}); //cout << i << " ";
        }
        else if(inc.back().sd < x) inc.pb({i, x});
        else if(dec.back().sd > x) dec.pb({i, x});
        else ANS("NO");
    }
    ll x = a[n-1], i = n-1;
    if(inc.back().sd < x) inc.pb({i, x});
    else if(dec.back().sd > x) dec.pb({i, x});
    else ANS("NO");

    ll ans[n];
    mem(ans, 0);
    //for(auto x: dec) printpii( x)
    cout << "YES\n";
    for(auto x: dec) ans[x.ft] = 1;
    print(ans, n);
}

int main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10 ;
int arr[maxn] ;
int main(int argc, char const *argv[])
{
	int n ;
	scanf("%d",&n) ;
	for(int i = 1 ; i <= n ; ++ i)
		scanf("%d",&arr[i]) ;
	arr[n+1] = maxn ;
	int down = maxn , up = -1 ;
	for(int i = 1 ; i <= n ; ++ i)
	{
		if(arr[i] < down && arr[i] > up)
		{
			if(arr[i + 1] > arr[i])
			{
				up = arr[i] ;
				arr[i] = 0 ;
			}
			else if(arr[i + 1] < arr[i])
			{
				down = arr[i] ;
				arr[i] = 1 ;
			}
		}
		else if(arr[i] < down)
		{
			down = arr[i] ;
			arr[i] = 1 ;
		}
		else if(arr[i] > up)
		{
			up = arr[i] ;
			arr[i] = 0 ;
		}
		else
		{
			printf("NO\n") ;
			return 0 ;
		}
	}
	printf("YES\n") ;
	for(int i = 1 ; i <= n ; ++ i) printf("%d ",arr[i]) ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10 ;
int arr[maxn] ;
int main(int argc, char const *argv[])
{
	int n ;
	scanf("%d",&n) ;
	for(int i = 1 ; i <= n ; ++ i)
		scanf("%d",&arr[i]) ;
	arr[n+1] = maxn ;
	int down = maxn , up = -1 ;
	for(int i = 1 ; i <= n ; ++ i)
	{
		if(arr[i] < down && arr[i] > up)
		{
			if(n == i)
			{
				arr[i] = 0 ;
				up = arr[i] ;
			}
			else
			{
				if(arr[i + 1] > arr[i])
				{
					up = arr[i] ;
					arr[i] = 0 ;
				}
				else if(arr[i + 1] < arr[i])
				{
					down = arr[i] ;
					arr[i] = 1 ;
				}
			}

		}
		else if(arr[i] < down)
		{
			down = arr[i] ;
			arr[i] = 1 ;
		}
		else if(arr[i] > up)
		{
			up = arr[i] ;
			arr[i] = 0 ;
		}
		else
		{
			printf("NO\n") ;
			return 0 ;
		}
	}
	printf("YES\n") ;
	for(int i = 1 ; i <= n ; ++ i) printf("%d ",arr[i]) ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10 ;
int arr[maxn] ;
int main(int argc, char const *argv[])
{
	int n ;
	scanf("%d",&n) ;
	for(int i = 1 ; i <= n ; ++ i)
		scanf("%d",&arr[i]) ;
	arr[n+1] = maxn ;
	int down = maxn , up = -1 ;
	for(int i = 1 ; i <= n ; ++ i)
	{
		if(arr[i] < down && arr[i] > up)
		{
			if(arr[i + 1] > arr[i])
			{
				up = arr[i] ;
				arr[i] = 0 ;
			}
			else if(arr[i + 1] <= arr[i])
			{
				down = arr[i] ;
				arr[i] = 1 ;
			}
		}
		else if(arr[i] < down)
		{
			down = arr[i] ;
			arr[i] = 1 ;
		}
		else if(arr[i] > up)
		{
			up = arr[i] ;
			arr[i] = 0 ;
		}
		else
		{
			printf("NO\n") ;
			return 0 ;
		}
	}
	printf("YES\n") ;
	for(int i = 1 ; i <= n ; ++ i) printf("%d ",arr[i]) ;
	return 0;
}


#pragma GCC optimize("trapv")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3e5 + 33, mlg = 18, mod = 1e9 + 7;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	vi a;
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i;
	int lst = -1;
	vi t;
	vi x;
	for(int i = 0; i < n; i++) {
//		cout << i << "ii" << endl;
		t.pb(i);
//		cout << t.size() << " " << i << endl;
		while(t.size()>1&&a[t[t.size()-2]]<=a[t[t.size()-1]]) {
			if(x.empty()||a[x.back()] < a[t.size()-2]) {
//				cout << "here" << endl;
				swap(t[t.size()-2], t.back());
//				cout << "here" << endl;
				x.pb(t.back());
//				cout << "here" << endl;
				t.pop_back();
//				cout << "here" << endl;
			} else if(a[x.back()] < a[t.back()]) {
				x.pb(t.back());
				t.pop_back();
			} else
				return cout << "NO", 0;
		}
	}
	bitset<200200> us;
	for(auto i : t) us[i]=1;
	cout << "YES\n";
//	for(int i = 0; i < n; i++)
//		if(us[i])
//		cout << a[i] << " ";cout << "\n";
//	for(int i = 0; i < n; i++)
//		if(!us[i])
//		cout << a[i] << " ";cout << "\n";
	for(int i = 0; i < n; i++)
		cout << us[i] << " ";
}


#pragma GCC optimize("trapv")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3e5 + 33, mlg = 18, mod = 1e9 + 7;
int n, t, li = -1, ld = 1e9;
bitset<200200> ans;
vi a;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i;
	for(int y, x,i = 0; i < n; i++) {
		x = a[i]>li;
		y = a[i]<ld;
		if(x^y) {
			if(x) li=a[i];
			else ld = a[i], ans.set(i);
		} else {
			if(x+y==0) return cout << "NO", 0;
			if(i+1==n||a[i+1]>a[i]) li=a[i];
			else ld = a[i], ans.set(i);
		}
	}
	cout << "YES\n";
	for(int i = 0; i < n; i++)
		cout << ans[i] << " ";
}


#pragma GCC optimize("trapv")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3e5 + 33, mlg = 18, mod = 1e9 + 7;
int n;
vi a, lis, pos, pred;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i;
	pred.resize(n);
	for(int I = 0; I < n; I++) {
		int i = a[I];
		int p = lower_bound(all(lis), i)-lis.begin();
		if(p==lis.size()) {
			lis.pb(i);
			pos.pb(I);
			pred.pb(0);
		} else {
			lis[p] = i;
			pos[p] = I;
		}
		pred[I] = p?pos[p-1]:-1;
	}
	bitset<200200> b;
	int x = pos.back();
	while(x!=-1) {
		b[x] = 1;
		x = pred[x];
	}
	vi c;
	for(int i = 0; i < n; i++)
		if(!b[i])
			c.pb(a[i]);
	for(int i = 1; i < c.size(); i++) {
		if(!(c[i]<c[i-1])) return cout << "NO\n", 0;
	}
	cout << "YES\n";
	for(int i = 0; i < n; i++)
		cout << !b[i] << " ";
}


#pragma GCC optimize("trapv")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3e5 + 33, mlg = 18, mod = 1e9 + 7;
int n;
vi a, lis, pos, pred, len, inv;
bitset<200200> us;
void pre() {
	inv.resize(n);
	inv[0] = -1;
	for(int i = 1; i < n; i++) {
		if(a[i]>=a[i-1]) inv[i] = i-1;
		else inv[i] = inv[i-1];
	}
}
void check(int pos) {
	int t = pos;
	while(t!=-1) {
		us[t] = 1;
		t = pred[t];
	}

	bool ok = true;
	t = n-1;
	while(t>=0&&us[t]) t--;
	while(ok) {
		int q = inv[t];
		while(q>=0&&us[q]) q--;
		if(q==-1) break;
		if(a[q]<=a[t]) {
			ok = false;
		}
		t=q;
	}
	if(!ok) {
		while(pos!=-1) {
			us[pos] = 0;
			pos = pred[pos];
		}
		return;
	}
	cout << "YES\n";
	for(int i = 0; i < n; i++)
		cout << !us[i] << " ";
	exit(0);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i;
	pre();
	pred.resize(n);
	len.resize(n);
	for(int I = 0; I < n; I++) {
		int i = a[I];
		int p = lower_bound(all(lis), i)-lis.begin();
		if(p==lis.size()) {
			lis.pb(i);
			pos.pb(I);
		} else {
			lis[p] = i;
			pos[p] = I;
		}
		len[I] = p+1;
		pred[I] = p?pos[p-1]:-1;
	}
	for(int i = 0; i < n; i++) {
		if(len[i]==lis.size()) check(i);
	}
	cout << "NO";
}


#pragma GCC optimize("trapv")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3e5 + 33, mlg = 18, mod = 1e9 + 7;
int n;
vi a, lis, pos, pred, len, inv;
bitset<200200> us;
void pre() {
	inv.resize(n);
	inv[0] = -1;
	for(int i = 1; i < n; i++) {
		if(a[i]>=a[i-1]) inv[i] = i-1;
		else inv[i] = inv[i-1];
	}
}
void check(int pos) {
	int t = pos;
	while(t!=-1) {
		us[t] = 1;
		t = pred[t];
	}

	bool ok = true;
	t = n-1;
	while(t>=0&&us[t]) t--;
	while(ok&&t>=0) {
		int q = inv[t];
		while(q>=0&&us[q]) q--;
		if(q==-1) break;
		if(a[q]<=a[t]) {
			ok = false;
		}
		t=q;
	}
	if(!ok) {
		while(pos!=-1) {
			us[pos] = 0;
			pos = pred[pos];
		}
		return;
	}
	cout << "YES\n";
	for(int i = 0; i < n; i++)
		cout << !us[i] << " ";
	exit(0);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i;
	pre();
	pred.resize(n);
	len.resize(n);
	for(int I = 0; I < n; I++) {
		int i = a[I];
		int p = lower_bound(all(lis), i)-lis.begin();
		if(p==lis.size()) {
			lis.pb(i);
			pos.pb(I);
		} else {
			lis[p] = i;
			pos[p] = I;
		}
		len[I] = p+1;
		pred[I] = p?pos[p-1]:-1;
	}
	for(int i = 0; i < n; i++) {
		if(len[i]==lis.size()) check(i);
	}
	cout << "NO";
}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef double db;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	vector<int> ans(n, 0);
	int inc = -1, dec = 1e9;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] > inc)
		{
			if (i == n - 1 || a[i + 1] > a[i] || a[i] >= dec)
				inc = a[i];
			else if (a[i] >= dec)
			{
				cout << "NO\n";
				return 0;
			}
			else
				dec = a[i], ans[i] = 1;
		}
		else if (a[i] < dec)
		{
			dec = a[i];
			ans[i] = 1;
		}
		else
		{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; ++i)
		cout << ans[i] << " ";
	return 0;
}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef double db;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	vector<int> ans(n, 0);
	int inc = -1, dec = 1e9;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] > inc)
		{
			if (i == n - 1 || a[i + 1] > a[i] || a[i] > dec)
				inc = a[i];
			else if (a[i] >= dec)
			{
				cout << "NO\n";
				return 0;
			}
			else
				dec = a[i], ans[i] = 1;
		}
		else if (a[i] < dec)
		{
			dec = a[i];
			ans[i] = 1;
		}
		else
		{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; ++i)
		cout << ans[i] << " ";
	return 0;
}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef double db;
bool check(map<int, int>& mp, int val)
{
	mp[val] -= 1;
	if (mp[val] >= 1)
	{
		cout << "NO\n";
		return true;
	}
	if (!mp[val])
		mp.erase(val);
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> mp;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		mp[a[i]] += 1;
	}
	int l = 0, r = n - 1;
	vector<int> ans(n, 0);
	while (l < r)
	{
		int low = mp.begin()->first;
		auto e = mp.end();
		--e;
		int high = e->first;
		if (mp[low] == 2)
		{
			if (a[l] != low || a[r] != low)
			{
				cout << "NO\n";
				return 0;
			}
			ans[r] = 1;
			++l, --r;
			mp.erase(low);
		}
		else if (mp[high] == 2)
		{
			if (a[l] != high || a[r] != high)
			{
				cout << "NO\n";
				return 0;
			}
			ans[l] = 1;
			++l, --r;
			mp.erase(high);
		}
		else if (a[l] == low)
		{
			if (check(mp, low))
				return 0;
			++l;
		}
		else if (a[r] == low)
		{
			ans[r] = 1;
			if (check(mp, low))
				return 0;
			--r;
		}
		else if (a[l] == high)
		{
			ans[l] = 1;
			if (check(mp, high))
				return 0;
			++l;
		}
		else if (a[r] == high)
		{
			if (check(mp, high))
				return 0;
			--r;
		}
		else
		{
			low = min_element(a.begin() + l, a.begin() + r + 1) - a.begin();
			high = max_element(a.begin() + l, a.begin() + r + 1) - a.begin();
			bool sign = (low < high);
			ans[low] = !sign;
			for (int i = low + 1; i <= high; ++i)
				if (sign != (a[i] > a[i - 1]))
				{
					cout << "NO\n";
					return 0;
				}
				else
					ans[i] = !sign;
			if (low != l) ans[l] = sign;
			for (int i = l + 1; i < low; ++i)
				if (sign == (a[i] > a[i - 1]))
				{
					cout << "NO\n";
					return 0;
				}
				else
					ans[i] = sign;
			if (high != r) ans[r] = sign;
			for (int i = high + 1; i <= r; ++i)
				if (sign == (a[i] > a[i - 1]))
				{
					cout << "NO\n";
					return 0;
				}
				else
					ans[i] = sign;
			break;
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; ++i)
		cout << ans[i] << " ";
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int vec[MAXN];
int at[MAXN];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> vec[i];

  int inc = -INT_MAX, dec = INT_MAX;
  for(int i=1;i<=n;i++){
    if(vec[i] <= inc and vec[i] >= dec){
      cout << "NO" << endl;
      return 0;
    } else if(vec[i] > inc and vec[i] < dec){
      if(i==n) at[i] = 1;
      else if(i < n and vec[i+1] > vec[i]) at[i] = true, inc = vec[i];
      else dec = vec[i];
    } else if(vec[i] > inc) at[i] = 1, inc = vec[i];
    else dec = vec[i];
  }

  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
  cout << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }

  int pos = -1;

  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      pos = i;
      break;
    }
  }

  if(pos != -1){
    bool att = false;
    for(int i=0;i<sz(aux);i++){
      if(pos){
        if(aux[i].F < aux2[pos-1].F and aux2[pos].F > aux[i-1].F){
          at[aux2[pos].S] = 1;
          at[aux[i].S] = 0;
          att = true;
          break;
        }
      }
    }

    if(att){
      cout << "YES" << endl;
      for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
      cout << endl;
      exit(0);
    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  // if(a[1] == 189999) cout << "eae" << endl;
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          // if(i < (sz(aux2) - 1)){
            // if(aux[j].F <= aux2[i+1].F) continue;
          // }
            // if(j < sz(aux) - 1)
            //   if(aux[j+1].F <= aux2[i].F) continue;
          at[aux[j].S] = 1;
          at[aux2[i].S] = 0;

          // if(a[1] == 189999){
          //   cout << "I : " << i << endl;
          //   cout << aux2[i].S << " - " << aux[j].S << endl;
          //   cout << aux2[180503].F << " -- " << aux2[180504].F << endl;
          // }
          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;
          exit(0);
        }
      }

    }
  }
  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  if(a[1] == 189999) cout << "eae" << endl;
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          at[aux[j].S] = 1;
          at[aux2[i-1].S] = 0;

          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << at[i] << " ";
          cout << endl;

          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << !at[i] << " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          at[aux2[j].S] = 1;
          at[aux2[i-1].S] = 0;

          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;

          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  // for(auto i : anss) cout << i << " ";
  // cout << endl;

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // int c = 0;
  // int aaa = 0;
  // for(int i=200000;i>=0;i--){
  //   if(c == 29) cout << aaa++ << " ", c = 0;
  //   else cout << i << " ";
  //   c++;
  // }

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          // if(i < sz(aux2) - 1){
            // if(aux[j].F < aux2[i+1].F) continue;
            // if(j < sz(aux) - 1)
              // if(aux[j+1].F < aux2[i].F) continue;
          // }
          at[aux[j].S] = 1;
          at[aux2[i].S] = 0;

          if(a[0] == 189999) cout << aux2[j].S << " - " << aux2[i].S << endl;
          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;
          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          at[aux[j].S] = 0;
          at[aux2[i-1].S] = 1;

          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << at[i] << " ";
          cout << endl;

          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(auto i : anss) cout << i << " ";
  cout << endl;

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << !at[i] << " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          if(i < sz(aux2) - 1){
            // if(aux[j].F < aux2[i+1].F) continue;
            // if(j < sz(aux) - 1)
              // if(aux[j+1].F < aux2[i].F) continue;
          }
          at[aux[j].S] = 1;
          at[aux2[i].S] = 0;

          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;
          if(a[0] == 189999) cout << aux2[j].S << " - " << aux2[i].S << endl;
          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          // if(i < sz(aux2) - 1){
            // if(aux[j].F < aux2[i+1].F) continue;
            // if(j < sz(aux) - 1)
              // if(aux[j+1].F < aux2[i].F) continue;
          // }
          at[aux[j].S] = 1;
          at[aux2[i].S] = 0;

          if(a[1] == 189999) cout << aux2[i].S << " - " << aux[j].S << endl;
          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;
          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  if(a[1] == 189999) cout << "eae" << endl;
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }

  int pos = -1;

  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      pos = i;
      break;
    }
  }

  if(pos != -1){
    bool att = false;
    for(int i=0;i<sz(aux);i++){
      if(pos){
        if(aux[i].F < aux2[pos-1].F){
          if(i){
            if(aux2[pos].F <= aux[i-1].F) continue;
          }
          at[aux2[pos].S] = 1;
          at[aux[i].S] = 0;
          att = true;
          break;
        }
      }
    }

    if(att){
      cout << "YES" << endl;
      for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
      cout << endl;
      exit(0);
    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  // if(a[1] == 189999) cout << "eae" << endl;
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          if(i < sz(aux2) - 1){
            if(aux[j].F < aux2[i+1].F) continue;
          }
          at[aux[j].S] = 1;
          at[aux2[i-1].S] = 0;

          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;
          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  // for(auto i : anss) cout << i << " ";
  // cout << endl;

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // int c = 0;
  // int aaa = 0;
  // for(int i=200000;i>=0;i--){
  //   if(c == 29) cout << aaa++ << " ", c = 0;
  //   else cout << i << " ";
  //   c++;
  // }

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN (int)(2*1e5 + 10)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
int a[MAXN], b[MAXN], f[MAXN];

int at[MAXN];

void tenta(vector<int> inc, vector<int> dec){

  vector<pair<int, int> > aux, aux2;

          if(a[0] == 189999) cout << aux2[j].S << " - " << aux2[i].S << endl;
  for(int i=1;i<=n;i++){
    if(at[i]){
      aux.push_back({a[i], i});
    } else {
      aux2.push_back({a[i], i});
    }
  }

  int cont = 0;
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F) cont++;
  }

  if(cont >= 2){
    cout << "NO" << endl;
    exit(0);
  }
  for(int i=1;i<sz(aux2);i++){
    if(aux2[i].F >= aux2[i-1].F){
      for(int j=0;j<sz(aux);j++){
        if(aux[j].F < aux2[i-1].F){
          // if(i < sz(aux2) - 1){
            // if(aux[j].F < aux2[i+1].F) continue;
            // if(j < sz(aux) - 1)
              // if(aux[j+1].F < aux2[i].F) continue;
          // }
          at[aux[j].S] = 1;
          at[aux2[i].S] = 0;

          cout << "YES" << endl;
          for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1) << " ";
          cout << endl;
          exit(0);
        }
      }

    }
  }

  cout << "NO" << endl;
  exit(0);
}

void LIS(){
  int ans = 0;
  for(int i=1;i<=n;i++){
    f[i] = lower_bound(b+1, b+ans+1, a[i]) - b;
    ans = max(ans, f[i]);
    b[f[i]] = a[i];
  }

  int require = ans;
  vector<int> anss;
  for(int i=n;i>=1;i--){
    if(f[i] == require) anss.push_back(a[i]), require--;
  }
  reverse(anss.begin(), anss.end());
  vector<int> anss2;
  int pos = 0;
  for(int i=1;i<=n;i++){
    if(pos < sz(anss)){
      if(a[i] == anss[pos]){
        at[i] = 1;
        pos++;
      } else anss2.push_back(a[i]);
    } else anss2.push_back(a[i]);
  }

  for(int i=1;i<sz(anss2);i++){
    if(anss2[i] >= anss2[i-1]){
      tenta(anss, anss2);
      break;
    }
  }
  cout << "YES" << endl;
  for(int i=1;i<=n;i++) cout << (at[i] == 1 ? 0 : 1)<< " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  LIS();

  return 0;
}