Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
x,y,z,k = map(int, input().split())

# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[x-1,y-1,z-1]]
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f = 0
    if temp[0] > 0:
        for j in t:
            if temp[0]-1 == j[0] and temp[1]== j[1] and temp[2]==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0]-1,temp[1],temp[2]])
            t.append([temp[0]-1,temp[1],temp[2]])
    f = 0
    if temp[1] > 0:
        for j in t:
            if temp[0] == j[0] and temp[1]-1== j[1] and temp[2]==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0],temp[1]-1,temp[2]])
            t.append([temp[0],temp[1]-1,temp[2]])
    f = 0
    if temp[2] > 0:
        for j in t:
            if temp[0] == j[0] and temp[1]== j[1] and temp[2]-1==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0],temp[1],temp[2]-1])
            t.append([temp[0],temp[1],temp[2]-1])

  


### FIXED CODE ###

# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
x,y,z,k = map(int, input().split())
 
# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort()
b.sort()
c.sort()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))
### BUGGY CODE ###

s = input()

dp = [[0 for _ in range(13)] for __ in range(len(s)+1)]

l = len(s)


if s[0] == '?':
    for j in range(10):
        dp[0][j*(10**(l-1)) % 13] = 1
else:
    dp[0][int(s[0])*(10**(l-1)) % 13] = 1

for i in range(1,len(s)):
    if s[i] == '?':
        for k in range(13):
            for j in range(10):
                dp[i][(j*(10**(l-i-1))+k)%13] += dp[i-1][k]
                dp[i-1][k] % (10**9 +7)
    else:
        for k in range(13):
            dp[i][(int(s[i])*(10**(l-i-1)) + k) %13] += dp[i-1][k]
            dp[i-1][k] % (10**9 +7)

print(dp[len(s)-1][5] % (10**9 + 7) )

### FIXED CODE ###

s = input()
 
s = s[::-1]
 
dp = [[0 for _ in range(13)] for __ in range(len(s)+1)]
 
l = len(s)
 
 
if s[0] == '?':
    for j in range(10):
        dp[0][j] = 1
else:
    dp[0][int(s[0])] = 1
 
m = 1
MOD = 10**9 +7
 
for i in range(1,len(s)):
    m = m*10 % 13
 
    if s[i] == '?':
        for k in range(13):
            for j in range(10):
                dp[i][(j*m+k)%13] += dp[i-1][k]
                dp[i][k] %= MOD
    else:
        for k in range(13):
            dp[i][(int(s[i])*m + k) %13] += dp[i-1][k]
            dp[i][k] %= MOD
 
print(dp[len(s)-1][5] % MOD )
### BUGGY CODE ###

### C

N , M = list(map(int , input().split()))

X = list(map(int , input().split()))

X = list(map(int , sorted(X)))

#print("X = " + str(X))

D = []

R = 0

if M-1 > 0 :
	for i in range(M-1):
		D.append(int(X[i+1]) - int(X[i]))


#print("D = " + str(D))

for i in range(N-1):
	if D !=[]:
		MAXD = max(D)
		D.remove(MAXD)
#		print(str(D) + "minus " + str(i+1) + "roots.")

if D != []:
	for d in D:
		R += d


print(R)



### FIXED CODE ###

### C

N , M = list(map(int , input().split()))

X = list(map(int , sorted(list(map(int , input().split())))))

#print("X = " + str(X))

D = []

R = 0

if M-1 > 0 :
	for i in range(M-1):
		D.append(int(X[i+1]) - int(X[i]))


#print("D = " + str(D))

if D !=[]:
	D = sorted(D)
	D = D[::-1]
	D = D[N-1:]
#print("D = " + str(D))

if D != []:
	for d in D:
		R += d


print(R)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(m):
    b, c = map(int, input().split())
    a.extend([c for i in range(b)])
    a.sort(reverse=True)
    a = a[:n]

print(sum(a))

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import defaultdict
n, m = map(int, input().split())
a = list(map(int, input().split()))

cards = defaultdict(int)
for num in a:
    cards[num] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cards[c] += b

count = n
ans = 0
for key, val in sorted(cards.items(), key=lambda x: -x[0]):
    if count - val < 0:
        ans += key * count
        break
    else:
        ans += key * val
        count -= val
print(ans)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

def main():
    ans = 10**5 * 2
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(A):
        for j in range(B):
            cost = a[i] + b[i]
            ans = min(ans, cost)

    for i in range(M):
        x, y, c =  map(int, input().split())
        cost = a[x-1] + b[y-1] - c
        ans = min(ans, cost)

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

input = sys.stdin.readline

def main():
    ans = 10**5 * 2
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = sorted(a)[0] + sorted(b)[0]
    
    for i in range(M):
        x, y, c =  map(int, input().split())
        cost = a[x-1] + b[y-1] - c
        ans = min(ans, cost)

    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

a,b,x = map(int,input().split())
n = 0
for i in range(a,b+1):
  if (i%x) == 0:
    n += 1
print(n)

### FIXED CODE ###

a,b,x = map(int,input().split())
print((b//x)-(a//x)+(a%x == 0))
### BUGGY CODE ###

from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from collections import deque
n,m = inm()
chi = [{} for i in range(n+1)]
par = [{} for i in range(n+1)]
for i in range(n-1+m):
    a,b = inm()
    chi[a][b] = 1
    par[b][a] = 1
dep = [0]*(n+1)
rpar = [0]*(n+1)
for i in range(1,n+1):
    if len(par[i])==0:
        root = i
        break
ddprint("chi")
ddprint(chi)
ddprint("par")
ddprint(par)
ddprint(root)
q = deque([root])
while len(q)>0:
    p = q.popleft()
    d = dep[p]
    for z in chi[p]:
        if dep[z]<d+1:
            dep[z] = d+1
            rpar[z] = p
            q.append(z)
for i in range(1,n+1):
    print(rpar[i])


### FIXED CODE ###

from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from collections import deque
n,m = inm()
chi = [{} for i in range(n+1)]
par = [{} for i in range(n+1)]
for i in range(n-1+m):
    a,b = inm()
    chi[a][b] = 1
    par[b][a] = 1
dep = [0]*(n+1)
rpar = [0]*(n+1)
for i in range(1,n+1):
    if len(par[i])==0:
        root = i
        break
ddprint("chi")
ddprint(chi)
ddprint("par")
ddprint(par)
ddprint(root)
q = deque([root])
while len(q)>0:
    p = q.popleft()
    d = dep[p]
    for z in chi[p]:
        del par[z][p]
        #if dep[z]<d+1 and len(par[z])==0:
        if len(par[z])==0:
            dep[z] = d+1
            rpar[z] = p
            q.append(z)
for i in range(1,n+1):
    print(rpar[i])
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
score_1=1
for i in range(k):
  score_1=score_1*a[i]
score_2=score_1*a[k]/a[0]
if score_1<score_2:
  print('Yes')
else:
  print('No')
for i in range(k+1,n):
  score_1=score_2
  score_2=score_2*a[i]/a[i-k]
  if score_1<score_2:
    print('Yes')
  else:
    print('No')


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k,n):
  if a[i-k]<a[i]:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for i in range(N//R+1):
    for j in range(N//G+1):
        x = i * R
        y = j*G
        z = N - x-y
        if z>= 0 and z%B == 0:
            ans += 1
print(int(ans))

### FIXED CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for i in range(N//R+1):
    x = i * R
    for j in range((N-x)//G+1):
        
        y = j*G
        z = N - x-y
        if z>= 0 and z%B == 0:
            ans += 1
print(int(ans))
### BUGGY CODE ###

n, m = map(int, input().split())
s = list(input())
connect = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)
def check(xs):
    a, b = 0, 0
    for x in xs:
        if s[x] == 'A':
            a = 1
        elif s[x] == 'B':
            b = 1
        if a & b:
            return True
    return False
update = True
while update:
    update = False
    for i in range(n):
        if s[i] != 'X':
            if not check(connect[i]):
                update = True
                s[i] = 'X'
if 'A' in s and 'B' in s: print('Yes')
else: print('No')

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
n, m = map(int, input().split())
s = input()
out = [set() for _ in range(n)]
count = [[0, 0] for _ in range(n)]
def f(c):
    if c == 'A': return 0
    else: return 1
for _ in range(m):
    a, b = map(int, input().split())
    if a == b:
        count[a-1][f(s[a-1])] += 1
    elif b-1 not in out[a-1]:
        count[a-1][f(s[b-1])] += 1
        count[b-1][f(s[a-1])] += 1
    out[a-1].add(b-1)
    out[b-1].add(a-1)
elim = set()
def eliminate(x):
    elim.add(x)
    c = f(s[x])
    for node in out[x]:
        if node not in elim:
            count[node][c] -= 1
            if count[node][0] * count[node][1] == 0:
                eliminate(node)
for i in range(n):
    if i not in elim and count[i][0] * count[i][1] == 0:
        eliminate(i)
if len(elim) < n: print('Yes')
else: print('No')
### BUGGY CODE ###

k,s = map(int,input().split())
n = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-(x+y)
        if z <= k and z >= 0:
            if x+y+z==s:
                n += 1
                
print(n)
                

### FIXED CODE ###

k,s = map(int,input().split())
n = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-(x+y)
        if z <= k and z >= 0 and x+y+z==s:
            n += 1
print(n)
### BUGGY CODE ###

N = int(input())

ans = 0
for i in range(N):
  ans += i
print(ans)

### FIXED CODE ###

N = int(input())

print(N * (N-1) // 2)
### BUGGY CODE ###

N = int(input())
S = list(input())

rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = 0
mx = max(len(rli), len(gli), len(bli))

if mx == len(rli):
    for i in gli:
        for j in bli:
            sa = max(i,j)-min(i,j)
            scr = len(rli)
            if min(i,j)-sa in rli:
                scr -= 1
            if (i+j)/2 in rli:
                scr -= 1
            if max(i,j)+sa in rli:
                scr -= 1
            ans += scr
elif mx == len(gli):
    for i in rli:
        for j in bli:
            sa = max(i,j)-min(i,j)
            scr = len(gli)
            if min(i,j)-sa in gli:
                scr -= 1
            if (i+j)/2 in gli:
                scr -= 1
            if max(i,j)+sa in gli:
                scr -= 1
            ans += scr
else:
    for i in rli:
        for j in gli:
            sa = max(i,j)-min(i,j)
            scr = len(bli)
            if min(i,j)-sa in bli:
                scr -= 1
            if (i+j)/2 in bli:
                scr -= 1
            if max(i,j)+sa in bli:
                scr -= 1
            ans += scr

print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = len(rli)*len(gli)*len(bli)
for i in range(N):
    for j in range(i+1, ((N-i)//2+(N-i)%2)+i):
        if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

#最大公約数、最小公倍数、階乗
import fractions
n = int(input())
a = list(map(int, input().split()))

def calcGCDr(i):
    ans = a[i+1]
    if i==n-2:
        return ans
    tmp = i+1
    while tmp+1<n:
        ans = fractions.gcd(ans,a[tmp+1])
        tmp+=1
    return ans
def calcGCDl(i):
    ans = a[i-1]
    if i==1:
        return ans
    tmp = i-1
    while tmp-1>=0:
        ans = fractions.gcd(ans,a[tmp-1])
        tmp-=1
    return ans

max_ans = 1
for i in range(1,n-1):
    pre_ans = fractions.gcd(calcGCDl(i), calcGCDr(i))
    max_ans = max(pre_ans, max_ans)
pre_ans = calcGCDr(0)
max_ans = max(pre_ans, max_ans)
pre_ans = calcGCDl(n-1)
max_ans = max(pre_ans, max_ans)

print(max_ans)

### FIXED CODE ###

#最大公約数、最小公倍数、階乗
import fractions
n = int(input())
a = list(map(int, input().split()))

def calcGCDr():
    R = [0 for i in range(n+1)]
    R[n] = 0
    for i in range(1,n+1):
        R[n-i] = fractions.gcd(R[n-i+1],a[n-i])
    return R

def calcGCDl():
    L = [0 for i in range(n+1)]
    L[0] = 0
    for i in range(n):
        L[i+1] = fractions.gcd(L[i],a[i])
    return L

R = calcGCDr()
L = calcGCDl()
max_ans = 1
for i in range(n):
    pre_ans = fractions.gcd(L[i], R[i+1])
    max_ans = max(pre_ans, max_ans)

print(max_ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

sq=A[0]
for i in range(1,N):
    sq *= A[i]

if sq>10**18:
    print(-1)
else:
    print(sq)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))


if 0 in A:
    print(0)
else:
    sq=A[0]
    for i in range(1,N):
        sq *= A[i]

        if sq>10**18:
            print(-1)
            exit()

    print(sq)
### BUGGY CODE ###

from collections import deque


n, m = map(int, input().split())
edges = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)


def bfs(node):
    seen = [0] * n
    todo = deque([])
    for to in edges[node]:
        todo.append([to, 1, {to}])

    while todo:
        now, distance, path = todo.popleft()
        seen[now] = distance
        if now == node:
            return distance, path

        for next_node in edges[now]:  # type: int
            if seen[next_node] != 0:
                continue
            new_path = path | {next_node}
            todo.append([next_node, distance + 1, new_path])

    return float('INF'), set()


cycle_size = [float('INF')] * n
cycle_nodes = [set()] * n

for i in range(n):
    cycle_size[i], cycle_nodes[i] = bfs(i)

mini_cycle = min(cycle_size)
if mini_cycle == float('INF'):
    print(-1)
else:
    idx = cycle_size.index(mini_cycle)
    ans = cycle_nodes[idx]
    print(mini_cycle)
    for node in ans:
        print(node+1)


### FIXED CODE ###

n, m = map(int, input().split())
edges = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)


def get_first_cycle(n, edges):
    seen = [-1] * n  # seen: -1: 未確認, 0: 非cycleのnode, 1: cycle候補
    for start in range(n):
        if seen[start] == 0:
            continue
        seen[start] = 1
        path = [start]
        while path:
            now = path[-1]
            if not edges[now]:
                path.pop()
                seen[now] = 0
                continue

            next_node = edges[now].pop()
            if seen[next_node] == -1:
                path.append(next_node)
                seen[next_node] = 1

            elif seen[next_node] == 1:
                idx = path.index(next_node)
                cycle = path[idx:]
                return cycle
    return False


cycle = get_first_cycle(n, edges)
if not cycle:
    print(-1)
    exit()

nodes = set(cycle)
length = len(cycle)
i = 0
while i < length:
    now = cycle[i]
    routes = edges[now]
    while routes:
        to = routes.pop()
        if to in nodes:
            update = True
            idx = cycle.index(to)
            cycle = cycle[:i+1] + cycle[idx:]
            nodes = set(cycle)
            length = len(cycle)
            break
    i += 1

print(len(cycle))
for node in cycle:
    print(node+1)
### BUGGY CODE ###

def main():
    H,W,M = map(int,input().split())
    list = []
    retuH = [0]*(H+1)
    gyoW = [0]*(W+1)
    for i in range(M):
        h,w = map(int,input().split())
        retuH[h] += 1
        gyoW[w] += 1
        list.append((h,w))
    #print(list)
    maxH = max(retuH)
    maxW = max(gyoW)
    wi = [i for i in range(1,W+1,1) if gyoW[i] == maxW]

    for h in [i for i in range(1,H+1,1) if retuH[i] == maxH]:
        for w in wi:
            if ((h,w) not in list):
                return maxH + maxW
    return maxH + maxW -1

print(main())


### FIXED CODE ###

def main():
    H,W,M = map(int,input().split())
    dict_gyo = {key: 0 for key in range(H)}
    dict_retu = {key: 0 for key in range(W)}
    dict_ichi = {}
    for i in range(M):
        h,w = map(int,input().split())
        dict_gyo[h-1] += 1
        dict_retu[w-1] += 1
        dict_ichi[(h-1,w-1)] = 1

    #print(dict_gyo,dict_ichi)

    maxgyo = max(dict_gyo.values())
    maxretu = max(dict_retu.values())
    #maxgyo_k = max(dict_gyo, key = dict_gyo.get)
    #maxretu_k = max(dict_retu, key = dict_gyo.get)
    #print(maxgyo_k,maxretu_k)
    result = maxgyo + maxretu - 1
    wi = [i for i in range(W) if dict_retu[i] == maxretu]
    for h in [i for i in range(H) if dict_gyo[i] == maxgyo]:
        for w in wi:
            if (h,w) not in dict_ichi:
                result = maxgyo + maxretu
                return result

    return result




print(main())
### BUGGY CODE ###

n, k = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 9
dp = [INF] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, k + 1):
        if j >= n - i:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[-1])


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


n, k = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 9
dp = [INF] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, k + 1):
        if j >= n - i:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))

c = 0
for i in range(n-1):
    for j in range(i+1,n):
        if (a[i] == j+1) and (a[j] == i+1):
            c += 1

print(c)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))

c = 0

for i in range(n):
    if a[a[i]-1] == i+1:
        c += 1

print(c//2)
### BUGGY CODE ###

n,k = map(int,input().split())
x = list(map(int,input().split()))
res = 10**10
for i in range(n-k+1):
    kx = x[i:i+k]
    l=kx[0]
    r = kx[-1]
    lrsmall = min(abs(l),abs(r))
    res = min(r-l+lrsmall,res)
print(res)

### FIXED CODE ###

n,k = map(int,input().split())
x = list(map(int,input().split()))
kx = x[0:k]
l=kx[0]
r = kx[-1]
lrsmall = min(abs(l),abs(r))
res = r-l+lrsmall
for i in range(1,n-k+1):
    del kx[0]
    kx.append(x[i+k-1])
    l=kx[0]
    r = kx[-1]
    lrsmall = min(abs(l),abs(r))
    res = min(r-l+lrsmall,res)
print(res)
### BUGGY CODE ###

N,K=map(int, input().split())
R,S,P=map(int, input().split())
T=input()
# N,K=7 ,1
# R,S,P=100 ,10, 1
# T="ssssppr"

# N,K=5, 2
# R,S,P=8, 7, 6
# T="rsrpr"


max_ans=T.count("s")*R+T.count("p")*S+T.count("r")*P
for i in range(K):
    tmp_ans=T[i::K]
    for i in range(len((tmp_ans))-1):
        if tmp_ans[i]==tmp_ans[i+1]:
            if tmp_ans[i]=="s":
                max_ans-=R
            if tmp_ans[i]=="p":
                max_ans-=S
            if tmp_ans[i]=="r":
                max_ans-=P
            s=tmp_ans[:]
            tmp_ans = s[:i+1] + 'X' + s[i+2:]

print(max_ans)
    
    


### FIXED CODE ###

N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
A=[]
for x in T:
    if x == 's':
        A.append('r')
    if x == 'p':
        A.append('s')
    if x == 'r':
        A.append('p')
 
for i in range(K,N):
    if A[i-K] == A[i]:
        A[i] = 'x'
 
ans = 0
for x in A:
    if x == 's':
        ans += S
    if x == 'p':
        ans += P
    if x == 'r':
        ans += R
print(ans)
### BUGGY CODE ###

N=int(input())
p=list(map(float,input().split()))

DP=[[0]*(N+1) for _ in range(N)]

DP[0][0]=1-p[0]
DP[0][1]=p[0]
for i in range(1,N):
    for j in range(i+2):
        if j==0:
            DP[i][j]=DP[i-1][j]*(1-p[i])
        else:
            DP[i][j]=DP[i-1][j-1]*p[i]+DP[i-1][j]*(1-p[i])
ans=sum(DP[N-1][(N+1)//2:])

print(ans)

### FIXED CODE ###

N=int(input())
p=list(map(float,input().split()))

DP=[[0]*(N+1) for _ in range(N)]

DP[0][0]=1-p[0]
DP[0][1]=p[0]
for i in range(1,N):
    for j in range(i+2):
        if j==0:
            DP[i][j]=DP[i-1][j]*(1-p[i])
        else:
            DP[i][j]=DP[i-1][j-1]*p[i]+DP[i-1][j]*(1-p[i])
ans=sum(DP[N-1][(N+1)//2:])

print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def compare(x):
  return x[0]


def find(x, lst):
  for value in lst:
    if value[0] == x:
      return True
  return False


n = int(input())
lst = [[0, 0, 0]]
for i in range(n):
  lst.append(list(map(int, input().split())))
lst.sort(key=compare)
x = lst[len(lst) - 1][0]
for i in range(1, x):
  if not find(i, lst):
    lst.append([i, -1, -1])
lst.sort(key=compare)

points = [[0, 0]]
flg = False
try:
  for i in range(1, x + 1):
    fix = False
    wk = []
    for point in points:
      wk.append((point[0] + 1, point[1]))
      wk.append((point[0] - 1, point[1]))
      wk.append((point[0], point[1] + 1))
      wk.append((point[0], point[1] - 1))

      ps = (lst[i][1], lst[i][2])
      x = point[0]
      y = point[1]
      if (i == lst[i][0]) and (x >= 0) and (y >= 0) and ((x + 1, y) == ps or (x - 1, y) == ps or (x, y + 1) == ps or (x, y - 1) == ps):
        flg = True
        wk = [ps]
        break
    points = list(set(wk))
    if (i == lst[i][0]) and (lst[i][1] >= 0) and (not flg):
      break
finally:
  print('Yes') if flg else print('No')


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
points = []
for i in range(n):
  points.append(list(map(int, input().split())))

flg = False
for point in points:
  flg = (point[0] >= (point[1] + point[2])) and ((point[0] % 2 == 1) and ((point[1] + point[2]) % 2 == 1) or (point[0] % 2 == 0) and ((point[1] + point[2]) % 2 == 0))
  if not flg:
    break
print('Yes') if flg else print('No')
### BUGGY CODE ###

import sys
input  = sys.stdin.readline

S = input()
N = len(S)

while True:
  n = len(S)
  S = S.replace('10','')
  S = S.replace('01','')
  if n == len(S):
    break
print(N-len(S))


### FIXED CODE ###

S = input()

c0=0
c1=0
for i in S:
  if i == '0':
    c0+=1
  else:
    c1+=1

print(2*min(c0,c1))