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. 如何用css实现"等高布局"。

    有时候为了让网页实现美观,在不知道高度的情况下,我们要用css实现等高布局效果,传统的方法, 我们可以用javascript实现,但是由于需求决定或者其他的情况下,我们只能用css实现,其方法主要是采 ...

  2. 【Codeforces 1120A】Diana and Liana

    Codeforces 1120 A 题意:给\(n\)个数\(a_1..a_n\),要从其中删去小于等于\(n-m\times k\)个数,使得将这个数组分成\(k\)个一段的序列时有至少一段满足以下 ...

  3. Spark运行时错误与解决

    Spark  java.io.IOException: Filesystem closed partition数量太小,读取数据后进行repartition重新分片再处理. Spark Streami ...

  4. maven 插

    一.maven插件元素 <?xml version="1.0" encoding="utf-8"?> <plugin> <!--插 ...

  5. [02] URL和HttpURLConnection类

    1.URL的概念 统一资源定位符URL(Uniform Resource Locator)是www客户机访问Internet时用来标识资源的名字和地址. URL的基本格式是: <METHOD&g ...

  6. 计算机网络协议OSI TCP/IP协议--001

    网桥:连接同构的LAN的网络互联设备,(同构的LAN 网是,应用层到逻辑层)   实  现的功能是:MAC子层和物理层.1.帧的发送与接收.2.缓冲的管理.3.协议转换. 路由器:在网络层实现互联,他 ...

  7. flask-admin 快速打造博客 系列一

    前言: 我想分享flask+flask-admin快速打造博客的详细教程,可是发现网易课堂已经有相应的免费课堂了,所以就不打算一点一滴的在这里做笔记,分享这些东西了.所以我主要集中在flask-adm ...

  8. tomcat多实例方案启动脚本

    批量启动 #!/bin/sh BASE_PATH="/usr/local/tomcat8/tomcat-ins/"bash $BASE_PATH/web1/tomcat.sh st ...

  9. Jmeter(三十五)_精确实现网页爬虫

    Jmeter实现了一个网站文章的爬虫,可以把所有文章分类保存到本地文件中,并以文章标题命名 它原理就是对网页提交一个请求,然后把返回的所有值提取出来,利用ForEach控制器去实现遍历.下面来介绍一下 ...

  10. asp.net mvc接收安卓post的json字符串

    筛选器: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syst ...