We are told: There are N cubes stacked vertically on a desk (so they are in a stack, one on top of another). The bottom cube is index 1, top is index N. Each cube has color red (0) or blue (1). Operation: choose a red cube and a blue cube that are adjacent, and remove them. After removal, the cubes above fall down. We want to maximize the number of cubes removed (i.e., total cubes removed after any sequence of operations). At most how many cubes can be removed?
This is reminiscent of a classic problem: Given a string of 0s and 1s, you can remove adjacent 01 or 10 pairs. After removal, the neighbors become adjacent. The question: what is the maximum number of characters that can be removed by repeatedly removing a pair of adjacent characters that are different? Equivalent to: you can delete any pair of opposite colors that become adjacent. Since removal is pairwise and each operation removes two cubes, we want max possible total removed. Because cubes cannot be removed singly, only in pairs of opposite colors that are adjacent at the time. The question: what is the maximum number of cubes that can be removed? Note that if we have an odd total count? Actually, we want the maximum possible number of cubes removed, which must be even, and at most N.
This is like: given a binary string, repeatedly remove "01" or "10" substrings (not necessarily consecutive originally, but after removals they become adjacent). This is similar to the process of reducing a string by canceling opposite bits. The result after no such pairs exist is a string consisting solely of all 0s or all 1s? Actually, if we keep removing adjacent opposite bits, the final string (if we cannot remove further) will consist only of characters that are all the same (either all 0 or all 1). Because if there is both a 0 and a 1, they might not be adjacent, but could they become adjacent? Possibly, but after maximum removal, we would end with a string that cannot have adjacent opposite pairs, meaning all characters are same. But is it always possible to reduce to a string of only one type? Consider string "010". We can remove the middle 1 with either left 0 or right 0? Actually we can choose an adjacent red-blue pair. Initially, pairs: (0,1) and (1,0). If we remove the left pair (positions 1 and 2) we remove "01", leaving "0". Or remove right pair (2 and 3) leaving "0". So final 0 remains. So we removed 2 out of 3, leaving 1. Could we remove all? No because need pair. So maximum removed is 2. So final remaining count = N - removed. So maximum removed = N - min possible remaining after optimal sequence. So problem reduces to: what is the minimum possible number of cubes that can remain after performing any sequence of adjacent opposite deletions? That is, we want to minimize the length of the final string after repeatedly deleting adjacent different characters.
Now this looks similar to the concept of reducing a binary string by cancelling opposites, which is analogous to treating 0 as -1 and 1 as +1? Or like stack-based elimination: when you see a character that is different from top, you could remove? Actually consider a process: you can remove any adjacent opposite pair at any time. This is not strictly a stack-based process where you always remove from left to right; but due to the ability to choose order, it might be equivalent to the absolute difference between counts of 0 and 1? Let's test: N=4, S=0011. Count of 0 = 2, count of 1 = 2. Difference = 0 => could remove all? Yes, we can remove all 4: maybe pair the first 0 with first 1? But they are adjacent? Initially: positions: 1:0,2:0,3:1,4:1. Adjacent opposite pairs exist only between positions 2 and 3 (0 and 1). If we remove them, we have "01"? Actually after removing positions 2 and 3 (the second 0 and the first 1), the stack collapses: original positions 1 and 4 remain, but now they become adjacent? The cubes above fall down: after removal, the cubes that were above the removed ones fall onto the ones below. So after removing positions 2 and 3 (i.e., the cube at position2 and cube at position3), what remains are cubes originally at positions 1 and 4. The cube at position4 falls onto the cube at position1, so they become adjacent: now we have a stack of two cubes: bottom is original 1 (position1:0), top is original 4 (position4:1). That's adjacent and opposite, so we can remove them as well, removing all four. So maximum removed = 4, indeed. So with equal counts, we can remove all.
Example: 11011010001011 length? Let's count: "11011010001011" length =? Count characters: 1,1,0,1,1,0,1,0,0,0,1,0,1,1 -> that's 14? Actually let's compute: string: 1 1 0 1 1 0 1 0 0 0 1 0 1 1 => 14 characters? But sample output says 12 removed, meaning 2 remain. Count zeros: positions: 3:0,6:0,8:0,9:0,10:0? Wait need to count precisely: S = "11011010001011". Let's list indices:
1:1
2:1
3:0
4:1
5:1
6:0
7:1
8:0
9:0
10:0
11:1
12:0
13:1
14:1
So zeros: at 3,6,8,9,10,12 => 6 zeros. Ones: at 1,2,4,5,7,11,13,14 => 8 ones. So counts: ones=8, zeros=6, diff=2. Output says removed=12, remaining=2. That matches diff = 2. So maybe maximum removed = N - |count1 - count0|? That is, we can remove all except the absolute difference between the numbers of 0s and 1s. Let's test on first example: N=4, counts: 0=2,1=2 diff=0, removed=4, matches. Third example: "0": N=1, count diff=1, removed=0, matches. Also on example like "01": N=2 diff=0, we can remove both? Yes, they are adjacent opposite, so remove both -> removed=2, matches N - diff=2. On "010": counts: 0=2,1=1 diff=1, N=3, N-diff=2, matches maximum removed=2. On "0101": counts: zeros=2 ones=2 diff=0, N=4, can we remove all? Let's see: "0101". Initially adjacent pairs: (0,1) positions1-2; (1,0) positions2-3? Actually positions:1:0,2:1,3:0,4:1. Adjacent opposite: 1-2 (01),2-3 (10),3-4 (01). If we remove 1-2, we get "01"? Actually remove 1 and 2 -> positions 3 (0) and 4 (1) become adjacent, they are opposite, so remove them -> all gone. So yes, remove all 4. So N - diff works.
But is it always achievable? It seems plausible that the maximum number of removals is limited by the fact that each removal removes one 0 and one 1. So total removed number of 0s equals total removed number of 1s, since each operation removes exactly one of each. So after any sequence, the remaining cubes consist of some number of 0s and some number of 1s. The numbers of remaining 0s and 1s must satisfy that the difference between the original counts and the removed counts: let removed0 = removed1 = k (since each operation removes one of each). So after removal, remaining zeros = count0 - k, remaining ones = count1 - k. The total remaining = count0 + count1 - 2k = N - 2k. The goal is to maximize k, i.e., minimize remaining. But we must also ensure that the remaining cubes cannot have any adjacent opposite pairs; i.e., the remaining configuration must be such that no 0 and 1 are adjacent. Since they are stacked vertically, the remaining cubes will be in some order (the order after collapses). The order of remaining cubes is the order of the original cubes with the removed ones taken out. So we end up with a subsequence of the original string, preserving original relative order. And we need that no two adjacent remaining cubes are of opposite colors. That means the remaining sequence must be all 0s or all 1s? Actually if there is both a 0 and a 1 in the remaining sequence, they might not be adjacent if they are separated? But if the remaining sequence is like 0 ... 0 1 ... 1, the 0 and 1 are adjacent at the boundary between the block of 0s and block of 1s. Since there is no other cube between them, they are adjacent. So any remaining sequence that contains both 0 and 1 will have at least one adjacent pair of opposite colors (the last of one type and first of the other type). However, could it be that the remaining sequence is interleaved but not adjacent? That's impossible because the sequence is a linear order; if it contains both 0 and 1, there must be a transition somewhere where the color changes. At that transition, the two consecutive elements are of opposite colors. Thus they would be an adjacent opposite pair, which should be removable. But the condition for being unable to perform further operations is that there is no adjacent opposite pair. So the final state must have no opposite adjacent, which implies all remaining cubes are of the same color. So the final state is either all zeros or all ones. Therefore, remaining cubes must all be of one color. So either remaining zeros = 0 or remaining ones = 0. That means the final count is either count0 - k = 0 or count1 - k = 0. Therefore the maximum possible k is min(count0, count1). Because we can remove all of the minority color, and an equal number of majority color. After removal, we are left with |count0 - count1| cubes of the majority color. So the maximum removed = 2 * min(count0, count1) = N - |count0 - count1|.
Thus the problem reduces to counting number of 0s and 1s, outputting N - abs(count0 - count1). But is it always achievable to remove min(count0, count1) pairs? This is a well-known result: In any binary string, you can eliminate all opposite adjacent pairs until only one color remains, and the number of remaining is the absolute difference. This is akin to the cancellation of parentheses or the reduction of a string by removing "01" and "10". It can be proven by a greedy stack simulation: scanning from bottom to top (or left to right), maintain a stack; when seeing a cube opposite to the top, you can remove them (like matching). However, careful: the operation can be performed at any time, not necessarily sequentially from bottom. But a classic argument: treat 0 as -1, 1 as +1; the process of removing adjacent opposite is like canceling out. The remaining after optimal reductions is the absolute sum? Actually if we simulate: keep a stack; for each cube from bottom to top, if stack is empty, push the cube; else if top of stack is opposite color, pop (i.e., remove this pair) else push. This simulates the effect of always removing adjacent opposite when they become adjacent in a left-to-right fashion. At the end, the stack contains the cubes that cannot be matched; they are all the same color? Actually consider "0011": stack: push 0, push 0 (stack: 0,0), then next 1: opposite to top? top=0 => pop -> stack: 0, then next 1: top=0 => pop -> stack empty. So all matched. Consider "010": stack: push 0; next 1: opposite to top, pop -> stack empty; next 0: push -> stack has 0. So leftover 0. That matches min removal. So this greedy stack algorithm yields the final unmatched count = |count0 - count1|? Actually does it always yield the difference? Let's check "1010": stack: push1; next0 opposite -> pop -> empty; next1 -> push; next0 opposite -> pop -> empty. So all matched, diff=0. Count: ones=2 zeros=2 diff=0. Good. "1100": push1; next1 same -> push1; next0 opposite to top->pop -> stack:1; next0 opposite -> pop -> empty. Good. "110": push1; next1 same-> push1; next0 opposite->pop -> stack:1. So leftover 1. Count diff = 2-1=1. Good. "0101": push0; next1 opposite->pop; next0 push; next1 opposite->pop -> empty. So matches diff=0. So indeed the greedy stack approach yields the minimal possible remaining as the absolute difference? Wait in stack, the leftover color(s) are all the same? In "110", leftover is a single 1, all same. In "101", let's test: push1; next0 opposite->pop (empty); next1 push -> leftover 1. So diff=2-1=1. So stack works. So the result is consistent.
But could there be a scenario where the greedy stack algorithm fails to achieve the maximum possible removals? In many similar problems (like removing adjacent opposite characters), the maximum number of removals equals N - |#0 - #1|, because each removal removes one of each and final must be all same. That is an upper bound, and it's achievable because you can always pair one of each until one color runs out. But is it always possible to actually remove all pairs? Might there be some constraints due to adjacency? Consider a scenario: all zeros on top of all ones? Actually the order matters: If all 0s are at the bottom and all 1s at the top, like "000111". That's easily removable: we can remove the boundary pairs gradually: remove the adjacent ones at the interface repeatedly. For example, "000111" -> remove the middle pair? Let's simulate: positions: 1:0,2:0,3:0,4:1,5:1,6:1. Adjacent opposite: between 3 and 4. Remove them -> left with "0011"? Actually after removing positions 3 and 4, we have: original positions 1,2,5,6? Wait careful: remove positions 3 and 4 (0 and 1). Then cubes above fall: originally positions 5 and 6 (both 1) fall onto position 2. So new stack: bottom: pos1:0, pos2:0, then pos5:1, pos6:1. That's "0011". Then remove the adjacent pair between pos2 and pos5 (0 and 1) -> leaves "01"? Actually remove those two, we get left with pos1:0 and pos6:1 => "01" -> remove them -> all gone. So yes. So that works.
What about interleaved like "010101"? Count diff = 0. Can we remove all? Possibly. Let's try: "010101". We can try to pair them: For length 6, we can try to remove all. Use greedy stack: it works and leaves empty. So yes.
What about "00100"? counts: zeros=4, ones=1 diff=3, N=5, max removed=2? Can we remove 2? Possibly we can only remove the 1 with one 0, leaving 3 zeros. Is that always possible? Yes: identify any adjacent opposite pair. There is a 1 surrounded by zeros: ...0,1,0... so adjacent opposite pairs exist (0,1) on both sides. Remove the 1 with one of its adjacent zeros, say remove positions 3 (0?) Actually S="00100": indices:1:0,2:0,3:1,4:0,5:0. Adjacent opposite: between 2-3 (0,1) and 3-4 (1,0). Remove, say, 2 and 3: we remove a 0 and 1 -> remaining: positions 1,4,5: 0,0,0 => all zeros, no further removal. So removed 2. Could we remove more? To remove more we would need another opposite pair, but after removal there are only zeros, so cannot. So max removed=2 = 2min(count)=21. So works.
So the answer seems straightforward: compute number of zeros and ones, answer = 2 * min(cnt0, cnt1).
But wait: The sample 2: "11011010001011" gave removed=12. cnt0=6, cnt1=8, min=6, 2min=12, matches. So indeed answer is 2min(cnt0,cnt1).
But is there any nuance? Operation chooses a red cube and a blue cube that are adjacent, and remove them. The cubes are stacked vertically, so adjacency is vertical: one directly on top of the other. So the stack is like a vertical column; each cube sits on top of the one below. So adjacency is only between cubes that are consecutive in the stack (i.e., one is directly above the other). That matches the string representation: index i from bottom to top. So operation removes two adjacent positions i and i+1? Actually if we choose a red cube and a blue cube that are adjacent, it could be that the red is above the blue, or blue above red. Both are allowed as long as they are adjacent and colors differ. After removal, the cubes above fall down, so the stack shrinks by two and the order of the remaining cubes is preserved (relative order). So the process is exactly as described: we can delete any adjacent pair of opposite bits.
Thus the answer is indeed 2 * min(cnt0, cnt1). But wait: Are there any constraints that might prevent achieving this bound? For example, suppose we have many zeros and ones but they are separated such that they never become adjacent? However, because of the collapsing nature, you can bring them together by removing intermediate cubes. The greedy stack algorithm shows that we can always match them as we scan from bottom to top. But does the stack algorithm correspond to a valid sequence of operations? The stack algorithm simulates matching each new cube with the previous unmatched one if they are opposite, which is effectively a specific sequence of operations that always removes adjacent opposite pairs when they become adjacent. Since the process can be done in that order, it yields a valid removal sequence. Let's articulate: We process cubes from bottom to top. Maintain a list representing the current stack. Initially empty. For each cube (from bottom to top), we place it on top of the current stack. Actually we can think of building the stack gradually. But operations remove pairs. Alternatively, consider the stack algorithm as: as we read the string, we can perform removals when the top of the stack (current last element) and the new element are opposite. This is like repeatedly removing adjacent opposites. It's a standard reduction. The number of remaining elements equals the absolute difference of counts. Since each removal removes one of each color, total removed is 2 * min(cnt0,cnt1). So that is achievable.
Therefore, the answer is simply 2 * min(count0, count1). But wait: The sample input 2 yields 12, which is indeed 2*min(6,8)=12. So that matches.
But let me double-check the constraints: N up to 1e5, trivial.
Now, are there any tricky aspects? Possibly the operation chooses a red cube and a blue cube that are adjacent, but does not specify which is on top? So you can choose any adjacent pair with opposite colors. That's fine.
Thus solution: read S, count zeros and ones, output 2 * min(cnt0, cnt1).
But wait: Could there be a scenario where you cannot remove all min pairs due to order? Let's try a tricky case: "101". counts: ones=2, zeros=1, min=1, so predicted removed=2. Can we remove 2? The string: 1,0,1. Adjacent pairs: (1,0) and (0,1). If we remove the middle 0 with either the top 1 or bottom 1, we remove two cubes: say remove positions 2 and 3 (0 and 1) -> remaining: 1 (bottom). That's one removal, removed 2 cubes. So yes removed=2. So we removed 2 cubes, which is 2*min=2. But could we possibly remove all 3? That would require removing both ones with the zero, but that's not allowed because each removal removes only two adjacent cubes. After first removal, we have a single cube left. So max removed is 2.
Another: "100". counts: ones=1, zeros=2, min=1, predicted removed=2. String:1,0,0. Adjacent opposite: (1,0) at positions1-2. Remove them -> remaining: 0. So removed 2.
Another: "0100". counts: zeros=3, ones=1, min=1, predicted removed=2. String:0,1,0,0. Adjacent opposite: (0,1) at 1-2 and (1,0) at 2-3. Remove pair (1,2) -> left: 0,0 -> no opposite, removed 2. Could we remove more? Maybe remove (2,3) first: remove positions 2 and 3 (1,0) -> left:0,0 -> same. So removed 2.
Now consider "01010"? counts: zeros=3, ones=2, min=2 => predicted removed=4. N=5, so one remains. Can we achieve that? Let's attempt: S=0,1,0,1,0. Adjacent opposite pairs: many. Goal: remove 4 cubes. Since min=2, we need to remove both ones and two zeros. Greedy stack: reading: push0; next1 opposite -> pop (empty); next0 push; next1 opposite -> pop (empty); next0 push -> final stack:0. So removed 4 (two pairs). So yes.
Now consider "0011100". counts: zeros=4, ones=3, min=3 => predicted removed=6, N=7 => one left. Is it possible? Let's test: 0,0,1,1,1,0,0. Greedy: push0; next0 -> push0 (stack:00); next1 -> opposite top? top=0 => pop -> stack:0; next1 -> top=0 => pop -> stack: empty; next1 -> push1; next0 -> opposite top1 => pop -> empty; next0 -> push0 -> final 0. So removed 6. Works.
Thus seems consistent.
But there might be a catch: The operation removes a red cube and a blue cube that are adjacent. But maybe the cubes are physical objects; after removal, the cubes above fall down. Could there be a scenario where we remove non-adjacent cubes? No, operation only allows adjacent.
Hence solution: compute zeros and ones.
But wait: The problem statement says: "choose a red cube and a blue cube that are adjacent, and remove them." That implies you select any red cube and any blue cube that are adjacent (i.e., one is directly on top of the other). So you cannot choose two cubes that are not adjacent. So it's as described.
Thus the answer is simply: 2 * min(count('0'), count('1')).
But the examples show that. So the problem is trivial? Possibly the intended solution is to compute the min, but maybe there is a nuance: The cubes are stacked vertically, so adjacency is only between consecutive cubes. But the operation allows to choose any red and any blue that are adjacent; it does not specify that the red must be below the blue; either order is fine.
Thus I think the answer is correct.
However, I recall a similar problem from AtCoder (maybe ABC something) where you have to output something like: the answer is the total length minus the absolute difference of counts, which is the same. But sometimes they ask: maximum number of cubes that can be removed, and the solution is N - abs(cnt0 - cnt1). Let's verify with examples: N=4, diff=0 -> 4, N=14, diff=2 -> 12, N=1, diff=1 -> 0. So matches.
Thus answer: print N - |cnt0 - cnt1| equivalently 2*min(cnt0,cnt1).
Now let's implement.
But wait, there might be a nuance about "choose a red cube and a blue cube that are adjacent". It says "choose a red cube and a blue cube that are adjacent, and remove them." In English, it might be interpreted as you pick one red and one blue that are adjacent (i.e., next to each other) and remove both. That's exactly what we used.
Thus solution is trivial: count zeros and ones.
But given the problem from AtCoder (maybe ABC124 C?), but that problem often is about minimum number of changes to make alternating pattern. However, this is different.
Actually, I recall a problem from AtCoder Beginner Contest something: "C - Cubes" or "D - ..."? There is a problem "C - 1D Matching" but not. Let's search memory: There is AtCoder ABC 136 C? Not sure. But anyway.
Let's double-check with a few random strings via simulation to be sure.
Simulate with brute force for small N to verify that maximum removable equals 2min(cnt0,cnt1). We could think of reduction as: any sequence of removals will remove equal number of 0s and 1s. So maximum removed is at most 2min. And we have constructive algorithm to achieve that. The constructive algorithm: repeatedly remove any adjacent opposite pair until no such pairs exist. But does that always remove 2*min? Not necessarily; it might get stuck with a configuration that still has both colors but no adjacent opposites? But if both colors exist, there must be at least one adjacent opposite pair? Actually consider a configuration like "010" after some removals? That has both colors and they are adjacent? In "010", there are both 0 and 1, but is there an adjacent opposite? Yes, positions 1-2 are 0,1 (adjacent opposite) and 2-3 are 1,0. So it has. But could there be a configuration where both colors exist but no adjacent opposite? Consider "0011"? That has both colors and there is a boundary where they meet: 0,0,1,1: at the boundary between 2 and 3: 0 and 1 adjacent. So any binary string containing both 0 and 1 will have at least one place where the value changes from 0 to 1 or 1 to 0. Because it's a sequence of bits. At the point of change, the two consecutive bits are opposite. So indeed any string containing both bits has at least one adjacent opposite pair. Therefore, a state with both colors but no adjacent opposites is impossible. So the process can continue as long as both colors remain. Therefore, if we keep removing any available adjacent opposite pair, we will eventually end with a homogeneous string (all 0s or all 1s). Because each removal reduces total count by 2, and as long as both colors remain, there will be at least one adjacent opposite pair, so we can continue. Thus we can always remove until one color is exhausted. However, we need to ensure that we don't get stuck early due to inability to make a move even though both colors remain. But as argued, any binary string containing both 0 and 1 necessarily has an adjacent opposite pair (since it's not constant). So we can always find a move. Therefore, we can continue removing until the string becomes constant. At that point, the number of remaining cubes is either all zeros or all ones. Thus the number removed is N - remaining, where remaining = |#0 - #1|. Since we can always achieve this by repeatedly removing any adjacent opposite pair, the maximum removed is exactly that. However, is it always maximum? Since each move removes exactly one 0 and one 1, the maximum possible k cannot exceed min(count0, count1). And we have a method that achieves that bound. So yes, the answer is exactly 2 * min(count0, count1).
Thus solution is straightforward.
But wait: The process described "choose a red cube and a blue cube that are adjacent" might allow you to remove them even if they are not consecutive in the current stack? Actually "adjacent" means they are next to each other, i.e., one is directly on top of the other. So they are consecutive. So our interpretation is correct.
Thus answer: print 2 * min(cnt0, cnt1).
But to be safe, we can also compute as len(S) - abs(cnt0 - cnt1).
Implementation in Python: read input string S, count zeros and ones, compute ans = 2 * min(S.count('0'), S.count('1')), print ans.
Edge cases: N=0? Not possible because N>=1.
Let's test with examples:
Input: "0011" -> zeros=2, ones=2, min=2, ans=4 -> matches.
Second: "11011010001011": zeros=6, ones=8, ans=12 -> matches.
Third: "0": zeros=1, ones=0, ans=0 -> matches.
Seems fine.
But could there be any scenario where we cannot remove min pairs because we might need to remove specific pairs that become non-adjacent due to ordering? The greedy removal of any adjacent opposite pair works until one color exhausted. But could it ever reduce to a state where both colors remain but no adjacent opposite? As argued, no.
Thus answer is correct.
But I recall a known problem: "AtCoder ABC 184 C"? No. Actually, there is an AtCoder problem named "C - 1D Matching" but not. There is also a problem "C - String Coloring" etc. But anyway.
Given that the problem is from some contest (maybe AtCoder Regular Contest 121 A? Actually ARC 121 A "2nd Greatest Distance"? Not). But anyway.
Thus we can implement.
But wait, the problem statement says "At most how many cubes can be removed?" So we are to output the maximum number that can be removed. That is exactly what we've computed.
Thus final answer.
But before finalizing, let's think if there is any scenario where we could remove more than min pairs by removing cubes that are not of opposite colors? No, the operation only removes a red and a blue together, so each removal removes exactly one of each. So total removals must be even and limited by 2*min.
Thus the answer is correct.
Now, implement in Python:
def solve():
S = input().strip()
cnt0 = S.count('0')
cnt1 = S.count('1')
ans = 2 * min(cnt0, cnt1)
print(ans)
That's it.
But wait: Some might argue that the process is like matching parentheses, but it's essentially the same.
Double-check with more complicated cases: Example: "01010101010101010101" length 20, 10 zeros, 10 ones -> ans=20. Can we remove all? Greedy stack works, so yes.
Example: "000111000111" zeros=6, ones=6 -> ans=12. Probably yes.
Thus solution stands.
Now, I'll produce a final answer.
But hold on: There might be a nuance: The cubes are stacked vertically; you can choose a red and a blue that are adjacent, but after removal, the cubes above fall down. That's exactly the same as removing two consecutive characters from a string and concatenating the parts. So it's just string reduction by deleting adjacent opposite characters.
Thus the solution is correct.
Time complexity O(N) for counting.
Now, output.
Thus final.
But perhaps the intended solution was to use a stack to simulate removal and count removed? But we derived a simpler formula.
We'll produce final answer accordingly.
However, I should double-check the sample input "11011010001011" gives 12. Our formula gives 12. All good.
Hence answer.
But wait, there is an alternative viewpoint: Because each removal reduces total by 2, and we can't remove if only one color remains, maximum removed is N if N even and zero diff? Actually if diff is 0, we can remove all. So answer is N - abs(cnt0-cnt1).
Thus solution.
Now I'll write the final response.
```python
def solve() -> None:
S = input().strip()
cnt0 = S.count('0')
cnt1 = S.count('1')
ans = 2 * min(cnt0, cnt1)
print(ans)
if name == "main":
solve()