Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    def f(i):
        if i == N:
            return 0

        n = 0
        m = min(A[i], B[i])
        n += m
        A[i] -= m
        B[i] -= m
        m = min(A[i+1], B[i])
        n += m
        A[i] -= m
        B[i] -= m
        return n + f(i+1)

    n = f(0)
    print(n)

main()


### FIXED CODE ###

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

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    n = 0
    for i in range(N):
        m = min(A[i], B[i])
        n += m
        A[i] -= m
        B[i] -= m
        m = min(A[i+1], B[i])
        n += m
        A[i+1] -= m
        B[i] -= m

    print(n)

main()
n,m = map(int,input().split())
a = list(map(int,input().split()))
sm = sum(a)
a.sort(reverse=True)
a = a[0:min(n,m)]
discount = 0
for i in range(m):
  newa = a[0]//2
  discount += a[0] - newa
  l = len(a)
  if l == 1:
    continue
  ain = a[1:min(l,m-i-1)]
  lin = len(ain)
  if newa > ain[0]:
    a = [newa] + ain
    continue
  j = 0
  k = lin-1
  while j < k:
    mid = (j+k)//2
    if newa <= ain[mid]:
      k = mid
    else:
      j = mid
  a = ain[0:j+1] + [newa] + ain[j+1:]
    
  
  


### FIXED CODE ###

from heapq import heappush, heappop,heapify
n,m = map(int,input().split())
def minusint(x):
  return -int(x)
a = list(map(minusint,input().split()))
heapify(a)
for _ in range(m):
  ai = heappop(a)*(-1)
  heappush(a,-(ai//2))
print(-sum(a))
N,H,W = map(int, raw_input().split())
a = []
a = []
for i in range(N):
    a.append(list(map(int, input().split())))

num =0
for i in range(N):
    if a[i][0]>=H:
        if a[i][1] >= W:
            num +=1
print(num)         

### FIXED CODE ###

a =[]
N,H,W = map(int, input().split())
for i in range(N):
    a.append(list(map(int, input().split())))

num =0
for i in range(N):
    if a[i][0]>=H:
        if a[i][1] >= W:
            num +=1
print(num)
s = input()
k = int(input())
st = set()
for i in range(len(s)):
    for j in range(min(k, len(s)-i+1))
        st.add(s[i:i+j])
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))


### FIXED CODE ###

s = input()
k = int(input())
st = set()
for i in range(len(s)):
    j = 1
    while j <= k and i+j <= len(s):
        st.add(s[i:i+j])
        j += 1
for _ in range(k-1):
    m = min(st)
    st = [x for x in st if x != m]
print(min(st))
N = input()
sum=0
for i in range(len(N)):
	sum += int(i)
print('Yes' if int(N) // sum == 0 else 'No')

### FIXED CODE ###

n = input()
print("Yes" if int(n) % sum(map(int,n)) == 0 else "No")
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(lists):
    print(lists[i])

### FIXED CODE ###

import collections
a,b,c = map(int,input().split())
lists = [str(a%2),str(b%2),str(c%2)]
abc = [a,b,c]
an = []
if len(set(lists)) != 1:

    d = collections.Counter(lists)
    jud = int(d.most_common()[0][0])
    for i in range(3):
        if jud == int(lists[i]):
            an.append(i)
    for i in an:
            abc[i] += 1
    cnt = 1
else:
    cnt = 0

while 1:
    Max = max(abc)
    count = 0
    for i in range(3):
        if Max == abc[i]:
            count += 1
    if count == 1:
        cnt += 1
        for i in range(3):
            if Max != abc[i]:
                abc[i] += 1

    elif count == 2:
        cnt += abs(max(abc) - min(abc)) // 2
        abc.sort()
        abc[0] += abs(max(abc) - min(abc))
    elif count == 3:
        break

print(cnt)
# AtCorder-Candy Distribution Again

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

a = 0
i = 0
list.sort()

if x < list[0]:
    print(0)

elif x >= list[0]:

    while x > 0 and x >= list[i]:
        x -= list[i]
        a += 1
        if x < list[i+1]:
            break
        i += 1

    print(a)


### FIXED CODE ###

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

a = 0
i = 0

list.sort()

if list[0] > x:
    print(0)

elif x > sum(list):
    print(n-1)

else:
    while x > 0 and x >= list[i]:
        x -= list[i]
        i += 1
        a += 1
        if i == n:
            break

    print(a)
import math

[n, x] = map(int, input().split())

xs = list(map(int, input().split()))
xs.append(x)

xs.sort()
gcd =  xs[1] - xs[0]

for i in range(1, len(xs)):
    gcd = math.gcd(gcd,  xs[i] - xs[i - 1])

print(gcd)

### FIXED CODE ###

def getGcd(num1, num2):
    while True:
        tmp = num1
        num1 = num2 % num1
        num2 = tmp
        if(num1 == 0):
            return tmp

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))

xs.append(x)
xs.sort()

gc = xs[1] - xs[0]

for i in range(1, n + 1):
    gc = getGcd(gc,  xs[i] - xs[i - 1])

print(gc)
from math import gcd
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a, gcd))
c = list(accumulate(reversed(a), gcd))
print(max(b[-2], c[-2], *map(gcd, b[:-2], c[-3::-1])))


### FIXED CODE ###

from fractions import gcd
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a, gcd))
c = list(accumulate(reversed(a), gcd))
print(max(b[-2], c[-2], *map(gcd, b[:-2], c[-3::-1])))
W,H,x,y,r = raw_input().split(" ")
if (x+r)<=W and 0<=(x-r) and 0<=(y-r) and (y+r)<=H:
    print "Yes"
else:
    print "No"

### FIXED CODE ###

a = raw_input().split(" ")
W = int(a[0])
H = int(a[1])
x = int(a[2])
y = int(a[3])
r = int(a[4])
if (x - r) >= 0 and (x + r) <= W and (y - r) >= 0 and (y + r) <= H:
    print "Yes"
else:
    print "No"
K = int(input())
A,B = map(int,input().split())
for i in range(A,B+1):
    if i % K == 0:
        print( 'OK' )
        stop()
else:
    print( 'NG' )

### FIXED CODE ###

K = int(input())
A,B = map(int,input().split())
for i in range(A,B+1):
    if i % K == 0:
        print( 'OK' )
        quit()
else:
    print( 'NG' )
import math 
x = int(input())
xi = math.floor(x/5.5)
print(xi)
for i in range(xi,100000000000000):
    # print(6*i - math.floor(i/2))
    if(x < 6*i-math.floor(i/2)):
        xa = i
        break

print(xa)


### FIXED CODE ###

import math 
x = int(input())
# x = 10**15
xi = math.floor(x/5.5)
# print(xi)
for i in range(xi,10000000000000000000000000000):
    # print(6*i - math.floor(i/2))
    if(x <= 6*i-math.floor(i/2)):
        xa = i
        break

print(xa)
A＝int(input())
B = int(input())
print(6-A-B)

### FIXED CODE ###

A = int(input())
B = int(input())
print(6-A-B)
# encoding:utf-8
    import copy
    import random
    import bisect #bisect_left　これで二部探索の大小検索が行える
    import fractions #最小公倍数などはこっち
    import math
     
    mod = 10**9+7
     
    N,K = map(int,input().split())
    S = str(input())
     
    replace = S[K-1]
    replace = replace.lower()
     
    print(S[:K-1]+replace+S[K:])

### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,K = map(int,input().split())
S = str(input())

replace = S[K-1]
replace = replace.lower()

print(S[:K-1]+replace+S[K:])
from bisect import bisect_right

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#a,bの累積和
a_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
b_sum = [0]
for i in range(n):
    b_sum.append(b_sum[i]+b[i])

ans = 0
#Aについて0-N冊読む場合の全探索
for i in range(n+1):
    cntA = i #Aをi冊読む
    rest = k - a_sum[i]#残り時間rest分
    if rest < 0:
        break
    cntB = bisect_right(b_sum,rest)-1 #Bで読むことができる冊数を二分探索で求める
    ans = max(ans,cntA + cntB)
print(ans)

### FIXED CODE ###

from bisect import bisect_right

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
#a,bの累積和
A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])

ans = 0
#Aについて0-N冊読む場合の全探索
for i in range(N+1):
    cntA = i #Aをi冊読む
    rest = K - A_sum[i] #残り時間rest分
    if rest < 0:
        break
    cntB = bisect_right(B_sum,rest)-1 #Bで読むことができる冊数を二分探索で求める
    ans = max(ans,cntA + cntB)
print(ans)
魔法両面テープ

### FIXED CODE ###

r = int(input())

print(r*r)
D=int(input())
if D==25:
  print("Christmas")
else:
  if D==24:
    print("Christmas Eve")
  else:
    if D=23:
      print("Christmas Eve Eve")
    else:
      print("Christmas Eve Eve Eve")

### FIXED CODE ###

D=int(input())
if D==25:
  print("Christmas")
else:
  if D==24:
    print("Christmas Eve")
  else:
    if D==23:
      print("Christmas Eve Eve")
    else:
      print("Christmas Eve Eve Eve")
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    H, N = map(int, input().split())
    M = [tuple(int(a) for a in input().split()) for _ in range(N)]
    DP = [[10000000 for _ in range(H + 2)] for i in range(N)]
    a0, b0 = M[0]
    for d in range(100000):
        if d * a0 >= H + 1:
            DP[0][H + 1] = d * b0
            break
        else: DP[0][d * a0] = d * b0
    for i in range(1, N):
        a, b = M[i]
        for j in range(H + 1):
            if DP[i - 1][j] < 10000000:
                if j < a: DP[i-1][j]
                else: DP[i][j] = min(DP[i-1][j], DP[i][j - a] + b)
        DP[i][H + 1] = min(DP[i][H + 1], DP[i-1][H + 1])
        DP[i][H + 1] = min(DP[i][H + 1], min(DP[i][H-a+1:H]) + b)
    
    print(min(DP[N-1][H], DP[N-1][H+1]))
    #print(DP)
    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    H, N = map(int, input().split())
    M = [tuple(int(a) for a in input().split()) for _ in range(N)]
    DP = [1000000000] * (H + 2) #ダメージiを与えるのに必要な最小MP, DP[H+1]はH以上のダメージを与えた場合
    DP[0] = 0
    for i, m in enumerate(M):
        a, b = m
        for j in range(max(H-a+1, 0)): DP[j + a] = min(DP[j + a], DP[j] + b)
        for j in range(max(H-a+1, 0), H): DP[H + 1] = min(DP[H + 1], DP[j] + b)
    print(min(DP[H], DP[H + 1]))

    return 0

if __name__ == "__main__":
    solve()
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])
A.sort()
i = 0
for b, c in BC[::-1]:
    for _ in range(b):
        if c > A[i]:
            A[i] = c
            i += 1
        else:
            break

print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])
A.sort()
i = 0
for b, c in BC[::-1]:
    for _ in range(b):
        if i == N:
            break
        if c > A[i]:
            A[i] = c
            i += 1
        else:
            break

print(sum(A))
from copy import copy
n = int(input())
a = list(map(int, input().split()))

ok, ng = n, 0
while ok-ng > 1:
	x = (ok+ng+1)//2
	#d = defaultdict(int)
	d = dict()
	last = 0
	valid = True
	if x == 1:
		for i in range(n-1):
			if a[i] >= a[i+1]:
				valid = False
				break
		if valid:
			ok = x
		else:
			ng = x
		continue

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

		else:
			for k in d.keys():
				if last < k:
					dels.append(k)

			j = a[i+1]
			while j > 0:
				if j in d and d[j] == x-1:
					d[j] = 0
					dels.append(j)
					j -= 1
				else:
					break

			if j in d:
				d[j] += 1
			else:
				d[j] = 1

		for k in dels:
			del d[k]

		if 0 in d:
			valid = False
			break

	if valid:
		ok = x
	else:
		ng = x
print(ok)

### FIXED CODE ###

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

ok, ng = n, 0
while ok-ng > 1:
	x = (ok+ng)//2
	#d = defaultdict(int)
	d = dict()
	last = 0
	valid = True
	if x == 1:
		for i in range(n-1):
			if a[i] >= a[i+1]:
				valid = False
				break
		if valid:
			ok = x
		else:
			ng = x
		continue

	for i in range(n-1):
		dels = []
		if a[i] < a[i+1]:
			last = a[i+1]
			continue

		j = a[i+1]
		for k in d.keys():
			if j < k:
				dels.append(k)

		while j > 0:
			if j in d and d[j] == x-1:
				#d[j] = 0
				dels.append(j)
				j -= 1
			else:
				break

		if j in d:
			d[j] += 1
		else:
			d[j] = 1

		for k in dels:
			del d[k]

		if 0 in d:
			valid = False
			break
		last = j

	if valid:
		ok = x
	else:
		ng = x
print(ok)
x=input()
  if x=="A":
    print("T")
  elif x=="T":
    print("A")
  elif x=="C":
    print("G")
  else:
    print("C")


### FIXED CODE ###

x=input()

if x=="A":
  print("T")
elif x=="T":
  print("A")
elif x=="C":
  print("G")
else:
  print("C")
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = [[] for _ in range(N + 1)]
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            testimonies[i].append(map(int, input().split()))

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = {i: {} for i in range(1, N + 1)}
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            testimonies[i][x] = y

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            honest_people = set(honest_people)
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i].items():
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()
for e in iter(input,'0 0'):
 H,W=map(int,e.split())
 s=[[*map(int,input().split())]for _ in[0]*H]
 print(max(sum(max(sum(c),H-sum(c))for x in range(2**H))for c in zip([c^int(b)for c in r]for r,b in zip(s,bin(x)[2:].zfill(H)))))


### FIXED CODE ###

def v():
 for e in iter(input,'0 0'):
  r=int(e.split()[0])
  d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
  a=0
  for m in range(1<<~-r):
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=max(c,r-c)
   if a<t:a=t
  print(a)
if'__main__'==__name__:v()
import sys 
RESOURCE_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])

def get_input():
    N,M = [ int(_) for _ in input().split()]
    A = [int(_) for _ in input().split()]
    return N,M,A


def solve(N,M,A):
    sorted_A = sorted(A)[::-1]
    dp = fill_dp(N,sorted_A)
    array = find_array(dp,N,sorted_A)
    return "".join(map(str,array))

def fill_dp(N,A):
    dp = [ -100*N for _ in range(N+1)]
    dp[0] = 0
    for i in range(1,N+1):
        fill(A,dp,i,N)
    return dp

def fill(A,dp,n,N):
    cand = [ dp[n-RESOURCE_DICT[num]]+1 for num in A if n - RESOURCE_DICT[num] >= 0 ]
    dp[n] = max(cand) if len(cand) > 0  else -100*N

def find_array(dp,N,sorted_A):
    array = []
    current_n = N
    for _ in range(dp[N]):
        for number in sorted_A:
            if dp[current_n-RESOURCE_DICT[number]] == dp[current_n]-1:
                array.append(number)
                current_n -= RESOURCE_DICT[number]
                break
    return array


if __name__ =="__main__":
    N,M,A = get_input()
    ans = solve(N,M,A)
    print(ans)

### FIXED CODE ###

import sys 
RESOURCE_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])

def get_input():
    N,M = [ int(_) for _ in input().split()]
    A = [int(_) for _ in input().split()]
    return N,M,A


def solve(N,M,A):
    sorted_A = sorted(A)[::-1]
    dp = fill_dp(N,sorted_A)
    array = find_array(dp,N,sorted_A)
    return "".join(map(str,array))

def fill_dp(N,A):
    dp = [ -100*N for _ in range(N+1)]
    dp[0] = 0
    for i in range(1,N+1):
        fill(A,dp,i,N)
    return dp

def fill(A,dp,n,N):
    cand = [ dp[n-RESOURCE_DICT[num]]+1 for num in A if n - RESOURCE_DICT[num] >= 0 ]
    dp[n] = max(cand) if len(cand) > 0  else -100*N

def find_array(dp,N,sorted_A):
    array = []
    current_n = N
    for _ in range(dp[N]):
        for number in sorted_A:
            if current_n-RESOURCE_DICT[number] >= 0  and dp[current_n-RESOURCE_DICT[number]] == dp[current_n]-1:
                array.append(number)
                current_n -= RESOURCE_DICT[number]
                break
    return array


if __name__ =="__main__":
    N,M,A = get_input()
    ans = solve(N,M,A)
    print(ans)
a_list = list(input())
b_list = list(input())
c_list = list(input())

a_turn = True
b_turn = False
c_turn = False

max_battle = len(a_list) + len(b_list) + len(c_list)

for i in range(max_battle):
    if(a_turn):
        a_list.pop(0)
        if(len(a_list) == 0):
            print("a")
            exit() 
        else:
           if(a_list[0] == 'b'):
                a_turn = False
                b_turn = True 
            elif(a_list[0] == 'c'):
                a_turn = False
                c_turn = True  
    elif(b_turn):
        a_list.pop(0)
        if(len(b_list) == 0):
            print("b")
            exit() 
        else:
            if(b_list[0] == 'a'):
                b_turn = False
                a_turn = True 
            elif(b_list[0] == 'c'):
                b_turn = False
                c_turn = True  
    elif(c_turn):
        c_list.pop(0)
        if(len(c_list) == 0):
           print("c")
           exit() 
        else:
            if(c_list[0] == 'a'):
                c_turn = False
                a_turn = True 
            elif(a_list[0] == 'b'):
                c_turn = False
                b_turn = True  


### FIXED CODE ###

# 入力
SA=list(input())
SB=list(input())
SC=list(input())

# 次に捨てる人（初期値は'A')
x='a'

while True:
  if x=='a':
    # リストの要素が0ならば終了する
    if len(SA)==0:
      print('A')
      exit()

    # 先頭要素を除去してxに代入
    x=SA[0]
    SA.remove(x)
  elif x=='b':
    # リストの要素が0ならば終了する
    if len(SB)==0:
      print('B')
      exit()

    # 先頭要素を除去してxに代入
    x=SB[0]
    SB.remove(x)
  else:
    # リストの要素が0ならば終了する
    if len(SC)==0:
      print('C')
      exit()

    # 先頭要素を除去してxに代入
    x=SC[0]
    SC.remove(x)
import math

ABC = input().split()

a = int(ABC[0])
b = int(ABC[1])
c = int(ABC[2])
#a = b = c = pow(10,9)

l = 2*math.sqrt(a*b)
r = c - a - b

lint = int(l)

rl = r-l

# print(str(l) + " " + str(r))

# print(str(l-float(lint)) + " " + str(rl))

# print(math.isclose(0,rl))
if  math.isclose(0,rl)==True:
    print("Yes")
elif 0 < rl:
    print("Yes")
else:
    print("No")




### FIXED CODE ###

import math

ABC = input().split()

a = int(ABC[0])
b = int(ABC[1])
c = int(ABC[2])
#a = b = c = pow(10,9)

l2  = 4 * a * b
r = c - a - b
r2 = r * r

# if l2 < r2:
#     print("Yes")
# else:
#     print("No")

if r > 0 :
    if l2 < r2:
        print("Yes")
    else:
        print("No")
else:
    print("No")
import sys
from io import StringIO
import unittest
import math


def check(A, F, x, N, K):
    for i in range(N):
        if A[i] * F[i] > x:
            k = math.ceil(A[i] - x / F[i])
            K -= k
    if K < 0:
        return False
    else:
        return True


def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse=True)
    F.sort()

    # binary search
    l = 0
    r = max(A) * max(F)
    result = None
    while l <= r:
        # print('l {}, r {}'.format(l, r))
        if l == r:
            result = l
            break
        mid = (l + r) // 2
        if check(A, F, mid, N, K):
            r = mid
        else:
            l = mid + 1

    print(result)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 5
4 2 1
2 3 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 8
4 2 1
2 3 1"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2"""
        output = """12"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


### FIXED CODE ###

import sys
from io import StringIO
import unittest
import math


def resolve():
    N = int(input())
    A = 1
    B = 1

    center = math.ceil(math.sqrt(N))
    for i in range(1, center + 1)[::-1]:
        if N % i == 0:
            A = i
            B = int(N / i)
            break
        else:
            continue

    result = A - 1 + B - 1
    print(result)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """50"""
        output = """13"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10000000019"""
        output = """10000000018"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()
def main():
    inputs = input()

    roop_num = len(inputs)
    if roop_num >= 80000:
        cnt = 0

    else:
        cnt = 0
        flag = False
        for start in range(roop_num-3):
            roop_num_end = roop_num - start
            ans_list = []
            ans_list = [int(inputs[start:end+start+4]) for end in range(roop_num_end-3) if int(inputs[start:end+start+4]) % 2019 == 0]

            cnt += len(ans_list)

    print(cnt)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    inputs = input().split(' ')
    sheep = int(inputs[0])
    wolf = int(inputs[1])

    if sheep > wolf:
        print('safe')

    else:
        print('unsafe')

if __name__ == '__main__':
    main()
import math
 
stri = input()
ary = stri.split()
n = int(ary[0])
k = int(ary[1])
 
ans1 = 1 * (n-k +1 )
ansi:int = ans1
print(ansi)
 
for i in range(2,k+1):
    ansi = ansi * (k- i + 1) / ( i - 1 ) *  (n-k - i + 2) / i 
    print(int(ansi % 1000000007))

### FIXED CODE ###

import math
 
stri = input()
ary = stri.split()
n = int(ary[0])
k = int(ary[1])
 
ans1 = 1 * (n-k +1 )
ansi = 0
ansi = int(ans1)
print(ansi)
for i in range(2,k+1):
    ansi = ansi * (k- i + 1) // int( i - 1 ) *  (n-k - i + 2) // int(i) 
    type(ansi)
    print(int(ansi % int(1000000007)))
A, B = map(input().split())
if A<10 and B<10:
  print(A*B)
else:
  print(-1)

### FIXED CODE ###

A, B = map(int, input().split())
if A<10 and B<10:
  print(A*B)
else:
  print(-1)