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:
from itertools import chain

s = input().rstrip()

def f(s):
    l = s.split('01')
    for i in range(len(l)):
        l[i] = l[i].split('10')
    l = list(chain.from_iterable(l))
    if len(l) == 1:
        return 0
    else:
        r = (len(l) - 1) * 2
        return r + f(''.join(l))

print(f(s))

Submission status: Runtime Error

Solution code:
input = input()

listInt = [int(i) for i in input]

index = 0
result = 0

while len(listInt) != index + 1:
	if listInt[index] != listInt[index+1]:
		listInt.pop(index)
		listInt.pop(index)
		index = index - 1 
		result = result + 2
		if(len(listInt) == 0):
			break
		continue		
	index = index + 1
print(result)

Submission status: Runtime Error

Solution code:
input = input()

listInt = [int(i) for i in input]

index = 0
result = 0

while len(listInt) != index + 1:
	if listInt[index] != listInt[index+1]:
		listInt.pop(index)
		listInt.pop(index)
		index = index - 1
		result = result + 2
		continue		
	index = index + 1
print(result)

Submission status: Runtime Error

Solution code:
S = input()

count = 0
for i in range(N):
    if S[i] == 0:
        count += 1

ans = min(count, N - count)
print(ans)

Submission status: Runtime Error

Solution code:
def D(i, S):
  if i < len(S):
    if S[-1*i] != S[-1*(i+1)]:
      del S[-1*(i+1)]
      del S[-1*i]
      if len(S) == 0:
        return S
      else:
      	return D(max(i-1,1),S)
    return D(i+1,S)
  else:
    return S
  
S = list(input())
SS = S.copy()
S_after = D(1, SS)
print(len(S) - len(S_after))

Submission status: Runtime Error

Solution code:
def D(i, S):
  if i < len(S):
    if S[-1*i] != S[-1*(i+1)]:
      del S[-1*(i+1)]
      del S[-1*i]
      if len(S) == 0:
        return S
      else:
      	return D(min(i-1,1),S)
    return D(i+1,S)
  else:
    return S
  
S = list(input())
SS = S.copy()
S_after = D(1, SS)
print(len(S) - len(S_after))

Submission status: Runtime Error

Solution code:
# S = '0011'
# S = '11011010001011'
# S = '0'
S = input()

cnt = 0


def www(s):
    global cnt

    if len(s) <= 1:
        return

    index = 0
    tmp = []
    c = 0

    while True:
        if len(s) < index + 1:
            break
        if s[index] == '0' and s[index + 1] == '1':
            index += 1
            c += 2
        else:
            tmp.append(S[index])
        index += 1
    cnt += c

    if 0 < c:
        www(tmp)


www(S)
print(cnt)

Submission status: Runtime Error

Solution code:
S = input()
ans = 0
while i < len(S):
    if any(['01' in S[i:i+2],'10' in S[i:i+2]]):
        S = S[:i]+S[i+2:]
        ans += 2
        i -= 1
    else:
        i += 1
print(ans)

Submission status: Runtime Error

Solution code:
S = str(input())
i, ans = (0, 0)
while i>=0 and i<len(S)-1:
    print(S)
    if S[i]!=S[i+1]:
        S = S[:i]+S[i+2:] if i+2<len(S) else S[:i]
        ans += 2
        i = max(0, i-1)
    else:
        i+=1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

s = list(input())
l = {}

for v in s:
    if l.get(v):
        l[v] += 1
    else:
        l[v] = 1
        
print(min(l["0"], l["1"]) * 2)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

s = list(input().replace("¥n", ""))
l = {
    "0": 0,
    "1": 0
}

for v in s:
    l[v] += 1
        
print(min(l["0"], l["1"]) * 2)

Submission status: Runtime Error

Solution code:
C = [int(i) for i in input()]

pre = len(C)

def recursive(list):
    if len(list) == 0:
        return []
    for i,l in enumerate(list):
        if i == len(list) -1:
            break
        if (list[i] ==0 and list[i + 1] == 1) or (list[i] ==1 and list[i +1 ] ==0 ):
            #print(list)
            list.pop(i)
            list.pop(i)
            recursive(list)

recursive(C)
print(pre -len(C))

Submission status: Runtime Error

Solution code:
C = [int(i) for i in input()]

def recursive(list):
    if len(list) == 0:
        return []
    for i,l in enumerate(list):
        if i == len(list) -1:
            break
        if list[i] ==0 and list[i + 1] == 1:
            list.pop(i)
            list.pop(i)
            recursive(list)

recursive(C)
print(len(C))

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]

ans = min(ls.count(0),ls.count(1))
pirnt(ans*2)

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

cnt=0
S=list(input())
# eprint(S)

L=list()
L.append(S.pop())
while len(S)!=0:
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append( S.pop() )
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[] and S!=[]:
            L.append(S.pop())
        cnt=cnt+2
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))

print(cnt)

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

cnt=0
S=list(input())
# eprint(S)

L=list()
L.append(S.pop())
while len(S)!=0:
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append(S.pop())
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[]:
            L.append(S.pop())
        cnt=cnt+2
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))

print(cnt)

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

cnt=0
S=list(input())
# eprint(S)

L=list()
L.append(S.pop())
while len(S):
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append(S.pop())
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[]:
            L.append(S.pop())
        cnt=cnt+2
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))

print(cnt)

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import numpy as np
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

cnt=0
S=list(input())
eprint(S)

L=list()
L.append(S.pop())
while len(S):
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append(S.pop())
        eprint("S: " + str(S))
        eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[]:
            L.append(S.pop())
        cnt=cnt+2
        eprint("S: " + str(S))
        eprint("L: " + str(L))

print(cnt)

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = list(input())
k = len(s)
i = 0
while i <= len(s) - 2:
    if int(s[i]) + int(s[i+1]) == 1:
        s.pop(i)
        s.pop(i)
        i -=1
    else:
        i +=1
print(k-len(s))

Submission status: Runtime Error

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

s = [int(c) for c in s]

c = 0

def fb(s, i):
    for i in reversed(range(0, i + 1)):
        if s[i] >= 0:
            return i
    return None

def ff(s, i):
    for i in range(i + 1, len(s)):
        if s[i] >= 0:
            return i
    return None

for i in range(len(s) - 1):
    j = 0
    while True:
        pos = fb(s, i - j), ff(s, i - j)
        if pos[0] is None:
            break

        if s[pos[0]] != s[pos[1]]:
            s[pos[0]] = s[pos[1]] = -1
            j += 1
            c += 2
        else:
            break

print(c)

Submission status: Runtime Error

Solution code:
S = input() 

if len(S) == 0:
    print(0)

else:
    # 見つけ次第消していく
    c = 0 # 消したキューブの数
    i = 1
    while i < len(S):
        if int(S[i-1]) + int(S[i]) == 1:
            S = S[:i-1] + S[i+1:]
            i -= 1
            c += 2
        else:
            i += 1

    print(c)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s = input()
S = [int(s[i]) for i in range(len(s))]
# print(S)
count = 0
before = 0
while 1:
    #print("S:", S)
    is_continue = False
    # print(len(S))
    #deleted = False
    for i in range(max([before, 0]), len(S) - 1):
        #print(before, i)
        #print(S[i], S[i + 1])
        # print(S)
        if S[i] != S[i + 1]:
            # print(count)
            del S[i]
            del S[i]
            count += 2
            is_continue = True
            before = i - 2
            #deleted = True
            break
    if not is_continue:
        break
print(count)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s = input()
n = len(s)
a = []
i = 0
ct = 0
for i in range(n):
    a.append(int(s[i]))
i = -1

while ct < 100000000000:
    n = len(a)
    i += 1
    if i >= n - 1: break
    if a[i] == 0 and a[i + 1] == 1:
        a.pop(i)
        a.pop(i)
        ct += 1
        i -= 2
        if i <= 1: i = -1
        continue
    elif a[i] == 1 and a[i + 1] == 0:
        a.pop(i)
        a.pop(i)
        ct += 1
        i -= 2
        if i <= 1: i = -1

print(ct * 2)

Submission status: Runtime Error

Solution code:
N = len(S)
num_one = S.count('1')
num_zero = S.count('0')
print(N - abs(num_one - num_zero))

Submission status: Runtime Error

Solution code:
s=input()
num0,num1=0,0
for i in s:
  if i=='0':
    nums0+=1
  elif i=='1':
    nums1+=1
print(2*min(num0,num1))

Submission status: Runtime Error

Solution code:
s=input()
a_1=s.count("1")
b_1=s.cpunt("0")
if a_1<=b_1:
  print(2*a_1)
else:
  print(2*b_1)

Submission status: Runtime Error

Solution code:
S = str(input())

def del_cube(s, i):
    s = s[:i] + s[i+2:]
    return s

def dfs(s):
    ans_list = []
    flag = True
    if '10' in s:
        flag = False
        s_10 = s.replace('10', '')
        ans_list.append(dfs(s_10))
    if '01' in s:
        flag = False
        s_01 = s.replace('01', '')
        ans_list.append(dfs(s_01))
    
            
    if flag == True:
        return(len(s))
    else:
        return(min(ans_list))
    
print(len(S) - dfs(S))

Submission status: Runtime Error

Solution code:
s = input()

count = 0
while True:
    n = len(s)
    if n == 0 or sum(s) == 0 or sum(s) == n:
        break
    sn = s + '\n'
    for i in range(n):
        if sn[i-1] + sn[i] == '10' or sn[i-1] + sn[i] == '01':
            s = sn[:i-1] + sn[i+1:n]
            count += 1
            break

print(count * 2)

Submission status: Runtime Error

Solution code:
S = str(input())

def del_cube(s, i):
    s = s[:i] + s[i+2:]
    return s

def dfs(s):
    ans_list = []
    flag = True
    for i in range(len(s) - 1):
        if s[i] == '0' and s[i+1] == '1' or s[i] == '1' and s[i+1] == '0':
            flag = False
            del_s = del_cube(s, i)
            ans_list.append(dfs(del_s))
            
    if flag == True:
        return(len(s))
    else:
        return(min(ans_list))
    
print(len(S) - dfs(S))

Submission status: Runtime Error

Solution code:
N = len(S)
zc,oc = 0,0
for i in range(N):
    if S[i]=='1':
        oc += 1
    else:
        zc += 1
print(2*min(oc,zc))

Submission status: Runtime Error

Solution code:
S = str(input())

zero_num = 0
one_num = 

for i in range(len(S)):
    if S[i] == "0":
        zero_num += 1

print(2*min(zero_num, len(S) - zero_num))

Submission status: Runtime Error

Solution code:
s = str(input())
n = s.size()
cntz = 0
cnto = 0
for i in range(n):
    if s[i] == '0':
        cntz += 1
    elif s[i] == '1':
        cnto += 1
print(min(cnto,cntz))

Submission status: Runtime Error

Solution code:
S = str(input())

red = S.count('0')
blue = S.count('1')
N = red + blue

if red > blue:
    ans = N - (red - blue)
elif blue < red:
    ans = N - (blue - red)
print(ans)

Submission status: Runtime Error

Solution code:
def removable(s):
	lst = []
	for i in range(0, len(s)-1):
		if s[i] != s[i+1]:
			lst.append(i)
	return lst

S = raw_input()
max = 0
queue = [[S, 0]]
while queue != []:
	now = queue.pop(0)
	removelist = removable(now[0])
	if removelist == []:
		if max < now[1]: max = now[1]
	else:
		for i in range(0, len(removelist)):
			queue.append([now[0][:removelist[i]]+now[0][removelist[i]+2:], now[1]+2])
			print queue

print max

Submission status: Runtime Error

Solution code:
S = input()
init_count = len(S)

tmp_i = 0
while len(S) > 1:
    no_01 = True
    before_s = None
    for i, s in enumerate(S[tmp_i:]):
        if i == 0:
            before_s = s
            continue
        if before_s != s:
            no_01 = False
            print(S[:tmp_i + i-1], '(', S[tmp_i + i - 1], ' | ', S[tmp_i + i],  ')', S[tmp_i + i+1:])
            newS = S[:tmp_i + i-1] + S[tmp_i + i+1:]
            S = newS
            print('newS: ', newS)
            tmp_i = tmp_i + i - 2
            if tmp_i < 0:
                tmp_i = 0
            print(tmp_i)
            break
    if no_01:
        break
print(init_count - len(S))

Submission status: Runtime Error

Solution code:
S = input()

if len(S) < 2:
    print('0')

else:
    # 最初に攻めていくパターンを仮ぎめ
    i = 0
    while True:
        if S[i] != S[-1-i]:
            left = S[i]
            right = S[-1-i]
            break
        i += 1
    pattern = right + left

    # マッチングして取り除いていく
    count = 0
    curr_S = S

    while True:
        count_increased = False
        new_S = ''
        j = 0
        while True:
#             print(curr_S, j, curr_S[j:j+2], new_S, pattern, count)
            if curr_S[j:j+2] == pattern:
                count += 2
                j += 2
                count_increased = True
            else:
                new_S += curr_S[j]
                j += 1
            if j == len(curr_S):
                break
        # １個も見つからなかった場合はパターンを反転させて継続
        if not count_increased:
            pattern = pattern[::-1]

        # 全てが0または1になったら終了
        if '0' not in new_S or '1' not in new_S:
            break
        curr_S = new_S

    print(count)

Submission status: Runtime Error

Solution code:
S = input()

if len(S) < 2:
    print('0')

else:
    # 最初に攻めていくパターンを仮ぎめ
    i = 0
    while True:
        if S[i] != S[-1-i]:
            left = S[i]
            right = S[-1-i]
            break
        i += 1
    pattern = right + left

    # マッチングして取り除いていく
    count = 0
    curr_S = S

    while True:
        count_increased = False
        new_S = ''
        j = 0
        while True:
            print(curr_S, j, curr_S[j:j+2], new_S, pattern, count)
            if curr_S[j:j+2] == pattern:
                count += 2
                j += 2
                count_increased = True
            else:
                new_S += curr_S[j]
                j += 1
            if j == len(curr_S):
                break
        # １個も見つからなかった場合はパターンを反転させて継続
        if not count_increased:
            pattern = pattern[::-1]

        # 全てが0または1になったら終了
        if '0' not in new_S or '1' not in new_S:
            break
        curr_S = new_S

    print(count)

Submission status: Runtime Error

Solution code:


s = input()
front = s[0]
back = s[1:]
sum = 0

while(len(back) > 0):
	if(front[-1:] != back[0]):
		front = front[:-1]
		back = back[1:]
		sum += 2
	else:
		front += back[0]
		back = back[1:]
	if(len(front) <= 0 and len(back) >= 2):
		front = back[0]
		back = back[1:]
	print(front+"+"+back)
print(sum)

Submission status: Runtime Error

Solution code:
i = 0
total = 0
while i < len(S):
    if S[i:i+2] == '01'or S[i:i+2] == '10':
        Sa = S[:i]
        Sb = S[i+2:]
        S = Sa+Sb
        total += 1
        i -= 1
    else:
        i += 1
print(total*2)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
S = input()

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    この並びの場合は順番にかかわらず削除しても良い
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    find_101 = s.find('101')
    find_010 = s.find('010')
    find_1100 = s.find('1100')
    find_0011 = s.find('0011')
    if find_101 > 0:
        return pre_remove(remove_target_point(s, find_101), i + 2)
    elif find_010 > 0:
        return pre_remove(remove_target_point(s, find_010), i + 2)
    if find_1100 > 0:
        return pre_remove(remove_target_point(s, find_1100 + 1), i + 2)
    elif find_0011 > 0:
        return pre_remove(remove_target_point(s, find_0011 + 1), i + 2)
    else:
        return (s, i)

def search_removable_point(s):
    return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))

Submission status: Runtime Error

Solution code:
S = input()

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    この並びの場合は順番にかかわらず削除しても良い
    '''
    find_101 = s.find('101')
    find_010 = s.find('010')
    if find_101 > 0:
        return pre_remove(remove_target_point(s, find_101), i + 2)
    elif find_010 > 0:
        return pre_remove(remove_target_point(s, find_010), i + 2)
    else:
        return (s, i)

def search_removable_point(s):
    return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))

Submission status: Runtime Error

Solution code:
def reject(S, char, cnt):
    count = cnt
    if S.count(char) == 0:
        return count
    if S.count(char) > 0:
        index = S.find(char)
        S = S[:index] + S[index+2:]
        count += 2
    return max(reject(S,"01", count), reject(S,"10", count))

def main():
    S = input()
    print(max(reject(S,"01",0), reject(S,"10",0)))

main()

Submission status: Runtime Error

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

counter = 0
i = 0
while(True):
    if not '0' in S or not '1' in S or S == []:
        break
    elif (S[i] == '1' and S[i+1] == '0') or (S[i] == '0' and S[i+1] == '1'):
        S.pop(i)
        S.pop(i)
        counter += 2
        i -= 1
    else:
        i += 1

print(counter)

Submission status: Runtime Error

Solution code:
from sys import stdin

# 標準入力の受取
sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
l = list(sdi)
l.reverse()
start = len(l)
i = 0
while len(l) - 1 >= i + 1:
    print(l)
    if l[i] != l[i + 1]:
        l.pop(i + 1)
        l.pop(i)
        i = max(i - 2, 0)
        continue
    i += 1
print(start - len(l))

Submission status: Runtime Error

Solution code:
from sys import stdin

# 標準入力の受取
sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]

l = list(sdi)
l.reverse()
start = len(l)
r = 0
i = 0
while len(l) >= i + 2:
    print(i, l)
    if l[i] != l[i + 1]:
        l.pop(i + 1)
        l.pop(i)
        print("cut", i, i+1)
        i = max(i-2, 0)
    i += 1

print(start - len(l))

Submission status: Runtime Error

Solution code:
s = list(input())
count = 0
find = False
while True:
    if len(s) <=2:
        break
    for i in range(0,len(s)-1):
        if s[i] != s[i+1]:
            count += 2
            del s[i]
            del s[i+1]
            break
    else:
        break
    
print(count)

Submission status: Runtime Error

Solution code:
#coding: utf-8
s = list(map(int, input()))
if len(s) <= 1:
    print(0)
else:
    zero = [i for i, x in enumerate(s) if x == 0]
    one = [i for i, x in enumerate(s) if x == 1]
    zeros = s[:zero[-1]].count(0)
    ones = s[:one[-1]].count(1)
    print(zeros * 2 if zeros < ones else ones * 2)

Submission status: Runtime Error

Solution code:
S = list(input())
cnt = 0
i = 0
while True:
    if S[i] != S[i + 1]:
        del S[i:i+2]
        cnt += 1
        i = 0
        continue
    elif i + 2 == len(S):
        print(cnt * 2)
        exit()
    i += 1

Submission status: Runtime Error

Solution code:
S = list(input())
i = 0
cnt = 0

while True:
    if len(S) < 2:
        break
    if S[i] != S[i+1]:
        cnt += 2
        S.pop(i)
        S.pop(i)
        if i > 0:
            i -= 1
    else:
        i += 1
print(cnt)

Submission status: Runtime Error

Solution code:
S = list(input())
i = 0
cnt = 0

while True:
    if i == len(S) - 2:
        break
    if S[i] != S[i+1]:
        cnt += 2
        S.pop(i)
        S.pop(i)
        if i > 0:
            i -= 1
    else:
        i += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
S = input()
u, counts = np.unique(list(S),return_counts=True)
result = 0 if len(u) == 1 else len(S) - abs(counts[0]-counts[1])
print(result)

Submission status: Runtime Error

Solution code:
S = input()
c0, c1 = 0,0
ans = 0
for ch in S:
  if c0 == 0 and ch = '1':
    c1 += 1
  elif c1 == 0 and ch = '0':
    c0 += 1
  elif ch == '1':
    ans += 2
    c0 -= 1
  else:
    ans += 2
    c1 -= 1
    
print(ans)

Submission status: Runtime Error

Solution code:
sin = input()
queue = deque(maxlen=len(sin))
for s in sin:
    if len(queue)>0 and queue[-1] != s:
        queue.pop()
    else:
        queue.append(s)
#print("".join(arr))
print(len(sin)-len(queue))

Submission status: Runtime Error

Solution code:
    s=input()
  	z,o=0,0
    for i in range(len(s)):
      if s[i]=="0":
        z+=1
      else:
        o+=1
    print(2*min(z,o))

Submission status: Runtime Error

Solution code:
s=input()
for i in range(len(s)):
  if s[i]=="0":
    z+=1
  else:
    o+=1
print(2*min(0,1))

Submission status: Runtime Error

Solution code:
def main120():
    import sys
    S_org = input()
    S = []

    for s in range(len(S_org)):
        S.append(S_org[s])
    S = list(map(int, S))

    cont = True
    index = 0
    count = 0

    if len(S) == 1:
        print(0)
        sys.exit()

    else:
        while(cont):
            print(index)
            if S[index] == S[index+1]:
                index += 1
            else:
                count += 2
                S.pop(index)
                S.pop(index)
                if index > 0:
                    index -= 1

            if index == len(S) - 2:
                if S[index] != S[index+1]:
                    count += 2
                print(count)
                sys.exit()


main120(

Submission status: Runtime Error

Solution code:
def main120():
    import sys
    S_org = input()
    S = []

    for s in range(len(S_org)):
        S.append(S_org[s])
    S = list(map(int, S))

    cont = True
    index = 0
    count = 0

    if len(S) == 1:
        print(0)
        sys.exit()

    else:
        while(cont):
            if S[index] == S[index+1]:
                index += 1
            else:
                count += 2
                S.pop(index)
                S.pop(index)
    
            if index == len(S) - 2:
                if S[index] != S[index+1]:
                    count += 2
                print(count)
                sys.exit()


main120()

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
for _ in range(N//2):
    S = S.replace('01','').replace('10','')S.replace('01','').replace('10','')S.replace('01','').replace('10','')S.replace('01','').replace('10','')S.replace('01','').replace('10','')
    if S.count('01') == 0 and S.count('10') == 0:
        break
print(N - len(S))

Submission status: Runtime Error

Solution code:
S=print()
N=len(S)
c0=0;c1=0
for i in range(N):
  if "0"==S[i]:
    c0=c0+1
  elif "1"==S[i]:
    c1=c1+1
print(str(min(c0,c1)))

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
count = 0

while True:
    if '10' in s:
        count += s.count('10') * 2
        s = s.replace('10','')
    elif '01' in s:
        count += s.count('01','') * 2
        s = s.replace('01','')
    else:
        break

print(count)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
count = 0

while True:
    if '10' in s:
        s = s.replace('10','',1)
        count += 2
        print(s)
    elif '01' in s:
        s = s.replace('01','',1)
        count += 2
        print(s)
    else:
        break

print(count)

Submission status: Runtime Error

Solution code:
s = input()
 
count = 0
 
def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str
 
def remove_cube(string, count):
  count = string.count('10')
  if count > 0:
    new_text = string.replace('10', '', count)
  count = string.count('01')
  if count > 0:
    new_text = string.replace('01', '', count)
  return new_text
 
string = s
can_remove = True
while can_remove:
  search_count = string.count('10')
  if search_count > 0:
    new_text = string.replace('10', '', search_count)
  else:
    search_count = string.count('01')
    if search_count > 0:
      new_text = string.replace('01', '', search_count)

  if new_text != string:
    string = new_text
    count += search_count * 2
    can_remove = True
  else:
    can_remove = False
 
print(count)

Submission status: Runtime Error

Solution code:
L = list(input())
L_ = []
a = L.pop(0)
cnt = 0

while True:
    if len(L) == 0:
        break
    else:
        b = L.pop(0)
    if a is not b:
        cnt += 1
        if len(L_) != 0:
            a = L_.pop()
        else:
            a = L.pop(0)
    elif a is b:
        L_.append(a)
        a = b
    # print(L_, a,  L)

print(cnt * 2)

Submission status: Runtime Error

Solution code:
L = list(input())
L_ = []
a = L.pop(0)
cnt = 0

while True:
    if len(L) == 0:
        break
    else:
        b = L.pop(0)
    if a is not b:
        cnt += 1
        L = L_ + L
        L_ = []
        a = L.pop(0)
    elif a is b:
        L_.append(a)
        a = b
    # print(L_, a,  L)

print(cnt * 2)

Submission status: Runtime Error

Solution code:
s = input()

count = 0

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

def remove_cube(string):
  for i in range(0, len(string)):
    print(len(string))
    if i+1 >= len(string):
      return string
    elif string[i] != string[i+1]:
      string = str_del(string, i)
      string = str_del(string, i)
      return string

string = s
can_remove = True
while can_remove:
  removed = remove_cube(string)
  if removed != string:
    string = removed
    count += 2
    can_remove = True
  else:
    can_remove = False

print(count)

Submission status: Runtime Error

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

# 削除した文字数
del_count = 0

# 削除する文字がなくなるまで処理を続ける
del_flg = True

while del_flg:
    del_flg = False
    for idx in range(max):
        target = string[idx : idx + 2]
        if target == "01" or target == "10":
            string_head = string[:idx]
            string_tail = string[idx + 2:]
            string = string_head + string_tail
            print(string)
            del_count += 2
            del_flg = True

print(del_count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import copy

string = [x for x in input()]

concat_string = copy.copy(string)
count = 0
while True:
    num_delete = 0
    flags_delete = [False] * len(string)
    
    i = 0
    j = 1
    while i < len(concat_string) - 1:
        if concat_string[i] != concat_string[j]:
            flags_delete[i] = True
            flags_delete[j] = True
            num_delete += 2
            
            if i == 0:
                i = j + 1
                j = i + 1
            else:
                i = i - 1
                j = j + 1
        else:
            i = j
            j = i + 1
           
    if num_delete == 0:
        break
    
    count += num_delete
    concat_string = [concat_string[i] for i in range(len(concat_string)) if flags_delete[i] == False]

print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import copy

string = [*input()]

concat_string = copy.copy(string)
count = 0
while True:
    num_delete = 0
    flags_delete = [False] * len(string)
    
    i = 0
    j = 1
    while i < len(concat_string) - 1:
        if concat_string[i] != concat_string[j]:
            flags_delete[i] = True
            flags_delete[j] = True
            num_delete += 2
            
            if i == 0:
                i = j + 1
                j = i + 1
            else:
                i = i - 1
                j = j + 1
        else:
            i = j
            j = i + 1
           
    if num_delete == 0:
        break
    
    count += num_delete
    concat_string = [concat_string[i] for i in range(len(concat_string)) if flags_delete[i] == False]

print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import copy

string = [*input()]

concat_string = copy.copy(string)
count = 0
while True:
    num_delete = 0
    flags_delete = [False] * len(string)
    
    i = 0
    while i < len(concat_string) - 1:
        if concat_string[i] != concat_string[i + 1]:
            flags_delete[i] = True
            flags_delete[i + 1] = True
            num_delete += 2
            i += 2
        else:
            i += 1
           
    if num_delete == 0:
        break
    
    count += num_delete
    concat_string = [concat_string[i] for i in range(len(concat_string)) if flags_delete[i] == False]

print(count)

Submission status: Runtime Error

Solution code:
N,M = list(map(int,input().split()))
xls = list(map(int,input().split()))
xls.sort()
dls =[xls[i+1]-xls[i] for i in range(M-1)]
dls.sort()

if N >= M:
    ans = int(0)
else:
    ans = sum(dls[0:M-N])

print(ans)