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

import sys
S = input()
num = len(S)
S = S + "zzzzzzzzzzzzzzzzzzzzzz"
cur = 0
while cur < num:
    if S[cur] == 'd':
        if S[cur:cur+11] == 'dreameraser':
            cur += 11
        elif S[cur:cur+10] == 'dreamerase':
            cur += 10
        elif S[cur:cur+7] == 'dreamer':
            cur += 7
        elif S[cur:cur+5] == 'dream':
            cur += 5
        else:
            print('NO')
            sys.exit()
    elif S[cur] == 'e':
        if S[cur:cur+6] == 'eraser':
            cur += 6
        elif S[cur:cur+5] == 'erase':
            cur += 5
        else:
            print('NO')
            sys.exit()
    if cur == num:
        print('YES')
        sys.exit()

### FIXED CODE ###

import sys
S = input()
num = len(S)
S = S + "zzzzzzzzzzzzzzzzzzzzzz"
cur = 0
while cur < num:
    if S[cur] == 'd':
        if S[cur:cur+11] == 'dreameraser':
            cur += 11
        elif S[cur:cur+10] == 'dreamerase':
            cur += 10
        elif S[cur:cur+7] == 'dreamer':
            cur += 7
        elif S[cur:cur+5] == 'dream':
            cur += 5
        else:
            print('NO')
            sys.exit()
    elif S[cur] == 'e':
        if S[cur:cur+6] == 'eraser':
            cur += 6
        elif S[cur:cur+5] == 'erase':
            cur += 5
        else:
            print('NO')
            sys.exit()
    else:
        print('NO')
        sys.exit()
    if cur == num:
        print('YES')
        sys.exit()
### BUGGY CODE ###

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353


n = INT()
d = MAP()

if d[0]!=0:
    print(0)
    exit(0)

l = [d.count(i) for i in range(max(d)+1)]
ans=1
for i in range(1,max(d)+1):
    ans*=pow(l[i-1],l[i],MOD)
    ans %= MOD
print(ans)

### FIXED CODE ###

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353


n = INT()
d = MAP()

if d[0]!=0 or not all(d[1:]):
    print(0)
    exit(0)

l = [0]*(max(d)+1)
for i in d:
    l[i]+=1

ans=1
for i in range(1,max(d)+1):
    ans*=pow(l[i-1],l[i],MOD)
    ans %= MOD
print(ans)
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def main():
    N, W = [int(x) for x in input().split()]
    wv = [[int(x) for x in input().split()] for _ in range(N)]

    dp = [[0] * (W + 1) for j in range(N)]

    for j in range(N):
        for i in range(W + 1):
            if j == 0:
                if i < wv[j][0]:
                    continue
                dp[j][i] = wv[j][1]
            else:
                if i < wv[j][0]:
                    dp[j][i] = dp[j - 1][i]
                else:
                    dp[j][i] = max(dp[j - 1][i], dp[j - 1][i - wv[j][0]] + wv[j][1])

    print(max(dp[-1]))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    N, W = [int(x) for x in input().split()]
    shina = []
    for i in range(N):
        a, b = [int(x) for x in input().split()]
        shina.append([a, b])

    dp = [[0 for i in range(N + 1)] for j in range(W + 1)]

    for i in range(N - 1, -1, -1):
        for j in range(W + 1):
            if shina[i][0] > j:
                dp[j][i] = dp[j][i + 1]
            else:
                dp[j][i] = max(dp[j][i + 1], dp[j - shina[i][0]][i + 1] + shina[i][1])

    ans = 0
    for j in range(W + 1):
        ans = max(ans, max(dp[j]))

    print(ans)


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

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

num = 1000000007
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

grad = y / x
if grad < 0.5 or grad > 2:
    print(0)
    exit()

turns = int((x + y) / 3)

total = 0
t = (x + y) // 2
u = t - min(x, y)
o = t // 3 - u

total = combinations_count(turns, o)
total %= num
print(total)

### FIXED CODE ###

import math


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

    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



num = 1000000007
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

grad = y / x
if grad < 0.5 or grad > 2:
    print(0)
    exit()

turns = int((x + y) / 3)

total = 0
t = (x + y) // 2
u = t - min(x, y)
o = t // 3 - u

total = cmb(turns, o)
total %= num
print(total)
### BUGGY CODE ###

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


def expected(n):
    return (1+n)/2

p=list(map(expected,p))
for i in range(N-K+1):
    sigmap=0
    for j in range(K):
        sigmap+=p[i+j]
    maxexp=max(sigmap,maxexp)
print(maxexp)


### FIXED CODE ###

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


def expected(n):
    return (1+n)/2


p=list(map(expected,p))

for i in range(K):
    maxexp+=p[i]
now=maxexp
for i in range(N-K):
    now=now+p[i+K]-p[i]
    maxexp=max(now,maxexp)
print(maxexp)
### BUGGY CODE ###

n = int(input())

word_list = {}
for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    for this_word in word_list:
        if this_word == input_word:
            word_list[this_word] += 1
            flag = 0
            break
    if flag:
        word_list[input_word] = 0

result = 0
for index in word_list:
    cnt = word_list[index]
    result += int(cnt*(cnt+1)/2)
print(result)

### FIXED CODE ###

n = int(input())

result = 0
word_list = {}

for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    if input_word in word_list:
        word_list[input_word] += 1
        result += word_list[input_word]
        flag = 0
    else:
        word_list[input_word] = 0

print(result)
### BUGGY CODE ###

n = int(raw_input())

dishes_a = list()
dishes_b = list()
dishes_diff = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    diff = b - a
    dishes_a.append(a)
    dishes_b.append(b)
    dishes_diff.append(diff)

takahashi = 0
aoki = 0
index = 0
diff_flag = True

if max(dishes_diff) == 0:
    diff_flag = False

for i in range(0, n):
    if i % 2 == 0:
        if diff_flag and max(dishes_diff) != 0:
            index = dishes_diff.index(max(dishes_diff))
        else:
            diff_flag = False
            index = dishes_a.index(max(dishes_a))

        takahashi = takahashi + dishes_a[index]
        dishes_a.pop(index)
        dishes_b.pop(index)
        dishes_diff.pop(index)
    else:
        index = dishes_b.index(max(dishes_b))
        aoki = aoki + dishes_b[index]
        dishes_a.pop(index)
        dishes_b.pop(index)
        dishes_diff.pop(index)

print(takahashi - aoki)


### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
import math


n = int(input())

dishes = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    sum = a + b
    dishes.append([a, b, sum])

takahashi = 0
aoki = 0
dishes.sort(key=lambda x: x[2], reverse=True)

for i in range(0, n):
    if i % 2 == 0:
        j = dishes[0]
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        j = dishes[0]
        dishes.pop(0)
        aoki = aoki + j[1]

print takahashi - aoki
### BUGGY CODE ###

#How many ways M=a1*a2*...*aN ex)N=2,M=6 a={1,6},{2,3},{3,2},{6,1}
import math
n,m=map(int,input().split())
factor=[]
c=0
mod=10**9+7

#Prime Factorization [number,times]
while m%2 == 0:
    m//=2
    c+=1
if c != 0:
    factor.append([2,c])
#Alternate
for i in range(3,m+1,2):
    c=0
    while m%i == 0:
        m//=i
        c+=1
    if c != 0:
        factor.append([i,c])


def C(n,k):
    ans=1
    for s in range(1,k+1):
        ans*=n
        ans//=s
        n-=1
    return ans

def funcount(length,rest):
    a=0
    if length==1:
        #print(rest)
        return 1
    elif rest <= 1:
        #print("not",rest)
        return 0
    else:
        for i in range(1,rest):
            #print(i,end=" ")
            a+=funcount(length-1,rest-i)
        return a


way=1
for f in factor:
    sum=0
    for k in range(1,f[1]+1):
        sum+=funcount(k,f[1])*C(n,k)
    way*=sum
    
print(way%mod)

### FIXED CODE ###

#How many ways M=a1*a2*...*aN ex)N=2,M=6 a={1,6},{2,3},{3,2},{6,1}
import math
n,m=map(int,input().split())
factor=[]
c=0
mod=10**9+7

#Prime Factorization [number,times]
while m%2 == 0:
    m//=2
    c+=1
    '''
    if c>=20:
        c=0
        break
        '''
if c != 0:
    factor.append([2,c])
#Alternate
for i in range(3,m+1,2):
    c=0
    while m%i == 0:
        m//=i
        c+=1
    if c != 0:
        #print(i,c)
        factor.append([i,c])
    if m == 1:
        break
    if i*i>=m:  # m is prime
        factor.append([m,1])
        break
        
#print(factor)

def C(n,k):
    ans=1
    for s in range(1,k+1):
        ans*=n
        ans//=s
        n-=1
    return ans

def funcount(length,rest,memo):
    a=0
    if length==1:
        #print(length,rest)
        memo[length][rest]=1
        return 1,memo
    elif rest <= 1:
        #print(length,rest)
        memo[length][rest]=0
        return 0,memo
    if memo[length][rest] != -1:
        return memo[length][rest],memo
    else:
        for i in range(1,rest):
            #print(i,end=" ")
            a+=funcount(length-1,rest-i,memo)[0]
            memo=funcount(length-1,rest-i,memo)[1]
            #print(memo)
        memo[length][rest]=a
        return a,memo
    

way=1
for f in factor:
    sum=0
    for k in range(1,f[1]+1):
        memo=[[-1 for r in range(f[1]+1)] for l in range(k+1)] 
        #print(memo)
        sum+=funcount(k,f[1],memo)[0]*C(n,k)
    way=(way*sum)%mod
    
print(way%mod)
### BUGGY CODE ###

from collections import deque
hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = deque()
chlist = [0]
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
for i in range(len(hlist)):
    ch = chlist[i+1]
    d = ch - chlist[i]
    if (hh > max(chlist[i+1:])):
        hh = max(chlist[i+1:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        s += ((hh - ch) + d * 0.5)
    elif (ch == hh and chlist[i+1] == chlist[i] + 1):
        f = 0
        s += 1/2
        slist.append(int(s))
        s = 0


print(int(sum(slist)))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
print(*slist)


### FIXED CODE ###

s=j=0
a=[];b=[];d=[]
for i,x in enumerate(input()):
    if x=='\\':a+=[i]
    elif x=='/' and a:
        j=a.pop()
        c=i-j;s+=c
        while b and b[-1]>j:c+=d.pop();b.pop()
        b+=[j];d+=[c]
print(s)
print(len(b),*(d))
### BUGGY CODE ###

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

list.sort(A, reverse=True)  # 降順にソート

for i in range(M):
    A[0] = A[0] // 2
    list.sort(A, reverse=True)
    
print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
hq = []

for i in range(N):
    heapq.heappush(hq, A[i]*(-1))

for i in range(M):
    tmp = heapq.heappop(hq) * (-1) // 2
    heapq.heappush(hq, tmp*(-1))
    
print(sum(hq)*(-1))
### BUGGY CODE ###

from collections import deque
inf = 10 ** 10

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

graph = [[] for i in range(N)]
dis = [[inf]*N for i in range(N)]

for i in range(M):
    L,R,D = map(int,input().split())
    L -= 1
    R -= 1
    graph[L].append(R)
    graph[R].append(L)
    dis[L][R] = D
    dis[R][L] = (-1)*D

data = [inf]*N
det = 0

for i in range(N):
    if data[i] != inf:
        continue
    data[i] = 0
    stack = deque()
    stack.append(i)
    while stack:
        x = stack.pop()
        for y in graph[x]:
            if data[y] == inf:
                data[y] = data[x] + dis[x][y]
                stack.append(y)
            else:
                if data[y] - data[x] != dis[x][y]:
                    det = -1
                    break
    if det == -1:
        break

if det == 0:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

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

graph = [[] for i in range(N)]

for i in range(M):
    L,R,D = map(int,input().split())
    L -= 1
    R -= 1
    graph[L].append([R,D])
    graph[R].append([L,-D])
    
data = [None]*N

for i in range(N):
    if data[i] != None:
        continue
    data[i] = 0
    stack = deque()
    stack.append(i)
    while stack:
        x = stack.popleft()
        for y in graph[x]:
            if data[y[0]] == None:
                data[y[0]] = data[x] + y[1]
                stack.append(y[0])
            else:
                if data[y[0]] - data[x] != y[1]:
                    print("No")
                    sys.exit()
    
print("Yes")
### BUGGY CODE ###

N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in range(10**5+1):
  numlist[i]=listA.count(i)
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  if numlist[B]!=0:
    sum=sum+(C-B)*numlist[B]
    # print(C)
    numlist[C]+=numlist[B]
    numlist[B]=0
    # print(numlist)
  print(sum)


### FIXED CODE ###

N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in listA:
  numlist[i]+=1
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  if numlist[B]!=0:
    sum=sum+(C-B)*numlist[B]
    # print(C)
    numlist[C]+=numlist[B]
    numlist[B]=0
    # print(numlist)
  print(sum)
### BUGGY CODE ###

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

s = input()
n = len(s)
dp = [[0 for j in range(4)] for i in range(n+1)]
dp[0][0] = 1

for i,c in enumerate(s):
    if c == "?":
        dp[i+1][0] = dp[i][0] * 3
        dp[i + 1][1] = dp[i][0] + dp[i][1] * 3
        dp[i + 1][2] = dp[i][1] + dp[i][2] * 3
        dp[i + 1][3] = dp[i][2] + dp[i][3] * 3

    elif c == "A":
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][0] + dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][3]


    elif c == "B":
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][1] + dp[i][2]
        dp[i + 1][3] = dp[i][3]

    else:
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][2] + dp[i][3]

print(dp[n][3] % 1000000007)



### FIXED CODE ###

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

s = input()
n = len(s)
xc, yc, zc, wc = 1,0,0,0

for c in s:
    if c == "?":
        x = xc*3
        y = xc + yc * 3
        z = yc + zc * 3
        w = zc + wc * 3

    elif c == "A":
        x = xc
        y= yc + xc
        z = zc
        w = wc

    elif c == "B":
        x = xc
        y = yc
        z = zc + yc
        w = wc

    else:
        x = xc
        y = yc
        z = zc
        w = wc + zc

    xc,yc,zc,wc = [cur%1000000007 for cur in [x,y,z,w]]

print(wc)
### BUGGY CODE ###

import collections
import math

def combinations_count(n, r):
    return (n*(n-1)//2)
    # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = list(map(int, input().split()))
Ay = list(set(A))
c = collections.Counter(A)
cnt = 0
ansx = []
ansy = []

for i in Ay:
    for x, y in c.items():
        if i == x and y >= 3:
            cnt += combinations_count(y - 1, 2)
        elif i != x and y >= 2:
            cnt += combinations_count(y, 2)
    ansx.append(i)
    ansy.append(cnt)
    cnt = 0

for i in A:
    print(ansy[ansx.index(i)])


### FIXED CODE ###

import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
cnt = 0


sumall = 0
for x, y in c.items():
    sumall += (y*(y-1)//2)

for i in range(N):
    print(sumall - c[A[i]] + 1)
### BUGGY CODE ###

import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = [tuple(map(int, input().split())) for _ in range(N)]
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        for c in range(N):
            if c == a or c == b:
                continue
            if matr[a][b] == matr[a][c] + matr[c][b]:
                break
        else:
            ans += matr[a][b]
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype=np.int64)
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        eq = (matr[a, b] == (matr[a] + matr[:, b]))
        eq[a] = eq[b] = False
        if not np.any(eq):
            ans += matr[a, b]
    print(ans)


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

n=int(input())
s={}
ans=[]
max=0
for i in range(n):
    st=input()
    if st in s:
        s[st]+=1
    else:
        s[st]=1
    if max<s[st]:
        max=s[st]
        ans=[st]
    elif max==s[st]:
        if not st in ans:
            ans.append(st)
ans.sort()
for i in ans:
    print(i)

### FIXED CODE ###

n=int(input())
s={}
ans=[]
max=0
for i in range(n):
    st=input()
    if st in s:
        s[st]+=1
    else:
        s[st]=1
    if max<s[st]:
        max=s[st]
        ans=[st]
    elif max==s[st]:
        ans.append(st)
ans.sort()
for i in ans:
    print(i)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
#print(a)
for i in range(n):
    tmp = a[:i]+a[i+1:]
    #print(tmp)
    print(max(tmp))

### FIXED CODE ###

n = int(input())
max_1 = 0
max_2 = 0
a_list = []
for i in range(n):
    a = int(input())
    a_list.append(a)
    if max_1 < a:
        max_2 = max_1
        max_1 = a
    elif max_2 < a:
        max_2 = a
#print(max_1,max_2)
for i in range(n):
    if a_list[i] == max_1:
        print(max_2)
    else:
        print(max_1)
### BUGGY CODE ###

s = input()
z = [0]
for i in range(len(s)):
    z.append(int(s[i:])%2019)

from collections import Counter
q = Counter(z)

ans=0
for i in q.values():
    ans+=i*(i-1)//2
print(ans)

### FIXED CODE ###

import collections
s = input()
u = collections.deque([0])
for i in range(len(s)):
    u.append((u[i]+int(s[-i-1])*10**(i%224))%2019)
u2 = collections.Counter(u)
sum = 0
for i in u2.values():
    sum += i*(i-1)/2
print(int(sum))
### BUGGY CODE ###

def main():
    c11, c12, c13 = map(int, input().split())
    c21, c22, c23 = map(int, input().split())
    c31, c32, c33 = map(int, input().split())

    r1max = max([c11, c12, c13])
    r2max = max([c21, c22, c23])
    r3max = max([c31, c32, c33])
    c1max = max([c11, c21, c31])
    c2max = max([c12, c22, c32])
    c3max = max([c13, c23, c33])
    for a1 in range(0, r1max + 1):
        for a2 in range(0, r2max + 1):
            for a3 in range(0, r3max + 1):
                for b1 in range(0, c1max + 1):
                    C11 = a1 + b1
                    C21 = a2 + b1
                    C31 = a3 + b1
                    if C11 == c11 and C21 == c21 and C31 == c31:
                        for b2 in range(0, c2max + 1):
                            C12 = a1 + b2
                            C22 = a2 + b2
                            C32 = a3 + b2
                            if C12 == c12 and C22 == c22 and C32 == c32:
                                for b3 in range(0, c3max + 1):
                                    C13 = a1 + b3
                                    C23 = a2 + b3
                                    C33 = a3 + b3
                                    if C13 == c13 and C23 == c23 and C33 == c33:
                                        print('Yes')
                                        return

    print('No')
    return


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    c11, c12, c13 = map(int, input().split())
    c21, c22, c23 = map(int, input().split())
    c31, c32, c33 = map(int, input().split())

    r1max = max([c11, c12, c13])
    r2max = max([c21, c22, c23])
    r3max = max([c31, c32, c33])
    c1max = max([c11, c21, c31])
    c2max = max([c12, c22, c32])
    c3max = max([c13, c23, c33])
    for a1 in range(0, r1max + 1):
        for a2 in range(0, r2max + 1):
            for a3 in range(0, r3max + 1):
                m = max([a1, a2, a3])
                for b1 in range(0, c1max - m + 1):
                    C11 = a1 + b1
                    C21 = a2 + b1
                    C31 = a3 + b1
                    if C11 == c11 and C21 == c21 and C31 == c31:
                        for b2 in range(0, c2max - m + 1):
                            C12 = a1 + b2
                            C22 = a2 + b2
                            C32 = a3 + b2
                            if C12 == c12 and C22 == c22 and C32 == c32:
                                for b3 in range(0, c3max - m + 1):
                                    C13 = a1 + b3
                                    C23 = a2 + b3
                                    C33 = a3 + b3
                                    if C13 == c13 and C23 == c23 and C33 == c33:
                                        print('Yes')
                                        return

    print('No')
    return


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

n=int(input())
import math
list=[ ]

for i in range(1,math.floor(n*0.5)+1):
  if (n/i)%1==0:
    j=n/i
    list.append(i+j)

print(int(min(list)-2))


### FIXED CODE ###

n=int(input())
import math
list=[ ]

for i in range(1,math.floor(n**0.5)+1):
  if (n/i)%1==0:
    j=n/i
    list.append(i+j)

print(int(min(list)-2))