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:
	index_list = []
	for cube_index in range(1, len(cubes)):
		if cube_index not in index_list and cubes[cube_index] == cubes[cube_index - 1]:
			index_list.append(cube_index - 1)
			index_list.append(cube_index)
	l = len(index_list)
	for i in reversed(index_list):
		cubes.pop(i)
	return (cubes, l)


cubes = input()
for c in cubes:
	if c not in ['0', '1']:
		exit(0)
cube_list = []
for cube in cubes:
	cube_list.append(cube)
l = len(cube_list)
k = 0
while (l != 0):
	cubes, l = next_check(cube_list)
	k += l
print(k)

Submission status: Runtime Error

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():

    def de(l,i):
        if len(l) == 0:
            return
        if len(l) == 2:
            if l[0] != l[1]:
                l = []
            return
        if l[i] != l[i-1]:
            l.pop(i)
            l.pop(i-1)
            de(l,i-1)
        elif len(l) >= i+1:
            if l[i] != l[i+1]:
                l.pop(i+1)
                l.pop(i)
                de(l,i)
        else:
            pass

    s = list(input().rstrip())
    l = len(s)
    for i in range(1,len(s)):
        de(s,i)
    print(l - len(s))

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#S =input().strip()
*S, = input() 
count =0
flag =1
while len(S) >=2 and flag==1:
    flag =0
    l =len(S)
    for i in range(l -1):
        if S[i:i+2] ==["1","0"] or S[i:i+2] ==["0","1"]:
            #print(S[i:i+2])
            del S[i:i+2]
            print(S,end=" ")
            count +=2
            flag =1
            #break
    #print()
print(count)

Submission status: Runtime Error

Solution code:
S=input()
X=len(S)
A=S.replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replac.replace("01","").replace.replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","")("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","")e("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","")
if X==1:
  print(0):
else:
  print(X-len(A))

Submission status: Runtime Error

Solution code:
s = list(input())
t = []
p = 0
flg = True

while flg:
    flg = False
    j = 0
    for i in range(len(s)):
        if s[j] == s[j+1]:
            t.append(s[j])
            j += 1
        else:
            p += 2
            j += 2
        if j >= len(s) - 1:
            if j == len(s) - 1:
                t.append(s[j])
                break
            else:
                break
    if len(t) == len(s) or len(t) == 0:
        pass
    else:
        s = t
        t.clear()
        flg = True

print(p)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
cnt1 = 0
cnt2 = 0
for i in range(n):
    if s[i] == '0':
        cnt1 += 1
    else:
        cnt2 += 1
print(min(cnt1, cnt2)*2)

Submission status: Runtime Error

Solution code:
import sys
i=0
L=list(input())
N=len(L)
if N==1:
  print(0)
  sys.exit()
for j in range(N):
  i=0
  while True:
    if L[i]!=L[i+1]:
      L.pop(i)
      L.pop(i)
      if L==[]:
        sys.exit()
    i+=1
    if i>len(L)-2:
      break
print(N-len(L))

Submission status: Runtime Error

Solution code:
import collections

s = raw_input()
stack = collections.deque([])
i = 0
j = 0
while(j < len(s)):
	while(j < len(s) and s[i] == s[j]): j += 1	
	stack.append(j-i)
	i = j
n = len(s)
while(len(stack) > 1) :
	v = stack.pop()
	u = stack.pop()
	if v > u:
		stack[-1] += v-u
	elif v < u:
		stack.append( u - v)

print n - (stack[-1] if stack else 0)

Submission status: Runtime Error

Solution code:
import collections
i,j = 0,0 
s = raw_input()
q = collections.deque([])
while(j < len(s)):
	while(s[j] == s[i]): j+=1
	q.append(j - i - 1)
	j = i

#5 6 5 1 1 4 2 1 1 1 1 1
ns = len(s)
while(len(q) > 1):
	u,v = q.popleft(), q.popleft()
	if q: q[0] += abs(u-v)
print ns - (q[0] if q else 0)

Submission status: Runtime Error

Solution code:
import collections
i,j = 0,0 
q = collections.deque([])
while(j < len(s)):
	while(s[j] == s[i]): j+=1
	q.append(j - i - 1)
	j = i

#5 6 5 1 1 4 2 1 1 1 1 1
ns = len(s)
while(len(q) > 1):
	u,v = q.popleft(), q.popleft()
	if q: q[0] += abs(u-v)
print ns - (q[0] if q else 0)

Submission status: Runtime Error

Solution code:
import collections
i,j = 0,0 
q = collections.deque([])
while(j < len(s)):
  while(s[j] == s[i]): j+=1
  q.append(j - i - 1)
  j = i

5 6 5 1 1 4 2 1 1 1 1 1

while(len(q) > 1):
  u,v = q.popleft(), q.popleft()
  if q: q[0] += abs(u-v)
print q[0] if q else 0

Submission status: Runtime Error

Solution code:
S=input()
s=[]
for i in S:
    s+=[i]
ans=0
que=[]
que+=[s[0]]
def cube(i):
    global ans
    if i==len(s):
        print(ans)
    else:
        que.append(s[i])
        flag=True
        while flag:
            if len(que)==0 or len(que)==1:
                flag=False
            elif que[-1]==que[-2]:
                flag=False
            elif que[-1]!=que[-2]:
                del que[-1]
                del que[-1]
                ans+=2
        cube(i+1)
cube(1)

Submission status: Runtime Error

Solution code:
S=input()
s=[]
for i in S:
    s+=[i]
ans=0
que=[]
que+=[s[0]]
def cube(i):
    global ans
    if i==len(s):
        return 1
    else:
        que.append(s[i])
        flag=True
        while flag:
            if len(que)==0 or len(que)==1:
                flag=False
            elif que[-1]==que[-2]:
                flag=False
            elif que[-1]!=que[-2]:
                del que[-1]
                del que[-1]
                ans+=2
        cube(i+1)
cube(1)
print(ans)

Submission status: Runtime Error

Solution code:
def sonu(a,count,pivot):
    if(a[pivot]!=a[pivot+1]):
        a.pop(pivot)
        a.pop(pivot)
        pivot=0
        count+=1
        if(len(set(a))!=1 and len(a)!=0):
            sonu(a,count,pivot)
        else:
            print(count*2)
        

    else:
        
        pivot+=1
        if(len(set(a))!=1):
            sonu(a,count,pivot)
        else:
            print(count*2)
        
    
    




a=list(input())
if(len(a)==1):
    print(0)
else:
    count=0
    pivot=0
    sonu(a,count,pivot)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
e=[]
o=[]
s=0

for i in range(n):
    if(int(a[i])==1):
        s+=1
    else:
        e.append(s)
        if(s==n):
            break
        for j in range(i,n):
            f=0
            if(int(a[j])==0):
                s+=1
            else:
                e.append(s)
                if(s==n):
                    break
                for k in range(j,n):
                    if(int(a[k])==1):
                        s+=1
                    else:
                        e.append(s)
                        if(s==n):
                            break
                        f=1
                        break
                if(f==1):
                    break
        
        e.append(s)
        if(s==n):
            break
        s=0
e.append(s)
if(len(e)==0):
    print("0")
else:
    print(max(e))
#print(o)

Submission status: Runtime Error

Solution code:
s = list(input())
n = len(s)
S = [int(s[i]) for i in range(n)]
count = 0

def f(X):
  p = 0
  if len(X) >= 4:
    for i in range(0,len(X)-4):
      if [X[i],X[i+1],X[i+2],X[i+3]] == [1,1,0,0] or [1,0,1,0] or [0,1,0,1]or[0,0,1,1]):
        X = X[0:i+2] + X[i+3:len(X)+1]
        return(X)

Submission status: Runtime Error

Solution code:
S = list(input())
A = 0
B = 0
for s in S:
    if s == '0':
        A += 1
    else:
        B += 1
print(min(A,B)

Submission status: Runtime Error

Solution code:
S = list(input())
from collections import deque
S = deque(S)
f = S.popleft()
stocked = f
ans = 0
while S:
    n = S.popleft()
    if f!=n:
        ans += 1
        if not S:
            break
        f = S.popleft()
    else:
        stocked = f
        f = n
if stocked!=n:
    ans += 1
print(ans*2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

ans = 0
i = 1
while len(s[i:]) >= 1:
  before = s[i-1]
  tmp = s[i]
  if before != tmp:
    s = s[:i-1] + s[i+1:]
    ans += 2
    i -= 1
  else:
    i += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
/* mytemplate.cpp {{{ */

/* header */
#include <bits/stdc++.h>
using namespace std;

/* rep */
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (ll)(n); i += (s))
#define per(...) GET_MACRO(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)
#define per1(a) per2(_, a)
#define per2(i, a) per3(i, a, 0)
#define per3(i, a, n) per4(i, a, n, 1)
#define per4(i, a, n, s) for (ll i = (a) - 1; i >= (ll)(n); i -= (s))
#define each(x, c) for(auto&& x : c)

/* short */
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define len(c) ((ll)(c).size())
#define temp_T template<typename T>
#define temp_TU template<typename T, typename U>

/* debug */
#define debug(x) {cerr << #x << " = " << (x) << "\n";}

/* alias */
temp_T using vec = vector<T>;
temp_T using heap = priority_queue<T>;
temp_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using ll = long long;
using str = string;
using vi = vec<ll>;
using vvi = vec<vi>;
using vs = vec<str>;
using vb = vec<bool>;
using pii = pair<ll, ll>;
using vp = vec<pii>;

/* const */
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

/* function */
inline ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
inline ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
bool isPrime(ll n) {if (n < 2) return false; rep(i, 2, (sqrt(n) + 1)) {if (n % i == 0) return false;} return true;}
void eratosthenes(vb& primes) {rep(i, len(primes)) primes[i] = true; primes[0] = primes[1] = false; rep(i, len(primes) / 2 + 1) {if (primes[i]) {rep(j, i + i, len(primes), i) primes[j] = false;}}}
inline ll minMultiple(ll a, ll n) {return n * (a / n + (a % n == 0 ? 0 : 1));}
vi listDivisors(ll n) {vi divs; rep(i, 1, sqrt(n) + 1) { if (n % i == 0) {divs.pb(i); divs.pb(n / i);}} sort(all(divs)); return divs; }
map<ll, ll> primeFactorize(ll n) {map<ll, ll> prime_factors; ll m = n; rep(i, 2, sqrt(n) + 1) {if (m < 1) break; while (m % i == 0) {++prime_factors[i]; m /= i;}} if (m != 1) ++prime_factors[m]; return prime_factors;}
inline ll mod_add(ll a, ll b) {return (a + b) % MOD;}
inline ll mod_sub(ll a, ll b) {return (a + MOD - b) % MOD;}
inline ll mod_mul(ll a, ll b) {return ((a % MOD) * (b % MOD)) % MOD;}
ll mod_pow(ll x, ll y) {if (y == 0) return 1; else if (y == 1) return x % MOD; else if (y % 2 == 0) {ll val = mod_pow(x, (ll)(y / 2)); return mod_mul(val, val);} else {ll val = mod_pow(x, (ll)(y / 2)); return mod_mul(mod_mul(val, val), x);}}
ll mod_inv(ll x) {return mod_pow(x, MOD - 2);}
ll mod_div(ll a, ll b) {return mod_mul(a, mod_inv(b));}
ll fact(ll n) {return n == 0 ? 1 : mod_mul(n, fact(n - 1));}
ll comb(ll n, ll r) {return fact(n) / fact(n - r) / fact(r);}
temp_T inline bool chmax(T& a, const T b) {if (a < b) a = b; return a < b;}
temp_T inline bool chmin(T& a, const T b) {if (a > b) a = b; return a > b;}
template<typename T = ll> inline T in() {T x; cin >> x; return x;}
temp_T inline void print(const T& x) {cout << x << "\n";}
temp_T inline void print(const vector<T>& v) {rep(i, len(v)) cout << v[i] << (i != len(v) - 1 ? " " : "\n");}
temp_T inline void print(const vector<vector<T>>& vv) {rep(j, len(vv)) print(vv[j]);}
temp_TU inline void print(const pair<T, U>& p) {cout << p.fi << " " << p.se << "\n";}
temp_TU inline void print(const vector<pair<T, U>>& vp) {rep(i, len(vp)) print(vp[i]);}
temp_TU inline void print(const map<T, U>& d) {each(x, d) print(x);}

/* init */
struct Init {Init(){cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

/* }}} */


//-----------------------------------------------------------------------------

int main() {
    str S = in<str>();
    ll n_0 = 0, n_1 = 0;
    rep(i, len(S)) {
        if (S[i] == '0') ++n_0;
        else ++n_1;
    }
    ll ans = 2 * min(n_0, n_1);
    print(ans);
}

Submission status: Runtime Error

Solution code:
S = input()
S = [Si for Si in S]

i = len(S) - 2
number_of_deleted_qube = 0
while i >= 0 and len(S) >= 2:
    current = S[i]
    right = S[i + 1]

    if current != right:
        del S[i + 1]
        del S[i]
        number_of_deleted_qube += 2

    i -= 1

print(number_of_deleted_qube)

Submission status: Runtime Error

Solution code:
S = input()
S = [Si for Si in S]

i = len(S) - 2
number_of_deleted_qube = 0
while i >= 0:
    current = S[i]
    right = S[i + 1]

    if current != right:
        del S[i + 1]
        del S[i]
        number_of_deleted_qube += 2

    i -= 1

print(number_of_deleted_qube)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

s = sys.stdin.readline().rstrip()
n = len(s)

def main():
    c = s.cout('0')
    print(min(n-c, c) * 2)

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
for a in Str:
    Codigo.append(a)

lenMax=len(Codigo)-1
k=0

while i < len(Codigo)-1:
    try:
        lenAnterior = len(Codigo)-1
    
        if Codigo[i] == "0" and Codigo[i+1]=="1":
            contador+=2
            Codigo.pop(i)
            Codigo.pop(i)
        elif Codigo[i] == "1" and Codigo[i+1]=="0":
            contador+=2
            Codigo.pop(i)
            Codigo.pop(i)
        
        if lenAnterior != len(Codigo)-1:
            i=i-1
        else:
            i=i+1

        k+=1

        if k >= lenMax:
            break
    except:
        break
    
print(contador)

Submission status: Runtime Error

Solution code:
for a in Str:
    Codigo.append(a)

lenMax=len(Codigo)-1
k=0

while i < len(Codigo)-1:
    lenAnterior = len(Codigo)-1
    
    if Codigo[i] == "0" and Codigo[i+1]=="1":
        contador+=2
        Codigo.pop(i)
        Codigo.pop(i)
    elif Codigo[i] == "1" and Codigo[i+1]=="0":
        contador+=2
        Codigo.pop(i)
        Codigo.pop(i)
        
    if lenAnterior != len(Codigo)-1:
        i=i-1
    else:
        i=i+1

    k+=1

    if k >= lenMax:
        break
    
print(contador)

Submission status: Runtime Error

Solution code:
Str = input()
Codigo = []
i=0
LenAnterior = 0
contador=0
for a in Str:
    Codigo.append(a)

while i < len(Codigo)-1:
    lenAnterior = len(Codigo)-1
    
    if Codigo[i] == "0" and Codigo[i+1]=="1":
        contador+=2
        Codigo.pop(i)
        Codigo.pop(i)
    elif Codigo[i] == "1" and Codigo[i+1]=="0":
        contador+=2
        Codigo.pop(i)
        Codigo.pop(i)
        
    if lenAnterior != len(Codigo)-1:
        i=i-1
    else:
        i=i+1
print(contador)

Submission status: Runtime Error

Solution code:
from collections import Counter
s = input()
ans = dict(Counter(s))
print(min(ans['0'],ans['1'])*2)

Submission status: Runtime Error

Solution code:
i

Submission status: Runtime Error

Solution code:
S=list(input())
s=0 #取り除いたキューブの数
i=0 
while len(set(S))!=len(S):
  if S[i]==S{i+1]==0 or S{i]==S[i+1]==1:
    s=s
    i+=1
  else:
    s+=2
    del S[i:i+2]
    i=0
print(s)

Submission status: Runtime Error

Solution code:
S=list(input())
N=len(S)
s=0 #取り除いたキューブの数
i=0 
while len(set(S))!=len(S):
  if S[i]==S{i+1]==0 or S{i]==S[i+1]==1:
    s=s
    i+=1
  else:
    s+=2
    i=0
print(s)

Submission status: Runtime Error

Solution code:
S=list(input())
s=0
i=0
if S[i]==S[i+1]==0 or S[i]==S[i+1]==1:
  s=s
  i+=1
else:
  s+=2
  del S[i:i+2]
  i=0
print(s)

Submission status: Runtime Error

Solution code:
S=list(int(input()))
s=0
i=0
if S[i]==S[i+1]==0 or S[i]==S[i+1]==1:
  s=s
  i+=1
else:
  s+=2
  del S[i:i+2]
  i=0
print(s)

Submission status: Runtime Error

Solution code:
S=list(int(input()))
s=0
i=0
if S[i]==S{i+1]==0 or S[i]==S[i+1]==1:
  s=s
  i+=1
else:
  s+=2
  del S[i:i+2]
  i=0
print(s)

Submission status: Runtime Error

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

l = []

i = 0
ans = 0
while i < n-1:
	if s[i] != s[i+1]:
		ans += 1
		num = 2
		while True:
			if len(l) == 0:
				break
			left = l.pop()
			right = s[i+num]
			if left != right:
				ans += 1
				num += 1
			else:
				break
		i += num
	else:
		l.append(i)
		i += 1
print(2*ans)

Submission status: Runtime Error

Solution code:
from collections import deque

s=input()
sd=deque(s)
d=deque()
while(len(sd)>0):
  crr = sd.popleft()
  if(len(d)<1):
    d.append(crr)
    continue
    if(len(d)>=1 and d[-1]!=crr):
      d.pop()
      else:
        d.append(crr)
print(len(s)-len(d))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = 0
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu = i
      ans += 2
      q = True
      break
  if kesu != 0:
    del slist[kesu-1:kesu+1]
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
ans = 0

def solve(s):
    if all((s[i]==s[i+1] for i in range(len(s)-1))):
        return 0
    for i in range(len(s)-1):
        if s[i:i+2] == '01' or s[i:i+2] == '10':
            return solve(s[:i]+s[i+2:])+2

print(solve(s))

Submission status: Runtime Error

Solution code:
S = input().strip()
x = sum(c == '0' for c in S)
y = len(n) - x
print(2 * min(x, y))

Submission status: Runtime Error

Solution code:
S = input()

ans = 0
pre = ''

while True:
    flag = 1
    for i, c in enumerate(S):
        if pre == '':
            pre = c
            continue

        if (pre == '1' and c == '0') or (pre == '0' and c == '1'):
            if i + 1 != len(S):
                S = S[:i - 1] + S[i + 1:]
            else:
                S = S[:i - 1]
            ans += 2
            flag = 0
            break
        pre = c
    if flag:
        break
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

ans = 0
pre = ''

while True:
    flag = 1
    for i, c in enumerate(S):
        if pre == '':
            pre = c
            continue

        if (pre == '1' and c == '0') or (pre == '0' and c == '1'):
            if i + 1 != len(S):
                S = S[:i - 1] + S[i + 1:]
            else:
                S = S[:i - 1]
            ans += 2
            flag = 0
            break
    if flag:
        break
print(ans)

Submission status: Runtime Error

Solution code:
n_list = list(input())
n_len_o = len(n_list)
#print(n_list)
a = 0
while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(a,n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i,i+1)
      if a != 0:
        a = i - 1
      flag = "ok"
      break
  if flag == "ng":
    break
print(n_len_o-len(n_list))

Submission status: Runtime Error

Solution code:
n_list = list(input())
n_len_o = len(n_list)
#print(n_list)
a = 0
while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(a,n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      a = i - 1
      flag = "ok"
      break
  if flag == "ng":
    break
#print(n_list)
print(n_len_o-len(n_list))

Submission status: Runtime Error

Solution code:
s=sorted(list(input()))
if s[0]==s[-1]:
  print(0)
else:
  a=s.index('1')
  print(2*min(a,len(s)-a)

Submission status: Runtime Error

Solution code:
s=sorted(list(input()));a=s.index('1');print(2*min(a,len(s)-a))

Submission status: Runtime Error

Solution code:
s=sorted(list(input());a=s.index('1');print(2*min(a,len(s)-a))

Submission status: Runtime Error

Solution code:
s=list(input()).sort();a=s.index('1');print(2*min(a,len(s)-a))

Submission status: Runtime Error

Solution code:
from collections import Counter
S = str(input())
SC = Counter(S)
v,c = zip(*SC.most_common())
print(len(S) - abs(c[1]-c[0]))

Submission status: Runtime Error

Solution code:
s_list = list(s)

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

Submission status: Runtime Error

Solution code:
S = input()
one = S.count('1')
zero = len(S) - one
print(min(one, zero) * 2py )

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

input = sys.stdin.readline
b = deque(map(int, input()))
cnt = 0
i = 0
while len(b) > 1:

    if len(list(set(b))) == 1:
        break
    if b[i] != b[i + 1]:
        b.pop(i)
        b.pop(i)
        cnt += 1
        i = 0
        continue
    i += 1
print(cnt * 2)

Submission status: Runtime Error

Solution code:
s = list(input())
n = len(s)
i = 0
cnt = 0
while i != n - 1:
    if (s[i] == '0' and s[i + 1] == '1') or (s[i] == '1' and s[i + 1] == '0'):
        s[i:i + 2] = []
        i -= 1
        cnt += 2
        n = len(s)
    else:
        i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

int main() {
  string S;
  cin >> S;
  int cnt_0 = 0;
  int cnt_1 = 0;
  int N = S.size();
  for (int i = 0; i < N; i ++) {
    if (S.at(i) == '0') {
      cnt_0 ++;
    }
    else {
      cnt_1 ++;
    };
  };
  
  int ans = min(min(cnt_0, cnt_1) * 2, N);
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
S = list(input())

last = S.pop(0)
stack = [last]
cnt = 0
for s in S:
    if last != s:
        stack.pop()
        # stack.append(s) 読み捨て
        cnt += 2
    else:
        stack.append(s)
        last = s

print(cnt)

Submission status: Runtime Error

Solution code:
S=list(input())
N=len(S)
def main():
  ans=0
  i=0
  while len(S)>0 and i<N-1:
    if (S[i]==0 and S[i+1]==1) or (S[i]==1 and S[i+1]==0):
      S=S.remove(S[i:i+2])
      ans+=1
      i=0
    else:
      ans=ans
      i+=1
  print(ans)
main()

Submission status: Runtime Error

Solution code:
S=list(input())
N=len(S)
def main():
  ans=0
  i=0
  while len(S)>0 :
    if (S[i]==0 and S[i+1]==1) or (S[i]==1 and S[i+1]==0):
      S.remove(S[i:i+2])
      ans+=1
    else:
      ans=ans
      i+=1
  print(ans)
main()

Submission status: Runtime Error

Solution code:
S=list(input())
N=len(S)
ans=0
i=0
while len(S)>0:
  if S[i]==0 and S[i+1]==1 or S[i]==1 and S[i+1]==0:
    S.remove(S[i:i+2])
    ans+=1
  else:
    ans=ans
    i+=1
print(ans)