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: Wrong Answer

Solution code:
import numpy as np

s = list(input())
s = np.array(s)
del_num = 0
 
while True:
    old_s = s[:]
    del_list = np.full_like(s,False)
    for i in range(len(s) - 1):
        if (del_list[i] == "T"):
            continue
        if (str("".join(s[i:i + 2])) == "01"):
            del_list[i:i + 2] = True
            for j in range(1,len(s)//2):
                if (0 <= i - j and i + j + 1 < len(s)) and ("".join([str(s[i - j]), str(s[i + j + 1])]) == "01"):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
        elif (str("".join(s[i:i + 2])) == "10"):
            del_list[i:i + 2] = True
            for j in range(1,len(s)//2):
                if (0 <= i - j and i + j + 1 < len(s)) and ("".join([str(s[i - j]), str(s[i + j + 1])]) == "10"):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
    s = np.delete(s, np.where(del_list == "T"))
    del_num += np.sum(len(np.where(del_list=="T")[0]))
    if (len(old_s) == len(s)):
        break
 
print(del_num)

Submission status: Wrong Answer

Solution code:
S = str(input())
count = 0
i = 0
def flag():
  global S,i,count
  S = S[i-1] + S[i+1:]
  count += 2
  i = 0
while True:
  if i == len(S) or len(S) == 0:
    break
  elif S[i-1] == "0" and S[i] == "1" and i-1 >= 0:
    flag()
  elif S[i-1] == "1" and S[i] == "0" and i-1 >= 0:
    flag()
  i += 1
print(count)

Submission status: Wrong Answer

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

# s = list(input())
#
# # print(S)
#
# i = 0
# count = 0
# s_sum = len(s)
#
# while i + 1 < len(s):
#     if s[i] != s[i + 1]:
#         s.pop(i)
#         s.pop(i)
#         i = 0
#         count += 1
#     else:
#         i += 1
#
# print(count * 2)


s = input()

count = 0


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

print(count)

Submission status: Wrong Answer

Solution code:

s = input()
count = 0

for i in range(1000):
    if not(("01" in s) | ("10" in s)):
        break
    if "01" in s:
        #count += 2 * s.count("01")
        s = s.replace("01", "", 1)
        count += 2
    else :
        #count += 2 * s.count("10")
        s = s.replace("10", "", 1)
        count += 2

print(count)

Submission status: Wrong Answer

Solution code:
cubes = input()

removed_cubes_count = 0

while True:
    removed_cubes = cubes.translate({
        '01': '',
        '10': ''
    })

    removed_cubes_count += len(cubes) - len(removed_cubes)

    if len(cubes) == len(removed_cubes):
        break

    cubes = removed_cubes_count


print(removed_cubes_count)

Submission status: Wrong Answer

Solution code:
import re

S = input()

count = 0

while '01' in S or '10' in S:

    m = re.search('(00+)(11+)', S)
    #print(m)
    if m:
        if len(m.group(1)) > len(m.group(2)):
            num = len(m.group(2))
            S = re.sub('0{' + str(num) + '}1{' + str(num) + '}', '', S)
            count += num * 2
        else:
            num = len(m.group(1))
            S = re.sub('0{' + str(num) + '}1{' + str(num) + '}', '', S)
            count += num * 2
    m = re.search('(11+)(00+)', S)
    #print(m)
    if m:
        # print('g0:' + m.group(1))
        # print('g1:' + m.group(2))
        if len(m.group(1)) > len(m.group(2)):
            num = len(m.group(2))
            S = re.sub('1{' + str(num) + '}0{' + str(num) + '}', '', S)
            count += num * 2
        else:
            num = len(m.group(1))
            S = re.sub('1{' + str(num) + '}0{' + str(num) + '}', '', S)
            count += num * 2

    if '01' in S:
        count += S.count('01') * 2
        S = S.replace('01', '')

        #print('count:' + str(count))
    if '10' in S:
        count += S.count('10') * 2
        S = S.replace('10', '')

        #print('count:' + str(count))



print(count)

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(1000):
    if not(("01" in s) | ("10" in s)):
        break
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "")
    else :
        count += 2 * s.count("10")
        s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

Solution code:
import queue
counter=0
S =input()
S = list(S)
q = queue.Queue()
for i in range(len(S)):
  q.put(S[i])
for i in range(len(S)-1):
  if(i == 0):
    s1 = q.get()
    s2 = q.get()
  else:
    s2 = q.get()
  if (s1 != s2):
    counter+=2
    s1 = q.get()
  else:
    q.put(s1)
    s1 = s2
print(counter)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(10):
    if not(("01" in s) | ("10" in s)):
        break
    count += 2 * s.count("01")
    s = s.replace("01", "")
    count += 2 * s.count("10")
    s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())

def f(S):
    new_array = []
    mark = False
    if len(S) == 2:
        if S[0] != S[1]:
            return []
        else:
            return S

    for i in range(0, len(S) - 2):
        if i % 3 == 0:
            if S[i] == S[i + 1] and S[i + 1] == S[i + 2]:
                new_array += [S[i], S[i+1], S[i+2]]
            elif S[i] != S[i + 1]:
                new_array += [S[i+2]]
                if mark == False:
                    mark = True
            elif S[i + 1] != S[i + 2]:
                new_array += [S[i]]
                if mark == False:
                    mark = True
    if len(S) % 3 == 1:
        new_array += [S[-1]]
    elif len(S) % 3 == 2:
        if S[-2] == S[-1]:
            new_array += [S[-2], S[-1]]

    if mark == True:
        return f(new_array)
    else:
        return new_array


print(len(S) - len(f(S)))

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(2):
    if not(("01" in s) | ("10" in s)):
        break
    count += 2 * s.count("01")
    s = s.replace("01", "")
    count += 2 * s.count("10")
    s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

Solution code:
import re
s=input()
N=len(s)
while True:
    n = len(s)
    s = re.sub(r'10|10', "", s)
    if n == len(s):
        print(N-n)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
res=0
for i in range(1000):
  S=S.replace("10","3")
  S=S.replace("01","3")
  res+=S.count("3")*2
  S=S.replace("3","")
print(res)

Submission status: Wrong Answer

Solution code:
import re

tmp = raw_input()

length = len(tmp)


tmp1 = tmp.replace("0", "")
tmp2 = tmp.replace("1", "")

if tmp1 > tmp2:
    tmp3 = len(tmp1) -len(tmp2)
else:
    tmp3 = len(tmp2) - len(tmp1)


division = length - tmp3

print(division)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
# import pandas as pd
# import torch


s = list(str(input()))

escape = False
begin = len(s)

def rem(s):
    for i in range(1,len(s)):
        # print(s)
        if s[i-1] != s[i]:
            s.pop(i)
            s.pop(i-1)
            break
    return s


for i in range(10**4):
    s = rem(s)

end = len(s)
print(begin-end)

Submission status: Wrong Answer

Solution code:
import sys

data= sys.stdin.readline()

a = data.count("01")
b = data.count("10")
c = 0
while a != 0 and b != 0:
    if a > 0:
        c += a * 2
        data = data.replace("01", "")
        a = data.count("01")
        b = data.count("10")
        
    if b > 0:
        c += b * 2
        data = data.replace("10", "")
        a = data.count("01")
        b = data.count("10")
    
print(c)

Submission status: Wrong Answer

Solution code:
s = str(input())
cnt=0
while len(s)//2 >1:
    if '10' in s:
        cnt+=2 * s.count('10')
        s=s.replace('10', '') 
        if '01' in s:
            cnt+=2 * s.count('01')
            s=s.replace('01', '') 
    if '01' in s:
        cnt+=2 * s.count('01')
        s=s.replace('01', '') 
        if '10' in s:
            cnt+=2 * s.count('10')
            s=s.replace('10', '') 
    else:
        break
print(cnt)

Submission status: Wrong Answer

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
            while flag:
                nowl = i
                nowr = i+1
                if nowl >= 0 and nowr <= n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 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)

Submission status: Wrong Answer

Solution code:
s=input()
t=1
ans=0
while t!=0:
    t=0
    t+=s.count('01')
    s=s.replace('01','')
    print(s)
    t+=s.count('10')
    s=s.replace('10','')
    ans+=t
print(ans*2)

Submission status: Wrong Answer

Solution code:
S=input()
print(S.count("0")*2)

Submission status: Wrong Answer

Solution code:
S=str(input())
l=list(S)
ilength=len(l)
recon=True
while(recon):
  recon=False
  jump=False
  sl=[]
  for i in range(len(l)-1):
    if(int(l[i])+int(l[i+1])==1 and not(jump)):
      recon=True
      jump=True
    else:
      sl.append(l[i])
      jump=False
  l=sl[:]
flength=len(l)
print(ilength-flength)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    count = 0
    while True:
        start_count = count
        for i, val in enumerate(S):
            while_loop = 0
            while True:
                while_loop += 1
                try:
                    if S[i] != S[i+1]:
                        S.pop(i)
                        S.pop(i)
                        i -= 1
                        count += 2
                    else:
                        break
                except IndexError:
                    if i < 0:
                        i == 0
                    else:
                        break
        if start_count == count:
            break

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = input()
count = 0
p = 0
q = 1
ng_list = []
for i in range(len(N) - 1):
  if i in ng_list:
    continue
  if N[i] != N[i + 1]:
    count += 2
    ng_list.append(q)
    q += 1
    if q == len(N):
      break
    while N[p] != N[q]:
      count += 1
      ng_list.append(q)
      q += 1
      if q == len(N):
        count += 1
        break
  else:
    p += 1
    q += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())

num_moto = int(len(s))

for ctr in range(1000):
    if int(len(s)) == 0:
        break
    s = s.replace('10','')
    s = s.replace('01','')
    
num_kekka = int(len(s))
print(num_moto - num_kekka)

Submission status: Wrong Answer

Solution code:
S = input()
S_array = []

for i in S:
    S_array.append(i)
    
answer = 0
i = 1

while (i <= len(S_array) -1):
    if len(S_array) < 2:
        print(answer)
        break
    elif S_array[i] != S_array[i-1]:
        del S_array[i-1:i+1]
        i = 1
        answer += 2
    else:
        i += 1
    print(answer)

Submission status: Wrong Answer

Solution code:
# 前方から現れた0の数をストックしていく
# 1が現れたら、そこから連続する1の数だけペアを生成する
# ストックの数 ＞ 連続する1の数のとき、ストックを保持(ペアの数＝連続する1の数)
# otherwise ストックを0にして再計算(ペアの数＝スタックの数)

string = input()
length = len(string)
string = string[::-1]
stuck_zeros = 0
number_of_pair = 0
index = 0


def debug(target, index_of_cursor, stuck, pair):
    print("THIS IS DEBUG DATA")
    print("stucks : " + str(stuck))
    print("pair : " + str(pair))
    print(target)
    print(" " * index_of_cursor + "^")
    print("---")


while index < length:
    # debug(string, index, stuck_zeros, number_of_pair)
    if string[index] == '1':
        stuck_zeros += 1
        index += 1
    else:
        # 1 appear
        if (stuck_zeros != 0):
            # ↓string[index]
            number_of_continues_1 = 1
            for i in range(index + 1, length):
                index += 1
                if (string[i] == '0'):
                    number_of_continues_1 += 1
                else:
                    index -= 1
                    break
            if (stuck_zeros > number_of_continues_1):
                number_of_pair += number_of_continues_1
                stuck_zeros -= number_of_continues_1
            else:
                number_of_pair += stuck_zeros
                stuck_zeros = 0
        else:
            index += 1


print(number_of_pair * 2)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    S = input()
    c = 0
    while(1):
        d = S.count('1100')
        if d > 0:
            S = S.replace("1100", "")
        e = 2*S.count('0011')
        if e > 0:
            S = S.replace("0011", "")
        a = 2*S.count('01')
        if a > 0:
            S = S.replace("01", "")
        b = S.count('10')
        if b > 0:
            S = S.replace("10", "")
        num = a+b+d+e
        if num == 0:
            print(c*2)
            exit()
        c += num

Submission status: Wrong Answer

Solution code:
s = input()
length_s = len(s)
list_s = list()
for i in range(length_s):
    list_s.append(s[:1])
    s = s[1:]
length = length_s
while(length > 2):
    for j in range(length - 1):
        if(list_s[j] != list_s[j+1]):
            del list_s[j:j+2]
            break;
    length = len(list_s)
print(length_s - len(list_s))

Submission status: Wrong Answer

Solution code:
import re
s = input()
vanishing_amount = 0

if s[0] == '0':
    pattarn = re.compile('01')
elif s[0] == '1':
    pattarn = re.compile('10')

while True:
    former_length = len(s)
    s = re.sub(pattarn, "", s, 1)
    later_length = len(s)
    if former_length == later_length:
        break
    vanishing_amount += 2

print(vanishing_amount)

Submission status: Wrong Answer

Solution code:
def check_01(inp):
    remove_list = []
    for i in range(1,len(inp)):
        if int(inp[i-1]) + int(inp[i]) ==1:
            remove_list.append(i)
    if remove_list:
        return remove_list
    else:
        return None
inp = list(input())
k = 0
while True:
    lists = check_01(inp)
    if lists is not None:
        k += 1
        for r in lists:
            del inp[r-1:r]
    else:
        break
print(k*2)

Submission status: Wrong Answer

Solution code:
s = str(input())
ss = s
for i in range(int(300)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
    
 
print(len(s)-len(ss))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    S = input()
    c = 0
    while(1):
        d = S.count('1100')
        if d > 0:
            S = S.replace("1100", "")
        e = S.count('0011')
        if e > 0:
            S = S.replace("0011", "")
        a = S.count('01')
        if a > 0:
            S = S.replace("01", "")
        b = S.count('10')
        if b > 0:
            S = S.replace("10", "")
        num = a+b+d+e
        if num == 0:
            print(c*2)
            exit()
        c += num

Submission status: Wrong Answer

Solution code:
s = str(input())

num_moto = int(len(s))

for ctr in range(500):
    if int(len(s)) == 0:
        break
    s = s.replace('10','')
    s = s.replace('01','')
    
num_kekka = int(len(s))
print(num_moto - num_kekka)

Submission status: Wrong Answer

Solution code:
import queue
counter=0
S =input()
S = list(S)
q = queue.Queue()
for i in range(len(S)):
  q.put(S[i])

for i in range(len(S)-1):
  if(i == 0):
    s1 = q.get()
    s2 = q.get()
  else:
    s2 = q.get()
  if (s1 != s2):
    counter+=2
  else:
    q.put(s1)
    s1 = s2
print(counter)

Submission status: Wrong Answer

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

S = input()
cnt = 0

# O(N^2)は不可。
# 010がある時、01と10を取り除くパターンを作る？
s = S
while True:
    ls = len(s)
    s1 = s.replace("01", "")
    s2 = s.replace("01", "")
    ls1 = len(s1)
    ls2 = len(s2)
    if ls == ls1 and ls == ls2:
        break
    elif ls1 <= ls2:
        cnt += (ls - ls1)
        s = s1
    else:
        cnt += (ls - ls2)
        s = s2

print(cnt)

Submission status: Wrong Answer

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

S = input()
cnt = 0

# O(N^2)は不可。
# 010がある時、01と10を取り除くパターンを作る？
s = S
while True:
    ls = len(s)
    s1 = s.replace("01", "")
    s2 = s.replace("01", "")
    ls1 = len(s1)
    ls2 = len(s2)
    if ls == ls1 and ls == ls2:
        break
    elif ls1 <= ls2:
        cnt += (ls - ls1)
        s = s1
    else:
        cnt += (ls - ls2)
        s = s2

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    S = input()

    ans = f(S)
    print(ans)


def f(S):
    """
    A,B,Cそれぞれが存在していたら終了
    存在しない場合
    diff をとる
    """
    b = []
    a = 0
    for c in S:
        if c == '1':
            a += 1
        else:
            a -= 1
        b.append(a)

    ans = 0
    c = Counter([0] + b)
    for v in c.values():
        ans += v // 2
    ans *= 2

    return ans
    return WA(S, b)


def WA(S, b):
    d = [b[0]]
    for a in b[1:]:
        d.append(d[-1] + a)

    print(d)

    c = Counter(b)
    ans = 0
    for v in c.values():
        ans += v // 2
    ans *= 2
    print(c)

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re,sys

s = str(input())
sl = list(s)

def ltox(s):
    if(len(s) <= 1):
        return (s)
    for i in range(1, len(s)-1):
        if(s[i-1] != s[i] and s[i-1] != 'x'):
            s[i] = 'x'
            s[i-1] = 'x'
    return [i for i in s if i != 'x']


bllx = len(s)
llx = sl.copy()
while True:
    llx = ltox(llx)
    # print(llx)
    if(len(llx) == bllx):
        if(len(llx) == 2 and llx[0] != llx[1]):
            print(len(list(str(s))))
        else:
            print(len(list(str(s)))-len(llx))
        sys.exit()
    else:
        bllx = len(llx)

Submission status: Wrong Answer

Solution code:
s = str(input())
ss = s
for i in range(int(200)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
    
 
print(len(s)-len(ss))

Submission status: Wrong Answer

Solution code:
N = input()
count = 0
p = 0
q = 1
ng_list = []
for i in range(len(N) - 1):
  if i in ng_list:
    continue
  if N[i] == N[i + 1]:
    count += 2
    ng_list.append(q)
    q += 1
    while N[p] == N[q]:
      count += 1
      ng_list.append(q)
      q += 1
      if q == len(N):
        break
  else:
    p += 1
    q += 1

print(count)

Submission status: Wrong Answer

Solution code:
import re,sys

s = str(input())
sl = list(s)

def ltox(s):
    if(len(s) <= 1):
        return (s)
    for i in range(1, len(s)-1):
        if(s[i-1] != s[i] and s[i-1] != 'x'):
            s[i] = 'x'
            s[i-1] = 'x'
    return [i for i in s if i != 'x']


bllx = len(s)
llx = sl.copy()
while True:
    # llx = ltox(llx)
    print(llx)
    if(len(llx) == bllx):
        if(len(llx) == 2 and llx[0] != llx[1]):
            print(len(list(str(s))))
        else:
            print(len(list(str(s)))-len(llx))
        sys.exit()
    else:
        bllx = len(llx)

Submission status: Wrong Answer

Solution code:
s = str(input())
ss = s
for i in range(int(80)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
    
 
print(len(s)-len(ss))

Submission status: Wrong Answer

Solution code:
import numpy as np
s = str(input())
cnt=0
l=["01","10"]
while len(s)//2 >1:
    if '10' in s:
        cnt+=2 * s.count('10')
        s=s.replace('10', '') 
    elif '01' in s:
        cnt+=2 * s.count('01')
        s=s.replace('01', '') 
    else:
        break
print(cnt)

Submission status: Wrong Answer

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

S = list(map(int, input().replace('\n', '')))

N = len(S)
stack = []
cnt = 0
index = N - 1
while index > -1:
    print(index, S, stack)
    if(len(stack) == 0):
        stack.append(S.pop())
        index -= 1
    else:
        if stack[-1] != S[index]:
            stack.pop()
            S.pop(index)
            index -= 1
            cnt += 2
        else:
            stack.append(S.pop())
            index -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
lt = len(s)

tmp = []
for it in range(lt-1):
	tmp.append(s[it:it+2])

it = 0
# print(tmp)
# if "01" in tmp:
# 	it = tmp.index("01")
# 	print(tmp.index("01"))
# 	tmp = tmp[:it-1]+tmp[it+2:]
# print(tmp[:it-1])
# print(tmp[it+2:])
# print(tmp)
count = 0
while True:
	if lt == 1:
		print(0)
		break

	if "01" in tmp:
		it = tmp.index("01")
		# print(tmp.index("01"))
		tmp = tmp[:it-1]+tmp[it+2:]
		count += 2
	elif "10" in tmp:
		it = tmp.index("10")
		# print(tmp.index("10"))
		tmp = tmp[:it-1]+tmp[it+2:]
		count += 2
	else:
		print(lt-len(tmp)*2)
		break

Submission status: Wrong Answer

Solution code:
s = input()
vanishing_amount = 0

if s[0] == '0':
    pattarn = '01'
elif s[0] == '1':
    pattarn = '10'

while True:
    former_length = len(s)
    s = s.replace(pattarn, "", 1)
    later_length = len(s)
    if former_length == later_length:
        break
    vanishing_amount += 2

print(vanishing_amount)

Submission status: Wrong Answer

Solution code:
import re
s = input()
c = 0
flag = True

if flag:
    if "01" in s:
        c = s.count("01")
        re.sub("01","",s)
        
        if "10" in s:
            c += s.count("10")
            re.sub("10","",s)
        
        if "01" in s:
            c += s.count("01")
            re.sub("01","",s)
            
    if "10" in s:
        c = s.count("10")
        re.sub("10","",s)
        
        if "01" in s:
            c += s.count("01")
            re.sub("01","",s)
            
        if "10" in s:
            c += s.count("10")
            re.sub("10","",s)
    else:
        flag = False
            
print(c)

Submission status: Wrong Answer

Solution code:
s = str(input())
cnt=0
while len(s)//2 >0:
    if '10' in s:
        cnt+=2 * s.count('10')
        s=s.replace('10', '') 
    elif '01' in s:
        cnt+=2 * s.count('01')
        s=s.replace('01', '') 
    else:
        print(cnt)
        break
    print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()
L=len(S)
print(abs(S.count("1")-S.count("0")))

Submission status: Wrong Answer

Solution code:
s = input()
lt = len(s)

tmp = []
for it in range(lt-1):
	tmp.append(s[it:it+2])

it = 0
# print(tmp)
# if "01" in tmp:
# 	it = tmp.index("01")
# 	print(tmp.index("01"))
# 	tmp = tmp[:it-1]+tmp[it+2:]
# print(tmp[:it-1])
# print(tmp[it+2:])
# print(tmp)
count = 0
while True:
	if lt == 1:
		print(0)
		break

	if "01" in tmp:
		it = tmp.index("01")
		# print(tmp.index("01"))
		tmp = tmp[:it-1]+tmp[it+2:]
		count += 2
	elif "10" in tmp:
		it = tmp.index("10")
		# print(tmp.index("10"))
		tmp = tmp[:it-1]+tmp[it+2:]
		count += 2
	else:
		# print(lt-len(tmp)*2)
		break

Submission status: Wrong Answer

Solution code:
S = list(input())

def f(S):
    new_array = []
    mark = False
    if len(S) == 2:
        if S[0] != S[1]:
            return []
        else:
            return S

    for i in range(0, len(S) - 2):
        if i % 3 == 0:
            if S[i] == S[i + 1] and S[i + 1] == S[i + 2]:
                new_array += [S[i], S[i+1], S[i+2]]
            elif S[i] != S[i + 1]:
                new_array += [S[i+2]]
                if mark == False:
                    mark = True
            elif S[i + 1] != S[i + 2]:
                new_array += [S[i]]
                if mark == False:
                    mark = True
    if len(S) % 3 == 1:
        new_array += [S[-1]]
    elif len(S) % 3 == 2:
        new_array += [S[-2], S[-1]]
    if mark == True:
        return f(new_array)
    else:
        return new_array


print(len(S) - len(f(S)))

Submission status: Wrong Answer

Solution code:
S = list(input())
Sremoved = [0] * len(S)

removed = 0
while True:
    removed_old = removed
    for i in range(len(S) - 1):
        if (Sremoved[i] == 0):
            idx1 = i
        for j in range(len(S)):
            if (Sremoved[i] == 0):
                idx2 = j
        if (int(S[idx1]) + int(S[idx2])) == 1:
            Sremoved[idx1] = 1
            Sremoved[idx2] = 1
            removed += 2
    if removed == removed_old:
        break
print(removed)

Submission status: Wrong Answer

Solution code:
s = input()
input_len = len(s)

for i in range(100000):
  sa = s.replace('10','')
  if len(sa)!=len(s):
    s=sa
  sb = s.replace('01','')
  if len(sb)!=len(s):
    s=sb
  if len(sa) == len(s) & len(sb) == len(s):
    break
print(input_len-len(s))

Submission status: Wrong Answer

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
            while flag:
                nowl = i
                nowr = i+1
                while b[nowl] > 0 and nowl >= 0 and nowr < n-1:
                    nowl -= 1
                    nowr += 1
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                else:
                    flag = False

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
cnt = 0
i = 0
while 1:
    if len(s) == 0 or len(s) == 1:
        break
    while i < len(s)-1:
        if s[i] == s[i+1]:
            s = s[:i:] + s[i+2::]
            cnt += 2
            continue
        i += 1
    if len(s)-1 == i:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
s = str(input())
ss = s
for i in range(int(100)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
    

print(len(s)-len(ss))

Submission status: Wrong Answer

Solution code:
S = input()
S = list(S)
count = 0


previousCount = 0
while(1) :
    if len(S) < 2:
        break
    
    if S[0] != S[1] :
        S.pop(0)
        S.pop(0)
        count+=2
    
    for i in range(1,len(S)-2) :
        if S[i] != S[i+1] :
            if S[i-1] != S[i+2] :
                S.pop(i)
                S.pop(i)
                count +=2
                break
    if previousCount == count :
        break
    previousCount = count
            
print(count)

Submission status: Wrong Answer

Solution code:
import re
S = input()
work=S
while(len(work)>=0):
    if('01' in work):
        work = re.sub('01','',work)
    if('10' in work):
        work = re.sub('10','',work)
    else:#01 or 10 の羅列も見つけることができなかった
        break

print(len(S)-len(work))

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    count = 0
    while True:
        start_count = count
        for i, val in enumerate(S):
            while_loop = 0
            while True:
                while_loop += 1
                try:
                    if S[i] != S[i+1]:
                        S.pop(i)
                        S.pop(i)
                        i -= 1
                        count += 2
                    else:
                        break
                except IndexError:
                    break
        if start_count == count:
            break

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
n = n0 = len(s)
nn = 0
while n > 1 and n != nn:
  n = len(s)
  for i in range(n-1, 0, -1):
    if s[i] != s[i-1]:
      s.pop(i)
      s.pop(i-1)
      nn = len(s)
      break
print(n0 - nn)

Submission status: Wrong Answer

Solution code:
#C
S = input()
N = len(S)
SL = list(map(int, list(S)))

cnt = 1
total = 0
while cnt != 0 and len(SL) >= 2:
    r = len(SL)
    cnt = 0
    i = 1
    tmpSL = []
    tp = tmpSL.append
    while i < r:
        if SL[i-1] != SL[i]:
            if i == r - 2:
                tp(SL[-1])
            i += 2
            cnt += 2
        else:
            tp(SL[i - 1])
            i += 1
    SL = tmpSL
    total += cnt
print(total)

Submission status: Wrong Answer

Solution code:
S = input()
dic = {"0": 0, "1": 0}

N = len(S)
ind = N-1
now = S[ind]
dic[now] = 1
ans = 0

def rev(s):
	if s == "0":
		return "1"
	else:
		return "0"

if N == 1:
	print(0)
else:
	while ind > 0:
		past = now
		now = S[ind-1]

		dic[now] += 1
		if past != now:
			ans += (dic[past] // 2) * 2
			dic[past] = dic[past] % 2
			if dic[past] == 1:
				dic[now] = 0
		ind -= 1
	dic[S[0]] += 1
	ans += (dic[S[0]] // 2) * 2

	print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

num_moto = int(len(s))

while True:
    if ( s.find('10') == -1 and s.find('01') == -1 ) or int(len(s)) == 0:
        break
    s = s.replace('10','')
    s = s.replace('01','')
print(s)
num_kekka = int(len(s))
print(num_moto - num_kekka)