Problem:


Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0



Sample input:
0011


Sample output:
4

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]
offset = 0
count = 0
while len(ls) >= 2:
    if ls[offset] != ls[offset +1]:
        del ls[offset:offset +2]
        count += 2
        offset = 0
    elif offset + 1 == len(ls):
        break
    else:
        offset += 1

print(count)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]
offset = 0
count = 0
while True:
    if ls[offset] == ls[offset +1]:
        del ls[offset:offset +2]
        count += 2
        offset = 0
    elif offset + 1 == len(ls):
        break
    else:
        offset += 1

print(count)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]
offset = 0
count = 0
while True:
    if ls[offset] == ls[offset +1]:
        del ls[offset:offset +2]
        count += 2
    elif offset +1 ==len(ls):
        break
    else:
        offset += 1

print(count)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]
offset = 0
count = 0
while True:
    if ls[offset] == ls[offset +1]:
        del ls[offset:offset +2]
        count += 2
    elif offset +1 ==len(ls):
        break

    else:
        offset += 1

print(count)

Submission status: Runtime Error

Solution code:
S=list(map(int,input()))
a=0
b=0
for i in range(lin(S)):
  if S[i]==1:
    a+=1
  else:
    b+=1
print(2*min(a,b))

Submission status: Runtime Error

Solution code:
count = 0

oi10 = "0"*10 + "1"*10
io10 = "1"*10 + "0"*10

while oi10 in s or io10 in s:
    while oi10 in s:
        s = s.replace(oi10, "", 1)
        count += 10
    while io10 in s:
        s = s.replace(io10, "", 1)
        count += 10

while "01" in s or "10" in s:
    while "01" in s:
        num = s.count("01")
        s = s.replace("01", "")
        count += num
    while "10" in s:
        num = s.count("10")
        s = s.replace("10", "")
        count += num

print(count * 2)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
zero = S.count('0')
one = S.count('1')
print(min(zero,one)*2)

Submission status: Runtime Error

Solution code:
S=input()
A=S.replace(01"")
B=A.replace(10"")
print(len(S)-len(B))

Submission status: Runtime Error

Solution code:
s = input()
a = 0
for i in s:
  a += i
print(2 * min(a, len(s)-a))

Submission status: Runtime Error

Solution code:
string = str(input())
zero = 0
one = 0
for char in string:
    if char == list(chars)[0]:
        zero += 1
    else:
        one += 1

if zero == 0 or one == 0:
    print(0)
else:
    print(min(zero, one) * 2)

Submission status: Runtime Error

Solution code:
string = str(input())

def take_zero_one(target, cnt=0):
    if len(target) <= 1:
        return (target, cnt)
    elif len(set(target)) == 1:
        return (target, cnt)

    prev = target[0]
    idx = 1
    while idx < len(target):
        if prev != target[idx]:
            cnt += 2
            remaining = target[:idx-1] + target[idx+1:]
            break

        prev = target[idx]
        idx += 1

    remaining, cnt = take_zero_one(remaining, cnt)

    return (remaining, cnt)

_, cnt = take_zero_one(string)
print(cnt)

Submission status: Runtime Error

Solution code:
string = input()

def take_zero_one(target, cnt=0):
    if len(target) <= 1:
        return (target, cnt)
    elif len(set(target)) == 1:
        return (target, cnt)

    prev = target[0]
    idx = 1
    while idx < len(target):
        if prev != target[idx]:
            cnt += 2
            remaining = target[:idx-1] + target[idx+1:]
            break

        prev = target[idx]
        idx += 1

    remaining, cnt = take_zero_one(remaining, cnt)

    return (remaining, cnt)

_, cnt = take_zero_one(string)
print(cnt)

Submission status: Runtime Error

Solution code:
s = input()
"""
lis = [int(x) for x in s]
counter = 0
che = 1

while che:
    che = 0
    for i in range(len(lis)-1):
        if lis[i] != lis[i+1]:
            lis.pop(i)
            lis.pop(i)
            che = 1
            counter += 2
            break

print(counter)
"""

print(min(s.count(0),s.count(1))

Submission status: Runtime Error

Solution code:
from math import factorial

class UnionFind:
  def __init__(self, n):
    self.par = [-1 for _ in range(n)]
  def root(self, x):
    return x if self.par[x] < 0 else self.root(self.par[x])
  def unite(self, x, y):
    x, y = self.root(x), self.root(y)
    if x != y:
      if self.par[y] < self.par[x]:
        x, y = y, x
      self.par[x] += self.par[y]
      self.par[y] = x
    return x != y
  def find(self, x, y):
    return self.root(x) == self.root(y)
  def size(self, x):
    return -self.par[self.root(x)]

n, m = map(int, input().split())
tree = UnionFind(n)
b = []
for _ in range(m):
  a, c = map(int, input().split())
  b.append([a - 1, c - 1])
b.reverse()
ans = [sum(range(n))]
for i, p in enumerate(b):
  if not tree.find(p[0], p[1]):
    ans.append(ans[-1] - tree.size(p[0])*tree.size(p[1]))
    tree.unite(p[0], p[1])
  elif i != m - 1:
    ans.append(ans[-1])
for i in reversed(ans):
  print(i)

Submission status: Runtime Error

Solution code:
s = input()
print(min(s.count(1), s.count(0))*2)

Submission status: Runtime Error

Solution code:
s = input()
s=list(s)
zeroc=0
onec=0
for i in s:
  if i == "0":
    zeroc++
  if i == "1":
    onec++
print(min(zeroc,onec)*2)

Submission status: Runtime Error

Solution code:
s = input()
s=list(s)
zeroc=0
onec=0
for i in s:
  if i == 0:
    zeroc++
  if i == 1:
    onec++
print(min(zeroc,onec)*2)

Submission status: Runtime Error

Solution code:
s = input()
s=list()
zeroc=0
onec=0
for i in s:
  if i == 0:
    zeroc++
  if i == 1:
    onec++
print(min(zeroc,onec)*2)

Submission status: Runtime Error

Solution code:
from collections import deque
S = input()
S = list(S)
counter = 0
que = deque([])
stack = deque([])
for i in range(len(S)):
    que.append(S[i])
for i in range(1000000):
  if stack:
    1
  else:
    stack.append(que.popleft())
  if que:
    s1 = que.popleft()
  else:
    break
  s2 = stack.pop()
  if(s1 != s2):
    counter+=2
  else:
    stack.append(s1)
    stack.append(s2)
print(counter)

Submission status: Runtime Error

Solution code:
s=input()
stk=0
h=0
for c in s:
  if x==1:
    if stk<0:
      h+=1
    stk+=1
  else:
    if stk >0:
      h+=1
    stk -=1
print(2*h)

Submission status: Runtime Error

Solution code:
string = input()
ones = 0
zeros = 0
for s in string:
  if s == '1':
    ones += 1
  else:
    zeroes += 1
print(2*min(ones, zeros))

Submission status: Runtime Error

Solution code:
from collections import deque
S =input()
counter = 0
S = list(S)
q = deque([])
for i in range(len(S)):
    q.append(S[i])
for i in range(len(S)):
    if q:
        s1 = q.popleft()
        s2 = q.popleft()
        if(s1 != s2):
            counter+=2
        else:
            q.append(s1)
            q.appendleft(s2)
    else:
        break
print(counter)

Submission status: Runtime Error

Solution code:
s = input().rstrip("\n")
from collections import Counter
count = Counter(s)
print(min(counter.values()) * 2)

Submission status: Runtime Error

Solution code:
s = input()
r = s.count(”0”)
print(min(r, len(s) - r) * 2)

Submission status: Runtime Error

Solution code:
s = input()

ans = 0
stack = [s[0]]

for c in s[1:-1]:
  if c == stack[-1]:
    ans += 2
    stack.pop(-1)
  else:
    stack.append(c)
    
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
count = 0
flag = True
while flag == True:
    flag = False
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            s = s[0:i]+s[i+2:]
            count += 2
            flag = True

print(count)

Submission status: Runtime Error

Solution code:
#A
"""
a, b, c = map(int, input().split())
print(min(b//a, c))
"""
#B
"""
a, b, k = map(int, input().split())
for i in range(max(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
             print(i)
"""

#C
s = input()
an0 = 0
an1 = 0
for i in s:
    if s == ""1":
        an1 += 1
    if s == "0":
        an0 += 1
print(min(an0, an1))

Submission status: Runtime Error

Solution code:
S=input()
stack=[]
ans=0
for s in S:
    if not stack:
        stack.append(s)
    elif stack[-1]!=s
        stack.pop()
        ans+=2
    else:
        stack.append(s)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
s = list(sys.stdin.readline())
l = len(s)
cnt = 0
ans = 0
while cnt < l-1:
    if int(s[cnt]) + int(s[cnt + 1]) == 1:
        del s[cnt:cnt + 2]
        cnt = 0
        ans += 2
        l = len(s)
    else:
        cnt += 1
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
stack = []
cnt = 0

for s in S:
    if s == S[0]:
        stack.append(s)
    elif s != stack[-1]:
        stack.pop()
        cnt += 2
    else:
        stack.append(s)
        
print(cnt)

Submission status: Runtime Error

Solution code:
S = []
ans = 0
for c in input():
    if c != S[-1] & len(S) > 0:
        S.pop()
        ans += 2
    else:
        S.append(c)
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
stack = []
cnt = 0

for s in S:
    if s == S[0]:
        stack.append(s)
    elif s == '0' and s != stack[-1]:
        stack.pop()
        cnt += 2
    elif s == '1' and s != stack[-1]:
        stack.pop()
        cnt += 2
    else:
        stack.append(s)
        
print(cnt)

Submission status: Runtime Error

Solution code:
s=input()

x='10'
y='01'

def hoge(s):
    if x in s or y in s:
        for i in range(len(s)-1):
            if s[i]+s[i+1]==x or s[i]+s[i+1]==y:
                s=s[:i]+s[i+2:]
                
                return hoge(s)+2
    else:
        return 0

print(hoge(s))

Submission status: Runtime Error

Solution code:
S = input()
stack = []
cnt = 0

for s in S:
    if s == S[0]:
        stack.append(s)
    elif s == '0' and s != stack[-1]:
        stack.pop()
        cnt += 2
    elif s == '1' and s != stack[-1]:
        stack.pop()
        cnt += 2
    else:
        stack.sppend(s)
        
print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    s = tokens[0]

    return (s,)

def solve(s):
    

    index_list = [(i, False) for i in range(len(s))]

    remained_index_list = [i for (i, removed) in index_list if not removed]

    while True:

        remained_index_list_len_before = len(remained_index_list)

        i = 0
        while i < len(remained_index_list) - 1:
            print("i=%d" % i)
            print("remained_index_list=%s" % remained_index_list)

            if s[remained_index_list[i]] == '0' and s[remained_index_list[i+1]] == '1':
                index_list[remained_index_list[i]] = (remained_index_list[i], True)
                index_list[remained_index_list[i+1]] = (remained_index_list[i+1], True)
                i = i + 2
            elif s[remained_index_list[i]] == '1' and s[remained_index_list[i+1]] == '0':
                index_list[remained_index_list[i]] = (remained_index_list[i], True)
                index_list[remained_index_list[i+1]] = (remained_index_list[i+1], True)
                i = i + 2
            else:
                i = i + 1

        remained_index_list = [i for (i, removed) in index_list if not removed]
        remained_index_list_len_after = len(remained_index_list)

        if remained_index_list_len_before == remained_index_list_len_after:
            break

    return len(s) - len(remained_index_list)

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
s=input()
print(2*min(s.count(0),s.count(1)))

Submission status: Runtime Error

Solution code:
S=input()
count=0
N=len(S)
for j in range(N//2):
  if (sum(map(int,S))==0)or(sum(map(int,S))==len(S)):
    break
  i=0
  while True:
    exam=str(S[i])+str(S[i+1])
    if exam[0]!=exam[1]:
      count+=1
      S.remove(exam)
      i-=1
    i+=1
    if i>=len(S)-1:
      break
print(2*count)

Submission status: Runtime Error

Solution code:
S = str(input())
l = len(S)
mem = l
i = 0
while (i < l-1):
    j = 0
    if (S[i] != S[i + 1]):
        if (i == 0):
            S = S[i + 2:]
        else:
            S = S[:i] + S[i + 2]
        i = 0
    else:
        i += 1
    l = len(S)

print(mem-len(S))

Submission status: Runtime Error

Solution code:
from collections import Counter
print(Counter(input()).most_common()[1][1]*2)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(string S) {
    long long A = count(S.begin(), S.end(), '1');
    long long B = count(S.begin(), S.end(), '0');
    cout << S.size() - abs(A-B) << endl;

}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}

Submission status: Runtime Error

Solution code:
s=str(input())
a=s.count('0')
print(min(ss,len(s)-ss)*2)

Submission status: Runtime Error

Solution code:
print(min(sorted(input()).split().map(len)))

Submission status: Runtime Error

Solution code:
S=input();print(2*min(S.count("0")-S.count("1")))

Submission status: Runtime Error

Solution code:
istr=input()
for ch in istr:
  if ch == '0':
    c0+=1
  else:
    c1+=1
print(min(c0,c1)*2)

Submission status: Runtime Error

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(100000):
    a = a.replace('01', '')
    a = a.replace('10', '')
    print(a)
print(a)
print(init - len(a))

Submission status: Runtime Error

Solution code:

def C():
    S = input()
    lS = []
    lS_val = []
    for a in S:
       lS.append(int(a)) 
    
    vx_1 = lS[0]
    if len(lS) <= 1:
        print('0')

    else:
        for i, value in enumerate(lS):
            if i==0:
                vx_1 = value
                continue

            if vx_1 != value:
                a = copy.deepcopy(lS)
                a.pop(i)
                a.pop(i-1)
                if len(a) != 0:
                    lS_val.append(roop(a, 2) + 2)

                else:
                    lS_val.append(2)

            vx_1 = value 
        
        print(max(lS_val))

    

def roop(lS, score): 
    vx_1 = lS[0]

    for i, value in enumerate(lS[1:]):
        if vx_1 != value:
            a = copy.deepcopy(lS)
            a.pop(i)
            a.pop(i-1)
            if len(a) != 0:
                score = roop(a, 2) + 2
            else:
                score = score + 2
        vx_1 = value 
    return score


def D():
    pass

if __name__ =='__main__':
    C()

Submission status: Runtime Error

Solution code:
s=input()
lis=[]
n=1
output=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        lis.append(n)
        n=1
    else:
        n+=1

    if i==len(s)-2:
        lis.append(n)
#print(lis)
if len(lis)==1:
    output=0
else:
    loop=True
    while loop:
        a=lis[0]
        b=lis[1]
        if a==b:
            output+=a+b
            del lis[0]
            del lis[0]
        elif a<b and len(lis)>2:
            output+=a*2
            lis[1]-=a
            del lis[0]
        elif a>b and len(lis)>2:
            output+=b*2
            lis[2]+=a-b
            del lis[0]
            del lis[0]
        elif len(lis)<=2:
            output+=min(a,b)*2
            del lis[0]

        if len(lis)==0 or len(lis)==1:
            loop=False

print(output)

Submission status: Runtime Error

Solution code:
P=input();print min(P.count('0'),P.count('1'))*2

Submission status: Runtime Error

Solution code:
s=str(input())
if s.count('1')>s.count('0'):
  print(s.count('1')-s.count('0')
else:
  print(s.count('0')-s.count('1')

Submission status: Runtime Error

Solution code:
S = input()

def recur_del(s):
  s2 = s.replace('01','A')
  s3 = s2.replace('10','A')
  lst = s3.split('A')
  s4 = ''.join(lst) 
  if len(s) == len(s4):
    return s4
  return recur_del(s4)

res = recur_del(S)

print(len(S) - len(res))

Submission status: Runtime Error

Solution code:
S = input()
num_len = len(S)
count=0
# for i in range(1,num_len):
#     if S[t]==S[i]:
#         t = t+1
#     elif S[t]!=S[i]:
#         count = count+1
#         t = t-1

#print(num_len)
i=1
t=0
test=2
while test ==2:
    #print(i,t,count)
    if S[t]==S[i]:
        t+=1
        i+=1
    elif S[t]!=S[i]:
        count+=1
        i+=1
        t-=1
        if S[t]==S[i]:
            t=i
            i+=1
        elif S[i]!=S[t]:
            count+=1
            t-=1
    if i==num_len and t==-1:
        if S[t-1]==S[i]:
            break
        else:
            count+=1
            break
        
    elif i==num_len:
        if S[t-1]==S[i-1]:
            break
        else:
            count+=1
            i=i-1
print(count)

Submission status: Runtime Error

Solution code:
n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)

Submission status: Runtime Error

Solution code:
S = input()
num_len = len(S)
count=0
# for i in range(1,num_len):
#     if S[t]==S[i]:
#         t = t+1
#     elif S[t]!=S[i]:
#         count = count+1
#         t = t-1

print(num_len)
i=1
t=0
test=2
while test ==2:
    #print(i,t,count)
    if S[t]==S[i]:
        t+=1
        i+=1
    elif S[t]!=S[i]:
        count+=1
        i+=1
        t-=1
        if S[t]==S[i]:
            t=i
            i+=1
        elif S[i]!=S[t]:
            count+=1
            t-=1
    if i==num_len and t==-1:
        if S[t-1]==S[i]:
            break
        else:
            count+=1
            break
        
    elif i==num_len:
        if S[t-1]==S[i-1]:
            break
        else:
            count+=1
            i=i-1
print(count)

Submission status: Runtime Error

Solution code:
S = input()

def recur_del(s):
  s = s.replace('01','A')
  s = s.replace('10','A')
  lst = s.split('A')
  s2 = ''.join(lst) 
  if len(s) == len(s2):
    return s2 
  return recur_del(s2)

res = recur_del(S)

print(len(S) - len(res))

Submission status: Runtime Error

Solution code:
s = str(input())
if s.count("0") > 0 and s.count("1")) > 0:
    print(2*min(s.count("0"),s.count("1")))
else:
    print(0)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s = input()
s = list(s)
x = 0
maxIndex = len(s) - 1
count = 0
while True:
    if len(s) == x + 1:
        break
    if s[x] != s[x + 1]:
        s.pop(x)
        s.pop(x)
        count += 1
        x -= 1
    else:
        x += 1
print("{}".format(count * 2))

Submission status: Runtime Error

Solution code:
S = input()
print(min(S.count('1'), S.count('0'))

Submission status: Runtime Error

Solution code:
inData = str(input())
ansList = []
dataLen = len(inData)
rpLen = len(inData)
for i in range(0, dataLen):
    for j in range(1, rpLen + 1):
        if inData[-j] != inData[-j - 1]:
            ansList.append(inData[-j])
            ansList.append(inData[-j - 1])
            tmp1 = str(inData[0:-j - 1])
            tmp2 = ''
            if -j + 1 != 0:
                tmp2 = str(inData[-j + 1:])
            reData = tmp1 + tmp2
            if reData == '[]':
                inData = '[]'
            else:
                inData = reData
            break
        else:
            if rpLen == j + 1:
                break
    if inData == '[]':
        break
    rpLen = len(inData)
    if rpLen < 2:
        break

print(len(ansList))

Submission status: Runtime Error

Solution code:
S=input()
result = 0
x = 0
a = '01'
b = '10'

def str_del(str,index):
    str = str[:index]+str[index+2:]
    return str

while 1:
    str1 = S[x]
    str2 = S[x+1]
    chk_str = str1 + str2
    if chk_str == a or chk_str == b:
        result += 1
        S = str_del(S, x)
        x = -1
    if (a not in S) and (b not in S):
        break
    x += 1

print(result)

Submission status: Runtime Error

Solution code:
s=input()
lis=[]
n=1
output=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        lis.append(n)
        n=1
    else:
        n+=1

    if i==len(s)-2:
        lis.append(n)
#print(lis)

loop=True
while loop:
    a=lis[0]
    b=lis[1]
    if a==b:
        output+=a*2
        del lis[0]
        del lis[0]
    elif a<b:
        output+=a*2
        lis[1]-=a
        del lis[0]
    elif a>b:
        if len(lis)<2:
            output+=b*2
            loop=False
        else:
            lis[2]+=abs(b-a)
            output+=b*2
            del lis[0]
            del lis[0]
    if len(lis)==0 or len(lis)==1:
        loop=False
print(output)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**5//2)
S = list(input())
n = len(S)
def Remove(binList,lenList):
    for i in range(0,lenList-1):
        if (binList[i] == "0" and binList[i+1] == "1") or (binList[i] == "1" and binList[i+1] == "0"):
            del binList[i:i+2]
            return Remove(binList,lenList - 2)
    return binList
if n > 10**5:
    sys.exit()
S = Remove(S,n)
print(n-len(S))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
 using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//____________________


int32_t main()
{ 
  io;
 
  
  string s;
  cin>>s;
  stack<char> st;
  int cnt=0;

  st.push(s[0]);
  for(int i=1;i<s.size();i++)
  {
    if(st.empty())
    {
      st.push(s[i]); 
      continue;
    }
    if(s[i]!=st.top())
    {
      st.pop();
      cnt+=2;
    }
    else
    {
      st.push(s[i]);
    }
  }
  
  cout<<cnt;
 return 0;
}

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
 using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//____________________


int32_t main()
{ 
  io;
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif 
  
  string s;
  cin>>s;
  stack<char> st;
  int cnt=0;

  st.push(s[0]);
  for(int i=1;i<s.size();i++)
  {
    if(st.empty())
    {
      st.push(s[i]); 
      continue;
    }
    if(s[i]!=st.top())
    {
      st.pop();
      cnt+=2;
    }
    else
    {
      st.push(s[i]);
    }
  }
  
  cout<<cnt;
 return 0;
}

Submission status: Runtime Error

Solution code:
S = str(input())
S = list(S)
print(S)

count = 0
"""
i = 0
while len(list(set(S))) != 1:
    if S[i] == S[i+1]:
        del S[i]
        del S[i+1]
        count += 2
        """
        if len(S) == 0:
            print(count)
            exit()
        """
    i += 1
    if i == len(S)-1:
        print(count)
        exit()
print(count)
"""

while len(list(set(S))) != 1:
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            del S[i]
            del S[i+1]
            count += 2
            if len(S) == 0:
                print(count)
                exit()
        break

print(count)

Submission status: Runtime Error

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(1000):
    a = a.sub('11', '')
    a = a.sub('00', '')
print(init - len(a))

Submission status: Runtime Error

Solution code:
s = list(input())
count = 0
l = []
while (True):
    old = count
    if (len(s) == 1 or len(s) == 0):
        break
    for n in range(len(s) - 1):
        if (s[n] != s[n+1]):
            s.pop(n)
            s.pop(n)
            count += 2
            n -= 1
        if (len(s) <= n + 2):
            break
    if (old == count):
        break
print(count)

Submission status: Runtime Error

Solution code:
s=input()
lis=[]
n=1
output=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        lis.append(n)
        n=1
    else:
        n+=1

    if i==len(s)-2:
        lis.append(n)
print(lis)

loop=True
while loop:
    a=lis[0]
    b=lis[1]
    if a==b:
        output+=a*2
        del lis[0]
        del lis[0]
    elif a<b:
        output+=a*2
        lis[1]-=a
        del lis[0]
    elif a>b:
        if len(lis)<2:
            output+=b*2
            loop=False
        else:
            lis[2]+=abs(b-a)
            output+=b*2
            del lis[0]
            del lis[0]
    if len(lis)==0 or len(lis)==1:
        loop=False
print(output)

Submission status: Runtime Error

Solution code:
S = input()

def operate_one(S):
  S = list(S)
  c = 0
  for i in range(len(S) - 1):
    if S[i] != S[i+1] and S[i] != "_":
      c += 2
      S[i] = "_"
      S[i+1] = "_"
  return "".join(list(filter(lambda x:x!="_",S)))

res = 0
while True:
  S_prev = S
  S,c = operate_one(S)
  res += c
  if S_prev == S:
    break
    
print(res)

Submission status: Runtime Error

Solution code:
S = list(map(int, input()))

count = 0
for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    del S[i],S[i+1]
    count =2+count 
  else:
    if len(S)==i+1:
      print(count)
    else:
  		continue
    
print(count)

Submission status: Runtime Error

Solution code:
a = input()
sum = 0
i = 0
while True:
  if a[i] == "0" and a[i+1] == "1" and i < len(a)-2 and len(a) > 2:
    sum += 2
    a = a[:i] + a[i+2:]
    i = 0
  elif a[i] == "1" and a[i+1] == "0" and i < len(a)-2 and len(a) > 2:
    sum += 2
    a = a[:i] + a[i+2]
    i = 0
  elif a[i] == "0" and a[i+1] == "1" and i == len(a)-2 and len(a) > 2:
    sum += 2
    a = a[:i]
    i = 0
  elif a[i] == "1" and a[i+1] == "0" and i == len(a)-2 and len(a) > 2:
    sum += 2
    a = a[:i]
    i = 0
  elif len(a) == 2 and a[i] == "0" and a[i+1] == "1":
    sum += 2
    break
  elif len(a) == 2 and a[i] == "1" and a[i+1] == "0":
    sum += 2
    break
  else:
    i += 1
    pass
  
print(sum)

Submission status: Runtime Error

Solution code:
S = list(input())
S_len = len(S)


def dfs(S):
    slen = len(S)
    for i in range(slen -1 ):
        if S[i] != S[i+1]:
            del S[i+1:i+2]
            dfs(S)
            break;
    End_len = len(S)
    ans = S_len - End_len
    return ans

if __name__ == '__main__':
    print(dfs(S))

Submission status: Runtime Error

Solution code:

in_num = str(input())
digit_num = len(in_num)
box = []
ans = 0
k = 0
r = 0
for i in range(digit_num):
    box.append(in_num[i])
def func(box, ans, r):
    for j in range(len(box)-1):
        if (int(box[j]) == 0 and int(box[j+1]) == 1)or(int(box[j]) == 1 and int(box[j+1]) == 0):
            if len(box) == 2:
                ans += 2
                r = 1
                break
            box.pop(j)
            box.pop(j+1)
            ans += 2
            break
        else:
            continue
    return box, ans, r

i = 0

for i in range(digit_num):
    if len(box) == 0:
        break

    box, ans, r = func(box, ans, r)
    if r == 1:
        break
    
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

def recur_del(s):
  s = s.replace('01','A')
#  s = s.replace('10','A')
  lst = s.split('A')
  s2 = ''.join(lst) 
  if len(s) == len(s2):
    return s 

  return recur_del(s2)

res = recur_del(S)

print(len(S) - len(res))

Submission status: Runtime Error

Solution code:
import copy
s = list(input())
def check01_2(s, pos):
    p = 0
    if abs(len(s) - pos)  > 2:
        for i in range(pos, len(s), 1):
            if s[i] != s[i+1]:
                del s[i:i+2]
                if i !=0:
                    p = i-1
                return check01_2(s, p)
    return s

s2 = copy.deepcopy(s)
s2 = check01_2(s2, 0)
print(len(s) - len(s2))

Submission status: Runtime Error

Solution code:
s = str(input())
n = len(s)
ans = 0
b = [0 for i in range(n)]
for i in range(n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            nowl = i
            nowr = i+1
            while flag:
                if nowl < 0 and nowr > n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                elif b[nowl] == 1 and b[nowr] == 0:
                    nowl -= 1
                elif b[nowl] == 0 and b[nowr] == 1:
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False
print(ans)