Link: Codeforces Round 572

A Keanu Reeves
Description: After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.

Let’s call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good.

We are given a string s of length n consisting of only zeroes and ones. We need to cut s into minimal possible number of substrings s1,s2,…,sk such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings s1,s2,…,sk such that their concatenation (joining) equals s, i.e. s1+s2+⋯+sk=s.

For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can’t cut 110010 to the smaller number of substrings as 110010 isn’t good itself. At the same time, cutting of 110010 into 1100 and 10 isn’t valid as both strings aren’t good. Also, cutting of 110010 into 1, 1, 0010 isn’t valid, as it isn’t minimal, even though all 3 strings are good.

Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.

Input
The first line of the input contains a single integer n (1≤n≤100) — the length of the string s.

The second line contains the string s of length n consisting only from zeros and ones.

Output
In the first line, output a single integer k (1≤k) — a minimal number of strings you have cut s into.

In the second line, output k strings s1,s2,…,sk separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to s and all of them have to be good.

If there are multiple answers, print any.

Examples
input

1
1

output

1
1

input

2
10

output

2
1 0

input

6
100011

output

2
100 011

Note

In the first example, the string 1 wasn’t cut at all. As it is good, the condition is satisfied.
In the second example, 1 and 0 both are good. As 10 isn’t good, the answer is indeed minimal.
In the third example, 100 and 011 both are good. As 100011 isn’t good, the answer is indeed minimal.

Code:

#include <bits/stdc++.h>
using namespace std;
int o[105], z[105];
int main()
{
    int    n, a, b;
    a = b = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
            a++;
        if (s[i] == '0')
            b++;
        o[i] = a;
        z[i] = b;
    }
    int ans = 0;
    if (a != b)
    {
        cout << "1\n" << s << endl;
    }
    else
    {
        cout << "2\n";
        for (int i = 0; i < s.size()-1; i++)
            cout << s[i];
        cout << " " << s[s.size() - 1] << endl;
    }
}
B Number Circle
Description: You are given n numbers a1,a2,…,an. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors?

For example, for the array [1,4,5,6,7,8], the arrangement on the left is valid, while arrangement on the right is not, as 5≥4+1 and 8>1+6.

Input
The first line contains a single integer n (3≤n≤105) — the number of numbers.

The second line contains n integers a1,a2,…,an (1≤ai≤109) — the numbers. The given numbers are not necessarily distinct (i.e. duplicates are allowed).

Output
If there is no solution, output “NO” in the first line.

If there is a solution, output “YES” in the first line. In the second line output n numbers — elements of the array in the order they will stay in the circle. The first and the last element you output are considered neighbors in the circle. If there are multiple solutions, output any of them. You can print the circle starting with any element.

Examples
input

3
2 4 3

output

YES
4 2 3

input

5
1 2 3 4 4

output

YES
4 4 2 1 3

input

3
13 8 5

output

NO

input

4
1 10 100 1000

output

NO

Note

One of the possible arrangements is shown in the first example:
4<2+3;
2<4+3;
3<4+2.
One of the possible arrangements is shown in the second example.
No matter how we arrange 13,8,5 in a circle in the third example, 13 will have 8 and 5 as neighbors, but 13≥8+5.
There is no solution in the fourth example.

Code:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
ll        a[maxn];
int main()
{
    queue<ll> f;
    stack<ll> e;
    ll        n;
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    if (a[n - 1] >= (a[n - 3] + a[n - 2]))
    {
        puts("NO");
        return 0;
    }
    puts("YES");
    int flag = 1;
    for (int i = n - 1; i >= 0; i--)
    {
        if (flag)
        {
            f.push(a[i]);
            if (a[i - 1] != a[i])
                flag = 0;
        }
        else
        {
            e.push(a[i]);
            if (a[i - 1] != a[i])
                flag = 1;
        }
    }
    while (!f.empty())
    {
        cout << f.front() << " ";
        f.pop();
    }
    while (!e.empty())
    {
        cout << e.top() << " ";
        e.pop();
    }
}