Harryxun/stf_run huggingface dataset:
# https://atcoder.jp/contests/abc176/submissions/16164430?lang=ja
import heapq

h, w = map(int, input().split())
sh, sw = map(lambda x: int(x) - 1, input().split())
gh, gw = map(lambda x: int(x) - 1, input().split())
S = [input() for i in range(h)]

inf = 10 ** 10
D = [[inf] * w for i in range(h)]

D[sh][sw] = 0
Q = [(0, (sh, sw))]
heapq.heapify(Q)
while Q:
  curr_h, curr_w = heapq.heappop(Q)
  for di in range(-2, 3):
    for dj in range(-2, 3):
      next_h, next_w = curr_h + di, curr_w + dj
      if 0 <= next_h < h and 0 <= next_w < w and S[next_h][next_w] == ".":
        nex = int(abs(di) + abs(dj) != 1)
        if D[next_h][next_w] > D[curr_h][curr_w] + nex:
          D[next_h][next_w] = D[curr_h][curr_w] + nex
          heapq.heappush(Q, (next_h, next_w))
if D[gh][gw] >= inf:
  print(-1)
else:
  print(D[gh][gw])


### FIXED CODE ###

# https://atcoder.jp/contests/abc176/submissions/16164430?lang=ja
import heapq

h, w = map(int, input().split())
sh, sw = map(lambda x: int(x) - 1, input().split())
gh, gw = map(lambda x: int(x) - 1, input().split())
S = [input() for i in range(h)]

inf = 10 ** 10
D = [[inf] * w for i in range(h)]

D[sh][sw] = 0
Q = [(0, (sh, sw))]
heapq.heapify(Q)
while Q:
  _, (curr_h, curr_w) = heapq.heappop(Q)
  for di in range(-2, 3):
    for dj in range(-2, 3):
      next_h, next_w = curr_h + di, curr_w + dj
      if 0 <= next_h < h and 0 <= next_w < w and S[next_h][next_w] == ".":
        nex = int(abs(di) + abs(dj) != 1)
        if D[next_h][next_w] > D[curr_h][curr_w] + nex:
          D[next_h][next_w] = D[curr_h][curr_w] + nex
          heapq.heappush(Q, (D[next_h][next_w], (next_h, next_w)))
if D[gh][gw] >= inf:
  print(-1)
else:
  print(D[gh][gw])
import math

n,d = map(str,input().split())
answer = 0
for i in range(n):
  x,y = map(str,input().split())
  if math.sqrt(x**2 + y**2) <= d:
    answer += 1
    
print(answer)

### FIXED CODE ###

import math
 
n,d = map(int,input().split())
answer = 0
for i in range(n):
  x,y = map(int,input().split())
  if math.sqrt(x**2 + y**2) <= d:
    answer += 1
    
print(answer)
def choose2(number):
	if number>=2:
		return (number*(number-1))/2
	else:
		return 0
N = int(input())
k = list(map(int,input().split()))
valArr = list(set(k))
occurence = []
occurenceIndex = []
for i in range(N):
	occurence.append(0)
for j in range(N):
	occurence[k[j]]+=1
	
			
'''6*5/2
5*4/2
N*(N-1)/2
(N-2)*(N-1)/2
N*(N-1)/2*(N-2)/N
occurence = [1,2,3]
ans = 0+2*1/2+3*2/2
k val = 3
correct = 0+2*1/2+2*1/2

'''
ans = 0
for time in range(len(occurence)):
	ans+=choose2(occurence[time])
for ball in range(N):
	kans = ans-choose2(occurence[k[ball]])+choose2(occurence[k[ball]]-1)
	
	print(int(kans))


### FIXED CODE ###

def choose2(number):
	if number>=2:
		return (number*(number-1))/2
	else:
		return 0
N = int(input())
k = list(map(int,input().split()))
valArr = list(set(k))
occurence = []
occurenceIndex = []
mx = 0
for l in k:
	if l>mx:
		mx=l
for i in range(mx+1):
	occurence.append(0)
for j in range(N):
	occurence[k[j]]+=1
	
			
'''6*5/2
5*4/2
N*(N-1)/2
(N-2)*(N-1)/2
N*(N-1)/2*(N-2)/N
occurence = [1,2,3]
ans = 0+2*1/2+3*2/2
k val = 3
correct = 0+2*1/2+2*1/2

'''
ans = 0
for time in range(len(occurence)):
	ans+=choose2(occurence[time])
for ball in range(N):
	kans = ans-choose2(occurence[k[ball]])+choose2(occurence[k[ball]]-1)
	
	print(int(kans))
N,A = map(int,input().split())
print((N*N)-A)

### FIXED CODE ###

N = int(input())
A = int(input())
print(N*N - A)
import sys
K,S = map(int,input().split())
if K < 2 or K > 2500:
  sys.exit()
if X > K or Y > K or Z > K:
  sys.exit()

X = 0
count = 0
while X <= K:
  Y = 0
  while Y <= K:
    Z = 0
    while Z <= K:
      if X + Y + Z == S:
        count += 1
      Z += 1
    Y += 1
  X += 1
print(count)

### FIXED CODE ###

import sys
import re
#X = list(map(str,input().split()))
X = str(input())
print(re.sub(',',' ',X))
a,b,c = map(int,input().split())
print(len(set(a,b,c)))

### FIXED CODE ###

a,b,c = map(int,input().split())
print(len(set([a,b,c])))
N, M = map(int, input().split())

A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

DP = [-1]*(N+1)
DP[0] = 0 

for i in range(N):
    for j in A:
        if i+B[j] <= N:
            DP[i+B[j]] = max(DP[i]*10+j, DP[i+B[j]])

print(DP[N+1]) 

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1]*(N+1)
dp[0]=0  
for i in range(N+1):
    for j in A:
        if i + B[j] <= N:
            dp[i+B[j]]= max(dp[i]*10+j, dp[i+B[j]])
print(dp[N])
n=int(input())
ans=0

def f(n):
    if n<2:
        return 1
    else:
        return n*f(n-2)

a=f(n)
while a%10==0:
    a=a/10
    ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
ans=0
keta=10

def count_2(num):
    return format(num, 'b')[::-1].find('1')

if n%2==1:
    print(0)
else:
    while n//keta!=0:
        ans+=n//keta
        keta*=5
    print(ans)
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
 
c1 = Counter(a[::2])
c2 = Counter(a[1::2])
c1f1 = max(c1, key = lambda k:c1[k])
c2f1 = max(c2, key = lambda k:c2[k])
 
if c1f1 != c2f1:
  return n - c1[c1f1] - c2[c2f1]
else:
  if c1[c1f1] > c2[c2f1]:
    del c2[c2f1]
    if not c2: return n-c1[c1f1]
    c2f1 = max(c2, key = lambda k:c2[k])
    return n-c1[c1f1] - c2[c2f1]
  else:
    del c1[c1f1]
    if not c1: return n-c2[c2f1]
    c1f1 = max(c1, key = lambda k:c1[k])
    return n-c1[c1f1] - c2[c2f1]

### FIXED CODE ###

from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))
_ = input()
a = input()

a = a.split(" ")
b = []
d = 0
flag = True
for i in a:
    if int(i)%2 == 0:
        b.append(int(i))
    else:
        print(0)
        flag = False
        break
c = min(b)
while c%2 == 0 and flag == True:
    c = c/2
    d += 1
print(d)

### FIXED CODE ###

a = input()

b=0
if a[0] == "1":
   b+=1
if a[1] == "1":
   b+=1
if a[2] == "1":
   b+=1

print(b)
l=list(map(int,input().split()))
a=l[0]
b=l[1]
n=l[2]
x=0
if b-1<n:
  i=b-1
  y=(((a*i)/b)//1)-(a*((i/b)//1))
else:
  i=n
  y=(((a*i)/b)//1)-(a*((i/b)//1))
print(int(x))

### FIXED CODE ###

k=int(input())
l=list(map(int,input().split()))
x=l[0]//k
if(x*k==l[0] or k*(x+1)<=l[1]):
  print("OK")
else:
  print("NG")
import math

x, n = map(int, input().split())
p = list(map(int, input().split()))

p.sort()
pnt_big = 0
pnt_small = 0
for i in range(x+1):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big == pnt_small:
    print(ans_small)
else:
    print(ans_big)

### FIXED CODE ###

import math

x, n = map(int, input().split())
p = list(map(int, input().split()))

pnt_big = 0
pnt_small = 0
ans_big = 100
ans_small = 100
for i in range(101):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big ==1 and pnt_small == 1:
    print(ans_small)
if pnt_big == 0 and pnt_small == 1:
    print(ans_small)
if pnt_big == 1 and pnt_small == 0:
    print(ans_big)
n,m = map(int,input().split())
l = sorted(list(map(int,input().split())))
l.reverse()
yl = [0]*n
r = [-(-l[0]//i) for i in l]
chk = 1
flag = False
while True:
  #group 1
  for i in range(n):
    if r[i] > chk:
        break
    elif r[i] > chk//2 :
        yl[i]+=1
        m-=1
        if m == 0:
            flag = True
        break
  if flag:
     break
  #group 2
  for i in range(n):
    if r[i] > chk//2:
      break
    else:
      yl[i]+=1
      m-=1
      if m == 0:
        flag = True
        break
  if flag:
    break
  chk *= 2
ans = 0
for i,j in zip(l,yl):
  ans += i//(2**j)
print(ans)

### FIXED CODE ###

s = input()
if s == 'Sunny':
  print('Cloudy')
elif s == ('Cloudy'):
  print('Rainy')
else:
  print('Sunny')
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

### FIXED CODE ###

import sys
sys.setrecursionlimit(3000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"
h,w,a,b = map(int, input().split())
if h == 1:
    S = "1"*a+"0"*(w-a)
    print(S)
elif w == 1:
    S = [1]*b+[0]*(h-b)
    for s in S:
        print(s)
elif h >= 2 and w >= 2:
    if b*w != a*h:
        print("No")
        exit()
    else:
        for i in range(h):
            S = ["0"]*w
            init = i//b
            for j in range(a*init,a*(init+1)):
                S[j] = "1"
            print("".join(S))

### FIXED CODE ###

h,w,a,b = map(int, input().split())
if h == 1:
    S = "1"*a+"0"*(w-a)
    print(S)
elif w == 1:
    S = [1]*b+[0]*(h-b)
    for s in S:
        print(s)
elif h >= 2 and w >= 2:
    # if b*w != a*h:
    #     print("No")
    #     exit()
    # else:
    for i in range(h):
        # print(a,i)
        if i < b:
            S = "1"*a + "0"*(w-a)
        else:
            S = "0"*a + "1"*(w-a)
        print(S)
l=[]
n,W=input().split()
n=int(n)
W=int(W)
for i in range(n):
	item=list(map(int,input().split()))
	l.append([item[1],item[0]])

dp=[[False for j in range(W)+1] for i in range(n)]

print(dp)
def solve(i,w):
	if dp[i][w]==False:
		if i==n:
			res=(0)
		elif w-l[i][0]<0:
			res=(solve(i+1,w))
		else:
			a=solve(i+1,w)
			b=l[i][1]+solve(i+1,w-l[i][0])
			if b>a:
				res=(b)
			else:
				res=(a)
		dp[i][w]=res
		return(res)
	else:
		return(dp[i][w])

print(solve(0,W))

### FIXED CODE ###

value=[0]
weight=[0]
n,W=input().split()
n=int(n)
W=int(W)
for i in range(n):
	item=list(map(int,input().split()))
	value.append(item[0])
	weight.append(item[1])

dp=[[0 for j in range(W+1)] for i in range(n+1)]
for i in range(n+1):
	for j in range(W+1):
		if i==0:
			res=0
		elif j-weight[i]<0:
			res=dp[i-1][j]
		else:
			res=max(dp[i-1][j-weight[i]]+value[i],dp[i-1][j])
		dp[i][j]=res
print(dp[n][W])
n,w_max = map(int,input().split())
w = [0]
v = [0]

for _ in range(n):
    W,V = map(int,input().split())
    w.append(W)
    v.append(V)
v_sum = sum(v)
lrg = 10**12
dp = [[lrg]*(v_sum+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
for i in range(1,n+1):
    for u in range(v_sum+1):
        if u>=v[i]:
            dp[i][u] = min(dp[i-1][u-v[i]]+w[i],dp[i-1][u])
        else:###
            dp[i][u] = min(w[i],dp[i-1][u])

ans = []
for u in range(v_sum+1):
    if dp[n][u] <= w_max:
        ans.append(u)
#print(*dp[n])
print(max(ans))


### FIXED CODE ###

n = int(input())
h = list(map(int, input().split( )))
dp =[0,0]

dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    ad0 = abs(h[i]-h[i-1])
    ad1 = abs(h[i]-h[i-2])
    dp.append(min(dp[i-1]+ad0,dp[i-2]+ad1))
print(dp[n-1])
a, p = map(int(), input().split())
print(int((3*a+p)/2))

### FIXED CODE ###

a, p = map(int, input().split())
print(int((3*a+p)/2))
from typing import List, Any, Union


def clear_maze(sx, sy, maze):

    INF=-10**9
    global cnt
    cnt=0


    distance = [[INF for i in range(w+1)] for j in range(h+1)]
    #    distance = [[None]*field_x_length]*field_y_length



    def bfs():
        global cnt
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()



            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))

                    distance[nx][ny] = distance[x][y] + 1
                    if cnt<=distance[nx][ny]:
                        cnt=distance[nx][ny]





        return cnt

    cnt=0
    distance = [[INF for i in range(w + 1)] for j in range(h + 1)]




    return bfs()

h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]
t=[[0]*w for i in range(h)]
for i in range(h):
    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]




ans=0

for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j]=='#':
            continue
        v=(clear_maze(i, j, maze))

        if ans<=v:
            ans=v
print(ans)

### FIXED CODE ###



def clear_maze(sx, sy, maze):

    INF=-10**9
    global cnt
    cnt=0


    distance = [[INF for i in range(w+1)] for j in range(h+1)]
    #    distance = [[None]*field_x_length]*field_y_length



    def bfs():
        global cnt
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()



            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))

                    distance[nx][ny] = distance[x][y] + 1
                    if cnt<=distance[nx][ny]:
                        cnt=distance[nx][ny]





        return cnt

    cnt=0
    distance = [[INF for i in range(w + 1)] for j in range(h + 1)]




    return bfs()

h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]
t=[[0]*w for i in range(h)]
for i in range(h):
    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]




ans=0

for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j]=='#':
            continue
        v=(clear_maze(i, j, maze))

        if ans<=v:
            ans=v
print(ans)
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
def fibo(i):
    c, b = 1, 0
    while i > 0:
        c, b = c + b, c
        i -= 1
    return c
m = a[0] + 1
num = fibo(m - 2)
for i in range(M - 1):
    m = a[i + 1] - a[i]
    if m > 1:
        num = num * fibo(m - 2)
    else:
        num = 0
        break
num = num * fibo(N - a[M - 1] - 1)
print(num % 1000000007)


### FIXED CODE ###

N, M = map(int, input().split())
kaidan = [0] * (N + 1)
for i in range(M):
    tmp = int(input())
    kaidan[tmp] = -1
kaidan[0] = 1
for i in range(1,N + 1):
    if i == 1:
        if kaidan[i] != -1:
            kaidan[i] = 1
        else:
            kaidan[i] = 0
    else:
        if kaidan[i] != -1:
            kaidan[i] = kaidan[i -1] + kaidan[i - 2]
        else:
            kaidan[i] = 0
print(kaidan[N] % (10 ** 9 + 7))
N, K = map(int, input().split())
A = list(map(int, input().split()))

table = {}
init_table = {}
move = {}

for i in range(N):
    if A[i] not in table:
        table[A[i]] = i
        init_table[A[i]] = i
    else:        
        move[table[A[i]]], move[i] = i+1, init_table[A[i]]+1
        table[A[i]] = i

T = K
next_idx = 0
remain = [0]
for i in range(1, K+1):
    while idx in move and idx < move[idx]:
        idx = move[idx]
    remain.append(idx)
    if idx in move:
        idx = move[idx]
    else:
        idx += 1
    if(idx == N and i != K):
        T = K % i
        break

if(T == 0):
    print()
    exit()
idx = remain[T]
ret = []
while idx < len(A):
    while idx in move and idx < move[idx]:
        idx = move[idx]
    if(idx < len(A)):
        ret.append(A[idx])
    idx += 1

print(*ret)



### FIXED CODE ###

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

if n == 1:
    if k % 2:
        print(*arr)
    else:
        print(*[])
    exit()

table = {}
original_table = {}
move = {}

for i, a in enumerate(arr):
    if a not in table:
        table[a] = i
        original_table[a] = i
    else:
        move[table[a]], move[i] = i + 1, original_table[a] + 1
        table[a] = i

res = {}
idx = 0

for i in range(1, k + 1):
    while idx in move and move[idx] > idx:
        idx = move[idx]

    res[i] = idx
    if idx == len(arr):
        k %= len(res)
        if not k:
            k = len(res)
        break

    if idx in move:
        idx = move[idx]
    else:
        idx += 1

idx = res[k]
response = []

while idx < len(arr):
    while idx in move and move[idx] > idx:
        idx = move[idx]
    if idx < len(arr):
        response.append(arr[idx])
    idx += 1

print(*response)
A, B, C, K = map(int, input().split())

l = [1]*A + [0]*B + [-1]*C
ans = sum(l[:K])

print(ans)

### FIXED CODE ###

A, B, C, K = map(int, input().split())

ans = 0
if A > K:
  ans += 1*K
else:
  ans += 1*A
  K = K - A
  if B > K: 
    ans += 0*K
  else:
    ans += 0*B
    K = K - B
    if C > K:
      ans += -1*K
    else:
      ans += -1*C

print(ans)
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n):
    if p[i - 1] < p[i] < p[i + 1]:
        count += 1
print(count)


### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1]:
        count += 1
    elif p[i + 1] < p[i] < p[i - 1]:
        count += 1
print(count)
s=input()
k=int(input())
a=[]
for i in range(0,len(s)):
    for j in range(1,len(s)+1):
        if i != j:
            a.append(s[i:j])
a.remove("")
a=sorted(a)
b=[]
for i in a:
    if i not in b:
        b.append(i)
print(b[k-1])


### FIXED CODE ###

s=input()
k=int(input())
a=[s[i:i+j+1] for i in range(len(s)) for j in range(k+1)]
a=set(a)
a=sorted(a)
print(a[k-1])
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = inputs
    N = 5
    kinds = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
    for n in persons:
        if n[0] in kinds:
            kinds[n[0]] += 1
    kinds_list = list(kinds.keys())

    if len(persons) < 3:
        return 0

    pattern = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                p1 = kinds_list[i]
                p2 = kinds_list[j]
                p3 = kinds_list[k]
                pattern += kinds[p1] * kinds[p2] * kinds[p3]
    return pattern


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(5))
    print(ret)


### FIXED CODE ###

import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = inputs
    N = 5
    kinds = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
    for n in persons:
        if n[0] in kinds:
            kinds[n[0]] += 1
    kinds_list = list(kinds.keys())

    if len(persons) < 3:
        return 0

    pattern = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                p1 = kinds_list[i]
                p2 = kinds_list[j]
                p3 = kinds_list[k]
                pattern += kinds[p1] * kinds[p2] * kinds[p3]
    return pattern


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)
n,m = map(int,input().split())
data = []
G = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    data.append((a-1,b-1))
    G[a].append(b)
    G[b].append(a)

def dfs(v,seen):
    if seen[v]: return
    seen[v] = True
    for nv in G[v]:
        dfs(nv,seen)

cnt = 0

for i in range(m):
    ra,rb = data[i]
    G[ra].remove(rb)
    G[rb].remove(ra)
    seen = [False]*n
    cnt += (sum(seen) == n)
    G[a].append(b)
    G[b].append(a)

print(cnt)

### FIXED CODE ###

n,m = map(int,input().split())
data = []
G = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    data.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)

def dfs(v,seen):
    if seen[v]: return
    seen[v] = True
    for nv in G[v]:
        dfs(nv,seen)

cnt = 0

for i in range(m):
    ra,rb = data[i]
    G[ra].remove(rb)
    G[rb].remove(ra)
    seen = [False]*n
    dfs(0,seen)
    cnt += (sum(seen) != n)
    G[ra].append(rb)
    G[rb].append(ra)

print(cnt)
import sys
while True:
    x = sys.stdin.readline.strip()
    if x == "0":
        break
    print("Case %d: %s"%(i, x))
    i += 1

### FIXED CODE ###

import sys
i = 1
while True:
    x = sys.stdin.readline().strip()
    if x == "0":
        break
    print("Case %d: %s"%(i, x))
    i += 1
n,l=map(int,input().split())
s =[]
for _ in range(n):
    t = input()
    s +=[t]

def dic(a,b):
    for i in range(l):
        if ord(a[i])<ord(b[i]):
            c =0
            break
        if ord(b[i])<ord(a[i]):
            c =1
            break
    return c

for i in range(1,n):
    for j in range(i):
        j = i - j
        if dic(s[j-1],s[j]):
            s[j],s[j-1]=s[j-1],s[j]
        else:
            break       

ans =""
for x in s:
    ans +=x

print(ans) 


### FIXED CODE ###

n,l=map(int,input().split())
s =[]
for _ in range(n):
    t = input()
    s +=[t]

s.sort()

ans =""
for x in s:
    ans +=x

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

if sum(A) < sum(B) : 
    print(-1)
else :
    diff=[A[i] - B[i] for i in range(len(A))]
    pos=sorted([x for x in diff if x > 0])
    neg=[x for x in diff if x < 0]
    nes=sum(neg)
    if nes >= 0 :
        print(0)
    else:
        items = 0
        total_pos = 0
        for p in reversed(pos):
            items += 1
            total_pos += p
            if(total_pos + nes >= 0) :
                print(items + len(neg))
                break


### FIXED CODE ###

print("YES" if "".join(sorted(input().split())) == "1479" else "NO")
b = input()
if b == "T":
  print "A"
elif b == "A":
  print "T"
elif b == "G":
  print "C"
else:
  print "G"

### FIXED CODE ###

b = input()
if b == "T":
  print ("A")
elif b == "A":
  print ("T")
elif b == ("G"):
  print ("C")
else:
  print ("G")
import sys


S_raw = sys.stdin.readline().strip()

def check_next(S):
    S = list(S)
    before_num=S[0]
    for i in range(len(S)):
        if S[i]!=before_num:
            S.pop(i-1)
            #S = list(S)
            S.pop(i-1)
            new_S = S
            return S,1
            break
    return S,0


cnt=0
N=0

while cnt<50000:
    S_raw, check_cnt = check_next(S_raw)
    N += check_cnt
    if check_cnt==0:
        break
    cnt+=1
    
print(N*2)

### FIXED CODE ###

S = input()

num0 = S.count("0")
num1 = len(S)-num0

print(min(num0,num1)*2)