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

N = int(input())

num=0

li = [i+1 for i in range(N)]

l4 = list(map(lambda x: str(x)[0]+str(x)[-1], li))
l5 = list(map(lambda x: str(x)[-1]+str(x)[0], li))

for l in l4:
  num += l5.count(l)
print(num)

### FIXED CODE ###

import collections
N = int(input())

num=0

li = [i+1 for i in range(N)]

l4 = list(map(lambda x: str(x)[0]+str(x)[-1], li))
ll = set(l4)
l5 = list(map(lambda x: str(x)[-1]+str(x)[0], li))
c4 = collections.Counter(l4)
c5 = collections.Counter(l5)

for l in ll:
  num += c4[l] * c5[l]
print(num)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            # print(x,y,z)
            count += 1

print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            count += 1

print(count)
### BUGGY CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, K = map(int, input().split())
h = list(map(int, input().split()))
#= [input(), input()]

dp = [0] * N

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

for i in range(2, N):
    t = dp[i - 1] + abs(h[i] - h[i - 1])
    for j in range(2, min(K + 1, i + 1)):
        tt = dp[i - j] + abs(h[i] - h[i - j])
        t = min(t, tt)

    dp[i] = t

print(dp[-1])
        

### FIXED CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, K = map(int, input().split())
h = list(map(int, input().split()))
#= [input(), input()]

dp = [0] * N

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

for i in range(2, N):
    t = dp[i - 1] + abs(h[i] - h[i - 1])
    for j in range(2, min(K + 1, i + 1)):
        tt = dp[i - j] + abs(h[i] - h[i - j])
        t = min(t, tt)

    dp[i] = t

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

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

for i in range(K):
  if i < A:
  	sum = sum + 1
  if A+B <= i < A+B+C:
  	sum = sum - 1
  
print(sum)


### FIXED CODE ###

A,B,C,K = map(int, input().split())
sum = 0
x = K - A
if x > 0:
	sum += A
else:
	sum += K
x = x - B
if x > 0 :
	sum -= x
print(sum)
### BUGGY CODE ###

import math
N = 10**9+7
n = int(input())
a = list(map(int,input().split()))

ans = 0

for i in range(61):
    sum=0
    for j in range(n):
        sum+=(a[j]>>i) & 1
    ans+=sum*(n-sum)*pow(2,i,N)
    ans%=10**9+7
print(ans)


### FIXED CODE ###

import numpy as np
N = 10**9+7
n = int(input())
a = np.array(input().split(), np.int64)

ans = 0

po = 1
for i in range(61):
    bit = (a>>i) & 1
    s=np.count_nonzero(bit)
    ans+=s*(n-s)%N*po
    ans%=N
    po*=2
    po%=N
print(ans)
### BUGGY CODE ###


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

dp = [0] * (n+1)
for i in range(n+1):
     if i in a:
          continue
     elif i == 0 or i == 1:
          dp[i] = 1
     else:
          dp[i] = (dp[i-1] + dp[i-2])%1000000007
print(dp[n])

### FIXED CODE ###

n, m = map(int, input().split())
mod = 10**9 + 7
dp = [1]*(n+1)
 
for _ in range(m):
    a = int(input())
    dp[a] = 0
 
for i in range(2, n+1):
    if dp[i]>0:
        dp[i] = (dp[i-1]+dp[i-2])%mod
 
print(dp[n])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
input=sys.stdin.readline

N,M=map(int,input().split())
P=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(a):
    if a==P[a]:
        return a
    else:
        return find(P[a])
        
def union(b,c):
    B=find(b)
    C=find(c)
    if size[B]<size[C]:
        P[B]=P[C]
        size[C]=size[B]
    else:
        P[C]=P[B]
        size[B]+=size[C]

for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        P[a]=find(a)
        P[b]=find(b)
        continue
    else:
        union(a,b)
for i in range(N+1):
    P[i]=find(P[i])
#print(P)
D={}
for i in range(1,N+1):
    if P[i] not in D:
        D[P[i]]=1
    else:
        D[P[i]]+=1
ans=0
for k,v in D.items():
    if ans<v:
        ans=v
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
input=sys.stdin.readline

N,M=map(int,input().split())
P=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(a):
    if a==P[a]:
        return a
    else:
        return find(P[a])
        
def union(b,c):
    B=find(b)
    C=find(c)
    if size[B]<size[C]:
        P[B]=P[C]
        size[C]+=size[B]
    else:
        P[C]=P[B]
        size[B]+=size[C]

for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        P[a]=find(a)
        P[b]=find(b)
        continue
    else:
        union(a,b)
for i in range(N+1):
    P[i]=find(P[i])
#print(P)
D={}
for i in range(1,N+1):
    if P[i] not in D:
        D[P[i]]=1
    else:
        D[P[i]]+=1
ans=0
for k,v in D.items():
    if ans<v:
        ans=v
print(ans)
### BUGGY CODE ###


def main():
  s = tuple(map(int, input()[::-1]))

  mod = 2019

  counts = [0] * mod
  counts[0] = 1
  t = 0
  x = 1
  for i in range(len(s)):
    t = t + s[i] * x
    counts[t % mod] += 1
    x = x * 10

  ans = 0
  for count in counts:
    if count > 1:
      ans += count * (count - 1) // 2

  print(ans)

main()


### FIXED CODE ###


def main():
  s = map(int, input()[::-1])

  mod = 2019

  counts = [0] * mod
  counts[0] = 1
  t = 0
  x = 1
  for num in s:
    t = (t + num * x) % mod
    counts[t] += 1
    x = (x * 10) % mod

  ans = 0
  for count in counts:
    if count > 1:
      ans += count * (count - 1) // 2

  print(ans)

main()
### BUGGY CODE ###

n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(n)]
lst=[]
for i in range(8):
    if i&1==1:
        a=1
    else:
        a=-1
    if (i>>1)&1==1:
        b=1
    else:
        b=-1
    if (i>>2)&1==1:
        c=1
    else:
        c=-1
    h=[0]
    for u in xyz:
        x,y,z=u
        h.append(a*x+b*y+c*z)
    lst.append(h)
ans=0
for u in lst:
    dp=[[0]*(m+1) for i in range(n+1)]
    for i in range(1,n+1):
        d=u[i]
        for j in range(1,m+1):
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+d)
    ans=max(ans,dp[n][m])
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(n)]
lst=[]
for i in range(8):
    if i&1==1:
        a=1
    else:
        a=-1
    if (i>>1)&1==1:
        b=1
    else:
        b=-1
    if (i>>2)&1==1:
        c=1
    else:
        c=-1
    h=[]
    for u in xyz:
        x,y,z=u
        h.append(a*x+b*y+c*z)
    lst.append(h)
ans=0
for u in lst:
    u.sort(reverse=True)
    e=0
    for i in range(m):
        e+=u[i]
    ans=max(ans,e)
print(ans)
### BUGGY CODE ###

import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
g = 0
lcm = 1
for x in a:
  g = gcd(lcm, x)
  lcm *= x // g
res = 0
for x in a:
  res += lcm // x
  res %= mod
print(res)

### FIXED CODE ###

import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
l = 1
res = 0
for x in a:
  l = x * l // gcd(x, l)
l %= mod
for x in a:
  res += l * pow(x, mod - 2, mod)
  res %= mod
print(res)
### BUGGY CODE ###

n, m = map(int, input().split())
work = [tuple(map(int, input().split())) for _ in range(n)]
work.sort(key = lambda x: (x[1], -x[0]), reverse = True)
do = [0] * (m+1)
money = 0
for a, b in work:
    if a > m:
        continue
    while do[a] != 0:
        a += 1
        if a > m:
            break
    if a > m:
        continue
    do[a] = 1
    money += b
print(money)

### FIXED CODE ###

import bisect as bi
n, m = map(int, input().split())
work = [tuple(map(int, input().split())) for _ in range(n)]
work.sort(key = lambda x: (x[1], -x[0]), reverse = True)
ava = list(range(0, m+1))
money = 0
for a, b in work:
    if a > m:
        continue
    l = bi.bisect_left(ava, a)
    if l >= len(ava):
        continue
    del ava[l]
    money += b
print(money)
### BUGGY CODE ###

n, m = map(int, input().split())
ab = []
for i in range(n):
  t = [int(inp) for inp in input().split()]
  if t[0] <= m:
    ab.append(t)

ab.sort(key = lambda x: -x[1])
ans = 0
slot = [False for i in range(m+1)]
for t in ab:
  b = t[0]
  a = t[1]
  if b > m:
    continue
  if False not in slot[b:m+1]:
    m = b-1
    continue
  ans += a
  ind = slot[b:m+1].index(False)
  slot[b+ind] = True
  if b+ind == m:
    m = m-1
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
ab = [[] for _ in range(m+1)]
for i in range(n):
  t = [int(inp) for inp in input().split()]
  if t[0] <= m:
    ab[t[0]].append(-t[1])
ans = 0
import heapq
h = ab[1]
heapq.heapify(h)
for i in range(1, m+1):
  if len(h) > 0:
    ans += heapq.heappop(h)
  if i != m:
    for t in ab[i+1]:
      heapq.heappush(h, t)
print(-ans)
### BUGGY CODE ###

H,W,M=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(M)]
Tr=[0 for _ in range(H+1)]
Tc=[0 for _ in range(W+1)]
for i in range(M):
    Tr[s[i][0]]+=1
    Tc[s[i][1]]+=1
mr=max(Tr)
mc=max(Tc)
Mr=[i for i,x in enumerate(Tr) if x==mr]
Mc=[i for i,x in enumerate(Tc) if x==mc]

ans=0
for i in range(len(Mr)):
    for j in range(len(Mc)):
        if not ([Mr[i],Mc[j]] in s):
            ans=mr+mc
            break
    else:
        continue
    break
if ans==0:
    ans=mr+mc-1
print(ans)

### FIXED CODE ###

H,W,M=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(M)]
Tr=[0 for _ in range(H+1)]
Tc=[0 for _ in range(W+1)]
for i in range(M):
    Tr[s[i][0]]+=1
    Tc[s[i][1]]+=1
mr=max(Tr)
mc=max(Tc)
Mr=[0 for _ in range(H+1)]
Mc=[0 for _ in range(W+1)]
Nmr=0
Nmc=0
for i in range(len(Tr)):
    if Tr[i]==mr:
        Mr[i]=1
        Nmr+=1
for i in range(len(Tc)):
    if Tc[i]==mc:
        Mc[i]=1
        Nmc+=1
cnt=0
for i in range(M):
    if Mr[s[i][0]]==1 and Mc[s[i][1]]==1:
        cnt+=1
if cnt<Nmr*Nmc:
    print(mr+mc)
else:
    print(mr+mc-1)
### BUGGY CODE ###

N = int(input())
S = str(input())
X = [0] * N

for i in range(N):
    if S[i] == "R":
        X[i] = 1
    elif S[i] == "G":
        X[i] = 2
    elif S[i] == "B":
        X[i] = 3

Sum = 0

for i in range(N - 2):
    s1 = X[i]
    for j in range(i + 1, N - 1):
        s2 = X[j]
        if s1 != s2:
            for k in range(j + 1, N):
                if (6 - s1 - s2 == X[k]) and (j - i) != (k - j):
                    Sum += 1

print(Sum)



### FIXED CODE ###

N = int(input())
S = str(input())
X = [0] * N

Sum1 = 0
Sum2 = 0
Sum3 = 0

for i in range(N):
    if S[i] == "R":
        X[i] = 1
        Sum1 += 1
    elif S[i] == "G":
        X[i] = 2
        Sum2 += 1
    elif S[i] == "B":
        X[i] = 4
        Sum3 += 1

Sum = Sum1 * Sum2 * Sum3

for i in range(N):
    for j in range(1, N):
        if i - j < 0 or N <= i + j:
            break
        else:
            if (X[i] + X[i - j] + X[i + j]) == 7:
                Sum -= 1

print(Sum)
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    import numpy as np

    np.set_printoptions(linewidth=200)

    N, W = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(N)]
    v_max = 10 ** 3 * 100 * 10
    w_max = 10 ** 9 * v_max
    # v_max = 150
    # v_max = 30

    # i以上の価値を持つときの最小重量
    dp = np.full((N + 1, v_max), w_max, dtype=np.int64)
    # initialize
    # w, v = lst[0]
    # dp[0][v:] = w
    dp[0][0] = 0
    for n in range(N):
        w, v = lst[n]
        dp[n + 1, v:] = np.minimum(dp[n + 1, v:], dp[n, :-v] + w)
        dp[n + 1, :] = np.minimum(dp[n + 1, :], dp[n, :])

    ans = 0
    for i, w in enumerate(dp[-1]):
        if w <= W:
            ans = i
    print(ans)
    # print(dp)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys


def resolve():
    readline = sys.stdin.readline

    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for x in [0] * N]

    # 配るDP
    # dp[i][sum_v]はi個の品物の内でsum_v以上となる最小の重量
    V = N * 10 ** 3 + 1  # 価値の最大値
    inf = 10 ** 10
    dp = [[inf] * V for _ in [0] * (N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for sum_v in range(V):
            weight, value = lst[i]
            if sum_v - value >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v],
                                       dp[i][sum_v - value] + weight)
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(V):
        if dp[N][sum_v] <= W:
            ans = sum_v
    print(ans)
    

resolve()
### BUGGY CODE ###

from collections import deque

S = input()

cands = ["dream", "dreamer", "erase", "eraser"]
searched = {}

queue = deque([""])
find_flag = 0
while len(queue) != 0:
    s = queue.pop()
#     print(s)
    searched[s] = 1
    if s == S:
        find_flag = 1
        break
        
    s_ = cands[0]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

    s_ = cands[1]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[2]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[3]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

if find_flag:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

S = input()

candidates = ["dream", "dreamer", "erase", "eraser"]

find_flag = 0
rest_S = S
while True:
#     print(rest_S[-5:], rest_S[-7:]) 
    if len(rest_S) == 0:
        find_flag = 1
        break
    elif (len(rest_S) >= 7) & (rest_S[-7:] in candidates):
        rest_S = rest_S[:-7]
    elif (len(rest_S) >= 6) & (rest_S[-6:] in candidates):
        rest_S = rest_S[:-6]
    elif (len(rest_S) >= 5) & (rest_S[-5:] in candidates):
        rest_S = rest_S[:-5]
    else:
        break

if find_flag:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()

while True:
    if vodd[0][0] != veven[0][0]:
        print(len(V) - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(len(V) - vodd[1][1] - veven[0][1],
                    len(V) - vodd[0][1] - veven[1][1]))

### FIXED CODE ###

from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()
vlen = len(V)
while True:
    if vodd[0][0] != veven[0][0]:
        print(vlen - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(vlen - vodd[1][1] - veven[0][1],
                    vlen - vodd[0][1] - veven[1][1]))
        exit()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 2 * pow(10, 5)  # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


n = int(input())
a = [int(i) for i in input().split()] 

count = [0 for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
for i in range(n+1):
    tmp = a.count(i)
    count[i] = tmp
    ans[i] = cmb(tmp, 2)
#print(count, ans)
sum_ans = sum(ans)
#print(sum_ans)
for k in range(n):
    #count[k] -= 1
    #print(a[k], count[a[k]])
    #print(cmb(count[a[k]]-1, 2) , cmb(count[a[k]], 2))
    ans = sum_ans + cmb(count[a[k]]-1, 2) - cmb(count[a[k]], 2)
    print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import collections

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    if n == 0: return 0
    if n == 1: return 0

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


"""
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 3 * pow(10, 5)  # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    #fact.append(fact[-1] * i)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    #inv.append(-inv[mod%i] * (mod // i))
    factinv.append((factinv[-1] * inv[-1]) % mod)
    #factinv.append(factinv[-1] * inv[-1])
"""

n = int(input())
a = [int(i) for i in input().split()] 

count = [0 for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
c = collections.Counter(a)
#print(c)
for i in range(n+1):
    #tmp = a.count(i)
    tmp = c[i]
    #print(tmp)
    count[i] = tmp
    ans[i] = cmb(tmp, 2)
    #print(tmp, ans[i])
#print(count, ans)
sum_ans = sum(ans)
#print(sum_ans)
for k in range(n):
    #count[k] -= 1
    #print(a[k], count[a[k]])
    #print(count[a[k]] - 1 ,cmb(count[a[k]]-1, 2))
    #print(count[a[k]] ,cmb(count[a[k]], 2))
    ans = sum_ans + cmb(count[a[k]]-1, 2) - cmb(count[a[k]], 2)
    print(ans)
### BUGGY CODE ###

from heapq import heappush,heappop
import queue
import re
import math
import functools

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


N = int_raw()
As = ints_raw()


def main():
    ans = 0
    for i in range(N):
        ans = max(ans,functools.reduce(gcd, As[:i]+As[i+1:]) )
    return ans
print(main())


### FIXED CODE ###

from heapq import heappush,heappop
import queue
import re
import math
import functools
import numpy

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


N = int_raw()
As = ints_raw()


def main():
    f_gcds = [As[0]]
    for i in range(1,N):
        f_gcds.append(gcd(As[i],f_gcds[-1]))
    b_gcds = [0]*(N-1)+[As[-1]]
    for i in range(N-2,-1,-1):
        b_gcds[i] = gcd(As[i],b_gcds[i+1])
    ans = max(b_gcds[1],f_gcds[-2])
    for i in range(1,N-1):
        ans = max(ans,gcd(f_gcds[i-1],b_gcds[i+1]))
    return ans

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

import sys
import re
#def INPUT_AS_INT(): return int(sys.stdin.readline().rstrip())
# def INPUT_AS_INT_LIST(): return list(map(int,sys.stdin.readline().rstrip().split()))
def INPUT_AS_STRING(): return sys.stdin.readline().rstrip()
# def INPUT_AS_STRING_LIST(): return list(sys.stdin.readline().rstrip().split())

str = INPUT_AS_STRING() # 入力受付
_str = str #　結果と比較用
while True:
    tmp = str
    tmp = re.sub("10", "", tmp)
    tmp = re.sub("01", "", tmp)
    if str == tmp:
        break
    str = tmp

print(len(_str) - len(str))


### FIXED CODE ###

import sys

cubes = list(input()) # 入力受付
stack = []
count = 0

for cube in cubes:
    if not stack:
        stack.append(cube)
    elif stack[-1] != cube:
        count += 2
        stack.pop()
    else:
        stack.append(cube)
print(count)
### BUGGY CODE ###

import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)
### BUGGY CODE ###

import sys
import math
import numpy as np
import copy

def main():
    n = int(input())
    l = [int(t) for t in input().split()]

    # まずはLを昇順にソートする
    l.sort()
    
    count = 0
    # 1番短い棒(i)と2番目に短い棒(j)を決める
    for i in range(0, n):
        for j in range(i+1, n):
            lb, ub = j, n
            while ub - lb > 1:
                half = (lb + ub) // 2
                if l[half] < l[i] + l[j]:
                    lb = half
                else:
                    ub = half
            count += ub - (j + 1)

    print(count)

    return 0

if __name__ == '__main__':
    sys.exit(main())

### FIXED CODE ###

import sys
import math
import copy

def main():
    n = int(input())
    l = [int(t) for t in input().split()]

    # まずはLを昇順にソートする
    l.sort()
    
    count = 0
    # 1番短い棒(i)と2番目に短い棒(j)を決める
    for i in range(0, n):
        for j in range(i+1, n):
            lb, ub = j, n
            while ub - lb > 1:
                half = (lb + ub) // 2
                if l[half] < l[i] + l[j]:
                    lb = half
                else:
                    ub = half
            count += ub - (j + 1)

    print(count)

    return 0

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

class Solver:

    def __init__(self):
        pass

    def solve(self, s):
        s0 = s
        while True:
            snew = s.replace('01','').replace('10','')
            if snew == s:
                return (len(s0) - len(snew))
            s = snew

if __name__ == '__main__':

    solver = Solver()

    s = input()

    n = solver.solve(s)
    print(n)


### FIXED CODE ###

class Solver:

    def __init__(self):
        pass


    def solve(self, s):
        one = 0
        zero = 0
        for ch in s:
            if ch == '1':
                one += 1
            else:
                zero += 1
        return len(s) - abs(one-zero)


if __name__ == '__main__':

    solver = Solver()
    s = input()
    n = solver.solve(s)
    print(n)
### BUGGY CODE ###

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = sorted([x+y for x in a for y in b])[:-k-1:-1]
abc = sorted([x+y for x in ab[:k] for y in c])[:-k-1:-1]

for i in abc:
  print(i)

### FIXED CODE ###

x, y, z, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

n = int(input())
i = 2
ans = n - 1
while i < n:
  if i * i > n:
    i += 1
    break
  if n % i > 0:
    continue
  j = n // i
  ans = min(ans, i + j - 2)
  i += 1
print(ans)

### FIXED CODE ###

n = int(input())
i = 2
ans = n - 1
while i < n:
  if i * i > n:
    i += 1
    break
  if n % i > 0:
    i += 1
    continue
  j = n // i
  ans = min(ans, i + j - 2)
  i += 1
print(ans)