peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
B = [0 for i in range(N+1)]
S = sum(A)
B[0]=1
flag=1
if A[0]>1 :
    flag=0
if A[0]>0 and N>0:
    flag=0

for i in range(N):
    if flag==0:
        break

    S = S-A[i]

    if 2*(B[i]-A[i])<A[i+1]:
        flag = 0

    B[i+1]=min(2*(B[i]-A[i]),S)

if flag==0:
    print(-1)
else:
    res = sum(B)
    print(res)
# Judge status: Accepted
s = input()
temp = "?"
ans = "Yes"
for c in s:
    if c != temp:
        if s.count(c) != 2:
            ans = "No"
            break
        temp = c
print(ans)
# Judge status: Accepted
n = int(input())
ans = 1
for num in range(n+1):
  if num*num <= n:
    ans = num*num
  else: 
    break
print(ans)
# Judge status: Wrong Answer
z=list(map(int,input().split()))
x=list(map(int,input().split()))
d={}
c=0
for i in x:
       if d.get(i,0)==0:
              c+=i
if c>=z[0]:
       print("YES")
else:
       print("NO")
# Judge status: Accepted
a, b, c = map(int, input().split())
m = max([a, b, c])
print((m * 3 - (a + b + c)) // 2 if (a + b + c) % 2 == (m * 3) % 2 else ((m + 1) * 3 - (a + b + c)) // 2)
# Judge status: Accepted
n, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
p = 0

for ai in a:
  if p + ai > x:
    d = p + ai - x
    ans += d
    p = ai - d
  else:
    p=ai
    
print(ans)
# Judge status: Accepted
X=int(input())
d,m=divmod(X,100)
print(1 if m<=(d*5) else 0)
# Judge status: Wrong Answer
n = int(input())
p = list(map(int, input().split()))

mins=[0]*n
mins[0]=p[0]
for i in range(0,n):
    mins[i] = min(p[i-1], p[i])
ans=1
for i in range(1, n):
    if p[i] <= mins[i]:
        ans+=1

print(ans)
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))
seiseki = []

for i in range(N - K):
  if A[i] < A[i + K]:
    print("Yes")
  else:
    print("No")
# Judge status: Wrong Answer
n=int(input())
v=[]
v+=list(map(int,input().split()))
v.sort()
l=len(v)
result=v[0]/(2**(l-1))
for i in range(1,n):
  result=result+v[i]/(2**(l-i))
print(int(result))
# Judge status: Accepted
n, q = map(int, input().split())
s = input()
tmp = [0 for i in range(len(s))]
for i in range(len(s)-1):
  if s[i] == "A" and s[i+1] == "C":
    tmp[i] = 1
    
ans = [0 for i in range(len(s)+1)]
for i in range(1, len(ans)):
  ans[i] = ans[i-1] + tmp[i-1]
  
for i in range(q):
  l, r = map(int, input().split())
  count = 0
  print(ans[r-1] - ans[l-1])
# Judge status: Accepted
N = int(input())
v = list(map(int, input().split()))
v.sort()

ans = v[0]
for i in v[1:]:
    ans += i
    ans /= 2
print(ans)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
print("delicious" if b>=c else "safe" if c-b-1<=a else "dangerous")
# Judge status: Accepted
L, R = map(int, input().split())
ama=[]
for i in  range(L,R+1):
    amari = i%2019
    if amari ==0:
        print(amari)
        exit()
minimi = 2019
for j in range(L,R+1):
    for s in range(j+1,R+1):
        waka = (j*s)%2019
        minimi = min(minimi,waka)
print(minimi)
# Judge status: Accepted
price = int(input())
if price % 1000 == 0:
    print(0)
else:
    print(1000-(price%1000))
# Judge status: Wrong Answer
s = input()
if s[2] == s[3] or s[4] == s[5]:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
N, C, K = map(int, input().split())
T = []

for n in range(N):
    l = int(input())
    T.append(l)

T.sort()

ans = 0
V = C # current vacancies

for i in range(N-1):
    if T[i] + K >= T[i+1]:
        V -= 1
    else:
        ans += 1
        V = C
    
    if V == 0:
        ans += 1
        V = C
    else:
        pass

ans += 1

print(ans)
# Judge status: Accepted
N = int(input())
*D, = map(int, input().split())
MOD = 998244353

import collections
dic = collections.Counter(D)

flag = 1 if dic[0] != 1 or D[0] != 0 else 0
ans = 1
for d in range(1, max(D)+1):
    ans *= pow(dic[d-1], dic[d], MOD)
    ans %= MOD

if flag: 
    print(0)
else:
    print(ans)
# Judge status: Accepted
S=input()
L=len(S)

for i in range(2,L,2):
  #print(S[0:(L-i)//2], S[(L-i)//2:(L-i)])
  if S[0:(L-i)//2]==S[(L-i)//2:(L-i)]:
    print(L-i)
    break
# Judge status: Wrong Answer
a,b,c,d=map(int,input().split())

while True:
    if abs(a-b)>d:
        print('No')
        break
    if abs(b-c)>d:
        print('No')
        break
    else:
        print('Yes')
    break
# Judge status: Wrong Answer
S = int(input())

x1,y1 = 0,0
x2 = 10**9
y2 =1
y3,x3 = divmod(S,x2)

for a in [x1,x2,x3,y1,y2,y3]:
	if a == y3:
		print(a)
	else:
		print(a,end=" ")
# Judge status: Accepted
N=int(input())
d=list(map(int,input().split()))
d.sort()
if d[N//2 -1]==d[N//2]:
    print(0)
else:
    ans=d[N//2]-d[N//2 -1]
    print(ans)
# Judge status: Wrong Answer
N,A,B = map(int,input().split())

ans =0

while N > 0:
    n = N
    t = 0

    while n > 0:
        t += n % 10
        n //= 10

    if A <= t <= B:
        ans += N

    N -= 1
# Judge status: Wrong Answer
a,b=map(int,input().split())
if (a+b)%2==0:
    print(abs((a-b)/2)+min(a,b))
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
def main():
    from collections import deque
    from math import ceil
    n, h, *ab = map(int, open(0).read().split())
    a = ab[::2]
    *b, = map(lambda x: -x, ab[1::2])
    c = a + b
    c.sort(key=lambda x: abs(x), reverse=True)

    q = deque(c)
    cnt = 0
    while h > 0:
        cnt += 1
        x = q.popleft()
        h -= abs(x)
        if x > 0:
            cnt += ceil(h / x)
            break

    print(cnt)


if __name__ == '__main__':
    main()
# Judge status: Accepted
a,b,c = map(int,input().split())

if a%2==0 or b%2==0 or c%2==0:
    print(0)

else:
    mx = max(a,b,c)
    print((a*b*c)//mx)
# Judge status: Accepted
a, b, c, x, y = map(int, input().split())

ans = float("inf")
for i in range(0, max(2*x, 2*y)+1, 2):
    na = 0 if x-i//2 < 0 else x-i//2
    nb = 0 if y-i//2 < 0 else y-i//2
    ans = min(ans, c*i + a*na + b*nb)

print(ans)
# Judge status: Accepted
#ARC091-C
a,b = map(int,input().split())
n,m = max(a,b),min(a,b)

if n <= 1:
    result = 1
elif m <= 1:
    result = n - 2
else:
    result = (m-2)*(n-2)
    
print(result)
# Judge status: Accepted
k=int(input())
num=7%k
for i in range(1, 10**6+1):
    if num%k==0:
        print(i)
        exit()
    else:
        num=(10*num+7)%k
print(-1)
# Judge status: Wrong Answer
a,b = map(float,input().split())
a_base_min = int(a * 25 /2)
a_base_max = int((a+1)*25/2)
b_base_min = int(b *10)
b_base_max = int((b+1) *10)

if (b_base_min <= a_base_min) and (a_base_min <= b_base_max):
    print(int(a_base_min))
elif (a_base_min < b_base_min) and (b_base_min <= a_base_max):
    print(int(b_base_min))
else:
    print(-1)
# Judge status: Accepted
a, b = map(str, input().split())
print(min (a * int(b), b * int(a)))
# Judge status: Accepted
S = list(input())
ls = len(S)

a = [0] * (len(S) + 1)


for i in range(ls):
    if S[i] == "<":
        a[i + 1] = max(a[i + 1], a[i] + 1)
        
for i in range(ls - 1, -1, -1):
    if S[i] == ">":
        a[i] = max(a[i], a[i + 1] + 1)
        
print(sum(a))
# Judge status: Wrong Answer
from math import ceil
x=int(input())
print(ceil(360//x))
# Judge status: Wrong Answer
a, b, k = map(int, input().split())
l = [i for i in range(a, b+1)]

for i in set(l[-k:] +l[:k]):
    print(i)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
s = sum(a) % mod
ans = s * s % mod
for i in a:
    ans -= i * i
    ans %= mod
ans = ans * pow(2, mod - 2, mod) % mod
print(ans)
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate

n = int(readline())
a = list(map(int, readline().split()))
cumsum = list(accumulate(a[::-1]))
ans = 0
check = 1
for aa, v in zip(a, cumsum[::-1]):
    if aa > check:
        print(-1)
        exit()
    else:
        ans += min(check, v)
        check -= aa
        check *= 2
print(ans)
# Judge status: Accepted
def resolve():
    S = input()
    K = int(input())
    for i in range(K):
        if S[i] != "1":
            print(S[i])
            exit()
    print("1")
resolve()
# Judge status: Accepted
from sys import *
from bisect import *

n = int(input())
a = list(map(int, stdin.readlines()))

dp = [1]
for j in a:
    j *= -1
    i = bisect(dp, j)
    if i < len(dp):
        dp[i] = j
    else:
        dp.append(j)
print(len(dp))
# Judge status: Accepted
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [tuple(map(int, input().split())) for _ in range(m)]

good_obs = [True] * n
for a, b in edges:
    if h[a - 1] >= h[b - 1]:
        good_obs[b - 1] = False
    if h[a - 1] <= h[b - 1]:
        good_obs[a - 1] = False
print(sum(good_obs))
# Judge status: Accepted
n, m = map(int, input().split())

root = [[] for i in range(n + 1)]
for i in range(m):
  a, b = map(int, input().split())
  root[a].append(b)
  root[b].append(a)

ans = 'IMPOSSIBLE'
for x in root[n]:
  if 1 in root[x]:
    ans = 'POSSIBLE'
    break

print(ans)
# Judge status: Wrong Answer
import math
a = int(input())
for i in range(a):
    if math.floor(i*1.08) == a:
        print(i)
        exit()
print(":(")
# Judge status: Accepted
# 初期入力
import sys
input = sys.stdin.readline
S =input().strip()

s12 =int(S[:2])
s34 =int(S[2:])
mm=[1,2,3,4,5,6,7,8,9,10,11,12]
yy=[i for i in range(100)]
if s12 in yy and s12 in mm and s34 in yy and s34 in mm:
    print("AMBIGUOUS")
elif s12 in yy and s34 in mm:
    print("YYMM")
elif s12 in mm and s34 in yy :
    print("MMYY")
else:
    print("NA")
# Judge status: Accepted
h,n = map(int,input().split())
a = list(map(int,input().split()))
k = sum(a)
if k>=h:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

# n, m = 3, 2
# a = [[1, 2], [2, 3]]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

if set(pot_starts).intersection(pot_ends):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
a,b=map(int,input().split())
ans=[a%3,b%3,(a+b)%3]
if 0 in ans:
  print("Possible")
else:
  print("Impossible")
# Judge status: Accepted
import math
x = int(input())
i = 1
sum = 100
while True:
  sum = math.floor(sum * 1.01)
  if x <= sum:
    break
  i += 1
print(i)
# Judge status: Accepted
S = input()
L = len(S)

dp = [[0 for _ in range(L + 1)] for over in range(2)]
dp[0][0] = 0
dp[1][0] = 1

for j, s in enumerate(S, 1):
    n = int(s)
    dp[0][j] = min(dp[0][j - 1] + n, dp[1][j - 1] + (10 - n))
    dp[1][j] = min(dp[0][j - 1] + (n + 1), dp[1][j - 1] + (10 - n - 1))
    
print(dp[0][-1])
# Judge status: Wrong Answer
# import collections
S = input()
# CS = collections.Counter(S)
# print(CS)
cn = S.count('N')
ce = S.count('E')
cs = S.count('S')
cw = S.count('W')
if cn > 1 and cs > 1 and ce < 0 and cw < 0:
    print('Yes')
elif cn < 0 and cs < 0 and ce > 1 and cw > 1:
    print('Yes')
elif cn > 1 and cs > 1 and ce > 1 and cw > 1:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 8
ok = True
for i in range(n-k+1):
    a = 0
    for j in range(k):
        if not ok and x[i+j] < 0: continue
        elif not ok and x[i+j] > 0: 
            a *= 2
            ok =True
        if x[i] < 0 and a == 0:
            ok = False
            a += abs(x[i])
        if ok and j == k-1:
            a += x[i+j]
    if ans > a: ans = a
print(ans)
# Judge status: Accepted
from sys import stdin

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

sa,sb,sc = [list(S()) for i in range(3)]

f = sa.pop(0)
l = {'a':sa, 'b':sb, 'c':sc}
p = {'a':'A', 'b':'B', 'c':'C'}
while True:
    if 0 < len(l.get(f)):
        f = l.get(f).pop(0)
    else:
        break

print(p.get(f))
# Judge status: Wrong Answer
import collections
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

c = collections.Counter(s).most_common()
C = []
for i in range(len(c)):
    C.append([c[i][0], c[i][1]])

ans = []
for j in range(len(C)):
    if C[j][0] in t:
        C[j][1] -= t.count(C[j][0])
    ans.append(C[j][1])

print(max(ans))
# Judge status: Accepted
def solve():
    N = int(input())
    S = input()
    attention = sum(s != 'W' for s in S[1:])
    min_val = attention
    # print(min_val)
    for i in range(1,N):
        if S[i] == 'E': attention -= 1
        if S[i-1] != 'E':
            attention += 1
        # print(attention)
        min_val = min(min_val, attention)
    
    # print('---')
    print(min_val)
    
solve()
# Judge status: Wrong Answer
N = int(input())
S = input()
if N // 2 != 0:
    print('No')
else:
    letter = S[1:1+N//2]
    if S == letter + letter:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
import math

H=int(input())
W=int(input())
N=int(input())

if W>H :
    if N%W==0:
        k=N/W
    else:
        k=math.ceil(N/W)
else:
    if N%H==0:
        k=N/H
    else:
        k=math.ceil(N/H)

k=int(k)
print(k)
# Judge status: Accepted
#A=65, Z=90
N=int(input())
S=input()
for i in range(len(S)):
  print(chr((ord(S[i])-65+N)%26+65),end="")
print()
# Judge status: Accepted
import string

S = input()
re_S = set(S)-set("AC")
bl = S[0] == "A"
bl &= (S[2:-1].count("C") == 1)
bl &= (re_S <= set(string.ascii_lowercase ))

print("AC" if bl else "WA")
# Judge status: Wrong Answer
x = int(input())
ans = 1 if x == 0 else 1

print(ans)
# Judge status: Accepted
N = int(input())
L = list(map(int, input().split()))

res = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            tmp = sorted([L[i], L[j], L[k]])
            if tmp[0] < tmp[1] < tmp[2] and (tmp[0] + tmp[1]) > tmp[2]:
                res += 1
print(res)
# Judge status: Accepted
x,y = map(int,input().split())

tsuru = (4 * x - y) // 2
kame = x - tsuru

if (4 * kame) + (2 * tsuru) == y and kame >= 0 and tsuru >= 0:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
a , b , c = map(int, input().split())
m = a % (b+c)
ans = a // (b+c)
if m > 0:
    print(ans)
else:
    print(ans-1)
# Judge status: Accepted
n = int(input())
A = list(map(int,input().split()))
from fractions import gcd
ans = A[0]
for a in A[1:]:
  ans = gcd(ans,a)
print(ans)
# Judge status: Wrong Answer
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(max(a)-1):
  if max_num < (c[x] + c[x+1] + c[x+2]):
      max_num = (c[x] + c[x+1] + c[x+2])
print(max_num)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

ans = 0
b = {}
for i in range(n):
    l = a[i] + (i+1)
    r = (i+1) - a[i]
    if r in b:
        ans += b[r]
    if l in b:
        b[l] += 1
    else:
        b[l] = 1

print(ans)
# Judge status: Accepted
N,M = map(int,input().split())




print(int(N*(N-1)/2 + M*(M-1)/2))
# Judge status: Wrong Answer
N = int(input())
print(N%1000)
# Judge status: Accepted
for i in range(365):print((19-i)%26+1)
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
orders = sorted([a, b, c, d, e], key=lambda x: 10 if x % 10 == 0 else x % 10, reverse=True)
total = 0
for o in orders[:-1]:
    total += ((o + 9) // 10) * 10
total += orders[-1]
print(total)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
Lis=[a,b,c]
sorted(Lis)
if a==b+c:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b,c,d=map(int,input().split())
n=int(input())

twoval=min(8*a,4*a+2*b,4*b,2*b+c,2*c,d)
oneval=min(4*a,2*b,2*a+b,c)

if n%2==0:
    print(twoval*(n//2))
else:
    print(oneval+twoval*((n-1)//2))
# Judge status: Accepted
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, C = map(int, readline().split())
    if A<=C<=B:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
s=input()
w=set()
for i in range(len(s)):
    w.add(s[i])
if len(s)==len(w):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
#!/usr/bin/env python3
from math import factorial
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))
N, M = map(int, input().split())
print(com(N, 2) + com(M, 2))
# Judge status: Accepted
N = int(input())
scores = list(int(i) for i in input().split())

sorted_scores = sorted(scores)[::-1]
alice = sum(sorted_scores[::2])
bob = sum(sorted_scores[1::2])

print(alice - bob)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
count = N//(A+B)
print(count*A+N-count*(A+B))
# Judge status: Wrong Answer
def main():
  s=int(input())
  max=pow(10,9)
  if s<=max:
    print(0,0,s,0,s,2)
  elif s%max==0:
    print(0,0,max,0,max,s//max)
  else:
    a=s%max
    b=s//max
    print(0,0,max, 1,max-a,b+1)
if __name__=='__main__':
  main()
# Judge status: Wrong Answer
num=int(input())
count=0
temp=""
while(num):
    something = input()
    if(temp!=something):
        count+=1
        temp=something
    num-=1
print(count)
# Judge status: Accepted
N = int(input())
A = int(input())
if (N % 500) <= A:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

def lcm(a, b):
  return a*b // gcd(a, b)

N = int(input())
T = [int(input()) for _ in range(N)]

ans = 1
for t in T:
  ans = lcm(ans, t)
  
print(ans)
# Judge status: Accepted
if __name__ == "__main__":
    x, y = map(int, input().split())

    ans = 0
    tmp = x

    while tmp <= y:
        tmp *= 2
        ans += 1

    print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
r = (n - 2) * (m - 2)
if (r < 0):
    r *= -1
print(r)
# Judge status: Wrong Answer
n = int(input())
for i in range(1,n+1):
    if(i**2>n):
        print((i-1)**2)
        quit()
# Judge status: Accepted
N = int(input())

E = N//2
O = N//2 + N%2

print(E*O)
# Judge status: Accepted
n = int(input())
s = input()
i = 0
j = len(s)-1
count = 0
while i<j:
    if s[i] == 'R':
        i+=1
    elif s[j] == 'W':
        j-=1
    else:
        i+=1
        j-=1
        count+=1
print(count)
# Judge status: Accepted
import math
a,b = map(int,(input().split()))
MOD = 10**9 +7
if abs(a-b) > 1:
    print(0)
elif abs(a-b) == 1:
    print(math.factorial(a)*math.factorial(b) %MOD)
else:
    print(((math.factorial(a)**2)*2 %MOD))
# Judge status: Accepted
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
Count=Counter(D)
if D[0]!=0 or Count[0]!=1:print(0);exit()

ans=1
for i in range(1,max(D)+1):
    ans *=Count[i-1]**Count[i]
    ans %=mod
print(ans)
# Judge status: Accepted
from math import atan2, degrees

a, b, x = map(int, input().split())

if a * a * b / 2 >= x:
    c = 2 * x / a / b
    print(degrees(atan2(b, c)))
else:
    c = 2 * x / a / a - b
    print(degrees(atan2(b - c, a)))
# Judge status: Accepted
from itertools import permutations


def solve(string):
    n, *pq = map(int, string.split())
    *ps, = permutations(range(1, n + 1))
    return str(abs(ps.index(tuple(pq[n:])) - ps.index(tuple(pq[:n]))))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
# Judge status: Accepted
n = int(input())
dp = [0, 0, 0]
for i in range(n):
    todo = list(map(int, input().split()))
    ndp = [0, 0, 0]
    ndp[0] = max(dp[1], dp[2]) + todo[0]
    ndp[1] = max(dp[0], dp[2]) + todo[1]
    ndp[2] = max(dp[0], dp[1]) + todo[2]
    dp = ndp
print(max(ndp))
# Judge status: Wrong Answer
w, h, n = map(int, input().split())
area = [0, 0, w, h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        area[0] = x
    elif a == 2:
        area[2] = x
    elif a == 3:
        area[1] = y
    else :
        area[3] = y
print((area[2]-area[0]) * (area[3] - area[1]) if (area[2]-area[0]) * (area[3] - area[1]) > 0 else 0)
# Judge status: Accepted
from collections import Counter
N = int(input())
factors = []
i = 2
while N > 1:
  if N < i * i:
    factors.append(N)
    break
  while N % i == 0:
    factors.append(i)
    N //= i
  i += 1

ans = 0
for count in Counter(factors).values():
  i = 1
  while count >= i:
    count -= i
    i += 1
    ans += 1
print(ans)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
S = input()

num = 0
num_b = 0

for i in range(N):
    if S[i] == "a":
        if num < A + B:
            print("Yes")
            num += 1
        else:
            print("No")
    elif S[i] == "b":
        if num < A + B and num_b < B:
            print("Yes")
            num += 1
            num_b += 1
        else:
            print("Np")
    else:
        print("No")
# Judge status: Accepted
x = int(input())
for i in range(1, 361):
    if x*i % 360 == 0:
        print(i)
        exit()
# Judge status: Wrong Answer
li = list(map(int,input().split()))

a = li[0]
b = li[1]
c = li[2]
d = li[3]

ac = a * c
bc = b * c
ad = a * d
bd = a * d
result = ac
if result < bc:
    result = bc
elif result < ad:
    result = ad
elif result < bd:
    result = bd
elif a < 0 and 0 < b and result < 0:
    result = 0
elif c < 0 and 0 < d and result < 0:
    result = 0
print(result)
# Judge status: Wrong Answer
a, b, c = list(map(int, input().split()))
if a != b != c:
    print(3)
elif a == b == c:
    print(1)
else:
    print(2)
# Judge status: Accepted
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    S = input()
    
    #solve
    N = len(S)
    cnt=0
    ans=0
    for i in range(N):
        if S[i]=='S':
            cnt+=1
        else:
            if cnt:
                cnt-=1
                ans+=2
    print(N-ans)


if __name__=='__main__':
    main()
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
ans=1
count=1
"""
for i in range(1,n+1):
    ans+=count*2
    count*=2
#print(ans)
"""
ans=1
count=1
now=1
for i in range(n+1):
    count=(count-a[i])*2
    if a[i]%2==1:
        now=now*2-a[i]-1
    else:
        now=now*2-a[i]
    ans+=count
    #print(count,ans,now)

print(max(-1,ans))
# Judge status: Accepted
N, M = map(int,input().split())
accepted = [0]*N
wrong_ans =[0]*N 
for i in range(M):
    p,s = input().split()
    p = int(p)-1
    if s =="AC":
        accepted[p] = 1
    elif s == "WA" and accepted[p]==0:
        wrong_ans[p] = wrong_ans[p]+1

AC = 0
penalty = 0
for i in range(N):
    if accepted[i] == 1:
        AC = AC+1
        if wrong_ans[i]>=1:
            penalty = penalty+wrong_ans[i]
print(AC,penalty)
# Judge status: Accepted
K, A, B = map(int, input().split())

ans = 1
yen = 0
if A+1 >= B:
    print(K+1)
    quit()
cycle = max(0, (K-(A-1))//2)
res = (K-(A-1)) % 2
ans = cycle * (B-A) + A + res
print(ans)
# Judge status: Wrong Answer
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

sabun=[B[i]-A[i] for i in range(N)]

print("Yes" if (sum([i for i in sabun if i>0])+sum([i for i in sabun if i<0])*2)>=0 else "No")
# Judge status: Accepted
import fractions
import itertools

n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

anslist=list(itertools.permutations(range(1,n+1)))
print(abs(anslist.index(p)-anslist.index(q)))
# Judge status: Accepted
s=input()
ans=0
cur=0
ACGT=["A","C","G","T"]
for ss in s:
  if ss in ACGT:
    cur+=1
  else:
    ans=max(cur,ans)
    cur=0
print(max(ans,cur))
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def div(n, t):
    if n < t:
        return n
    else:
        return div(n // t, t) + n % t


def main():
    N = int(input())
    print(min(div(i, 6) + div(N - i, 9) for i in range(N + 1)))


if __name__ == "__main__":
    main()