https://codeforces.com/contest/1150/problem/C
2 1 2 2 2 2 2 2 1 1 1 1 1
会发现第一个是2质数
第二前缀和是3
2 3 5 7 9 11 13 15 16 17 18 19 20
为什么呢??2和从3开始 到n的前缀和
奇+偶=奇得到第一个3
一直+2 对应值2的前缀和为奇数
到的1范围后 偶 奇 偶 奇交替
构造尽可能多的从3开始的奇数前缀和 即可能的素数前缀和
素数在2之后从奇数中产生
使前缀和奇数尽可能多意味着素数尽可能多
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb emplace_back
#define pii pair<int,int>
#define all(n) (n).begin(),(n).end()
#define rep(i,a,n) for (int i=a;i<=n;i++)
typedef vector<int> vi;
typedef set<int> si;
const int maxn = 2e5+5;
const ll mod = 998244353;
const int inf = 0x3f3f3f3f;
int t;
int main(){
IO;
int n,c1=0,c2=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t;
if(t==1)
c1++;
else
c2++;
}
if(c1 && c2) //1 2都出现 起码有1个
{
cout<<2<<" ";
c2--;
cout<<1<<" ";
c1--;
rep(i,1,c2)
cout<<2<<" ";
rep(i,1,c1)
cout<<1<<" ";
}
else if(c1==0)
{
rep(i,1,c2)
cout<<2<<" ";
}
else //c2==0
{
rep(i,1,c1)
cout<<1<<" ";
}
return 0;
}