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:
S=input()
i=0
s=S
count=0
while True:
    if (i==(len(s)-1))or(len(s)==0):
        break
    if not(s[i]==s[i+1]):
        #print(s[:i],s[i+2:])
        s="".join((s[:i],s[i+2:]))
        #print(s)
        input()
        i=0
        count=count+1
    else:
        i=i+1
print(count*2)

Submission status: Runtime Error

Solution code:
S = input()

S = list(S)

from collections import Counter
c = Counter(S)
d = c.most_common()

print(2*min(d[0][1],d[1][1]))

Submission status: Runtime Error

Solution code:
s = list(input())
count = 0
s_1 = s.copy()
i = 0
while i < len(s)-1:
    if s[i] != s[i+1]:
        del s[i]
        del s[i]
        count += 2
        i = 0
    else:
        i += 1
    print(s)
        


print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
c = Counter(list(input())).values()
print(2 * min(c))
from collections import Counter
c = Counter(list(input())).values()
print(0 if len(c) == 1 else 2 * min(c))

Submission status: Runtime Error

Solution code:
import sys
s = list(sys.stdin.readline())
n = len(s)
cntd = {'0':0, '1':0}
for i in range(n):
    cntd[s[i]] += 1
ans = 2 * min(cntd.values())
print(ans)

Submission status: Runtime Error

Solution code:
import sys
*s, = sys.stdin.readline()
n = len(s)
cntd = {'0':0, '1':0}

for i in range(n):
    cntd[s[i]] += 1

ans = 2 * min(cntd.values())
print(ans)

Submission status: Runtime Error

Solution code:
import sys
*s, = sys.stdin.readline()
n = len(s)
cntd = {'0':0, '1':0}
for i in range(n):
    cntd[s[i]] += 1
ans = 2 * min(cntd.values())
print(ans)

Submission status: Runtime Error

Solution code:
s = list(map(str, input()))

change = 0
count = 0
i = 0

while True:
    if not s:
        break
    if i + 1 >= len(s):
        if change != 0:
            i = 0
            change = 0
        else:
            break

    if s[i] != s[i + 1]:
        del s[i: i + 2]
        count += 1
        change += 1
    else:
        i += 1

print(count * 2)

Submission status: Runtime Error

Solution code:
def main():
    s = input()

    zero = s.count('0')
    one = len(s) - zero

    print(min(zero, one) *)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if n==0:
    print(0)
elif none<=nzero:
    print(nall-none*2)
else:
    print(nall-nzero*2)

Submission status: Runtime Error

Solution code:
s = input()
ls = list(int(s))

ans = 0
lf = [1]*n
while '01' in s or '10' in s:
  for i in range(len(ls)):
    if sum(ls[i:i+2]) == 1:
      lf[i] = 0
      lf[i+1] = 0
      ans += 1
  ls,lf = *[s,f for s,f in zip(ls,lf) if lf[i]>0]
print(ans)

Submission status: Runtime Error

Solution code:
a, b, c = map(int, input().split())
print(min(b//a, c))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
l=[]
for ak in range(len(s)):
    l.append(s[ak])
no=[]
s=l
no.append(s[0])
br=0
for i in range(1,len(s)):
    no.append(s[i])
   
    if no[-1]!=no[-2]:
        no.pop(-1)
        no.pop(-1)
        br+=2
print(br)

Submission status: Runtime Error

Solution code:
import deque
S=input()

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

Submission status: Runtime Error

Solution code:
n = int(input())
input_list = list(map(int, input().split()))
ans_list = input_list[::-2] + input_list[n%2::2]
print(*ans_list)

Submission status: Runtime Error

Solution code:
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> S;
  ll count0 = 0, count1 = 0;
  rep(i, S.length()){
    if (S[i] == '0') count0++;
    else count1++;
  }
  cout << min(count0, count1)*2 << endl;

}

Submission status: Runtime Error

Solution code:
s = input()
zero = 0
one = 0

for i in len(s):
    if s[i]=="0":
        zero += 1
    else:
        one += 1
else:
    ans = min(zero,one)*2

print(ans)

Submission status: Runtime Error

Solution code:
S = str(input())
stack = []
N = len(S)
for i, s in enumerate(S):
  if i == 0:
    stack.append(s)
    else:
      if len(stack) == 0:
        stack.append(s)
        else:
          if s != stack[-1]:
            tmp = stack.pop()
            else:
              stack.append(s)
print(N - len(stack))

Submission status: Runtime Error

Solution code:
from collections import deque
s=input()
d=deque(s)
ans=deque([])
ans.append(d[0])
c=0
for i in range(len(s)):
    if ans==[]:
        ans.append(d[i])
    elif ans[-1]==d[i]:
        ans.append(d[i])
    else:
        ans.pop()
        c+=2
print(c)

Submission status: Runtime Error

Solution code:
l = []
ans = 0

for s in input():
    if s == "0":
        if l and l[-1] == "1":
            l.pop()
            ans += 2
        else:
            l.append(s)
    else:
        if l and l[-1] == "0":
            l.pop()
            ans += 2
        else:
            l.append(i)

print(ans)

Submission status: Runtime Error

Solution code:
S1 = input()
S2 = '2' + S1[0]
res = 0

if len(S1) == 1:
    print(0)

else:
    for s in S1[1::]:
        if S2[-1] == s:
            S2 += s
        else:
            S2 = S2[:-1:]
            res += 2

    print(res)

Submission status: Runtime Error

Solution code:
S1 = input()
S2 = '2' + S1[0]
res = 0

if len(S1) == 1:
    print(0)

else:
    for s in S1:
        if S2[-1] == s:
            S2 += s
        else:
            S2 = S2[:-1:]
            res += 2

    print(res)

Submission status: Runtime Error

Solution code:
S1 = input()
S2 = '2' + S1[0]
res = 0

for s in S1[1::]:
    if S2[-1] == s:
        S2 += s
    else:
        S2 = S2[:-1:]
        res += 2

print(res)

Submission status: Runtime Error

Solution code:
S1 = input()
S2 = '2' + S1[0]
res = 0

for s in S1:
    if S2[-1] == s:
        S2 += s
    else:
        S2 = S2[:-1:]
        res += 2

print(res)

Submission status: Runtime Error

Solution code:
S1 = input()
S2 = S1[0]
res = 0

for s in S1:
    if S2[-1] == s:
        S2 += s
    else:
        S2 = S2[:-1:]
        res += 2

print(res)

Submission status: Runtime Error

Solution code:
n=input()
s=len(n)
if s%2==0:
    l0=n[:s//2].count("0")
    l1=s//2-l0
    r0=n[s//2:].count("0")
    r1=s//2-r0
    print(min(l0,r1)*2+min(l1,r0)*2)
if s%2==1:
    l0=n[:s//2].count("0")
    l1=s//2-l0
    r0=n[s//2+1:].count("0")
    r1=s//2-r0
    tmp=min(l0,r1)*2+min(l1,r0)*2
    if n[s//2]=="0":
        if ri-l0>0 or r0-l1>0:
            tmp+=2
    else:
        if l0-r1>0 or l1-r0>0:
            tmp+=2
    print(tmp)

Submission status: Runtime Error

Solution code:
S = input()

s = S
index = 0
ans = 0
while index < len(s)-1:
    c = s[index]
    next_c = s[index+1]
    if c != next_c:
        s = s[:index] + s[index+2:]
        index = 0
        ans += 2
    else:
        index += 1
    print(s + ' ans:' + str(ans))

print(ans)

Submission status: Runtime Error

Solution code:
import copy

s = input()
l1 = len(s)

for i in range(n):
    if '01' in s:
        s = s.replace('01', '')
    elif '10' in s:
        s = s.replace('10', '')
    else:
        break
        
print(l1 - len(s))

Submission status: Runtime Error

Solution code:
S = list(int(input()))
a = S.count(0)
b = S.count(1)
ans = 2 * min(a, b)
print(ans)

Submission status: Runtime Error

Solution code:
S = list(int(input()))
a = S.counter(0)
b = S.counter(1)
ans = 2 * min(a, b)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
c = 0
while "00" in s or "11" in s:
  c += 2 * s.count("00")
  c.replace("00", "")
  c += 2 * s.count("11")
  c.replace("11", "")
print(c)

Submission status: Runtime Error

Solution code:
S=list(input())
c=0
while len(S)>1:
    before=len(S)
    l=0
    # 双方向から見ればループ回数は半分になる？
    for i in range(before//2):
    #for i in range(before-1):
        if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
            c+=2
            #S.pop(i)
            #S.pop(i)
            del S[i:i+2]
            #break
            l=1
        if S[-i-1]+S[-i-2]=="10" or S[-i-1]+S[-i-2]=="01":
            c+=2
            if i==0:
                del S[-i-2:]
            else:
                del S[-i-2:-i]
            break
        if l:
          	break
    if before==len(S):
        break
print(c)

Submission status: Runtime Error

Solution code:
a = input()
s = [int(i) for i in a]
count = 0
ans = 0
while True:
    if (len(s) == count+1) or len(s) == 0:
        break
    if (s[count] == 0 and s[count+1] == 1) or (s[count] == 1 and s[count+1] == 0):
        ans += 1
        s.pop(count)
        s.pop(count)
        count -= 1
    else:
        count += 1
print(ans*2)

Submission status: Runtime Error

Solution code:
S = input()
print(S)
stack = []
ans = 0
for c in S:
    if stack and stack[0] != c:
        print("stack={}, c={} pop!".format(stack, c))
        stack.pop()
        ans += 2
    else:
        print("stack={}, c={} append!".format(stack, c))
        stack.append(c)
#     print("c={0}, st={1}".format(c, stack))
print(ans)

Submission status: Runtime Error

Solution code:
# ABC120 C - Unification
# 2019/10/28

def main():
    S = list(map(int, list(open(0).read())))
#     print(S)
    
    cnt = 0
    i=0

    while (i<len(S)-1):
        if (S[i] == 0 and S[i+1] == 1) or (S[i] == 1 and S[i+1] == 0):
            S.pop(i)
            S.pop(i)
            cnt+=2
#             print("i={0}, S={1}, cnt={2}".format(i, S, cnt))
            i=0
        i+=1
    
    print(cnt)
    
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def remove01Pair(R):
    for i in range(len(R) - 1):
        #print(i)
        if R[i:i + 2] == '01':
            R = R[:i] + R[i + 2:]
            #print(R)
            return R
    flag[0] = 1
    return R

def remove10Pair(R):
    for i in range(len(R) - 1):
        #print(i)
        if R[i:i + 2] == '10':
            R = R[:i] + R[i + 2:]
            #print(R)
            return R
    flag[0] = 1
    return R

N = input().strip()
#print(N)
length = len(N)
#print(length)
flag = []
flag.append(0)
while flag[0] == 0:
    N = remove01Pair(N)
    #print(N)
    #time.sleep(1)
flag[0] = 0
while flag[0] == 0:
    N = remove10Pair(N)
    #print(N)
    #time.sleep(1)
#print()
#print(len(N))
f.close()
print(length - len(N))

Submission status: Runtime Error

Solution code:
s = list(input())

cnt = 0
i = 0

while i < len(s):
    while len(s) != 0 and s[i] != s[i + 1]:
        s.pop(i)
        s.pop(i)
        cnt += 2
        i -= 1
    i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import deque
s = deque(input())

cnt = 0
i = 1

while i < len(s):
    while len(s) != 0 and s[i - 1] != s[i]:
        s.pop(i)
        s.pop(i - 1)
        i -= 1
        cnt += 2
    i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
s = list(input())

cnt = 0
i = 1

while i < len(s):
    while len(s) != 0 and s[i - 1] != s[i]:
        s.pop(i)
        s.pop(i - 1)
        i -= 1
        cnt += 2
    i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
S=list(str(input()))
N=len(S)
s=0
ans=0
tmp=[]
def dp(s,ans,tmp):
  if s==N-1:
    return ans
  if (S[s]!=S[s+1]):
    ans+=2
    if tmp!=[] and s+1==N-2:
      if S[-1]!=tmp[-1]:
        return ans+2
    if s+1==N-1:
      return ans
    return dp(s+2,ans,tmp)
  elif tmp!=[] and tmp[-1]!=S[s]:
    ans+=2
    return dp(s+1,ans,tmp)
  else:
    tmp.append(S[s])
    return dp(s+1,ans,tmp)

print(dp(s,ans,tmp))

Submission status: Runtime Error

Solution code:
s = list(map(int,input()))
#print(s)
bool =True
x =0
cnt = 0
while bool:
    if  1  not in s or 0 not in s:
        #print('finA')
        break
    if len(s)>=2 and x==len(s)-1:
        x=0
    else:
        if s[x]==1 and s[x+1]==0:
            s.pop(x+1)
            s.pop(x)
            cnt+=2
            #print(len(s))
            #print(s)
            if len(s)<=1:
                #print('finB')
                break
        if s[x]==0 and s[x+1]==1:
            s.pop(x+1)
            s.pop(x)
            cnt+=2
            #print(len(s))
            #print(s)
            if len(s)<=1:
                #print('finC')
                break
        else:
            x+=1
print(cnt)

Submission status: Runtime Error

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    string s; cin >> s;
    int cnt0 = 0,cnt1 = 0;
    for(char ch : s) {
        if(ch == '0') cnt0++;
        else cnt1++;
    }
    int cnt;
    cnt = min(cnt0, cnt1);
    cout << cnt * 2<< endl;
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

print(2*mmin(s.count(0), s.count(1))

Submission status: Runtime Error

Solution code:
one = len([i for i in s if i == '1'])
zero = len(s)- one

print(2*min(one,zero))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    
    long n = s.size();
    int a,b;
    a = 0;
    b = 0;
    rep(i,n){
        if(s[i]=='0') a++;
        else if (s[i]=='1') b++;
    }
    cout << 2*min(a,b);
}

Submission status: Runtime Error

Solution code:
s = list(input())
count = 0
while True:
    for i,n in enumerate(s):
        if s[i] != s[i+1]:
            del s[i:i+2]
            count += 2
            break
    else:
        break
print(count)

Submission status: Runtime Error

Solution code:
s = input()
count = 0
while True:
    for i,n in enumerate(s):
        if s[i] != s[i+1]:
            s = s[:i] + s[i+2:]
            count += 2
            break
    else:
        break
print(count)

Submission status: Runtime Error

Solution code:
s = input()
c = 0
for i in s:
  if i == '0':
    break
  c += 1
r = list(range(len(s)))
r.reverse()
for i in r:
  if s[i] == '1':
    break
  c += 1
print(len(s) - c + d)

Submission status: Runtime Error

Solution code:
S = input()
ans = len(S)
def check(S):
	first = S[0]
	for i in range(1,len(S)):
		if first != S[i]:
			S = S[0:i-1] + S[i+1:]
			return S
		else:
			first = S[i]
while 1:
	S = check(S)
	if ('1' in S) and ('0' in S):
		continue
	else:
		print(ans-len(S))
		break

Submission status: Runtime Error

Solution code:
S=input()

count=0

for i in S:
  if i=="1":
    count +=1

print(min(i,len(S)-count))

Submission status: Runtime Error

Solution code:
str = input()
n = len(str)

ls = []

for i in range(n):
  ls.append(str[i])


for i in range(len(ls)):
  if (ls[i] == ls[i+1]) or (len(ls) == 1):
    break
  if (ls[i] == 0 and ls[i + 1] == 1) or (ls[i] == 1 and ls[i + 1] == 0):
    del ls[i]
    del ls[i]

nokori = len(ls)
print(n - nokori)

Submission status: Runtime Error

Solution code:
s = input()
count = 0

while S.find("01") != -1 or S.find("10") != -1:
    count += 2 * s.count("01")
    s = s.replace("01", "")
    count += 2 * s.count("10")
    s = s.replace("10", "")
print(count)

Submission status: Runtime Error

Solution code:
s = input()
o = len(s)
while True:
  len(s) = b
  s.replace('00','')
  s.replace('11','')
  if(len(s) == b):
    break
print(o - len(s))

Submission status: Runtime Error

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
data = list(n)

cntOne = 0
cntZero = 0

for i in range(len(data)):
    if data[i] == "0":
        cntZero += 1
    else:
        cntOne += 1

ans(int(2*min(cntOne, cntZero)))

Submission status: Runtime Error

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
data = list(n)

cntOne = 0
cntZero = 0

for i in range(data):
    if data[i] == "0": 
        cntZero += 1
    else: 
        cntOne += 1

ans(int(2*min(cntOne, cntZero)))

Submission status: Runtime Error

Solution code:
s = input()
result = 0
while True:
  t = len(s)
  for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
      result += 2
      s = s[:i] + s[i+2:]
      print(s)
      break
  if len(s) == t:
    break
print(result)

Submission status: Runtime Error

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

count0=0
count1=0
lastElm=-1
S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
lenS = len(S)
if lenS==1:
        print(0)
        exit()
S.sort()
for i in range(lenS):
        if i==0:
                count0=S.count("0")
                count1=S.count("1")
                if count0 == 0 or count1==1:
                        print(0)
                        exit()
        else:
                if lastElm == "0":
                        count0 -= 1
                elif lastElm == "1":
                        count1 -= 1

        if count0 == count1:
                print(count0*2)
                exit()
        else:
                if S[lenS//2] == "1":
                        lastElm = S[-1]
                        S.pop(-1)
                else:
                        lastElm = S[0]
                        S.pop(0)

Submission status: Runtime Error

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

count0=0
count1=0
lastElm=-1
S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
lenS = len(S)
if lenS==1:
        print(0)
        exit
S.sort()
for i in range(lenS):
        if i==0:
                count0=S.count("0")
                count1=S.count("1")
        else:
                if lastElm == "0":
                        count0 -= 1
                elif lastElm == "1":
                        count1 -= 1

        if count0 == count1:
                print(count0*2)
                exit()
        else:
                if S[lenS//2] == "1":
                        lastElm = S[-1]
                        S.pop(-1)
                else:
                        lastElm = S[0]
                        S.pop(0)

Submission status: Runtime Error

Solution code:
S = input()
ans = 0

N = len(S)
Slist = []

for i in range(N):
    Slist.append(S[i])

def f(A, ans):
    n = len(A)
    if n == 0 or n == 1:
        print(ans)
        return 0
        
    for j in range(n-1):
        if A[j] == '0' and A[j+1] == '1':
            del A[j:j+2]
            ans += 2
            break
        elif A[j] == '1' and A[j+1] == '0':
            del A[j:j+2]
            ans += 2
            break
        if j == n-2:
            print(ans)
            return 0 
    f(A, ans)

f(Slist, ans)

Submission status: Runtime Error

Solution code:
S = input()
length_0 = len(S)
for k in range((length_0+1)//2):
  S = S.replace("01", "")
  S = S.replace("10", "")
lengyh_1 = len(S)
print(length_0 - length_1)

Submission status: Runtime Error

Solution code:
S = input()
length_0 = len(S)
for k in range((length_0+1)//2):
  print(S.replace("01", ""))
  print(S.replace("10", ""))
lengyh_1 = len(S)

Submission status: Runtime Error

Solution code:
s=input()
l=len(s)
a=[0 for i in range(l)]

for i in range(l):
  a[i]=int(s[i])
  
ichi=0
zero=0

for i in range(l):
  if a[i]==1:
    ichi+=1
  else:
    zero+=1
    
print(2*min(ichi.zero))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = list(str(input()))
n = len(s)
ans = 0
s2 = s
for i in range(n):
    for j in range(n):
        if s2[i:i+2] == ['0','1'] or  s2[i:i+2] == ['1','0']:
            ans += 2
            s2.remove(s2[i])
            s2.remove(s2[i+1])
            continue
        else:
            continue

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    string s;
    cin >> s;

    int zero_num = 0;
    int one_num = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') {
            zero_num++;
        } else {
            one_num++;
        }
    }
    cout << s.size() - abs(zero_num - one_num) << endl;
}

Submission status: Runtime Error

Solution code:
s=int(input())
l=[]
def func(a):
    if a%2==0:
        return a/2
    else:
        return 3*a+1

while (s not in l):
    l.append(s)
    s=func(s)

print(len(l)+1)

Submission status: Runtime Error

Solution code:
S = input()
l = len(S)
T = list(S)


tmp = 0

while tmp != len(T)-1:
    if T[tmp] != T[tmp+1]:
     
        T.pop(tmp)
        T.pop(tmp)
        tmp -= 1
    else:

        tmp += 1





k = len(T)

ans = l - k

print(ans)

Submission status: Runtime Error

Solution code:
S = input()


count_1 = 0
count_0 = 0

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

if count_1 >= count_0:
  print(count_0*2)
elif:
  print(count_1*2)

Submission status: Runtime Error

Solution code:
S = input()

len_now = len(S)
count = 0
pivot = len(S)-1

while True:
  if len(S)==1:
    break
  elif S[0]=="1" and S[1]=="1":
    break
  elif S[0]=="0" and S[1]=="0":
    break
  
  if S[pivot]=="0" and S[pivot+1]=="1":
    S = S[pivot+2:len(S)]
    count = count + 2
  elif S[pivot]=="1" and S[pivot+1]=="0":
    S = S[pivot+2:len(S)]
    count = count + 2
  pivot = pivot+1

print(count)

Submission status: Runtime Error

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

import sys
#import math

hoge = input()
#hoge=[]
#for i in range(0,len(tmp)):
#	hoge.append(tmp[i])
#hoge = list(map(lambda a: int(a), tmp))

n = len(hoge)

sum=0
i=0
while(1):
#	print(i)
	if(hoge[i]!=hoge[i+1]):
#		print("hoge:{} i:{} {} {}".format(hoge,i,hoge[i],hoge[i+1]))
		newhoge=hoge[0:i]+hoge[i+2:n]
		hoge = newhoge
		i=max(i-2,-1)
		n=len(hoge)
		sum+=2
#	print(i)
#	print("---")
	i+=1
	if(i>=n-1):
		break


print(sum)

Submission status: Runtime Error

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

import sys
#import math

hoge = input()
#hoge=[]
#for i in range(0,len(tmp)):
#	hoge.append(tmp[i])
#hoge = list(map(lambda a: int(a), tmp))

n = len(hoge)

sum=0
i=0
while(1):
#	print(i)
	if(hoge[i]!=hoge[i+1]):
#		print("hoge:{} i:{} {} {}".format(hoge,i,hoge[i],hoge[i+1]))
		newhoge=hoge[0:i]+hoge[i+2:n]
		hoge = newhoge
		i=max(i-2,-1)
		n=len(hoge)
		sum+=2
#	print(i)
#	print("---")
	i+=1
	if(i>=n-2):
		break


print(sum)

Submission status: Runtime Error

Solution code:
s = input()
data = []
for i in s:
    data.append(int(i))
one = 0
zero = 0
for i in range(len(data))
    if i == 0:
        zero += 1
    else:
        one += 1
print(min(zero, one))

Submission status: Runtime Error

Solution code:
S = input()

N = len(S)

cnt_zero = 0
for i in range(N):
  if S[i] == '0':
    cnt += 1
if cnt_zero <= N - cnt_zero:
  print(cnt_zero*2)
else:
  print((N-cnt_zero)*2)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    bit = list(sys.stdin.readline().rstrip())
    print(2 * min(bit.count("0"), bit.count("1")))

Submission status: Runtime Error

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

red=0
blue=0
for i in range(N):
    if S[i]==0:
        red+=1
    else:
        blue+=1
print(min(red,blue)*2)

Submission status: Runtime Error

Solution code:
S=input()
red=0
blue=0
for i in range(N):
    if S[i]==0:
        red+=1
    else:
        blue+=1
print(min(red,blue)*2)

Submission status: Runtime Error

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

i  = 1
counter = 0
length = len(S)
while i < length or length < 2:
	if S[i - 1] != S[i]:
		del(S[i - 1 : i + 1])
		counter += 1
		length -= 2
		i -= 1
	else:
		i += 1
		
print(counter * 2)

Submission status: Runtime Error

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

i  = 1
counter = 0
while i < len(S):
	if S[i - 1] != S[i]:
		del(S[i - 1 : i + 1])
		counter += 1
		i -= 1
	else:
		i += 1
		
print(counter * 2)

Submission status: Runtime Error

Solution code:
a = input()

print(2* min(a.count('1'),a.count('0') )

Submission status: Runtime Error

Solution code:
s=input()
c=0
while n>0:
  n=s.count('01')
  s=s.replace('01','')
  c=c+n
  n=s.count('10')
  s=s.replace('10','')
  c=c+n
print(c)

Submission status: Runtime Error

Solution code:
s=input()
c=0
while n>0:
  n=s.count('01')
  s.replace('01','')
  c=c+n
  n=s.count('10')
  s.replace('10','')
  c=c+n
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def resolve():
    S = int(input())
    zeros = S.count("0")
    print(min(zeros, len(zeros)*2)

if '__main__' == __name__:
    resolve()

Submission status: Runtime Error

Solution code:
data = input()
data_list = [c for c in data]
# print(data_list)
count = 1
delete_count = 0
while ('0' in data_list) and ('1' in data_list):
    if count == len(data_list):
        count = 1

    if data_list[count - 1] != data_list[count]:
        del data_list[count - 1: count + 1]
        delete_count += 2
        # count = 1
    else:
        count += 1

print(delete_count)

Submission status: Runtime Error

Solution code:
data = input()
data_list = [c for c in data]
#print(data_list)
count = 0
delete_count = 0
while ('0' in data_list) and ('1' in data_list):
    #print("count" + str(count))
    if data[count] != data[count + 1]:
        data_list.pop(count)
        data_list.pop(count)
        delete_count += 2
    else:
        count += 1

  #  print(data_list)
 #   print("delete_count" + str(delete_count))
    #if delete_count >= len(data_list) // 2:
    #   break

#print(data_list)
print(delete_count)

Submission status: Runtime Error

Solution code:
s = input()

print(abs(s.count("1")-abs(s.count("0")))

Submission status: Runtime Error

Solution code:
s = input();
l = len(s)
zero=0,one=0
for i in s:
	if i=='0': zero+=1
	else one+=1
print(min(zero, one))

Submission status: Runtime Error

Solution code:
S = input()
print(min(len(re.findall('0', S)), len(re.findall('1', S))) * 2 if len(S) > 1 else 0)