String can be called correct if it consists of characters "0" and "1" and there are no…
- User
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string s.
You can perform two different operations on this string:
- swap any pair of adjacent characters (for example, "101" "110");
- replace "11" with "1" (for example, "110" "10").
Let val(s) be such a number that s is its binary representation.
Correct string a is less than some other correct string b iff val(a) < val(b).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). Input
The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.
The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.
Output
Print one string — the minimum correct string that you can obtain from the given one.
Examples
Input
4 1001
Output
100
Input
1 1
Output
1
Note
In the first example you can obtain the answer by the following sequence of operations: "1001" "1010" "1100" "100".
In the second example you can't obtain smaller answer no matter what operations you use.
Assistant
We need to find minimal correct string (binary representation without leading zeros) reachable from the given correct string s, using operations:
- swap any adjacent characters (i.e., we can reorder arbitrarily? Swapping adjacent means we can achieve any permutation? Since we can swap adjacent repeatedly, we can reorder the string arbitrarily. Indeed, with adjacent swaps we can bubble sort to any permutation. So operation 1 effectively allows us to rearrange the bits arbitrarily. But note: we can swap any adjacent characters, but we cannot change the total count of '0's and '1's? Actually operation 2 modifies the string: replace "11" with "1". That reduces the number of '1's by one and reduces length. It effectively merges two adjacent '1's into a single '1'. So operation 2 can reduce the number of '1's, but not increase. Also note: after replacements, we can still swap adjacent characters (presumably after replacement, we have a new string). So overall, we start with a correct string s (no leading zeros), and we can arbitrarily reorder bits (by swaps) and also replace any occurrence of "11" with "1". However, note that after replacing "11" with "1", the string length decreases, and we can continue operations.
Goal: find minimum correct string (minimum numeric value) achievable.
Observations: Since we can rearrange bits arbitrarily, we can reorder the zeros and ones in any order we like. However, we must ensure the resulting string is "correct": it must consist of characters '0' and '1', and have no leading zeros. So the first character must be '1'. So any valid string must start with 1, and then any binary string without leading zeros.
We can reduce the number of '1's via operation 2: whenever there are at least two '1's, we can combine them. But does operation 2 require the two '1's to be adjacent? Yes: replace "11" with "1". So we need to bring two '1's together to combine them. Since we can reorder arbitrarily, we can bring all '1's together into a block, then repeatedly combine them to a single '1'? Let's think: Starting with m ones and k zeros (where m >= 1 because s is correct so starts with 1, so m >=1). We can rearrange the string as we like. The minimal numeric value for a correct binary string given some resources (counts of 1's and 0's) after possible reductions? But note operation 2 can reduce the count of ones, but we are not forced to reduce; we can choose when and how many times to apply operation 2. So we can end up with some number of ones, say m' (1 <= m' <= original m), and number of zeros, say k' (but zeros cannot be reduced? Operation 2 only affects ones; swapping doesn't change counts. So zeros remain the same count? Actually operation 2 replaces "11" with "1": it removes one '1' but does not affect zeros. So the total number of zeros remains constant throughout. We cannot create new zeros, nor remove zeros. But can we introduce zeros via something else? No. So the count of zeros is fixed: let z = number of zeros in the original string.
So we have: initial: ones = m, zeros = z. After some sequence of combine operations, we can reduce ones to any number between 1 and m, inclusive? But careful: to combine two ones, they need to be adjacent. If we have many ones, we can bring them together to form consecutive ones. For example, if we have m ones, we can arrange them as a block of m ones, then we can repeatedly replace "11" with "1". Each operation reduces the count of ones by 1. Starting with m ones, we can combine them until only 1 one remains (since any two can be combined). However, is it always possible to reduce to exactly 1? Let's simulate: If we have block of ones, say "111". Operation replace "11" with "1" -> if we replace the first two, we get "11"? Actually careful: starting with "111": we can pick the first two, replace them with "1", resulting in "11". Then we can replace that "11" with "1", resulting in "1". So yes, from m ones we can get to 1. So we can reduce to any number between 1 and m? Not necessarily any number, but we can achieve any number because we can choose to stop at some point. But is it possible to end with, say, 2 ones? Yes, if we combine only some pairs, but careful: we must end with a string where there is no "11" pattern? Actually we can have "11" still in final string; there's no requirement that we cannot have consecutive ones. The final string just has to be correct (no leading zeros). So we could have multiple ones that are not adjacent? But we can arrange them as we like. To end with 2 ones, we could combine m-2 times, leaving 2 ones, and we could place them separated by zeros to avoid further combination. But note: if they become adjacent, we might inadvertently combine them if we apply operation again; but we don't have to apply operation. So we can decide to not combine further. So yes, we can achieve any number of ones from 1 to m, by appropriate combination and arrangement.
Now, zeros are fixed at z. So the final string consists of some number of ones (1 ≤ o ≤ m) and exactly z zeros. However, is it possible to have zeros only? No, because the string must start with 1 to be correct (unless the value is zero? But "0" is a correct string, but it represents zero. But note definition: correct string if it consists of "0" and "1" and there are no redundant leading zeroes. So "0" is allowed? The examples include "0" as correct. They said: "Here are some examples: "0", "10", "1001"." So "0" is considered correct. But also note that if we have only zeros, would that be correct? The string "0" is correct, but "00" would have redundant leading zeroes, so not correct. So the only correct string consisting solely of zeros is "0". So we might end up with "0" if we have no ones? But we start with at least one 1 because s is correct and not "0"? Actually s is correct and could be "0"? Check constraints: n>=1, s correct. Could s be "0"? Possibly. But examples include "1". However, problem statement: "Correct string can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string s." So s could be "0". But the examples are not exhaustive. So we must consider that s may be "0". However, note that operation 2: replace "11" with "1". If s = "0", there is no '1', so we cannot perform operation 2. Also swapping adjacent doesn't change anything. So the minimal correct string would be "0". That's fine.
But if s has at least one '1', we cannot remove all ones because operation 2 only reduces ones by combining two into one; it never eliminates the last one. So the number of ones can be reduced but never to zero, unless initial ones count is zero. So for initial m >= 1, we cannot reach "0" (since zeros can't combine, and we cannot remove the last one). So final string must contain at least one '1'.
Thus, we have to choose final string (binary without leading zeros) with exactly z zeros (the same as original) and o ones (1 ≤ o ≤ m) and perhaps we can also rearrange the order arbitrarily. Our goal is to minimize numeric value.
Given that we can arrange the bits arbitrarily (since we can swap), we can choose any permutation of the o ones and z zeros, with the constraint that the first character must be '1' (to avoid leading zero). So the string must start with 1, and then any ordering of the remaining (o-1) ones and z zeros.
We want the smallest binary number given fixed counts of ones and zeros. For binary strings, to minimize numeric value, we want the string to be as short as possible? Actually numeric value: For binary numbers, given length L (number of bits), the value is determined by the binary digits; smaller length yields smaller number? Not necessarily: "100" (4) is larger than "11" (3)? Actually "11" is 3, length 2; "100" is 4, length 3. Typically for numbers without leading zeros, a shorter string (fewer bits) always yields a smaller number? Let's check: The smallest binary number with L bits is 2^{L-1} (a 1 followed by L-1 zeros). The largest binary number with L-1 bits is 2^{L-1} - 1 (all ones). So 2^{L-1} > 2^{L-1} - 1. So any L-bit number is >= 2^{L-1}, and any (L-1)-bit number is <= 2^{L-1} -1. Thus, any L-bit number is strictly greater than any (L-1)-bit number. So indeed, length is the primary factor: a shorter string always yields a smaller number than any longer string, regardless of bits. So the minimal possible number would be achieved by minimizing the length of the string, given constraints.
Now, the length of final string = o + z. Since z is fixed, the length can be minimized by minimizing o, i.e., the number of ones. The smallest possible o is 1 (since we need at least one 1 to have a non-zero number, or if z=0, the string could be "1", which is length 1; if z>0, length = 1+z). So the minimum length is 1+z. But can we always reduce to exactly o=1? As argued, we can combine all ones down to 1. However, we must consider if any restrictions prevent us from reducing to 1? For example, if we have zeros that might interfere? But we can reorder bits arbitrarily. So we can bring all ones together to combine them into 1, then place that single 1 at the beginning, followed by all zeros. That yields the string "1" followed by z zeros. That's a valid correct string: it's "1" + "0"*z. That seems to be minimal in length: length = 1+z. Could there be a string even shorter? The only way to have length less than 1+z would be to have fewer zeros, but zeros are fixed, we cannot remove zeros. So 1+z is the minimum possible length.
But is it always achievable? Let's test: Starting with any s (correct, so first char is 1), we have m ones, z zeros. We want final string "1" + "0"*z. We need to be able to combine all ones into one. Since we can swap arbitrarily, we can arrange all ones consecutively, then perform combinations until one remains. After that, we need to arrange the zeros after the one. However, after we combine ones, we might have zeros interspersed that could block combination? But since we can reorder at any time via swaps, we can first collect all ones together, ignoring zeros. For example, we can bring all ones to some contiguous block (by swapping). Then we can combine them step by step to a single 1. At that point, we have a single 1 and all zeros possibly scattered. Then we can move the single 1 to the front (by swaps) and move zeros after it. So yes, it's achievable.
But wait: The operation 2 reduces length, but also may affect positions. However, after we combine a block of ones into one, the zeros originally between ones might get moved? But we can plan: we can first reorder the string to be all ones followed by all zeros: "111...1100...0". That's possible via swaps. Then we have a block of ones at front. Then we can repeatedly apply operation 2 on the first two ones: the string becomes "11...1100...0" after first combine? Actually if we have m ones followed by zeros: "111...1" (m times) then zeros. Replace first two ones (positions 1 and 2) with "1": that yields string "11...1" (m-1 ones) followed by zeros. So after m-1 operations, we get "1" followed by zeros. So indeed we can get exactly "1"+"0"*z.
Thus, it appears that the minimal string is always "1" followed by all zeros. But is there any case where the result would be even smaller than that? Consider the possibility of obtaining "0". If we can get "0", that's smaller than any "1"+"0"*z (since "0" is value 0). But can we ever get "0"? Starting with m>=1 ones, we cannot eliminate all ones because operation 2 reduces number of ones but never eliminates the last one (since it requires two adjacent ones). So we cannot get rid of the last one. Unless we can combine the last one with something else? No. So "0" is only possible if initial s is "0". So if s is "0", answer is "0". But wait: Could we use swaps to make something like "00" and then perhaps reduce? No operation reduces zeros. So "0" only if initial string is exactly "0". However, what about if s = "10"? That has one zero and one one. Minimal should be "10"? Since we have one one and one zero, the minimal possible is "10"? Could it be "1"? If we could get rid of the zero, we could have "1". But we cannot remove zeros. So the only strings possible are those with exactly one one and the zero. Could we rearrange to "01"? That's invalid because leading zero. So "10" is the only valid correct string (if we require exactly those bits). Is "10" smaller than "1"? Actually "1" is 1, "10" is 2, so "1" is smaller. But can we achieve "1"? That would require removing the zero. But operation 2 doesn't affect zeros, and swapping doesn't change counts. So we cannot remove zeros. So we must keep the zero. So the answer for "10" should be "10"? But our earlier reasoning said we can reduce ones to 1 and then put zeros after: "1"+"0" = "10". So indeed answer is "10". So consistent.
Now consider s = "1". Then z=0, m=1. Minimal string is "1". That's "1"+"0"*0 = "1". Good.
Consider s = "0". Then answer "0". But note "0" is a correct string, but it doesn't start with 1. So our general rule of "1 followed by zeros" fails. So we must treat the case where initial m=0 separately. But initial s is correct; if it's "0", it's valid. Could there be other correct strings with m=0? Only "0". Because "00" would have leading zeros. So only "0". So special case: if s == "0", answer "0". But what about s being something like "000"? Not possible because that's not correct (redundant leading zeros). So only "0".
Thus, answer seems trivial: if s contains any '1', answer is "1" followed by as many zeros as there are in s. If s is "0", answer is "0".
But wait, is there any catch? Let's test with examples. Example 1: Input: 4, "1001". This has zeros: count of '0's? s = "1001": characters: '1','0','0','1' -> zeros = 2, ones = 2. Our answer would be "1" + "00" = "100". That matches output "100". Good.
Example 2: Input: 1, "1": zeros=0 -> "1". Output "1". Good.
What about s = "10"? zeros=1 -> "10". That seems plausible. But is there any possibility to get a smaller string than "10"? For instance, could we use operations to get "01"? That's not correct because leading zero. Could we get "0"? No. Could we get "1"? No because zero can't be removed. So "10" is minimal.
What about s = "1010"? zeros=2, ones=2. Answer "100". That would be "1" + "00" = "100". Compare numeric: "100" = 4, "1010" = 10. Could we get "10"? That would be length 2, but we have two zeros, so length would be at least 1+2 = 3. So "10" length 2 is impossible because we must have both zeros. So "100" is indeed minimal length (3). But could there be a string of length 3 that is smaller than "100"? The smallest 3-bit number is "100" (4). "011" is invalid (leading zero). So "100" is minimal among 3-bit strings. So correct.
Now consider s = "110". zeros=1, ones=2. Our answer: "10". Actually zeros=1 -> "1"+"0" = "10". Can we get "10"? Starting with "110": we could combine the two ones: "110" -> replace "11" -> "10". So yes. So answer "10". That is minimal? Could we get "1"? That would be length 1 but we have a zero, so cannot remove zero. So "10" minimal.
Now consider s = "101". zeros=1, ones=2. Answer "10"? But we have ones=2, zeros=1 -> "10". But can we get "10"? Let's try: s="101". Rearrange to "110"? Swapping last two? "101" -> swap positions 2 and 3 gives "110". Then combine "11" -> "10". So yes. So answer "10". But is "10" the smallest? Yes.
Now consider s = "111". zeros=0, ones=3 -> answer "1". Can we get "1"? Yes combine to "1". So answer "1".
Now consider s = "0". Answer "0".
Now, is there any scenario where we could get a string with fewer zeros? No, because zeros are conserved. Could we use operation 2 to somehow remove zeros? No. So zeros count fixed.
Thus, the problem seems trivial: output "1" followed by all zeros from original string, unless the original string is "0". But wait: are we allowed to use operation 2 multiple times? Yes. So indeed answer is "1" + (number of zeros) times '0'.
But is there any nuance about leading zeros? The resulting string must not have leading zeros. Our construction "1"+"0"*z starts with 1, so it's fine.
Now, consider that we might be able to get an even smaller number by having zeros before the 1? That would be invalid. So not possible.
But is there any scenario where having fewer ones than 1? That's impossible.
Thus, the minimal correct string is simply a '1' followed by all zeros from original.
But hold on: The problem statement says: "Let val(s) be such a number that s is its binary representation. Correct string a is less than some other correct string b iff val(a) < val(b)." So they compare numeric values. So indeed shorter length yields smaller number. So our answer is minimal length.
Now, is there any trick regarding the possibility of reducing the number of zeros indirectly through some operation? Operation 2 only affects pairs of ones. Could there be a scenario where by swapping and combining we could somehow eliminate zeros? For instance, if we have "10" and we swap to "01"? That's invalid if we consider leading zero? But maybe we could then combine something? No. So zeros stay.
Thus the answer is simple.
But maybe we need to consider that we could also use operation 2 to combine ones in a way that also reduces zeros? No.
Thus answer: if the string contains at least one '1', output '1' followed by the count of zeros in the original string many '0's. If the string is "0", output "0".
But we must ensure that the output is indeed reachable. As argued, yes.
Let's double-check with some random strings.
Case: n=5, s="10101". zeros=2? Actually "10101": characters: 1,0,1,0,1 -> zeros=2, ones=3. Answer "100". Can we get "100"? Steps: rearrange to "11100" (swap to bring ones together). Then combine two ones: "11100" -> combine first two: "1100". Combine first two: "100". So we get "100". So yes.
Case: s="1000". zeros=3, ones=1 -> answer "1000". That's same as original, because we cannot reduce ones further (already 1) and zeros fixed. So output "1000". But could we get something smaller like "100"? That would have only two zeros, but we have three zeros; cannot remove zeros. So no.
Case: s="0". Answer "0". Works.
Now, but there is nuance: Could we use operation 2 in a way that also reduces zeros by merging with ones? No.
Thus solution seems trivial.
But why does the problem have constraints up to 100? It's just to make it implementable in any language. Perhaps there is a twist: Could there be a scenario where we could get a string that is even smaller than "1"+"0"*z? For instance, if we have zeros, we might want to put some zeros before the 1? That would make number smaller? Actually if we had leading zeros, that's not allowed because the string must be correct (no redundant leading zeros). However, what about the string "0"? That's allowed. But any other string with leading zero would be invalid. So not allowed.
What about the possibility of making the string empty? Not allowed.
Thus answer stands.
But wait, maybe there is a nuance: Operation 2 replaces "11" with "1". This reduces length by 1 and removes a '1'. But note that after replacing, the characters become adjacent to neighbors; could this create new "11"? Yes. But that's fine.
Also, we can perform swaps any number of times. So effectively we have ability to arbitrarily permute the characters before and after replacements. There's no restriction on using swaps to rearrange characters after reducing the number of ones? Yes.
Thus the minimal string is determined solely by the count of zeros.
But is it always optimal to reduce all ones to a single one? What if we keep some extra ones to make the number smaller? Consider we have zeros count z. String "1"+"0"*z is of length 1+z. If we have more ones, length becomes larger, so number will be larger because it's longer. However, could a longer string with leading ones and zeros be smaller than a shorter one? No, as argued: any binary number with L bits is at least 2^{L-1}, while any number with L-1 bits is at most 2^{L-1} - 1. So longer length always gives larger number. So minimal length gives minimal number. Therefore we should minimize length. Since zeros fixed, length = o + z. So we need to minimize o, which is 1 (lowest possible given we must have at least one 1, unless no ones, then string "0" length 1 as well). So answer is as described.
But wait: what about the case where the original string is "0"? Then zeros count? Actually "0" has one zero and zero ones. Our logic: if no ones, answer "0". That's fine.
Thus algorithm: read n, read s. Count zeros. If there is any '1' (i.e., s contains '1'), output '1' followed by zeros count times '0'. Else (s is all zeros, but correct implies only "0" possible), output "0".
But careful: Could s be "0...0" but length > 1? That wouldn't be correct because it would have redundant leading zeros. So input guarantees s is correct, so it's either "0" or starts with '1'. So if it starts with '1', it contains at least one '1'. So condition: if s[0] == '1', then answer is '1' + (count of '0') zeros. If s[0] == '0' (only possible if n==1 and s=="0"), answer "0".
But to be safe, we can just count zeros, and if there is at least one '1', output '1' + zeros*'0', else output "0".
Now, confirm with sample: 4, "1001": zeros=2 => "1"+"00" = "100", matches.
Edge cases: n=1, s="1": zeros=0 => "1", correct.
n=1, s="0": zeros=1, but there is no '1', so output "0". That's correct.
Now, what about s="10"? zeros=1 => "10". But is there any possible smaller string like "1"? No.
All good.
But perhaps there is a nuance: Could we use operation 2 to reduce the number of zeros indirectly? Suppose we have "101". Could we combine something to get "01"? No.
Thus answer is trivial.
Given the problem is from Codeforces (maybe problem "Minimum Binary Number"? Actually I recall a problem: "Minimum number" with operations: swap any two adjacent, replace "11" with "1". The answer is indeed "1" plus all zeros. So I'm confident.
Now we need to implement. Input reading: n (int), then string s. Compute zeros = s.count('0'). If s contains '1', output '1' + '0'*zeros else output '0'.
Implementation detail: if s contains any '1', there is at least one 1. But also consider the case where there are no zeros? Then output "1". That's fine.
Thus solution is O(n).
But wait, there is a potential subtlety: Could we ever produce a string that is "0" when there is at least one '1'? That would require eliminating that one, but operation 2 only reduces ones when there are at least two adjacent ones. If we have exactly one '1', we cannot eliminate it. So no.
Thus final answer.
But I recall a Codeforces problem: 976A - Minimum Binary Number, actually problem name? Let me recall: There is a problem "Minimum Binary Number" from Codeforces Round #... The operations were exactly: you can swap any two adjacent characters, and you can replace "11" with "1". The answer is "1" followed by all zeros. So indeed.
Hence solution.
Now provide explanation.
But let's double-check the possibility that we might be able to reduce zeros by moving them to the front and then removing leading zeros? The definition of correct string prohibits redundant leading zeros, but does it allow us to have a string that becomes "0" if we have zeros only? Not if we have any ones, we can't get rid of all ones. So no.
Thus answer is clear.
But wait: what about the possibility of using operation 2 to combine ones that are not adjacent originally, but we can make them adjacent via swaps. That we already accounted for.
Thus solution is trivial.
Now, let's think if there is any hidden constraint: The operations can be used any number of times in any order. Could there be any scenario where we cannot bring all ones together because of some limitation? No, because swapping adjacent allows full permutation.
Thus solved.
Now let's implement.
Pseudo:
read n read s zeros = 0 has_one = False for ch in s: if ch == '0': zeros += 1 else: has_one = True if has_one: print('1' + '0'*zeros) else: print('0')
Test:
Input: 4 1001 Output: '100'
Input: 1 1 Output: '1'
Input: 3 110 Output: '10' (zeros=1 => '10') but check: possible? s=110 has zeros=1, answer '10'. That's valid.
Edge: s=0, n=1: has_one false => '0'.
All good.
But wait: Could s be something like "10...0" (starts with 1, many zeros) but with multiple ones later? Then answer is "1" + all zeros, which is same as the smallest representation of 2^{zeros}. However, consider original s="1010": zeros=2, answer "100". That is 4. Could we get "10"? That's 2, but we have two zeros, so not possible. So fine.
Thus answer.
Now, but there is also an alternative approach: The minimal string is just the original string after removing all ones except one, and moving that one to the front, and then all zeros. So it's "1" + zeros.
So final solution.
Let's also consider if there is any possibility to get a string shorter than 1+z by using operation 2 to also remove zeros? No.
But what about the possibility of creating a "0" string if we have zeros and one one? Could we combine that one with something to get rid of it? For example, if we have "10", we can swap to "01", but that's not correct. But if we then combine something? There is no "11". So no.
Thus final answer.
Now, write the solution.
Note: In C++ we need to print string. Use std::string.
Alright.
But hold on: The problem statement includes an image for operations but it's fine.
I'll produce final solution.
Wait: There's a nuance: The string after operations must be correct: no redundant leading zeros. That means it cannot have leading zeros, but it could be "0". So output "0" only when there are no ones.
Now, what about the case where we have zeros but the ones count is zero? That can only happen if s is "0". Because any correct string with no ones and length>1 would have leading zeros. So input will not give that.
Thus code.
But maybe we need to consider that the initial string is correct, but after operations we might produce a string that starts with zero and then we could later remove that zero? We can't remove zeros. So we must ensure final string has no leading zero.
Thus answer stands.
Now implement.
But there is a potential trap: The operation 2 reduces length, but also we might inadvertently create a leading zero after combining? For example, if we have string "011"? But such a string would have leading zero, but it's not allowed as a correct string. However, intermediate strings are not required to be correct; only the final string we output must be correct. So we can have intermediate strings with leading zeros. But we must ensure we can achieve the final correct string. So no problem.
Thus solution.
Now, final answer. We need to find the smallest correct binary string (no leading zeros) that can be obtained from the given string using two operations: swap any adjacent characters, and replace any occurrence of "11" with "1".
Observing the operations:
- Swapping adjacent characters allows any permutation of the characters.
- Replacing "11" with "1" reduces the number of '1's by one; the number of '0's never changes.
Thus the final string must contain exactly the same number of '0's as the original, and at least one '1' (unless the original had none, which only happens when the original is "0").
The numeric value of a binary string is smaller when its length is smaller. Since the number of zeros is fixed, the length is minimized by minimizing the number of ones. The smallest possible number of ones is 1 (or 0 only for the special case "0"). Therefore the optimal final string consists of a single '1' followed by all the original zeros.
Construction: bring all '1's together (using swaps), repeatedly replace "11" with "1" until only one '1' remains, then move that '1' to the front and all zeros to the back (using swaps). This yields the string "1" + ('0' * countZeros).
If the original string contains no '1' (i.e., it is "0"), the answer is "0".
Implementation: read n and s, count zeros, check for presence of '1', and output accordingly.
#include <iostream> #include <string> int main() { int n; std::string s; std::cin >> n >> s; int zeros = 0; bool has_one = false; for (char ch : s) { if (ch == '0') zeros++; else has_one = true; } if (has_one) { std::cout << '1' << std::string(zeros, '0') << '\n'; } else { std::cout << "0\n"; } return 0; }