Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old.

They will have dinner around some round tables. You want to distribute foxes such that:

1. Each fox is sitting at some table.
2. Each table has at least 3 foxes sitting around it.
3. The sum of ages of any two adjacent foxes around each table should be a prime number.

If k foxes f1, f2, ..., fk are sitting around table in clockwise order, then for 1 ≤ i ≤ k - 1: fi and fi + 1 are adjacent, and f1 and fk are also adjacent.

If it is possible to distribute the foxes in the desired manner, find out a way to do that.

### Input

The first line contains single integer n (3 ≤ n ≤ 200): the number of foxes in this party.

The second line contains n integers ai (2 ≤ ai ≤ 104).

### Output

If it is impossible to do this, output "Impossible".

Otherwise, in the first line output an integer m (): the number of tables.

Then output m lines, each line should start with an integer k -=– the number of foxes around that table, and then k numbers — indices of fox sitting around that table in clockwise order.

If there are several possible arrangements, output any of them.

### Sample Input

Input
`43 4 8 9`
Output
`14 1 2 4 3`
Input
`52 2 2 2 2`
Output
`Impossible`
Input
`122 3 4 5 6 7 8 9 10 11 12 13`
Output
`112 1 2 3 6 5 12 9 8 7 10 11 4`
Input
`242 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25`
Output
`36 1 2 3 6 5 410 7 8 9 12 15 14 13 16 11 108 17 18 23 22 19 20 21 24　　建二分图，再用流量为2限制度数，即可用网络流AC。`
``` #include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int N=,M=,INF=;
int cnt,fir[N],fron[N],nxt[M],to[M],cap[M];
int dis[N],gap[N],path[N],vis[N],q[N],h,t;
int n,m,a[N],tp[N],tot;vector<int>ans[N];
struct Net_Flow{
void Init(){
memset(fir,,sizeof(fir));
memset(gap,,sizeof(gap));
memset(dis,,sizeof(dis));
h=t=cnt=;
}
nxt[++cnt]=fir[a];to[fir[a]=cnt]=b;cap[cnt]=c;
nxt[++cnt]=fir[b];to[fir[b]=cnt]=a;cap[cnt]=;
}
bool BFS(int S,int T){
dis[q[h]=T]=;
while(h<=t){
int x=q[h++];
for(int i=fir[x];i;i=nxt[i])
if(!dis[to[i]])dis[q[++t]=to[i]]=dis[x]+;
}
return dis[S];
}
int ISAP(int S,int T){
if(!BFS(S,T))return ;
for(int i=S;i<=T;i++)gap[dis[i]]+=;
for(int i=S;i<=T;i++)fron[i]=fir[i];
int ret=,f,p=S,Min;
while(dis[S]<=T+){
if(p==T){f=INF;
while(p!=S){
f=min(f,cap[path[p]]);
p=to[path[p]^];
}ret+=f,p=T;
while(p!=S){
cap[path[p]]-=f;
cap[path[p]^]+=f;
p=to[path[p]^];
}
}
for(int &i=fron[p];i;i=nxt[i])
if(cap[i]&&dis[to[i]]==dis[p]-){
path[p=to[i]]=i;break;
}
if(!fron[p]){
if(!--gap[dis[p]])break;Min=T+;
for(int i=fir[p];i;i=nxt[i])
if(cap[i])Min=min(Min,dis[to[i]]);
gap[dis[p]=Min+]+=;fron[p]=fir[p];
if(p!=S)p=to[path[p]^];
}
}
return ret;
}
void DFS(int x,int id){
vis[x]=;ans[id].push_back(x);
for(int i=fir[x];i;i=nxt[i]){
if(vis[to[i]]||to[i]<||to[i]>n)continue;
if(a[to[i]]%==&&cap[i^]==)DFS(to[i],id);
if(a[to[i]]%!=&&cap[i]==)DFS(to[i],id);
}
}
void Solve(int S,int T){
for(int x=;x<=n;x++)
if(a[x]%==&&!vis[x])
DFS(x,++tot);
printf("%d\n",tot);
for(int i=;i<=tot;i++){
printf("%d ",ans[i].size());
for(int j=;j<ans[i].size();j++)
printf("%d ",ans[i][j]);
puts("");
}
}
}isap;
int S,T;
bool Check(int x){
for(int i=;i*i<=x;i++)
if(x%i==)return false;
return true;
}
int main(){
scanf("%d",&n);isap.Init();T=n+;
if(n%==){puts("Impossible");return ;}
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++){
}
for(int i=;i<=n;i++)if(a[i]%==)
for(int j=;j<=n;j++)if(a[j]%)
if(Check(a[i]+a[j]))
if(isap.ISAP(S,T)!=n){
puts("Impossible");
return ;
}
isap.Solve(S,T);
return ;
}```

## 网络流（最大流）CodeForces 512C：Fox And Dinner的更多相关文章

1. 【Codeforces】512C Fox and Dinner

[解析]欧拉筛法,奇偶分析.建二分图,网络流 [Analysis] http://blog.csdn.net/qq574857122/article/details/43453087. 所谓的连通块就 ...

2. codeforces 510E. Fox And Dinner 网络流

题目链接 给出n个人, 以及每个人的值, 要求他们坐在一些桌子上面, 每个桌子如果有人坐, 就必须做3个人以上. 并且相邻的两个人的值加起来必须是素数.每个人的值都>=2. 由大于等于2这个条件 ...

3. CodeForces 510E Fox And Dinner

网络流. 原点到偶数连边,容量为2, 奇数到汇点连边,容量为2, 偶数到与之能凑成素数的奇数连边,容量为1 如果奇数个数不等于偶数个数,输出不可能 如果原点到偶数的边不满流,输出不可能 剩下的情况有解 ...

4. Codeforces Round #290 (Div. 2) E. Fox And Dinner 网络流建模

E. Fox And Dinner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

5. CF510E. Fox And Dinner

CF510E. Fox And Dinner https://codeforces.com/contest/510 分析: 由于\(a_i>2\), 相邻两个数一定一奇一偶,按奇偶建立二分图. ...

6. POJ 1459-Power Network（网络流-最大流-ISAP）C++

Power Network 时间限制: 1 Sec  内存限制: 128 MB 题目描述 A power network consists of nodes (power stations, cons ...

7. [POJ1273][USACO4.2]Drainage Ditches (网络流最大流)

题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio ...

8. HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)

HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...

9. HDU1532 网络流最大流【EK算法】(模板题)

<题目链接> 题目大意: 一个农夫他家的农田每次下雨都会被淹,所以这个农夫就修建了排水系统,还聪明的给每个排水管道设置了最大流量:首先输入两个数n,m ;n为排水管道的数量,m为节点的数量 ...

10. Redraw Beautiful Drawings（hdu4888）网络流+最大流

Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...

## 随机推荐

1. 如何成为python高手

本文是从 How to become a proficient Python programmer 这篇文章翻译而来. 这篇文章主要是对我收集的一些文章的摘要.因为已经有很多比我有才华的人写出了大量关 ...

2. 【JAVA】Math.Round()函数常见问题“四舍5入”

java.lang.Math.Round()使用时候,处理方式整理,方便以后查找   /**  * 测试函数 2014-01-10  */ public class TestMath {     pu ...

3. Ubuntu安装nodeJS

安装环境 ubuntu12.04 64bit nodejs-v0.8.14.tar.gz Node.js是一个基于google v8+javascript的服务端编程框架.但是Node.js又不是js ...

4. OkHttp 详解

OkHttp使用: http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0106/2275.html OkHttp源码: http:/ ...

5. （原）JNI中env-&gt;GetByteArrayElements和AndroidBitmap_getInfo的冲突

也不是很确定,前段时间的代码没有出问题,但是今天调试了半天,一直崩溃:vm aborting. 以前的部分代码: JNIEXPORT void JNICALL XXX (JNIEnv* env,job ...

6. jQuery源码笔记——四

each()实现 var jQuery = function( selector, context ) { return new jQuery.fn.init( selector, context ) ...