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 sys
from collections import Counter
S = input()
ct = Counter(list(S))
if len(S) == 1:
    print(0)
else:
    print(min(ct.values()) * 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = list(map(int, list(str(N))))

def solve():
    ones = sum(n)
    zeros = len(n) - ones
    return len(n) - abs(ones - zeros)

print(solve())

Submission status: Wrong Answer

Solution code:
S=raw_input()
A=[S[0]]
Ans=0
for i in range(len(S)):
    if len(A)>0:
        if A[-1]!=S[i]:
            A=[a for a in A[:-1]]
            Ans+=2
        else:
            A.append(S[i])
    else:
        A.append(S[i])

print Ans

Submission status: Wrong Answer

Solution code:
[a] = list(map(str, input().split()))

flag=1
count=0

while(flag==1):
    flag=0
    for i in range(len(a)-1):
        if(int(a[i])+int(a[i+1])==1):
            count+=1
            b=a
            if(i==len(a)-2):
                a=b[:i+1]
            else:
                a=b[:i+1]+b[i+2:]
            flag=1
            break
            
print(count*2)

Submission status: Wrong Answer

Solution code:
t = input()
s = [c for c in t]
count = 0
while True and len(s)>1:
    u = []
    tmp = len(s)
    for i in range(len(s)-1):
        if int(s[i])+int(s[i+1]) == 1:
            s[i+1] = '2'
            count += 2
        elif not s[i] == '2':
            u.append(s[i])
    s = u
    if tmp == len(s):
        break
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
n1 = len(s)
while True:
    n = len(s)
    _s = []
    skip = False
    for i in range(n):
        if skip:
            skip = False
            continue
        if i == n-1 or s[i] == s[i+1]:
            _s += s[i]
        else:
            skip = True
    s = _s
    if len(s) == 0 or n == len(s):
        break
print(n1 - n)

Submission status: Wrong Answer

Solution code:
s = list(input())
ans = 0
while True:
    t = []
    i = 0
    while i < len(s) - 1:
        if s[i] == s[i+1]:
            i += 1
            t.append(s[i])
        elif s[i] != s[i+1]:
            i += 2
            ans += 2
    t.append(s[-1])
    s = t
    if all([item == '1' for item in s]) or all([item == '0' for item in s]) or len(s) == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = 0
n = list(map(int, list(str(N))))

def solve():
    ones = sum(n)
    zeros = len(n) - ones
    return len(n) - abs(ones - zeros)

print(solve())

Submission status: Wrong Answer

Solution code:
def solve(S):
    ans = 0
    i = 0
    j = 1
    taken = [1 for _ in S]
    while j < len(S):
        if S[i] != S[j]:
            taken[i] = 0
            taken[j] = 0
            ans += 2

            j += 1
            while taken[i] == 0:
                i -= 1
                if i == -1:
                    i = j
                    j = j + 1
                if j >= len(S):
                    break
        else:
            i += 1
            j += 1

    return ans

if __name__ == "__main__":
    S = input()
    print(solve(S))

Submission status: Wrong Answer

Solution code:
def solve(S,crs=0):
    if crs >= len(S):
        return 0
    while crs + 1 < len(S):
        if S[crs] != S[crs+1]:
            return max(solve(S,crs+1),solve(S[:crs]+S[crs+2:],crs-1)+2)
        crs += 1
        
    return 0
  
S = input()
print(S,0)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
answer = 0
while 1:
  c_01 = s.count("01")*2
  answer += c_01*2
  s = s.replace("01","")
  
  c_10 = s.count("10")
  answer += c_10*2
  s = s.replace("10","")
  
  if c_01 == 0 and c_10 == 0:
    break
print(answer)

Submission status: Wrong Answer

Solution code:
S = input()

cnt = 0

while True:
    sRep = S.replace('01', '')
    if len(sRep) != len(S):
        cnt += len(S) - len(sRep)
        S = sRep
        #print(S, cnt)
    else:
        break

print(cnt)

Submission status: Wrong Answer

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

while ct < n:
  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: Wrong Answer

Solution code:
S = input()
S = S + S[-1]
res = 0
tmp1 = 0
tmp0 = 0
now = 0
while True:
    if S[now] != S[now + 1]:
        res += 2
        flag = True
        now += 1
    else:
        if S[now] == '1':
            tmp1 += 1
        else:
            tmp0 += 1
            
        flag = False
        
    now += 1
    if now >= len(S) - 1:
        break
        
    
    
if flag == False:
    if S[len(S) - 1] == '1':
        tmp1 += 1
    else:
        tmp0 += 1
        
print(res + 2 * min(tmp1, tmp0))

Submission status: Wrong Answer

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

while ct < n:
  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 < 0: i=-1
    continue
  elif a[i] == 1 and a[i+1] == 0:
    a.pop(i)
    a.pop(i)
    ct += 1
    i -= 2
    if i <0 :i = -1
    
print(ct*2)

Submission status: Wrong Answer

Solution code:
#ABC120C
S=input()
a=''
c=0
for s in S:
	if a[-1:]==s:
		a=a[:-1]
		c+=2
	else:
		a+=s
print(c)

Submission status: Wrong Answer

Solution code:
st = input()
countone = st.count('1')
countzero = st.count('0')
if countone > countzero and countzero > 0:
    print(countone)
elif countone <= countzero and countone > 0:
    print(countzero)
else:
    print('0')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
t = S

while '01' in t:
    t= t.replace('01', '').replace('10', '')

print(len(S) - len(t))

Submission status: Wrong Answer

Solution code:
S = input()
ans = len(S)
while True:
    if S.find('01') >= 0:
        S = S.replace('01', '')
    if S.find('10') >= 0:
        S = S.replace('10', '')
    else:
        break
ans -= len(S)
print(ans)

Submission status: Wrong Answer

Solution code:
a = input()

init_len = len(a)
print(len(a))

while True:
  flg = True
  if a.find("01") > 0:
    a = a.replace("01","")
    flg = False
    
  if a.find("10") > 0:
    a = a.replace("10","")
    flg = False
  
  if flg:
    break
print(str(init_len-len(a)))

Submission status: Wrong Answer

Solution code:
S=list(input())
ans=0
for i in range(10):
    for j in range(len(S)-1):
        if j<len(S)-1:
            if S[j]!=S[j+1]:
                S.pop(j)
                S.pop(j)
                ans+=2
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def aa(li):
    for i in range(len(li) - 1):
        if li[i] != li[i+1]:
            return i
    return "END"


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    # s = list("11011010001011")
    s = list(ip.S())
    n = len(s)
    while True:
        res = aa(s)
        if res != "END":
            s.pop(res)
            s.pop(res)
            print(s)
        else:
            break
    print(n - len(s))



main()

Submission status: Wrong Answer

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

while ct < n:
  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 < 0: i=0
    continue
  elif a[i] == 1 and a[i+1] == 0:
    a.pop(i)
    a.pop(i)
    ct += 1
    i -= 2
    if i <0 :i = 0
    
print(ct*2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
count = 0

while True:
    if s.find("01") != -1:
        index = s.find("01")
        s = s[:index] + s[index+1:]
        count += 2
    elif s.find("10") != -1:
        index = s.find("10")
        s = s[:index] + s[index+1:]
        count += 2
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
n=0
while True:
    f = S.find("01")
    if f != -1:
        S = S[:f]+S[f+2:]
        n += 1
    ff = S.find("10")
    if ff != -1:
        S = S.replace("01","")
        n += 1

    if f==-1 and ff==-1:
        break
print(n*2)

Submission status: Wrong Answer

Solution code:
S=list(input())
ans=0
for i in range(100):
    for j in range(len(S)-1):
        if j<len(S)-1:
            if S[j]!=S[j+1]:
                S.pop(j)
                S.pop(j)
                ans+=2
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def aa(li):
    for i in range(len(li) - 1):
        if li[i] != li[i+1]:
            return i
    return "END"


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    s = list("11011010001011")
    # s = list(ip.S())
    n = len(s)
    while True:
        res = aa(s)
        if res != "END":
            s.pop(res)
            s.pop(res)
            print(s)
        else:
            break
    print(n - len(s))



main()

Submission status: Wrong Answer

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

for i in range(len(S)-1):
    if len(stack)==0:
        stack.append(S[i])
    elif stack[len(stack)-1]!=S[i]:
        stack.pop()
        ans+=2
    else:
        stack.append(S[i])

print(ans)

Submission status: Wrong Answer

Solution code:
S = input().rstrip()
found = True
cnt = 0
while(found):
    if S == '01' or S == '10':
        cnt += 2
        break
    for i in range(len(S) - 2):
        if S[i:i+2] == '01' or S[i:i+2] == '10':
            S = S[:i] + S[i+2:]
            cnt += 2
            found = True
            break
    else:
        found = False
print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()
lenS=len(S)
ls=[]
ls.append(S[0])
for i in range(1,lenS):
	if len(ls)==0:
		ls.append(S[0])
		continue
	tmp=ls.pop(-1)
	if tmp==S[i]:
		ls.append(tmp)
		ls.append(S[0])
print(lenS-len(ls))

Submission status: Wrong Answer

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

while ct < n:
  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
    continue
  elif a[i] == 1 and a[i+1] == 0:
    a.pop(i)
    a.pop(i)
    ct += 1
    i -= 2
  if i <0 :i = 0
    
print(ct*2)

Submission status: Wrong Answer

Solution code:
s=input()
count0=0
count1=0
for i in range(len(s)-1):
	if s[i]=='0':
		count0+=1
	else:
		count1+=1
print(min(count0,count1)*2)

Submission status: Wrong Answer

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

while True:
    T = S[:]
    S = S.replace('00', '')
    S = S.replace('11', '')
    if S == T:
        break

print(L - len(S))

Submission status: Wrong Answer

Solution code:
s = input()
N = len(s)
s = list(map(int, sorted(s, reverse=True)))

ans = 0
left_edge = 0
a, b = 0, 1
while b < N:
    if (s[a] == 0 and s[b] == 1) or (s[a] == 1 and s[b] == 0):
        ans += 2
        if a == left_edge:
            a += 2
            b += 2
            left_edge += 2
        else:
            a -= 1
            b += 1
    else:
        a += 1
        b += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
res = 0
while S:
    p = S[0]
    T = []
    i = 1
    while i < len(S):
        if S[i] != S[i-1]:
            i += 1
            res += 2
        else:
            T.append(S[i])
        i += 1
    if len(S) == len(T):
        break
    S = T
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def SR(self, s):
        """
        昇順ソート（reverse書くのが面倒
        返り値はありません。注意して下さい。
        SR(s) と書いたらsが昇順ソートされるだけです。
        Sort Reverse
        :param s: ソートしたいリスト
        :return: None
        """
        s.sort(reverse=True)

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def aa(li):
    for i in range(len(li) - 1):
        if li[i] != li[i+1]:
            return i
    return "END"


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    s = ip.S()
    s = list(s)
    n = len(s)
    while True:
        res = aa(s)
        if res != "END":
            s.pop(res)
            s.pop(res)
        else:
            break
    print(n - len(s))



main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
N = len(s)
s = list(map(int, sorted(s, reverse=True)))

ans = 0
a, b = 0, 1
while b < N:
    if (s[a] == 0 and s[b] == 1) or (s[a] == 1 and s[b] == 0):
        ans += 2
        if a == 0:
            a += 2
            b += 2
        else:
            a -= 1
            b += 1
    else:
        a += 1
        b += 1
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()

z = 0
o = 0
count = 0
for c in t:
    if c == '0':
        if o > 0:
            o -= 1
            count += 2
        else:
            z += 1
    else:
        if z > 0:
            z -= 1
            count += 1
        else:
            o += 2
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

a = S.count("0")
b = S.count("0")
print(min(a,b)*2)

Submission status: Wrong Answer

Solution code:
s=input()
zero=0
one=0
for i in range(len(s)):
  if s[i]=='0':
    zero+=1
  else:
    one+=1
print(abs(one-zero))

Submission status: Wrong Answer

Solution code:
v = input()
l = len(v)
a = 0
b = 0
for c in v:
    if c == '0':
        a += 1
    else:
        b += 1
print(min(a, b))

Submission status: Wrong Answer

Solution code:
def inpl():
    return list(map(int, input().split()))


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

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
L=len(S)
a=1
while a==1:
    l=len(S)
    a=0
    for i in range(l-1):
        if S[i]!=S[i+1]:
            S.pop(i)
            S.pop(i)
            a=1
            break
print(L-len(S))

Submission status: Time Limit Exceeded

Solution code:
import sys
import re

str = sys.stdin.readline().rstrip()
_str = str #　結果と比較用
while True:
    tmp = str
    tmp = re.sub("10", "", tmp)
    tmp = re.sub("01", "", tmp)
    if str == tmp:
        break
    str = tmp

print(len(_str) - len(str))

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
#def INPUT_AS_INT(): return int(sys.stdin.readline().rstrip())
# def INPUT_AS_INT_LIST(): return list(map(int,sys.stdin.readline().rstrip().split()))
def INPUT_AS_STRING(): return sys.stdin.readline().rstrip()
# def INPUT_AS_STRING_LIST(): return list(sys.stdin.readline().rstrip().split())

str = INPUT_AS_STRING() # 入力受付
_str = str #　結果と比較用
while True:
    tmp = str
    tmp = re.sub("10", "", tmp)
    tmp = re.sub("01", "", tmp)
    if str == tmp:
        break
    str = tmp

print(len(_str) - len(str))

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
t = s.replace('01','').replace('10','')
while s != t:
  s = t
  t = s.replace('01','').replace('10','')
print(l-len(t))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
while True:
  smash = 0
  for i in range(len(S)):
    if len(S) < 2:
      break
    if i > len(S)-2:
      break
    if S[i] == '0':
      if S[i+1] == '1':
        del S[i:i+2]
        count += 2
        smash = 1
    elif S[i] == '1':
      if S[i+1] == '0':
        del S[i:i+2]
        count += 2
        smash = 1
  if len(S) == 0:
    break
  if smash == 0:
    break
  continue

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
while True:
  smash = 0
  for i in range(len(S)-1):
    if len(S) == 0:
      break
    if S[i] == '0':
      if S[i+1] == '1':
        S.pop(i+1)
        S.pop(i)
        count += 2
        smash = 1
        break
    elif S[i] == '1':
      if S[i+1] == '0':
        S.pop(i+1)
        S.pop(i)
        count += 2
        smash = 1
        break
  if len(S) == 0:
    break
  if smash == 0:
    break
  continue

print(count)

Submission status: Time Limit Exceeded

Solution code:
import re


def main():
    s = input()
    n = 1e9
    ans = 0
    while n > 0:
        s, n = re.subn("01|10", "", s)
        ans += n*2
    print(ans)
    
main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    S = input()

    ans = 0

    for i in range(10**4):
        if '0011' in S:
            ans += 4 * S.count('0011')
            S = S.replace('0011', '')
        if '1010' in S:
            ans += 4 * S.count('1010')
            S = S.replace('1010', '')
        if '0101' in S:
            ans += 4 * S.count('0101')
            S = S.replace('0101', '')
        if '1100' in S:
            ans += 4 * S.count('1100')
            S = S.replace('1100', '')
    for i in range(10**4):
        if '01' in S:
            ans += 2 * S.count('01')
            S = S.replace('01', '')
        if '10' in S:
            ans += 2 * S.count('10')
            S = S.replace('10', '')
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
x = len(S)
while '01' in S:
  S = S.replace('01', '')
while '10' in S:
  S = S.replace('01', '')
y = len(S)
print(x-y)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

ans = 0
flag = 1
while (flag):
    flag = 0
    i = 0
    loop_len = len(s)
    while (i < (loop_len - 1)):
        # print(loop_len)
        # print(s)
        if (s[i] != s[i + 1]):
            flag = 1
            ans += 2
            del s[i: i + 2]
        loop_len = len(s)
        i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
cnt = 0
start_s = ''
while start_s != s:
    start_s = s
    for i in range(len(s)-1):
        #print(s[:i],s[i:i+2],s[i+2:])
        if s[i:i+2] == '01' or s[i:i+2] == '10':
            cnt += 2
            s = s[:i]+s[i+2:]
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#C - Unification
S = list(input())

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

count = 0
i = 0
while len(set(S))>1:
    if S[i] != S[i+1]:
        S.remove('0')
        S.remove('1')
        count += 2
        if i != 0:
            i -= 1
    else:
        i += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

count = 0
i = 0
while len(set(S))>1:
    if S[i] != S[i+1]:
        S.remove('0')
        S.remove('1')
        count += 2
        i = 0
    else:
        i += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
b=input()
n=len(b)
while "10" in b or "01"in b:
    b=b.replace("01","")
    b=b.replace("10","")
print(n-len(b))

Submission status: Time Limit Exceeded

Solution code:
import copy
S=list(str(input()))
kae=copy.copy(S)
ans=0
while True:
  con=0
  S=[i for i in S if i!=-100]
  for i in range(len(S)-1):
    if int(S[i])+int(S[i+1])==1:
      S[i]=-100
      S[i+1]=-100
      ans+=2
      con+=1
  if con==0:
    break
print(ans)