Harryxun/stf_run huggingface dataset:
N = int(input())
memo = [-1] * 200000

def search(i): 
    if i == 0:
        return 0
    if memo[i] != -1:
        return memo[i]
    
    tmp = i
    cnt = 0
    while True: 
        n = 6 ** cnt
        if n > i:
            break       
        tmp = min(tmp, search(i-n)+1)
        cnt += 1
    cnt = 0
    while True:
        n = 9 ** cnt
        if n > i:
            break       
        tmp = min(tmp, search(i-n)+1)
        cnt += 1
    
    memo[i] = tmp
    return tmp

print(search(N))

### FIXED CODE ###

N = int(input())

dp = [200000] * 200000
dp[0] = 0

for i in range(N+1):
    for j in range(i+1):
        tmp = 6**j
        if tmp > N or i - tmp < 0:
            break
        dp[i] = min(dp[i], dp[i-tmp]+1)
    for j in range(i+1):
        tmp = 9**j
        if tmp > N or i - tmp < 0:
            break
        dp[i] = min(dp[i], dp[i-tmp]+1)

print(dp[N])
from sympy import isprime
n = int(input())
if isprime(n) == True:
    print(n)
else:
    print(sympy.nextprime(n))

### FIXED CODE ###

x = int(input())
while True:
    for i in range(2,x):
        if x%i == 0:
            break
    else:
        print(x)
        break
    x+= 1
def find_lcd(A,B):
  if A==B:
    return A
  else:
    return find_lcd(min(A,B), abs(A-B))
  
def find_num_prime(X):
  if X==1:
    return 1
  count = 1 # 1
  i=2
  sqrt_org=int(X**0.5)
  while X != 1 and i<=sqrt_org:
    if X%i == 0:
      count += 1
      while X%i == 0:
        #print(str(X)+' '+str(i))
        X = X/i
    if i== 2:
      i += 1
    else:
      i += 2
  return count
  
A,B = map(int, input().split())
lcd=find_lcd(A,B)
#print(lcd)
print(find_num_prime(lcd))

### FIXED CODE ###

def find_lcd(A,B):
  if A==1 or B==1:
    return 1
  if A==B:
    return A
  else:
    return find_lcd(min(A,B), abs(A-B))
  
def find_num_prime(X):
  if X==1:
    return 1
  count = 1 # 1
  i=2
  sqrt_org=int(X**0.5)
  while X != 1:
    if i**2 > X:
      count += 1
      break
    if X%i == 0:
      count += 1
      while X%i == 0:
        #print(str(X)+' '+str(i))
        X = int(X/i)
    if i== 2:
      i += 1
    else:
      i += 2
  return count
  
A,B = map(int, input().split())
lcd=find_lcd(A,B)
#print(lcd)
print(find_num_prime(lcd))
while True:
    H,W=[int() for x in input().split()]
    if H == 0 and W == 0:
        break
    for a in range (H):
        if a == 0 or a == H-1:
            print("#"*W)
        else:
            print("#" + "."*(W-2) + "#")


### FIXED CODE ###

while True:
    H,W=[int(x) for x in input().split()]
    if H == 0 and W == 0:
        break
    for a in range (H):
        if a == 0 or a == H-1:
            print("#"*W)
        else:
            print("#" + "."*(W-2) + "#")
    print('')
a,b,c = map(int, input().strip())
print(c,a,b)

### FIXED CODE ###

a,b,c = map(int, input().strip().split())
print(c,a,b)
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(4)],[])
for b in [input()for i in range(int(A[10]))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print("YNeos"[S.find("  ")<0::2])

### FIXED CODE ###

A=[0]*9
for i in range(3):
    A[i*3:i*3+3]=input().split()
for i in range(int(input())):
    b=input()
    for j in range(9):
        if A[j]==b:
            A[j]="0"
s="012345678036147258048246"
a=f=0
for i in range(24):
    a+=int(A[int(s[i])])
    if i%3==2:
        if a==0:
            f+=1
        a=0
if f>0:
    print("Yes")
else:
    print("No")
N=int(input())

if N < 10:
  print(N)
elif N < 100:
  print(9)
elif N < 1000:
  print(9+ N-99)
elif N < 10000:
  print(909)
elif N < 100000:
  print(909 + N - 9999)
else:
  print(90909)


### FIXED CODE ###

A, B, C = (int(i) for i in input().split(" "))
 
D = A - B

 
if C - D <= 0:
  print(0)
else:
  print(C-D)
#coding: utf-8

import sys

def keitai(n1,n2):
    li1 = ['.', ',', '!', '?'] 
    li2 = ['a','b','c']
    li3 = ['d','e','f']
    li4 = ['g','h','i']
    li5 = ['j','k','l']
    li6 = ['m','n','o']
    li7 = ['p','q','r','s']
    li8 = ['t','u','v']
    li9 = ['w','x','y','z']
    li = [li1,li2,li3,li4,li5,li6,li7,li8,li9]
    lis = li[n1 - 1]
    n2 = n2 % len(li)
    a = lis[n2 - 1]
    return a

for line in sys.stdin:
    a = str(line)
    num = 0
    for i in len(a):
        if int(a[i]) == 0:
            if i = len(a) - 1:
                print keitai(b,num)
            else:
                print keitai(b,num),
        else:
            num = num + 1
            b = int(a[i])

### FIXED CODE ###

#coding: utf-8
 
n = int(raw_input())
 
def keitai(n1,n2):
    li1 = ['.', ',', '!', '?',' '] 
    li2 = ['a','b','c']
    li3 = ['d','e','f']
    li4 = ['g','h','i']
    li5 = ['j','k','l']
    li6 = ['m','n','o']
    li7 = ['p','q','r','s']
    li8 = ['t','u','v']
    li9 = ['w','x','y','z']
    li = [li1,li2,li3,li4,li5,li6,li7,li8,li9]
    lis = li[n1 - 1]
    n2 = n2 % len(lis)
    a = lis[n2 - 1]
    return a
 
for k in range(n):
    a = str(raw_input())
    num = 0
    string = ''
    for i in range(len(a)):
        if int(a[i]) == 0:
            if num != 0:
                string = string + keitai(b,num)
                num = 0
            else:
                pass
        else:
            num = num + 1
            b = int(a[i])
    print string
k,s = [int(i) for i in input().split()]


def a(n):
  if n == 1:
    return n
  else:
    return n + a(n-1)
  
if k >= s:
  print(a(s+1))
elif s >= 2 * k and s <= 3 * k:
  print(a(3 * k - s + 1))
else:
  print(a(s + 1) -3 * a(s - k))

### FIXED CODE ###

k,s = [int(i) for i in input().split()]
def a(n):
  return int(n * (n + 1) / 2)
  
if s <= k:
  print(a(s + 1))
elif s >= 2 * k and s <= 3 * k:
  print(a(3 * k - s + 1))
elif s > k and s < 2 * k:
  print(a(s + 1) - 3 * a(s - k))
else:
  print(0)
N = int(input())
S = []
for i in range(N):
    si = input()
    S = S + [si]
print(len(set(S)))

### FIXED CODE ###

S,W = map(int,input().split())
if S > W:
    print("safe")
else:
    print("unsafe")
s=[]
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
  
s=list(map(int,input().split()))
slist=sorted(s)
  
for i in range(0,1000):
  for j in range(n):
    if slist[j]==x-i:
        flaga=1
    if slist[j]==x+i:
        flagb=1
            
  if flaga=1 and flagb=1:
    flaga=0
    flagb=0
  elif flagb==0:
    print(x-i)
    exit()
  elif flaga==0:
    print(x+i)
    exit()

### FIXED CODE ###

s=[]
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
  
s=list(map(int,input().split()))
slist=sorted(s)
out=0
for i in range(0,1000):
  out=0
  for j in range(n):
    if slist[j]==x-i:
      out=1
  if out !=1:
   print(x-i)
   exit()
  out=0
  for k in range(n):
    if slist[k]==x+i:
      out=1
  if out !=1:
    print(x+i)
    exit()
S=long(input())
#N=list(map(int,input().split()))

ans=long((S-1)*S/2)

print(ans)

### FIXED CODE ###

S=int(input())
#N=list(map(int,input().split()))
ans=(S-1)*S//2
print(ans)
n, q = map(int, input().split())
g = [[] for _ in range(n)]
value = [0] * n
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
for _ in range(q):
    p, x = map(int, input().split())
    value[p-1] += x

seen = [False] * n
def dfs(v):
    seen[v] = True
    for nv in g[v]:
        if seen[nv]:
            continue
        value[nv] += value[v]
        dfs(nv)
dfs(0)
print(*value)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 8)
n, q = map(int, input().split())
g = [[] for _ in range(n)]
value = [0] * n
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
for _ in range(q):
    p, x = map(int, input().split())
    value[p-1] += x

seen = [False] * n
def dfs(v):
    seen[v] = True
    for nv in g[v]:
        if seen[nv]:
            continue
        value[nv] += value[v]
        dfs(nv)
dfs(0)
print(*value)
int1 = lambda s: int(s)-1

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

X = []
visited = set()
now = 0
while now not in visited:
    visited.add(now)
    X.append(now)
    now = A[now]

if K < len(X):
    print(X[k])
else:
    s = X.index(now)
    print(X[s + ((K - s) % (len(X) - s))] + 1)


### FIXED CODE ###

int1 = lambda s: int(s)-1

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

X = []
visited = set()
now = 0
while now not in visited:
    visited.add(now)
    X.append(now)
    now = A[now]

if K < len(X):
    print(X[K] + 1)
else:
    s = X.index(now)
    print(X[s + ((K - s) % (len(X) - s))] + 1)
import sys 
sys.setrecursionlimit(10**5)

def search_unseen(fr,to,cost):  
  cost_from_k[to] += cost_from_k[fr] + cost
  for n_to,n_cost in es[to]:
    if cost_from_k[n_to] == 0 and k!=n_to:
      search_unseen(to, n_to, n_cost)

n = int(input())
es = {i:[] for i in range(n)}
for i in range(n-1):
  a,b,c = map(int,input().split())
  es[a-1].append((b-1,c))
  es[b-1].append((a-1,c))      
      
q,k = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(q)]
k -=1

cost_from_k = [0]*n      
search_unseen(k, k, 0)

for x,y in xy:
  print(cost_from_k[x-1] + cost_from_k[y-1])      

### FIXED CODE ###

import sys 
sys.setrecursionlimit(10**8)

def search_unseen(fr,to,cost):  
  cost_from_k[to] += cost_from_k[fr] + cost
  for n_to,n_cost in es[to]:
    if cost_from_k[n_to] == 0 and k!=n_to:
      search_unseen(to, n_to, n_cost)

n = int(input())
es = {i:[] for i in range(n)}
for i in range(n-1):
  a,b,c = map(int,input().split())
  es[a-1].append((b-1,c))
  es[b-1].append((a-1,c))      
      
q,k = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(q)]
k -=1

cost_from_k = [0]*n      
search_unseen(k, k, 0)

for x,y in xy:
  print(cost_from_k[x-1] + cost_from_k[y-1])
N = int(input())
cake = int(N/4)
donuts = int(N/7)

for i in range(donuts+1):
    for m in range(cake+1):
        sum_price = i*7 + m*4
        if N == sum_price:
            print('Yes')
            exit()

print('No')

### FIXED CODE ###

N, K = [int(i) for i in input().split()]

if N % K != 0:
    print('1')
    exit()
print('0')
s = input()
t = input()

ls = len(s)
lt = len(t)
ans = ""
dp = [[0]*(ls+1) for i in range(lt+1)]
memo = [[""]*(ls+1) for i in range(lt+1)]

for i in range(1,lt+1):
    for j in range(1,ls+1):
        dp[i][j] = max(dp[i-1][j],dp[i][j-1])
        memo[i][j] = memo[i-1][j-1]
        if s[j-1] == t[i-1]:
            dp[i][j] = dp[i-1][j-1]+1
            memo[i][j] = memo[i-1][j-1]+s[j-1]

i = lt
j = ls
while i-1>=0 and j-1>=0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
        continue
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
        continue
    else:

    i -= 1
    j -= 1
    ans = s[j] + ans

print(ans)



### FIXED CODE ###

s = input()
t = input()
N = len(s)
M = len(t)

dp = [[0]*(N+1) for i in range(M+1)]

for i in range(1,M+1):
  for j in range(1,N+1):
    if s[j-1] == t[i-1]:
      dp[i][j] = dp[i-1][j-1]+1
    else:
      dp[i][j] = max(dp[i-1][j],dp[i][j-1])
L = dp[-1][-1]
i = M
j = N
ans = [""]*L
cur = L-1
while i>=0 and j>=0:
  if dp[i][j] != dp[i-1][j] and dp[i][j] != dp[i][j-1]:
    ans[cur] = s[j-1]
    i -= 1
    j -= 1
    cur -= 1
  elif dp[i][j] == dp[i-1][j]:
    i -= 1
  else:
    j -= 1
print("".join(ans))
a, b = map(int, input())
print(6-(a+b))


### FIXED CODE ###

a = int(input())
b = int(input())
print(6-(a+b))
while True:
    a = float(raw_input())
    sum = a
    for i in range(2,11):
        if i % 2 == 0:
            a *= 2.0
            sum += a
        else:
            a /= 3.0
            sum += a
    print sum

### FIXED CODE ###

while True:
    try:
        a = sum = float(raw_input())
        for i in range(2,11):
            if i % 2 == 0:
                a *= 2.0
                sum += a
            else:
                a /= 3.0
                sum += a
        print sum
    except:
        break
N=int(input())
k=0
for i in range(N):
  if ((i+1)%3!=0)&&((i+1)%5!=0):
    k=k+i
print(k)
  

### FIXED CODE ###

N=int(input())
k=0
for i in range(N):
  j=i+1
  if (j%3!=0)and(j%5!=0):
    k=k+j
print(k)
int x

print(x*x*x)


### FIXED CODE ###

x = int(input())

print(x*x*x)
LI = lambda: list(map(int, input().split()))

N, X = LI()
L = LI()


def main():
    ans = X // L
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

LI = lambda: list(map(int, input().split()))

N, X = LI()
L = LI()


def main():
    ans = 1
    d = 0
    for l in L:
        d += l
        if d > X:
            break
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()
from collections import deque

n = int(input())
a = list(map(int, input().split()))
s = deque([])

for i in range(n):
    if i%2==1:
        s.insert(0, a[i])
    else:
        s.append(a[i])
if n%2 == 1:
    s.reverse()
print(*s)

### FIXED CODE ###

from collections import deque

n = int(input())
a = list(map(int, input().split()))
s = deque([])

for i in range(n):
    if i%2==1:
        s.appendleft(a[i])
    else:
        s.append(a[i])
if n%2 == 1:
    s.reverse()
print(*s)
n,a=map(int,input().splitlines())
print((n**2) -a )

### FIXED CODE ###

N = int(input())
A = int(input())
print(N**2-A)
import math

# define
a = [0] * int(1e5 + 100)
# functions
# main

n, m = (int(s) for s in input().split())

inp = input().split()
for i in range(1, n + 1) :
    a[i] = int(inp[i - 1])

flag = False
lcm = a[1]

for i in range(2, n + 1) :
    gcd = math.gcd(lcm, a[i])
    #lcm = int(lcm * a[i] / gcd)
    if(lcm > m):
        flag = True
        break

for i in range (1, n + 1):
    if lcm / a[i] % 2 == 0 : flag = True

if flag or lcm > m : print(0)
else : print(int( (m - int(lcm / 2)) / lcm ) + 1)


### FIXED CODE ###

# define
a = [0] * int(1e5 + 100)
# functions
def _gcd(a, b):
    if a % b == 0 : return b
    if b % a == 0 : return a
    while a != 1 and b != 1:
        if a > b: a %= b
        else : b %= a
        if a % b == 0: return b
        if b % a == 0: return a
# main

n, m = (int(s) for s in input().split())

inp = input().split()
for i in range(1, n + 1) :
    a[i] = int(inp[i - 1])

flag = False
lcm = a[1]

for i in range(2, n + 1) :
    gcd = _gcd(lcm, a[i])
    lcm = int(lcm * a[i] / gcd)
    if(lcm > 2 * m):
        flag = True
        break

for i in range (1, n + 1):
    if int(lcm / a[i]) % 2 == 0 : flag = True

if flag : print(0)
else : print(int( (m - int(lcm / 2)) / lcm ) + 1)
n,x=[int(i) for i in input().split()]
p=[1]
b=[0]
z=[]
for i in range(n):
  p.append(p[i]*2+1)
  b.append(b[i]*2+2)
  z.append(p[i]+b[i])
ans=0
ici=0
for i in range(n-1, -1, -1):
  if x-ici>z[i]+1:
    ici+=z[i]+2
    ans+=p[i]+1
  elif x-ici<z[i]+1:
    ici+=1
  else:
    ans+=p[i]
    break
print(ans)

### FIXED CODE ###

d=int(input())
ans="Christmas"
for i in range(25-d):
  ans+=" Eve"
print(ans)
def gcd(x, y):
	if x < y:
		x, y = y, x
	if y == 0:
		return x
	z = x % y
	return gcd(y, z) 
	
N=int(input())
prenum = 1
for i in range(N):
	T = int(input())
	lcm = prenum / gcd(prenum, T) * T
	prenum = lcm
print(str(lcm))

### FIXED CODE ###

def gcd(x, y):
	if x < y:
		x, y = y, x
	if y == 0:
		return x
	z = x % y
	return gcd(y, z) 
	
N=int(input())
prenum = 1
for i in range(N):
	T = int(input())
	lcm = prenum // gcd(prenum, T) * T
	prenum = lcm
print(lcm)
n = int(input())
h = list(map(int, input().split()))

# i:足場
dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

### FIXED CODE ###

import sys
n = int(input())
h = list(map(int, input().split()))
dp = [-1] * n

sys.setrecursionlimit(n + 2)
def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))
#!/usr/bin/env python


matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
h = 0
w = 0

def dfs(x,y,fruit):
  #visited.append((x,y))
  visited[y][x] = 1
  for v in vec:
    nx = x + v[0]
    ny = y + v[1]
    if nx in xrange(w) and ny in xrange(h):
      if visited[ny][nx]==0 and matrix[ny][nx] == fruit:
        dfs(nx,ny,fruit)
  return 0


while True:
  h,w = map(int,raw_input().split())
  if h == 0 and w == 0:
    break
#  print h,w
  matrix = []
  visited = []
  ans = 0
  for i in xrange(h):
    s = raw_input().rstrip()
    matrix.append(list(s))
    visited.append([0]*w)
  for i in xrange(h):
    for j in xrange(w):
      #if not (j,i) in visited:
      if visited[i][j] == 0:
        dfs(j,i,matrix[i][j])
        ans+=1
  print ans

### FIXED CODE ###

#!/usr/bin/env python
import sys

sys.setrecursionlimit(20000)

matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
h = 0
w = 0

def dfs(x,y,fruit):
  #visited.append((x,y))
  visited[y][x] = 1
  for v in vec:
    nx = x + v[0]
    ny = y + v[1]
    if nx in xrange(w) and ny in xrange(h):
      if visited[ny][nx]==0 and matrix[ny][nx] == fruit:
        dfs(nx,ny,fruit)
  return 0


while True:
  h,w = map(int,raw_input().split())
  if h == 0 and w == 0:
    break
#  print h,w
  matrix = []
  visited = []
  ans = 0
  for i in xrange(h):
    s = raw_input().rstrip()
    matrix.append(list(s))
    visited.append([0]*w)
  for i in xrange(h):
    for j in xrange(w):
      #if not (j,i) in visited:
      if visited[i][j] == 0:
        dfs(j,i,matrix[i][j])
        ans+=1
  print ans
N = input()
n = N[len(n)]
if n == "2" or n== '4' or n=='5' or n=='7' or n=='9':
  print("hon")
elif n == '0' or n=='1' or n=='6' or n=='8':
  print('pon')
else:
  print('bon')

### FIXED CODE ###

N = input()
n = N[len(N)-1]
if n == "2" or n== '4' or n=='5' or n=='7' or n=='9':
  print("hon")
elif n == '0' or n=='1' or n=='6' or n=='8':
  print('pon')
else:
  print('bon')
import numpy as np
n,m,x=map(int,input().split())
a=0
b=[[np.array(list(map(int,input().split())))]for i in range(n)]
for i in range(2**n):
    c=bin(i)
    c="0"*(n-len(c))+c
    l=np.zeros(m)
    q=0
    for j in range(n):
        if c[j]=="1":
            q+=b[j][0]
            l+=b[j]
    if np.min(l)==x:
        a=min(a,q)
if a:
    print(a)

### FIXED CODE ###

import numpy as np
n,m,x=map(int,input().split())
a=2**64
b=[np.array(list(map(int,input().split())),"i8")for i in range(n)]
for i in range(2**n):
    c=bin(i)[2:]
    c="0"*(n-len(c))+c
    l=np.zeros(m)
    q=0
    for j in range(n):
        if c[j]=="1":
            q+=b[j][0]
            l+=b[j][1:]
    if np.min(l)>=x:
        a=min(a,q)
if a==2**64:
    print(-1)
else:
    print(a)
# E - Three Substrings

a = list(input())
b = list(input())
c = list(input())

A, B, C = len(a), len(b), len(c)

M = max(A, B, C)
cons = 3*M + 10
rel_match_b_against_a = [True] * 2 * cons
rel_match_b_against_c = [True] * 2 * cons
rel_match_c_against_a = [True] * 2 * cons

for rel_idx in range(-B+1, A):
    if rel_idx < 0:
        for i in range(min(A, rel_idx + B)):
            if a[i] != b[i + rel_idx] and a[i] != "?" and b[i + rel_idx] != "?":
                rel_match_b_against_a[rel_idx + cons] = False
                break
    else:
        for i in range(min(A - rel_idx, B)):
            if a[i + rel_idx] != b[i] and a[i + rel_idx] != "?" and b[i] != "?":
                rel_match_b_against_a[rel_idx + cons] = False
                break

for rel_idx in range(-B+1, C):
    if rel_idx < 0:
        for i in range(min(C, rel_idx + B)):
            if c[i] != b[i + rel_idx] and c[i] != "?" and b[i + rel_idx] != "?":
                rel_match_b_against_c[rel_idx + cons] = False
                break
    else:
        for i in range(min(C - rel_idx, B)):
            if c[i + rel_idx] != b[i] and c[i + rel_idx] != "?" and b[i] != "?":
                rel_match_b_against_c[rel_idx + cons] = False
                break

for rel_idx in range(-C+1, A):
    if rel_idx < 0:
        for i in range(min(A, rel_idx + C)):
            if a[i] != c[i + rel_idx] and a[i] != "?" and c[i + rel_idx] != "?":
                rel_match_c_against_a[rel_idx + cons] = False
                break
    else:
        for i in range(min(A - rel_idx, C)):
            if a[i + rel_idx] != c[i] and a[i + rel_idx] != "?" and c[i] != "?":
                rel_match_c_against_a[rel_idx + cons] = False
                break

ans = 3*M
for rel_idx_b_against_a in range(-2*M, 2*M):
    for rel_idx_c_against_a in range(-2*M, 2*M):
        if rel_match_b_against_a[rel_idx_b_against_a + cons] and rel_match_c_against_a[rel_idx_c_against_a + cons] and rel_match_b_against_c[rel_idx_b_against_a - rel_idx_c_against_a + cons]:
            ans = min(ans, max(A, B + rel_idx_b_against_a, C + rel_idx_c_against_a) - min(0, rel_idx_b_against_a, rel_idx_c_against_a))

print(ans)

### FIXED CODE ###

# E - Three Substrings

a = list(input())
b = list(input())
c = list(input())

A, B, C = len(a), len(b), len(c)

M = max(A, B, C)
cons = 6*M
a_not_match_b = [False] * 2 * cons
b_not_match_c = [False] * 2 * cons
a_not_match_c = [False] * 2 * cons

def fill_match_list(d1, d2, l):
    for i in range(len(d1)):
        for j in range(len(d2)):
            if d1[i] != d2[j] and d1[i] != "?" and d2[j] != "?":
                l[i-j+cons] = True
    return l

a_not_match_b = fill_match_list(a, b, a_not_match_b)
b_not_match_c = fill_match_list(b, c, b_not_match_c)
a_not_match_c = fill_match_list(a, c, a_not_match_c)

ans = 3*M
for b_idx in range(-2*M, 2*M):
    for c_idx in range(-2*M, 2*M):
        if not a_not_match_b[b_idx + cons] and not a_not_match_c[c_idx + cons] and not b_not_match_c[c_idx - b_idx + cons]:
            ans = min(ans, max(A, B + b_idx, C + c_idx) - min(0, b_idx, c_idx))

print(ans)
a=input();b=input();r=[];l=len(lb)
for i in range(l):
    r.append(a[i]); r.append(b[i])
if l != len(a):
    r.append(a[-1])
print(''.join(r))

### FIXED CODE ###

import sys
read=lambda:sys.stdin.readline().rstrip()
readi=lambda:int(sys.stdin.readline())
writeln=lambda x:sys.stdout.write(str(x)+"\n")
write=lambda x:sys.stdout.write(x)
a=read();b=read();la,lb=len(a),len(b);r=[]
for i in range(lb):
    r.append(a[i]);r.append(b[i])
if la != lb:
    r.append(a[-1])
print(''.join(r))
print(int((input()))**3/27)


### FIXED CODE ###

N, M = map(int, input().split())
print(int((N * (N - 1) + M * (M-1)) / 2))
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0

for i in range(0,N,1):
    minj =i
    for j in range(i,N,1):
        if num_list[j] < num_list[minj]:
        minj = j
    a = num_list[i]
    num_list[i] = num_list[minj]
    num_list[minj] = a
    c += 1
print " ".join(map(str,num_list))
print c

### FIXED CODE ###

N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0

for i in range(0,N,1):
    flag =0
    minj =i
    for j in range(i,N,1):
        if num_list[j] < num_list[minj]:
            minj = j
            flag = 1
    c += flag
    num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c
print(input().replace(","." "))

### FIXED CODE ###

print(input().replace(","," "))
a, b = map(int,input().split())
print("GREATER" if a > b else "LESS" if a < b else "EQUAL")

### FIXED CODE ###

a = int(input())
b = int(input())
print("GREATER" if a > b else "LESS" if a < b else "EQUAL")
n = int(input())
d = []

if i in range(n):
    order = input().split()
    if order[0] == 'insert':
        d.append(order[1])
    else:
        if order[1] in d:
            print("yes")
        else:
            print("no")

### FIXED CODE ###

n = int(input())
d = {}

for i in range(n):
    order = input().split()
    if order[0] == 'insert':
        d[order[1]] = i
    else:
        if order[1] in d:
            print("yes")
        else:
            print("no")
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return int(a * b / gcd(a, b))

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

LCM = lcm(a[0], a[1])
for i in range(1, N-1):
    LCM = lcm(LCM, a[i+1])
LCM -= 1

modTotal = 0
for i in range(N):
    modTotal += LCM % a[i]
print(modTotal)

### FIXED CODE ###

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

modTotal = 0
for i in range(N):
    modTotal += a[i]-1
print(modTotal)