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

from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
checked=[[0 for i in range(W)] for m in range(H)]

count=0
for h1 in range(H):
    for w1 in range(W):
        if S[h1][w1]=="#" and checked[h1][w1]==0:
            visited=[[0 for i in range(W)] for m in range(H)]
            checked[h1][w1]=1
            stack=deque([[h1,w1,"#"]])
            kuro=1
            siro=0
            while stack:
                h,w,iro=stack.popleft()
                for y,x in [[-1,0],[1,0],[0,1],[0,-1]]:
                    Y,X=y+h,x+w
                    if 0<=Y<H and 0<=X<W and visited[Y][X]==0:
                        if iro=="#" and S[Y][X]==".":
                            siro+=1
                            visited[Y][X]=1
                            stack.append([Y,X,"."])
                        elif iro=="." and S[Y][X]=="#" and checked[Y][X]==0:
                            kuro+=1
                            visited[Y][X]=1
                            checked[Y][X]=1
                            stack.append([Y,X,"#"])
            count+=kuro*siro
print(count)


### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
checked=[[0 for i in range(W)] for m in range(H)]

count=0
count2=0
for h1 in range(H):
    for w1 in range(W):
        if S[h1][w1]=="#" and checked[h1][w1]==0:
            checked[h1][w1]=1
            stack=deque([[h1,w1,"#"]])
            kuro=1
            siro=0
            count2+=1
            visited=set([h1*400+w1])
            while stack:
                h,w,iro=stack.popleft()
                for y,x in [[-1,0],[1,0],[0,1],[0,-1]]:
                    Y,X=y+h,x+w
                    visitednum=Y*400+X
                    if 0<=Y<H and 0<=X<W and not visitednum in visited:
                        if iro=="#" and S[Y][X]==".":
                            siro+=1
                            visited.add(visitednum)
                            stack.append([Y,X,"."])
                        elif iro=="." and S[Y][X]=="#" and not visitednum in visited:
                            kuro+=1
                            checked[Y][X]=1
                            visited.add(visitednum)
                            stack.append([Y,X,"#"])
            count+=kuro*siro
print(count)
### BUGGY CODE ###

import numpy as np

N = int(input())

A = list(map(int, input().split()))
X = np.zeros(N+1, dtype='int64')

for i in range(1,N+1): # 1 から N まで
    X[i] = X[i-1] + A[i-1]

ans = 0
for l in range(1,N+1): # 1 から N まで
    for r in range(l,N+1): # l から N まで
        if X[r] - X[l-1] == 0: ans += 1
print(ans)

### FIXED CODE ###

import numpy as np

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

S = np.zeros(N+1, dtype='int64') # 累積和
D = {0: 1} # ディクショナリ（連想配列） 各値が何回出てくるか
for i in range(1,N+1): # 1 から N まで
    S[i] = S[i-1] + A[i-1]
    if S[i] in D: D[S[i]] += 1
    else: D[S[i]] = 1

ans = 0
for i in D:
    ans += int(D[i]*(D[i]-1)/2) # 同じ値を2つ選ぶ選び方
print(ans)
### BUGGY CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]
dist = [[-1]*W for _ in range(H)]

Q = []
cnt = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            Q.append([i, j])
            dist[i][j] = 0
            cnt += 1

DX = [-1, 1, 0, 0]
DY = [0, 0, -1, 1]
d = 0
# for _ in range(5):
while cnt < H*W:
    d += 1
    tmp = []
    #print("d->", d)
    # print(Q)
    # print(dist)
    # print(cnt)
    # print("-------")
    while Q:
        x, y = Q.pop(0)
        for dx, dy in zip(DX, DY):
            nx = x+dx
            ny = y+dy
            if 0 <= nx < H and 0 <= ny < W:
                if grid[nx][ny] == "." and dist[nx][ny] == -1:
                    dist[nx][ny] = d+1
                    tmp.append([nx, ny])
                    cnt += 1
            else:
                continue
    Q = tmp
# print(dist)
print(d)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

Q = []
cnt = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            Q.append([i, j])
            cnt += 1

DX = [-1, 1, 0, 0]
DY = [0, 0, -1, 1]
d = 0
# for _ in range(5):
while cnt < H*W:
    d += 1
    tmp = []
    #print("d->", d)
    # print(Q)
    # print(dist)
    # print(cnt)
    # print("-------")
    for x, y in Q:
        for dx, dy in zip(DX, DY):
            nx = x+dx
            ny = y+dy
            if 0 <= nx < H and 0 <= ny < W:
                if grid[nx][ny] == ".":
                    grid[nx][ny] = "#"
                    tmp.append([nx, ny])
                    cnt += 1
            else:
                continue
    Q = tmp
# print(dist)
print(d)
### BUGGY CODE ###

H, W, M = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(M)]

Y = [0] * H
X = [0] * W

for i in range(M):
    y, x = S[i]
    y, x = y-1, x-1
    Y[y] += 1
    X[x] += 1

YM = max(Y)
XM = max(X)

YI = []
for i in range(H):
    if Y[i] == YM:
        YI.append(i)

XI = []
for i in range(W):
    if X[i] == XM:
        XI.append(i)

for y in YI:
    for x in XI:
        if (y+1, x+1) not in S:
            print(YM+XM)
            exit()
else:
    print(YM+XM-1)

### FIXED CODE ###

H, W, M = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(M)]
ss = set(S)

Y = [0] * H
X = [0] * W

for i in range(M):
    y, x = S[i]
    y, x = y-1, x-1
    Y[y] += 1
    X[x] += 1

YM = max(Y)
XM = max(X)

YI = []
for i in range(H):
    if Y[i] == YM:
        YI.append(i)

XI = []
for i in range(W):
    if X[i] == XM:
        XI.append(i)

for y in YI:
    for x in XI:
        if (y+1, x+1) not in ss:
            print(YM+XM)
            exit()
else:
    print(YM+XM-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
l = IL()

dp = [0]*N
dp[1] = abs(l[0]-l[1])

for i in range(2,N):
  num = int(10e10)
  for j in range(1,K+1):
    if i-j < 0:
      dp[i] = num
      break
    else:
      tmp = dp[i-j]+abs(l[i]-l[i-j])
      num = min(tmp,num)
  dp[i] = num

print(dp[N-1])

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
l = np.array(IL())

dp = np.zeros(N,dtype=int)
dp[0] = 0

for i in range(1,N):
    if i-K < 0:
        dp[i] = np.min(dp[:i]+np.abs(l[i]-l[:i]))
    elif i-K >= 0:
        dp[i] = np.min(dp[i-K:i]+np.abs(l[i]-l[i-K:i]))

print(dp[-1])
### BUGGY CODE ###

x,y,z,k = map(int,input().split())
lia = sorted(list(map(int,input().split())),reverse = True)
lib = sorted(list(map(int,input().split())),reverse = True)
lic = sorted(list(map(int,input().split())),reverse = True)
li = []

for s in range(x):
    for t in range(y):
        for u in range(z):
            if s*t*u <= k:
                li.append(lia[s]+lib[t]+lic[u])
ans = sorted(li,reverse = True)[:k]

print('\n'.join(map(str,ans)))


### FIXED CODE ###

def main():
    x,y,z,k = map(int,input().split())
    lia = sorted(list(map(int,input().split())))
    lib = sorted(list(map(int,input().split())))
    lic = sorted(list(map(int,input().split())))

    li2 = sorted(list(a+b for a in lia for b in lib),reverse = True)[:k]
    li3 = sorted(list(ab + c for ab in li2 for c in lic),reverse = True)[:k]

    print('\n'.join(map(str,li3)))

main()
### BUGGY CODE ###

N = int(input())

A = [list(map(int, input().split())) for _ in range(N)]

cnt = [0] * N

S = []
for i in range(N):
  t = A[i][cnt[i]] - 1
  if i == A[t][cnt[t]] - 1:
    if cnt[i] != N - 2:
      S.append(i)

ans = 1
while S:
  ans += 1
  L = [True] * N
  for i in S:
    cnt[i] += 1
  T = []
  for i in S:
    if L[i]:
      t = A[i][cnt[i]] - 1
      if i == A[t][cnt[t]] - 1:
        if cnt[i] != N - 2:
          L[i] = False
          T.append(i)
        if L[t]:
          L[t] = False
          if cnt[t] != N - 2:
            T.append(t)
  S = T

for i in range(N):
  if cnt[i] != N - 2:
    print(-1)
    break
else:
  print(ans)


### FIXED CODE ###

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]    

cnt = [0] * N

S = []
for i in range(N):
  t = A[i][cnt[i]] - 1
  if i == A[t][cnt[t]] - 1:
    if cnt[i] != N - 2:
      S.append(i)

ans = 1
L = [True] * N
while S:
  ans += 1
  for i in S:
    cnt[i] += 1
    L[i] = True
  T = []
  for i in S:
    if L[i]:
      t = A[i][cnt[i]] - 1
      if i == A[t][cnt[t]] - 1:
        if cnt[i] != N - 2:
          L[i] = False
          T.append(i)
        if L[t]:
          L[t] = False
          if cnt[t] != N - 2:
            T.append(t)
  S = T

for i in range(N):
  if cnt[i] != N - 2:
    print(-1)
    break
else:
  print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
L= sorted(list(map(int, input().split())))
L = np.array(L)

def find_nearest(array, value):
  idx = (np.abs(array-value)).argmin()
  return idx

count = 0
for i in range(N):
  for j in range(i + 1, N):
    x = L[i] + L [j]
    y = find_nearest(L, x)
    #print(y, j)
    if L[y] < x:
      if y - j > 0:
        count += y - j
    else:
      if y - j > 1:
        count += y - j - 1

print(count)


### FIXED CODE ###

N = int(input())
L= sorted(list(map(int, input().split())))

count = 0
for i in range(N):
  z = 0
  for j in range(i + 1, N):
    x = L[i] + L[j]
    if z < N:
      while L[z] < x:
        z += 1
        if z == N:
          break
    count += z - j - 1
    #print(count)
print(count)
### BUGGY CODE ###

import math
import fractions

N=int(input())
t,a=1,1
for i in range(N):
    T,A=map(int,input().split())
    Te,Ae=T,A
    if t>T or a>A:
        T,A=T*math.ceil((t+a)/(T+A)),A*math.ceil((t+a)/(T+A))
        while t>T or a>A:
            T+=Te
            A+=Ae
    t,a=T,A

print(t+a)


### FIXED CODE ###

import fractions

N=int(input())
t,a=1,1
for i in range(N):
    T,A=map(int,input().split())
    n=max(-(-a//A),-(-t//T))
    # n=max(fractions.ceil(a/A),fractions.ceil(t/T))
    t,a=n*T,n*A

print(t+a)
### BUGGY CODE ###

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

def search(xs, i=0, m=0):
    if len(xs) == 0:
        if i==A*m and m>0:
            return 1
        else:
            return 0
    else:
        return search(xs[1:], i+xs[0], m+1)  + search(xs[1:], i, m)


print(search(xs))

### FIXED CODE ###

import numpy as np

N, A = map(int, input().split())
xs = np.array(list(map(int, input().split()))) - A

dp = np.zeros((50*50*2+1, N+1), dtype=np.int64)
dp[50*50,0] = 1

for i, x in enumerate(xs):
    dp[:,i+1] = dp[:,i]
    dp[max(0,x):min(len(dp),len(dp)+x),i+1] += dp[max(0,-x):min(len(dp),len(dp)-x),i]

print(dp[50*50,N]-1)
### BUGGY CODE ###

num_limit = int(input())
for i in range(1,num_limit+1):
    xyz_count = 0
    j_limit = int(i ** 0.5)
    for j in range(1,j_limit+1):
        for k in range(1,j + 1):
            if i <= j**2 + k**2 + j*k + j + k:
                break
            for l in range(1,k+1):
                if i < j**2 + k**2 + l**2 + j*k + k*l + l*j:
                    break
                elif i == j**2 + k**2 + l**2 + j*k + k*l + l*j:
                    if j > k:
                        if k > l:
                            xyz_count += 6
                        else:
                            xyz_count += 3
                    elif k > l:
                        xyz_count += 3
                    else:
                        xyz_count += 1
    print(xyz_count)

### FIXED CODE ###

num_limit = int(input())
num_list = [0] * num_limit
j_limit = int(num_limit ** 0.5)
for j in range(1,j_limit+1):
    for k in range(1,j + 1):
        for l in range(1,k+1):
            if num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j:
                if j > k:
                    if k > l:
                        num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6
                    else:
                        num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
                elif k > l:
                    num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
                else:
                    num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1
for i in num_list:
    print(i)
### BUGGY CODE ###

N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
A.extend(A)
odds = [s for s in range(N) if s%2 ==0]
Ans=[]
for i in range(N):
    sum_i=0
    for odd in odds:
        sum_i += A[i+odd] 
    Ans.append( 2*sum_i -S )    
print(" ".join(map(str,Ans) ))

### FIXED CODE ###

N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
odds = range(0,N,2)
Ans=[]
Ans.append(-S + 2*sum([s for s,num in zip(A, range(N)) if num in odds] ) )
for i in range(1,N):
    Ans.append(2*A[i-1]-Ans[i-1])
print(" ".join(map(str,Ans) ))
### BUGGY CODE ###

n,m = map(int,input().split())
l = m//n
for i in range(l,-1,-1):
  if m % i == 0:
    print(i)
    break

### FIXED CODE ###

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

m = M
f = {}
while m%2 == 0:
    f[2] = f.get(2,0) + 1
    m = m//2

k = 3
l = int(m**0.5)+1
while m != 1:
    if k > l:
        f[m] = f.get(m,0)+1
        break
    while m%k == 0:
        f[k] = f.get(k,0)+1
        m = m//k
    k += 2
C=[1]
for k in f:
    C_tmp = []
    for c in C:
        for i in range(f[k]):
            C_tmp.append(c*(k**(i+1)))
    C.extend(C_tmp)
ans_r = M
for c in C:
    if c>=N and c<ans_r:
        ans_r = c
print(M//ans_r)
### BUGGY CODE ###

n, q = list(map(int, input().split()))
count = (n - 2) ** 2
c = [n] * n
r = [n] * n
for _ in range(q):
  m,q = list(map(int, input().split()))
  if m == 1:
    pos = r[q-1]
    c[:pos] = [min(q, v) for v in c[:pos]] 
    r[q-1] = 1
    if q not in [1,n]:
    	count -= max(0, pos - 2)
  else:
    pos = c[q-1]
    r[:pos] = [min(q, v) for v in r[:pos]]
    c[q-1] = 1
    if q not in [1,n]:
   		count -= max(0, pos-2)
print(count)

### FIXED CODE ###

import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


n, q = list(map(int, input().split()))
count = (n - 2) ** 2
c = [n] * (n + 1)
r = [n] * (n + 1)
mc = n
mr = n
for _ in range(q):
    m,q = list(map(int, input().split()))
    if m == 1:
        if q <= mc:
            count -= mr -2
            for p in range(q+1, mc):
                c[p] = mr
            c[q] = 0
            mc = q
        else:
            count -= c[q] - 2
    else:
        if q <= mr:
            count -= mc -2
            for p in range(q+1, mr):
                r[p] = mc
            r[q] = 0
            mr = q
        else:
            count -= r[q] - 2
print(count)
### BUGGY CODE ###

from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

@lru_cache(maxsize=1000000)
def dp(rest,score):
    ansbox=[]
    scorebox=[]
    for i in m_list:
        if (rest-i)>0:
            ansbox.append(dp(rest-i,score+1))
            scorebox.append(dp(rest-i, score+1)[1])
    if ansbox:
        max_index=scorebox.index(max(scorebox))
        return ansbox[max_index][0],ansbox[max_index][1]
    else:

        return rest,score
    pass

N,X=map(int,input().split())
m_list=[]
newX=X
sum=0
for i in range(N):
    inp=int(input())
    m_list.append(inp)
    newX-=inp

score=dp(newX,N)

print(score[1])


### FIXED CODE ###

N,X=map(int,input().split())
M=[int(input()) for _ in range(N)]
print(len(M)+(X-sum(M))//min(M))
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    """ ????????? """
    num = int(input().strip())
    A = list(map(int,input().split()))
    cnt = 0
    for i in range(num-1):
        for j in range(i,num):
            if A[i] > A[j]:
                cnt+= 1

    print(cnt)

if __name__ == '__main__':
    main()

### FIXED CODE ###

MAX = 1000000001

def merge(A, left, mid, right, cnt):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    R = A[mid:right]
    ls = len(L)
    L.append(MAX)
    R.append(MAX)
    
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            cnt += ls - i
            j = j + 1
    return cnt

def mergeSort(A, left, right, cnt):
    if left + 1 < right:
        mid = int((left + right) / 2)
        cnt = mergeSort(A, left, mid, cnt)
        cnt = mergeSort(A, mid, right, cnt)
        cnt = merge(A, left, mid, right, cnt)
    return cnt

def main():
    """ ????????? """
    num = int(input().strip())
    A = list(map(int,input().split()))
#    print(A)
    cnt = mergeSort(A, 0, num, 0)
    print(cnt)

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

from collections import Counter
from math import factorial
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
count=0
def combination(x,y):
    return factorial(x) // (factorial(x - y) * factorial(y))
for key,b in B.items():
    if b>=2:
        count+=combination(b,2)
for a in A:
    ans=count
    if B[a]==2:
        ans-=1
    elif B[a]>=3:
        ans+=combination(B[a]-1,2)-combination(B[a],2)
    print(ans)


### FIXED CODE ###

from collections import Counter
from math import factorial
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
count=0
def combination(x,y):
    return factorial(x) // (factorial(x - y) * factorial(y))
for key,b in B.items():
    if b>=2:
        count+=combination(b,2)
for a in A:
    ans=count
    ans-=B[a]-1
    print(ans)
### BUGGY CODE ###

from collections import defaultdict
h, w, m = map(int, input().split())
targets = []
targets_count_yoko = [0]*w
targets_count_tate = [0]*h
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets.append((y, x))

max_row = max(targets_count_yoko)
max_line = max(targets_count_tate)
y_idx = [i for i, v in enumerate(targets_count_tate) if v == max_line]
x_idx = [i for i, v in enumerate(targets_count_yoko) if v == max_row]

ans = max_line + max_row
flag = False
for y in y_idx:
    for x in x_idx:
        if (y, x) not in targets:
            flag = True
            break
    else:
        continue
    break

if flag:
    print(ans)
else:
    print(ans-1)


### FIXED CODE ###

from collections import defaultdict
h, w, m = map(int, input().split())
targets = defaultdict(int)
targets_count_yoko = defaultdict(int)
targets_count_tate = defaultdict(int)
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets[(y, x)] = -1

max_row = max(targets_count_yoko.values())
max_line = max(targets_count_tate.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx[i] = True
        max_count_x += 1
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx[i] = True
        max_count_y += 1


ans = max_line + max_row
kumi = max_count_x*max_count_y
for key_y, key_x in targets.keys():
    if y_idx[key_y] and x_idx[key_x]:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print(ans-1)
else:
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
broken_floors = [int(input()) for _ in range(M)]
dp = [0]*(N+2)
dp[1] = 1

for i in range(1, N+1):
    if i not in broken_floors:
        dp[i+1] = (dp[i] + dp[i-1]) % MOD

print(dp[-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
broken_floors = set(int(input()) for _ in range(M))
dp = [0]*(N+2)
dp[1] = 1

for i in range(1, N+1):
    if i not in broken_floors:
        dp[i+1] = (dp[i] + dp[i-1]) % MOD

print(dp[-1])
### BUGGY CODE ###

N,Q = map(int, input().split())
S = input()
A = [0]*N
L = []
R = []
for _ in range(Q):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)
for i in range(N-1):
    if S[i] == "A" and S[i+1] =="C":
        A[i+1] += 1

for a,b in zip(L,R):
    print(sum(A[:b])-sum(A[:a]))

### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
A = [0]*N


for i in range(1, N):
    if S[i-1] == "A" and S[i] =="C":
        A[i] = A[i-1]+1
    else:
        A[i] = A[i-1]

for i in range(Q):
    a, b = map(int, input().split())
    print(A[b-1] - A[a-1])
### BUGGY CODE ###

from collections import deque

s = input()
q = int(input())
query = [input().split() for i in range(q)]

d = deque(['S'])

#d = ['S']

rev = 0

for i in range(q):
    if query[i][0] == '2':
        if query[i][1] == '1':
            d.appendleft(query[i][2])
        else:
            d.append(query[i][2])
    else:
        d.reverse()
        rev += 1

ans = deque()

if rev % 2 == 1:
    #s = ''.join(list(reversed(s)))
    s = s[::-1]

while len(d):
    tmp = d.popleft()
    if tmp == 'S':
        ans.append(s)
    else:
        ans.append(tmp)

print(*ans,sep='')


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())
query = [input().split() for i in range(q)]

d = deque(['S'])

#d = ['S']

rev = False

for i in range(q):
    if query[i][0] == '1':
        rev = not rev
        continue
    
    if not rev:
        if query[i][0] == '2':
            if query[i][1] == '1':
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
    else:
        if query[i][0] == '2':
            if query[i][1] == '1':
                d.append(query[i][2])
            else:
                d.appendleft(query[i][2])

#ans = deque()
if rev:
    #d = ''.join(list(reversed(d)))
    s = s[::-1]



while len(d):
    if rev:
        tmp = d.pop()
    else:
        tmp = d.popleft()
    if tmp == 'S':
        #ans.append(s)
        print(s,end='')
    else:
        print(tmp,end='')
        #ans.append(tmp)

#print(*ans,sep='')
### BUGGY CODE ###

N = int(input())
ans = N
pred = N
for i in range(1, N//2):
    d = 0
    if N % i == 0:
        d = max(len(str(i)), len(str(N//i)))
        ans = min(ans, d)
        if d > pred:
            break
        pred = d
print(ans)

### FIXED CODE ###

N = int(input())
ans = N
for i in range(1, N):
    if i**2 > N:
        break
    d = 0
    if N % i == 0:
        d = max(len(str(i)), len(str(N//i)))
        ans = min(ans, d)
print(ans)
### BUGGY CODE ###

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

c.sort()

ans = 10**9
for i in range(n-k+1):
    ls = c[i:k+i]
    ans = min(ans,max(ls)-min(ls))

print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
c = [int(input()) for _ in range(n)]
c.sort()
ans = []
for i in range(n-k+1):
    ans.append(c[i+k-1]-c[i])
print(min(ans))
### BUGGY CODE ###

S = input()
len_ini_S = len(S)

S = S.replace('01','').replace('10','')
len_rep_S = len(S)
tmp_len_rep_S = len_rep_S

while True:
  S = S.replace('01','').replace('10','')
  len_rep_S = len(S)
  if tmp_len_rep_S == len_rep_S:
    break
  else:
    tmp_len_rep_S = len_rep_S
    

print(len_ini_S - len_rep_S)

### FIXED CODE ###

s_list = [int(s) for s in input()]

if s_list.count(0) < s_list.count(1):
  print(s_list.count(0) * 2)
else:
  print(s_list.count(1) * 2)