C. Two Shuffled Sequences

Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.

Strictly increasing sequence is a sequence of integers [x1<x2<⋯<xk]. And strictly decreasing sequence is a sequence of integers [y1>y2>⋯>yl]. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

They were merged into one sequence a. After that sequence a got shuffled. For example, some of the possible resulting sequences a for an increasing sequence [1,3,4] and a decreasing sequence [10,4,2] are sequences [1,2,3,4,4,10] or [4,2,1,10,4,3].

This shuffled sequence a is given in the input.

Your task is to find any two suitable initial sequences. One of them should be strictly increasing and the other one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

If there is a contradiction in the input and it is impossible to split the given sequence a to increasing and decreasing sequences, print “NO”.

Input

The first line of the input contains one integer n (1≤n≤2⋅105) — the number of elements in a.

The second line of the input contains n integers a1,a2,…,an (0≤ai≤2⋅105), where ai is the i-th element of a.

Output

If there is a contradiction in the input and it is impossible to split the given sequence a to increasing and decreasing sequences, print “NO” in the first line.

Otherwise print “YES” in the first line and any two suitable sequences. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

In the second line print ni — the number of elements in the strictly increasing sequence. ni can be zero, in this case the increasing sequence is empty.

In the third line print ni integers inc1,inc2,…,incni in the increasing order of its values (inc1<inc2<⋯<incni) — the strictly increasing sequence itself. You can keep this line empty if ni=0 (or just print the empty line).

In the fourth line print nd — the number of elements in the strictly decreasing sequence. nd can be zero, in this case the decreasing sequence is empty.

In the fifth line print nd integers dec1,dec2,…,decnd in the decreasing order of its values (dec1>dec2>⋯>decnd) — the strictly decreasing sequence itself. You can keep this line empty if nd=0 (or just print the empty line).

ni+nd should be equal to n and the union of printed sequences should be a permutation of the given sequence (in case of “YES” answer).

Examples

input

7
7 2 7 3 3 1 4

output

YES
2
3 7
5
7 4 3 2 1

input

5
4 3 1 5 3

output

YES
1
3
4
5 4 3 1

input

5
1 1 2 1 2

output

NO

input

5
0 1 2 3 4

output

YES
0

5
4 3 2 1 0

思路:

用map储存出现次数,出现一次的存入一个数组b,出现两次的一个存入数组b,一个存入数组c,出现三次以上就输出NO(数组B先输出有多少个再正序输出,数组A最后输出有多少个再倒叙输出)

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<map>>
using namespace std;
int a[200030],b[200030],c[200030];
int main(){
	int n;
	while(cin>>n){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		map<int ,int>q;
		for(int i=0;i<n;i++){
			cin>>a[i];
			q[a[i]]++;
		}
		sort(a,a+n);
		int x=0,y=0,flag=0;
		for(int i=0;i<n;i++){
			if(q[a[i]]==1){
				b[x++]=a[i];
			} //出现一次的存入一个数组b
			else if(q[a[i]]==2){
				b[x++]=a[i++];
				c[y++]=a[i];
			}//出现两次的一个存入数组A,一个存入数组c
			else if(q[a[i]]>2){
				flag=1;
				break;
			}//出现三次以上就输出NO
		}
		if(flag==0){
			cout<<"YES"<<endl;
			printf("%d\n",y);
			for(int i=0;i<y;i++){
				printf("%d ",c[i]);
			}//数组c先输出有多少个再正序输出
			printf("\n%d\n",x);
			for(int i=x-1;i>=0;i--){
				printf("%d ",b[i]);
			}
			printf("\n");
		}//数组b最后输出有多少个再倒叙输出
		else if(flag==1){
			cout<<"No"<<endl;
		}//出现三次以上就输出NO
	} 
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值