Harryxun/stf_run huggingface dataset:
s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break

### FIXED CODE ###

def hantei(s, h):
    try:
        slen = len(s)
        hlen = len(h)
        res = s.index(h, slen - hlen, slen + 1)
        return res
    except ValueError as e:
        return -1


def resolve():
    s = input()
    a = 'dream'
    b = 'dreamer'
    c = 'erase'
    d = 'eraser'
    while True:
        # 後ろから文字列検索
        # 合ったらその文字を削除
        D = hantei(s, d)
        if D > -1:
            s = s[:-len(d)]
            continue
        B = hantei(s, b)
        if B > -1:
            s = s[:-len(b)]
            continue
        C = hantei(s, c)
        if C > -1:
            s = s[:-len(c)]
            continue
        A = hantei(s, a)
        if A > -1:
            s = s[:-len(a)]
            continue
        if len(s) == 0:
            print('YES')
        else:
            print('NO')
        break
        
resolve()
S=input()
list(S)
if S[0]==S[1]==s[2]:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

S=input()
list(S)
if S[0]==S[1] and S[1]==S[2]:
  print('No')
else:
  print('Yes')
n,x=map(int,input().split())
l=[int(input()) for _ in range(n)]

ans=0
a=0
for i in range(n):
  if i==0:
    ans+=1
    continue
  else:
    if a<=x:
      ans+=1
      a+=l[i-1]
    else:
      break

print(ans)

### FIXED CODE ###

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

ans=1
a=0
for i in range(n):
  a+=l[i]
  if a>x:
    break
  else:
    ans+=1
    
print(ans)
A = int(input())
B = int(input())
c = A + B
d = A - B
e = A * B
f = [c, d, e]
maxvalue = c
for i in range(len(f)):
    if f[i] > maxvalue:
        maxvalue = f[i]
print(maxvalue)


### FIXED CODE ###

A, B = map(int, input().split())
c = A + B
d = A - B
e = A * B
f = [c, d, e]
maxvalue = c
for i in range(len(f)):
    if f[i] > maxvalue:
        maxvalue = f[i]
print(maxvalue)
n = int(raw_input()) 
r,cumul, ais, m = 0, 0, [int(raw_input()) for _ in range(n)],+float('inf')
for ai in ais:# in range(0, len(ais)):
	cumul += ai
	m = min(m, ais[i] if ai % 10 else +float('inf'))
	r = max(r, cumul - (m if cumul % 10 else 0))
print r

### FIXED CODE ###

n = int(raw_input()) 
ais = [int(raw_input()) for _ in range(n)]
r = 0
cumul = 0
m = +float('inf')
for i in range(0, len(ais)):
	cumul += ais[i]
	if ais[i] % 10:
		m = min(m, ais[i])

	if cumul % 10 == 0:
		r = max(r, cumul - m)
	else:
		r = max(r, cumul)

print r
N=int(input())
A=list(map(int, input().split()))
str = ""
for i in range(N):
  str += str(A.index(i+1)+1) + " "

### FIXED CODE ###

N=int(input())
As=list(map(int, input().split()))
man = [""] * N
for i in range(N):
  man[As[i]-1] = str(i+1)
result = ' '.join(man)
print(result)
def solve():
    
    N = int(input())
    a  = list(map(int, input().split()))

    lists = [0] * ((10**5)+2)

    for i in range(a):
        lists[v] += 1
        lists[v+1] += 1
        lists[v-1] += 1

    print(max(lists))    

if __name__ == "__main__":
    solve()


### FIXED CODE ###

def solve():
    
    N = int(input())
    a  = list(map(int, input().split()))

    lists = [0] * ((10**5)+2)

    for i in a:
        lists[i] += 1
        lists[i+1] += 1
        lists[i-1] += 1

    print(max(lists))    

if __name__ == "__main__":
    solve()
INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2
 
n = int(input())
M = [list(map(int, input().split())) for i in range(n)]
 
d = [INFTY for i in range(n)]
color = [WHITE for i in range(n)]
 
for i in range(n):
    u = int(input())
    k = int(input())
    for j in range(k):
        v = int(input())
        c = int(input())
        M[u][v] = c
        
def dijkstra():
    global M, d, color
    d[0] = 0
    color[0] = GRAY
    while(1):
        minv = INFTY
        u = -1
        for i in range(n):
            if (minv > d[i] and color[i] != BLACK):
                u = i
                minv = d[i]
        if (u == -1):
            break
        color[u] = BLACK
        for v in range(n):
            if (color[v] != BLACK and M[u][v] != INFTY):
                if (d[v] > d[u] + M[u][v]):
                    d[v] = d[u] + M[u][v]
                    color[v] = GRAY
    for i in range(n):
        print(i, (-1 if d[i] == INFTY else d[i]))
dijkstra()

### FIXED CODE ###

from sys import stdin

INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2

n = int(stdin.readline())
M = [[INFTY for i in range(n)] for j in range(n)]

for u in range(n):
    U = list(map(int, stdin.readline().split()[2:]))
    for j in range(0, len(U), 2):
        M[u][U[j]] = U[j+1]

d = [INFTY for i in range(n)]
color = [WHITE for i in range(n)]

def dijkstra():
    global n
    d[0] = 0
    color[0] = GRAY
    while(1):
        minv = INFTY
        u = -1
        for i in range(n):
            if (minv > d[i] and color[i] != BLACK):
                u = i
                minv = d[i]
        if (u == -1):
            break
        color[u] = BLACK
        for v in range(n):
            if (color[v] != BLACK and M[u][v] != INFTY):
                if(d[v] > d[u] + M[u][v]):
                    d[v] = d[u] + M[u][v]
                    color[v] = GRAY
    for i in range(
n):
        print(i, (-1 if d[i] == INFTY else d[i]))
dijkstra()
n,m = map(int,input().split())
price_list = sorted(list(map(int,input().split())),reverse = True)
for num in range(m):
    price_list[0] = price_list[0]//2
    price_list = sorted(price_list,reverse = True)
sum(price_list)

### FIXED CODE ###

i  = input()
if i == 'Sunny':
    print('Cloudy')
elif i == 'Cloudy':
    print('Rainy')
elif i == 'Rainy':
    print('Sunny')
a, b = map(int,raw_input().split())
if a > b:
    print 'a > b'
if a == b:
    print 'a == b'
else
    print 'a < b'

### FIXED CODE ###

a, b = map(int, raw_input().split())

if a>b:
  print "a > b"
if a<b:
  print "a < b"
if a==b:
  print "a == b"
s = list(input())
b = 0
if s[0] == "A" and "C" in s[2:-2] and s.replace("A","",1).replace("C","",1).islower():
    print("AC")
else:
    print("WA")

### FIXED CODE ###

s = input()
b = 0
if s[0] == "A" and "C" in s[2:-1] and s[1:].replace("C","",1).islower():
    print("AC")
else:
    print("WA")
N, X, M = [int(x) for x in input().split()]

A = [0] * (M + 1)
firstApearAt = {i:0 for i in range(M)}
A[1] =  X
firstApearAt[X] = 1
for i in range(2, M + 1):
    A[i] = (A[i - 1] * A[i - 1]) % M
    if firstApearAt[A[i]]:
        r = i
        l = firstApearAt[A[i]]
        break
    firstApearAt[A[i]] = i

ans = 0
if N <= l - 1:
    ans = sum(A[1:N + 1])
else:
    q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)
    ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])

print(ans)

### FIXED CODE ###

N, X, M = [int(x) for x in input().split()]

A = [0] * (M + 1)
firstApearAt = {i:0 for i in range(M)}
A[1] =  X
firstApearAt[X] = 1
l, r = 1, 2
for i in range(2, M + 1):
    A[i] = (A[i - 1] * A[i - 1]) % M
    if firstApearAt[A[i]] > 0:
        r = i
        l = firstApearAt[A[i]]
        break
    firstApearAt[A[i]] = i

ans = 0
if N <= l - 1:
    ans = sum(A[1:N + 1])
else:
    q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)
    ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])

print(ans)
N, K = map(int, input().split())
import numpy as np
As = list(map(lambda x: int(x)-1, input().split()))

cnt = 1
v = 0
checked = [-1]*N
checked[0] = 0
while True:
    v = As[v]
    if checked[v]!=-1:
        loop = cnt-checked[v]
        road = checked[v]
        break
    cnt += 1
    checked[v] = cnt-1

ite = K if K<=road else road+((K-road)%loop)

v = 0
for i in range(ite):
    v = As[v]

print(v+1)

### FIXED CODE ###

N, K = map(int, input().split())
As = list(map(lambda x: int(x)-1, input().split()))

cnt = 1
v = 0
checked = [-1]*N
checked[0] = 0
while True:
    v = As[v]
    if checked[v]!=-1:
        loop = cnt-checked[v]
        road = checked[v]
        break
    cnt += 1
    checked[v] = cnt-1

ite = K if K<=road else road+((K-road)%loop)

v = 0
for i in range(ite):
    v = As[v]

print(v+1)
N, M = map(int, input().split())

mod = 998244353
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


A = []
tmp = 0
for i in range(3*M+N+2):
    tmp = (tmp + cmb(N-2+i, N-2)) % mod
    A.append(tmp)

ans = 0
for k in range(min(N, M)+1):
    if (M-k) % 2 != 0: continue
    l = (3*M-k)//2
    a = cmb(N-1+l, N-1) * cmb(N, k)
    b = N * (cmb(N-1, k-1)*A[l-M])
    if l >= M+1:
        b += N * cmb(N-1, k)*A[l-M-1]
    #print(k,a-b)
    ans = (ans + a - b) % mod 
print(ans)

# C = set()
# def calc(d, A):
#     if d == M:
#         t = ""
#         for a in A:
#             t += str(a)
#         C.add(t)
#         return
#     for i in range(N):
#         for j in range(N):
#             if i == j: continue
#             B = A[:]
#             B[i] += 2
#             B[j] += 1
#             calc(d+1, B)
#     return

#calc(0, [0]*N)
#print(len(C))
#print(C)


### FIXED CODE ###

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

mod = 998244353
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 4*10**6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


A = []
tmp = 0
for i in range(2*M+N+2):
    tmp = (tmp + cmb(N-2+i, N-2)) % mod
    A.append(tmp)

ans = 0
for k in range(min(N, M)+1):
    if (M-k) % 2 != 0: continue
    l = (3*M-k)//2
    a = cmb(N-1+l, N-1) * cmb(N, k)
    b = N * (cmb(N-1, k-1)*A[l-M])
    if l >= M+1:
        b += N * cmb(N-1, k)*A[l-M-1]
    #print(k,a-b)
    ans = (ans + a - b) % mod 
print(ans)

# C = set()
# def calc(d, A):
#     if d == M:
#         t = ""
#         for a in A:
#             t += str(a)
#         C.add(t)
#         return
#     for i in range(N):
#         for j in range(N):
#             if i == j: continue
#             B = A[:]
#             B[i] += 2
#             B[j] += 1
#             calc(d+1, B)
#     return

#calc(0, [0]*N)
#print(len(C))
#print(C)
a = []
[a.append(list(map(int, input().split()))) for _ in range(3)]
n = int(input())
b = [int(input())for _ in range(n)]
for i in b:
  for j in range(3):
    for k in range(3):
      if a[j][k] == i:
        a[j][k] = 1
ans = 0
count =0
for j in range(3):
  if a[j].count(1) == 3:
    ans += 1
  elif (a[0][j] == a[1][j] == a[2][j]) == 1:
    ans += 1
  elif (a[0][0] == a[1][1] == a[2][2]) == 1:
    ans += 1
  elif (a[0][2] == a[1][1] == a[2][0]) == 1:
    ans += 1
if ans > 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
if N % 2 == 0:
  print( N // 2)
else:
  print( N // 2 + 1)
60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

### FIXED CODE ###

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

for _ in range(n):
  b = int(input())
  for y in range(3):
    for x in range(3):
      if a[y][x] == b:
        a[y][x] = -1

for y in range(3):
  f = True
  for x in range(3):
    if a[y][x] != -1:
      f = False
  if f:
    print('Yes')
    exit()
    
for x in range(3):
  f = True
  for y in range(3):
    if a[y][x] != -1:
      f = False
  if f:
    print('Yes')
    exit()
    
f = True
for x in range(3):
  if a[x][x] != -1:
    f = False
if f:
  print('Yes')
  exit()
  
f = True
for x in range(3):
  if a[x][2-x] != -1:
    f = False
if f:
  print('Yes')
  exit()
  
print('No')
a, b, _, k = [int(i) for x in input().strip().split(" ")]

if k % 2 == 0:
    print(a-b)
else:
    print(b-a)


### FIXED CODE ###

a, b, _, k = [int(x) for x in input().strip().split(" ")]

if k % 2 == 0:
    print(a-b)
else:
    print(b-a)
from sys import stdin
a,b = stdin.readline().rstrip().split()
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")


### FIXED CODE ###

from sys import stdin

a,b = [int(x) for x in stdin.readline().rstrip().split()]

if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")
from collections import deque
H,W = list(map(int,input().split()))
start = list(map(lambda x:int(x)-1,input().split()))
goal = list(map(lambda x:int(x)-1,input().split()))
A = [input() for _ in range(H)]
visited = [[0]*W for _ in range(H)]
B = deque([[start[0],start[1],0]])
warp = []
for i in range(-2,3):
    for j in range(-2,3):
            warp.append([i,j])

num = 0
# print(start,warp)
while 1:
    y,x,n = B.popleft()
    if visited[y][x] == 1:continue
    if [y,x] == goal:
        num = n
        break
    visited[y][x] = 1
    for dy,dx in [[1,0],[0,1],[-1,0],[0,-1]]:
        if (y+dy<0)|(x+dx<0)|(y+dy>=H)|(x+dx>=W):continue
        if (A[y+dy][x+dx]==".")&(visited[y+dy][x+dx]==0):
            B.appendleft([y+dy,x+dx,n])
    for dy,dx in warp:
        if (y+dy<0)|(x+dx<0)|(y+dy>=H)|(x+dx>=W):continue
        if (A[y+dy][x+dx]==".")&(visited[y+dy][x+dx]==0):
            B.append([y+dy,x+dx,n+1])
    if not B:
        num = -1
        break

print(num)

### FIXED CODE ###

from collections import deque
H,W = list(map(int,input().split()))
start = list(map(lambda x:int(x)-1,input().split()))
goal = list(map(lambda x:int(x)-1,input().split()))
A = [input() for _ in range(H)]
visited = [[0]*W for _ in range(H)]
B = deque([[start[0],start[1],0]])
warp = []
for i in range(-2,3):
    for j in range(-2,3):
            warp.append([i,j])

num = -1

while B:
    y,x,n = B.popleft()
    if visited[y][x] == 1:continue
    if [y,x] == goal:
        num = n
        break
    visited[y][x] = 1
    for dy,dx in [[1,0],[0,1],[-1,0],[0,-1]]:
        if (y+dy<0)|(x+dx<0)|(y+dy>=H)|(x+dx>=W):continue
        if (A[y+dy][x+dx]==".")&(visited[y+dy][x+dx]==0):
            B.appendleft([y+dy,x+dx,n])
    for dy,dx in warp:
        if (y+dy<0)|(x+dx<0)|(y+dy>=H)|(x+dx>=W):continue
        if (A[y+dy][x+dx]==".")&(visited[y+dy][x+dx]==0):
            B.append([y+dy,x+dx,n+1])

print(num)
# coding: utf-8
import sys
input = sys.stdin.readline

N= input()
S = sum(map(int, N))
print("Yes" if int(N)%S==0 else "No")

### FIXED CODE ###

# coding: utf-8
N= input()
S = sum(map(int, N))
print("Yes" if int(N)%S==0 else "No")
a, b, c = map(str, input().str())
a = int(a)
c = int(c)

if b=="+":
    print(int(a+c))
else:
    print(int(a-c))

### FIXED CODE ###

a, b, c = map(str, input().split())
a = int(a)
c = int(c)

if b=="+":
    print(int(a+c))
else:
    print(int(a-c))
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(1,n-1):
  if a[i]<a[i+1] and a[i+1]<a[i+2]:
    c+=1
  elif a[i]>a[i+1] and a[i+1]>a[i+2]:
    c+=1
print(c)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(0,n-2):
  if a[i]<a[i+1] and a[i+1]<a[i+2]:
    c+=1
  elif a[i]>a[i+1] and a[i+1]>a[i+2]:
    c+=1
print(c)
X, Y, Z, K = map(int, input().split())

list_cake_1 = []
list_cake_2 = []
list_cake_3 = []

while len(list_cake_1) < X:
	element = list(map(int, input().split()))
	list_cake_1.extend(element)

while len(list_cake_2) < Y:
	element = list(map(int, input().split()))
	list_cake_2.extend(element)
	
while len(list_cake_3) < Z:
	element = list(map(int, input().split()))
	list_cake_3.extend(element)

list_cake_1.sort()
list_cake_2.sort()
list_cake_3.sort()
	
list_total_K = []

for i in range(1, X+1):
	for j in range(1, Y+1):
		for k in range(1, Z+1):
			if i*j*k < K:
				continue
			else:
				total_ijk = list_cake_1[i-1]+list_cake_2[j-1]+list_cake_3[k-1]
				list_total_K.append(total_ijk)
				
list_total_K.sort()

for i in range(1, K+1):
	print(list_total_K[-i])

### FIXED CODE ###

import sys

input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())

list_cake_1 = list(map(int, input().split()))
list_cake_2 = list(map(int, input().split()))
list_cake_3 = list(map(int, input().split()))

list_cake_1 = sorted(list_cake_1, reverse=True)
list_cake_2 = sorted(list_cake_2, reverse=True)
list_cake_3 = sorted(list_cake_3, reverse=True)

list_total_sum = []

for i, cake_1 in enumerate(list_cake_1, 1):
	for j, cake_2 in enumerate(list_cake_2, 1):
		for k, cake_3 in enumerate(list_cake_3, 1):
			if i*j*k > K:
				break
			list_total_sum.append(cake_1 + cake_2 + cake_3)

for element in sorted(list_total_sum, reverse=True)[:K]:
	print(element)
N = int(input())
ans = 0

if N % 2 = 0:
  ans = N / 2
else:
  ans = (N + 1) / 2
  
print(ans)

### FIXED CODE ###

N = int(input())
odd = 0
 
if N % 2 == 0:
  odd = N / 2
else:
  odd = (N + 1) / 2
 
print(odd / N)
array = input()

char = ["" for _ in range(len(array))]
for i in range(len(array)):
    char[i] = array[i:i+1]

alp = [0 for _ in range(26)]
for j in range(len(array)):
    for i in range(26):
        if char[j] == chr(i+ord("A")) or c == chr(i+ord("a")):
            alp[i] += 1

for i in range(26):
    print("{0} : {1}".format(chr(i+ord("a")), alp[i]))

### FIXED CODE ###

import sys

count = [0 for _ in range(26)]

for line in sys.stdin:
    array = line
    char = ["" for _ in range(len(array))]
    for i in range(len(array)):
        char[i] = array[i:i+1]
    for c in char:
        for i in range(26):
            if c == chr(i+ord("A")) or c == chr(i+ord("a")):
                count[i] += 1


for i in range(26):
    print("{0} : {1}".format(chr(i+ord("a")), count[i]))
INF = 10 ** 18
N, M = map(int, input().split())
abc = []
d = [INF] * N
d[0] = 0
loop = [False] * N

for i in range(M):
    a, b, c = map(int, input().split())
    abc.append([a - 1, b - 1,  -c])

for j in range(N):
    for i in range(M):
        if d[abc[i][0]] != INF and d[abc[i][1]] > d[abc[i][0]] + abc[i][2]:
            d[abc[i][1]] = d[abc[i][0]] + abc[i][2]
ans = -1 * d[-1]
for i in range(N):
    for j in range(M):
        if d[abc[i][0]] != INF and d[abc[j][1]] > d[abc[j][0]] + abc[j][2]:
            d[abc[j][1]] = d[abc[j][0]] + abc[j][2]
            loop[abc[j][1]] = True
        if loop[abc[j][0]] == True:
            loop[abc[j][1]] = True

if loop[N - 1]:
    print('inf')
else:
    print(ans)

### FIXED CODE ###

INF = 10 ** 18
N, M = map(int, input().split())
abc = []
d = [INF] * N
d[0] = 0
loop = [False] * N

for i in range(M):
    a, b, c = map(int, input().split())
    abc.append([a - 1, b - 1,  -c])

for j in range(N):
    for i in range(M):
        if d[abc[i][1]] > d[abc[i][0]] + abc[i][2]:
            d[abc[i][1]] = d[abc[i][0]] + abc[i][2]
ans = -1 * d[-1]

for i in range(N):
    for j in range(M):
        if d[abc[j][1]] > d[abc[j][0]] + abc[j][2]:
            d[abc[j][1]] = d[abc[j][0]] + abc[j][2]
            loop[abc[j][1]] = True

        if loop[abc[j][0]] == True:
            loop[abc[j][1]] = True

if loop[N - 1]:
    print('inf')
else:
    print(ans)
l,r = map(int,input().split())

if (l==2019)or(r==2019)or(r-l>=2019):
    print('0')
    
elif r-l==1:
    ans = (r*l)%2019
else:
    ans=2019
    for i in range(l,r-1):
        for j in range(i+1,r):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
            if ans == 1:
                break
            
print(str(ans))

### FIXED CODE ###

l,r = map(int,input().split())

if (l==2019)or(r==2019)or(r-l>=2019):
    ans=0
    
elif r-l==1:
    ans = (r*l)%2019
else:
    ans=2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
            if ans == 1:
                break
print(str(ans))
from collections import deque
N=int(input())
X=[chr(i+97) for i in range(N)]
q=deque(["a"])
while(len(q)>0):
    r=q.popleft()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            print(p)
        else:
            q.append(p)


### FIXED CODE ###

from collections import deque
N=int(input())
if N==1:
    print("a")
    exit()
X=[chr(i+97) for i in range(N)]
#print(X)
Y=[]
q=deque(["a"])
while(len(q)>0):
    r=q.pop()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            Y.append(p)
        else:
            q.append(p)
Y.sort()
for line in Y:
    print(line)
from collections import Counter

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

c = Counter(a)
s = set(a)
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
elif len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
    elif l == 3:
        if s[0] ^ s[1] ^ s[2] == 0:
            tmp = c[a[0]]
            if all(x == tmp for x in c.values()):
                print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')


### FIXED CODE ###

from collections import Counter

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

c = Counter(a)
s = list(set(a))
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
    exit()
if len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
        exit()
    if l == 3 and s[0] ^ s[1] ^ s[2] == 0:
        tmp = n//3
        if all(x == tmp for x in c.values()):
            print('Yes')
            exit()

print('No')
import numpy as np

n = int(input())

U = np.arange(1, n, dtype = np.int64)

div = U[n % U == 0]

ans = min((n / div) + div) - 2

print(int(ans))

"""
from itertools import combinations
import numpy as np

n = int(input())

a = 2
cnt = 0
ans = []


def walk_counter(ll, n):
    left = np.prod(ll)
    right = n // left
    return left + right - 2


tmp_n = n

while tmp_n >= a:
    while tmp_n % a == 0:
        tmp_n = tmp_n // a
        # cnt += 1
        ans.append(a)
    # if cnt > 0:
    #     ans.append([a, cnt])
    #     cnt = 0
    a = a + 1

if tmp_n == a:
    ans.append(a)

fin = 0

for i in range(len(ans)):
    for v in combinations(ans, i):
        tmp = walk_counter(v, n)
        if i == 0:
            fin = tmp
        elif fin > tmp:
            fin = tmp

# 組み合わせでなく、√nまでの試し割法のほうが早い

print(fin)
"""


### FIXED CODE ###

import numpy as np

n = int(input())

U = np.arange(1, n ** 0.5 + 1, dtype = np.int64) # +1を忘れない！

div = U[n % U == 0]
ans = min((n / div) + div) - 2

print(int(ans))

"""old


from itertools import combinations
import numpy as np

n = int(input())

a = 2
cnt = 0
ans = []


def walk_counter(ll, n):
    left = np.prod(ll)
    right = n // left
    return left + right - 2


tmp_n = n

while tmp_n >= a:
    while tmp_n % a == 0:
        tmp_n = tmp_n // a
        # cnt += 1
        ans.append(a)
    # if cnt > 0:
    #     ans.append([a, cnt])
    #     cnt = 0
    a = a + 1

if tmp_n == a:
    ans.append(a)

fin = 0

for i in range(len(ans)):
    for v in combinations(ans, i):
        tmp = walk_counter(v, n)
        if i == 0:
            fin = tmp
        elif fin > tmp:
            fin = tmp

# 組み合わせでなく、√nまでの試し割法のほうが早い

print(fin)
"""
import math
N, X = map(int, input().split())
x_list = list(map(int, input().split()))

x_list.sort()
if N ==1:
    print(x_list[0]-X)
    exit()

if N==2:
    g1 = abs(X-x_list[0])
    g2 = math.gcd(g1, x_list[1]-x_list[0])
    print(g2)
    exit()

m0 = abs(X - x_list[0])

D = 10**9
for i in range(N-2):
    m1 = abs(x_list[i] - x_list[i+1])
    m2 = abs(x_list[i] - x_list[i+2])
    g = math.gcd(m1, m2)

    if g <= D:
        D = g
print(D)


### FIXED CODE ###

N, X = map(int, input().split())
x_list = list(map(int, input().split()))

x_list.sort()
def gcd(a, b):
    if a >= b:
        return a if b == 0 else gcd(b, a % b)
    else:
        return gcd(b, a)


D = abs(X-x_list[0])
for i in range(0, N):
    D = gcd(D,  abs(x_list[i]-X))

print(D)
N = int(input())
d = list(map(int, input()))
S = d[0]
delic = 0
for i in range(N-1):
  P = d[i+1]
  delic += P * S
  S += P
print(delic)

### FIXED CODE ###

N = int(input())
d = list(map(int, input().split()))
S = 0
for i in range(N - 1):
  for j in range(i+1, N):
    S += d[i] * d[j]
    
print(S)