-
Notifications
You must be signed in to change notification settings - Fork 3
/
A_Prefix_Sum_Primes.cpp
130 lines (112 loc) · 2.03 KB
/
A_Prefix_Sum_Primes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <bits/stdc++.h>
#define ll long long
#define ld long int
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
using namespace std;
// 8""""8
// 8 " eeeee eeeee eeee
// 8e 8 88 8 8 8
// 88 8 8 8e 8 8eee
// 88 e 8 8 88 8 88
// 88eee8 8eee8 88ee8 88ee
// --------MATHS OPERATIONS---------
const int N = 2e5 + 1;
const int MOD = 1e9 + 7;
ll fact[N], inv[N], invfact[N];
void factInverse()
{
fact[0] = inv[1] = fact[1] = invfact[0] = invfact[1] = 1;
for (long long i = 2; i < N; i++)
{
fact[i] = (fact[i - 1] * i) % MOD;
inv[i] = MOD - (inv[MOD % i] * (MOD / i) % MOD);
invfact[i] = (inv[i] * invfact[i - 1]) % MOD;
}
}
int add(int a, int b)
{
if ((a += b) >= MOD)
a -= MOD;
else if (a < 0)
a += MOD;
return a;
}
ll mul(int x, int y)
{
return (1LL * x * y) % MOD;
}
ll nCr(int n, int r)
{
if (r > n)
return 0;
return mul(mul(fact[n], invfact[r]), invfact[n - r]);
}
long long pow(long long base, long long n, long long m = MOD)
{
long long ans = 1ll;
while (n != 0)
{
if (n % 2)
{
ans = (ans * base) % m;
n--;
}
else
{
base = (base * base) % m;
n /= 2;
}
}
return ans;
}
// --------SOLVE---------
void solve()
{
int n;
cin >> n;
int o_cnt = 0, t_cnt = 0;
int temp;
for (int i = 0; i < n; i++)
{
cin >> temp;
if (temp == 1)
{
o_cnt++;
}
else
{
t_cnt++;
}
}
if (o_cnt >= 1 and t_cnt >= 1)
{
cout << 2 << " " << 1 << " ";
o_cnt--;
t_cnt--;
}
while (t_cnt)
{
cout << 2 << " ";
t_cnt--;
}
while (o_cnt)
{
cout << 1 << " ";
o_cnt--;
}
}
// --------XXXXXXXXX---------
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}