MUH and Important Things

CodeForces - 471B

It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are ntasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary.

Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the n tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.

Output

In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line ndistinct integers that represent the numbers of the tasks in the order they are done according to the first plan. In the third and fourth line print two remaining plans in the same form.

If there are multiple possible answers, you can print any of them.

Examples

Input
4
1 3 3 1
Output
YES
1 4 2 3
4 1 2 3
4 1 3 2
Input
5
2 4 1 4 8
Output
NO

Note

In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer.

In the second sample there are only two sequences of tasks that meet the conditions — [3, 1, 2, 4, 5] and [3, 1, 4, 2, 5]. Consequently, it is impossible to make three distinct sequences of tasks.

sol:XJB构造三串不同的字典序最小的序列,十分容易,两个相同的就两两交换,多个相同的就用第一个与第二个或第三个(最后一个)交换,这样就凑到三种情况了

Ps:可能构造多种会比较困难,感觉只会n!的方法(GG)

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,Hash[N];
struct data
{
int Shuz;
}a[N];
int Pailie[N];
int Used[N];
vector<int>Jih[N];
int main()
{
int i,j,Fas=;
R(n);
for(i=;i<=n;i++)
{
R(a[i].Shuz); Hash[++*Hash]=a[i].Shuz;
}
sort(Hash+,Hash+*Hash+);
*Hash=unique(Hash+,Hash+*Hash+)-Hash-;
for(i=;i<=n;i++)
{
a[i].Shuz=lower_bound(Hash+,Hash+*Hash+,a[i].Shuz)-Hash;
Jih[a[i].Shuz].push_back(i);
}
for(i=;i<=*Hash&&Fas<;i++)
{
if(Jih[i].size()==) Fas*=;
else if(Jih[i].size()>) Fas=;
}
if(Fas<) return *puts("NO");
puts("YES");
for(int Step=;Step<=;Step++)
{
bool Bo=;
for(i=;i<=*Hash;i++)
{
if(Bo)
{
Used[i]=;
for(j=;j<Jih[i].size();j++) W(Jih[i][j]);
continue;
}
if(Jih[i].size()==)
{
W(Jih[i][]); continue;
}
else if(Jih[i].size()==)
{
if(Used[i]==)
{
W(Jih[i][]); W(Jih[i][]); Bo=;
Used[i]++;
}
else if(Used[i]==)
{
W(Jih[i][]); W(Jih[i][]); Bo=;
Used[i]++;
}
else
{
W(Jih[i][]); W(Jih[i][]);
}
}
else
{
if(Used[i]==)
{
for(j=;j<Jih[i].size();j++) W(Jih[i][j]);
Bo=;
Used[i]++;
}
else if(Used[i]==)
{
W(Jih[i][]); W(Jih[i][]);
for(j=;j<Jih[i].size();j++) W(Jih[i][j]);
Bo=;
Used[i]++;
}
else
{
W(Jih[i][Jih[i].size()-]);
for(j=;j<Jih[i].size()-;j++) W(Jih[i][j]);
W(Jih[i][]);
Bo=;
}
}
}
puts("");
}
return ;
}
/*
input
4
1 3 3 1
output
YES
1 4 2 3
4 1 2 3
4 1 3 2
*/

codeforces471B的更多相关文章

随机推荐

  1. Zabbix 3.4.2 install && Configuration

    原理: 1)zabbix server:负责接收agent发送的报告信息的核心组件,所有配置.统计数据及操作数据都由它组织进行: 2)database storage:专用于存储所有配置信息,以及由z ...

  2. Objective-C 单例实现

    Objective-C中用的最多的设计模式就是单例,它最常见的实现如下: + (WPXXService *)sharedInstance { static WPXXService *g_service ...

  3. 8-51单片机ESP8266学习-AT指令(单片机采集温湿度数据通过8266发送给C#TCP客户端显示)

    http://www.cnblogs.com/yangfengwu/p/8785516.html 先写单片机端的程序 先把源码和资料链接放到这里 链接: https://pan.baidu.com/s ...

  4. proxy config (firefox config)

    sudo apt-get install shadowsocks sudo apt-get install polipo 编辑polipo config: sudo vim /etc/polipo/c ...

  5. Python 爬取 11 万 Java 程序员信息竟有这些重大发现!

    一提到程序猿,我们的脑子里就会出现这样的画面: 或者这样的画面: 心头萦绕的字眼是:秃头.猝死.眼镜.黑白 T 恤.钢铁直男-- 而真实的程序猿们,是每天要和无数数据,以及数十种编程语言打交道.上能手 ...

  6. Luogu4173 残缺的字符串 FFT

    传送门 考虑如何使用FFT计算两个子串是否匹配.如果字符集比较小可以把每个字符都拿出来暴力做一遍,但是字符集比较大的时候复杂度就会有问题.这个时候可以考虑匹配函数. 先考虑没有通配符的情况.将\(A\ ...

  7. UOJ219 NOI2016 优秀的拆分 二分、字符串哈希

    传送门 题目可以转化为求\(AA\)的数量,设\(cnt1_x\)表示左端点为\(x\)的\(AA\)的数量,\(cnt2_x\)表示右端点为\(x\)的\(AA\)的数量,那么答案就是\(\sum ...

  8. iptables限制连接数(如sftp) 以及 谨防CC/DDOS攻击的配置 ( connlimit模块)

    之前在公司服务器上部署了sftp,用于上传业务系统的附件.后来由于程序连接问题,使的sftp连接数过多(最多时高达400多个sftp连接数),因为急需要对sftp的连接数做严格限制.操作记录如下: 启 ...

  9. python基础学习笔记(十二)

    模块 前面有简单介绍如何使用import从外部模块获取函数并且为自己的程序所用: >>> import math >>> math.sin(0) #sin为正弦函数 ...

  10. B. Vova and Trophies

    链接 [https://codeforces.com/contest/1082/problem/B] 题意 给你一个包含GS的字符串,只允许交换一次任意不同位置的字符,问最长的连续G串是多少 分析 很 ...