Harryxun/stf_run huggingface dataset:
import numpy
import math
import collections
from decimal import *
import sys

def main():
    n = int(input())
    a = input_list()
    ca = collections.Counter(a)
    max_n = 10 ** 18
    if 0 in a:
        print(0)
        exit()
    ans = 1
    for num, count in ca.items():
        if num == 1:
            continue
        ans *= num**count
        if ans > max_n:
            print(-1)
            exit()
    print(ans)


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, sys.stdin.readline().split()))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#import numpy
import math
import sys

def main():
    n = int(input())
    a = sorted(input_list())
    max_n = 10 ** 18
    ans = 1
    for v in a:
        ans *= v
        if ans > max_n:
            ans = -1
            break
        if ans == 0:
            break
    print(ans)


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, sys.stdin.readline().split()))


if __name__ == '__main__':
    main()
s=list(input())
l=len(s)
ans=0
for i in range(l-3):
    sum_keta=int(s[i])
    num=s[i]
    index=i+1
    while sum_keta<=100:
        num+=s[i+j]
        if int(num)%2019==0:
            ans+=1
        index+=1
        sum_keta+=int(s[i+j])
        if l-1<index:
            break
print(ans)

### FIXED CODE ###

s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)
S=["MON","TUE","WED","THU","FRY","SAT","SUN"]

a=input()
n=S.index(a)

if a=="SUN":
    print(7)
else:
    print(6-n)


### FIXED CODE ###

S=["MON","TUE","WED","THU","FRI","SAT","SUN"]

a=input()
n=S.index(a)

if a=="SUN":
    print(7)
else:
    print(6-n)
N=int(input())
n=0
for i in range(1,10):
   if N<=(n+26**i):
       break
   else:
       n+=26**i
#print(i)

N-=n
N-=1
#print(N)
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans=""
for j in range(i):
    ans+=A[N//(26**(i-1-j))]
    N%=(26**(i-1-j))
print(ans)

### FIXED CODE ###

N=int(input())
n=0
for i in range(1,15):
   if N<=(n+26**i):
       break
   else:
       n+=26**i
#print(i)

N-=n
N-=1
#print(N)
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans=""
for j in range(i):
    ans+=A[N//(26**(i-1-j))]
    N%=(26**(i-1-j))
print(ans)
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  for i in range(min(p,q),0,-1):
    if p%i=0 and q%i=0:
      return i


def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  

  s=so(e,f)


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      g=(b-e)//f
      e=e+f*g
      while e>c:
        if e<b :
          return "No"
          
        e-=s

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

from fractions import gcd

for i in range(n):
    a = C[i][0]
    b = C[i][1]
    c = C[i][2]
    d = C[i][3]
    ng = 0

    e = 0  # 最初に補充が発生する直前の本数
    e0 = a - b
    e1 = ((c - a%b) // b) * b + a%b
    e = min(e0, e1)

    if e < 0 or b > d:
        ng = 1
    else:
        g = gcd(b, d)
        # print(c+1, b-1, g)
        if c+1 <= b-1 and (c - e) // g < (b-1 - e) // g:
            ng = 1

    if ng == 1:
        print("No")
    else:
        print("Yes")
# -*- coding: utf-8 -*-
a = int(input())
b = list(int(input().split()))
count = list()
for i in range(a):
  count[i-1] = 0
  while b[i-1] % 2 == 0:
    b[i-1] = b[i-1] / 2
    count[i-1] += 1
print(min(count))

### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
count = []
for i in range(n):
    count.append(0)
    while a[i] % 2 == 0:
        a[i] = a[i] / 2
        count[i] += 1
print(min(count))
str=raw_input()
if int(str[2])>int(str[1]):
  str[1]=str(int(str[1])+1)
  str[2]=str[1]
else:
  str[2]=str[1]
if int(str[1])>int(str[0]):
  str[0]=str(int(str[0])+1)
  str[1]=str[0]
else:
  str[1]=str[0]
print(str)

### FIXED CODE ###

st=raw_input()
s=list(st)
if int(s[2])>int(s[1]):
  s[1]=str(int(s[1])+1)
  s[2]=s[1]
else:
  s[2]=s[1]
if int(s[1])>int(s[0]):
  s[0]=str(int(s[0])+1)
  s[1]=s[0]
  s[2]=s[1]
else:
  s[1]=s[0]
  s[2]=s[1]
unko=""
for i in s:
  unko+=i
print(unko)
def resolve():
    '''
    code here
    '''
    S = input()
    is_flag = True
    while is_flag:
        # print(S, len(S))
        if len(S)>=5:
            temp = S[:5]
            # print(temp)
            if temp == 'dream':
                S = S[5:]
                if S[:5] == 'erase':
                    pass
                elif S[:2] == 'er':
                    S = S[2:]
                
            elif temp == 'erase':
                S = S[5:]
                if S[0] == 'r':
                    S = S[1:]
            else:
                print('NO')
                is_flag = False
        elif len(S) == 0:
            print('YES')
            is_flag = False
        else:
            print('NO')
            is_flag = False


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    S = input()
    is_flag = True
    while is_flag:
        # print(S, len(S))
        if len(S)>=5:
            temp = S[:5]
            # print(temp)
            if temp == 'dream':
                S = S[5:]
                if len(S) != 0:
                    if S[:5] == 'erase':
                        pass
                    elif S[:2] == 'er':
                        S = S[2:]
                
            elif temp == 'erase':
                S = S[5:]
                if len(S) != 0:
                    if S[0] == 'r':
                        S = S[1:]

            else:
                print('NO')
                is_flag = False
        elif len(S) == 0:
            print('YES')
            is_flag = False
        else:
            print('NO')
            is_flag = False


if __name__ == "__main__":
    resolve()
def main():
    cells, moves = [int(x) for x in input().split()]
    nexts = [int(x) - 1 for x in input().split()]
    scores = [int(x) for x in input().split()]
    ans = - 10 ** 9 - 5
    for start in range(cells):
        route = []
        seen = [False] * cells
        now = start
        for _step in range(cells):
            nex = nexts[now]
            if seen[nex]:
                break
            route.append(scores[nex])
            now = nex
            seen[now] = True
        length = len(route)
        total = sum(route)
        if total > 0 and moves > length:
            q, mod = divmod(moves, length)
            candidate = max(sum(route[:x + 1]) for x in range(mod)) + total * q
        else:
            candidate = max(sum(route[:x + 1])
                            for x in range(max(min(moves, length), 1)))
        ans = max(ans, candidate)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import accumulate


def main():
    cells, moves = [int(x) for x in input().split()]
    jumps_from = [int(x) - 1 for x in input().split()]
    score_on = [int(x) for x in input().split()]

    ans = - 10**10
    for start in range(cells):
        route = []
        route_append = route.append
        position = start
        while True:
            route_append(score_on[position])
            position = jumps_from[position]
            if position == start:  # Looped
                break

        length = len(route)
        total = sum(route)
        accum_tmp = 0
        for i, score in enumerate(route):
            accum_tmp += score
            if i + 1 > moves:
                break
            accum = accum_tmp
            if total > 0:
                accum += total * ((moves - (i + 1)) // length)
            ans = max(ans, accum)

        # if total > 0:
        #     q, mod = divmod(moves, length)
        #     if mod == 0:
        #         candidate = total * q
        #     else:
        #         candidate = max(list(accumulate(route))[:mod]) + total * q
        # else:
        #     candidate = max(list(accumulate(route))[:min(moves, length)])
        # ans = max(ans, candidate)
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)
import numpy as np

N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        # white
        L[i] = 1
    else:
        L[i] = 0
L = np.array(L, dtype=np.int8)
a = np.zeros((N+1, N), dtype=np.int8)
for i in range(N):
    a[i, :i] = 1
a[N] = 1

ans = (a - L)**2
ans = ans.sum(axis=1).min()
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        L[i] = 1
    else:
        L[i] = 0

leftblack = 0
rightwhite = len([x for x in L if x == 0])
ans = leftblack + rightwhite

for i in range(N):
    if S[i] == "#":
        leftblack += 1
    else:
        rightwhite -=1
    ans = min(ans, leftblack + rightwhite)
print(ans)
import math
X = int(input())
res = False
for A in range(1,1000):
    for B in range(-1000, A):
        if math.pow(A, 5) - math.pow(B, 5) == X:
            res = Trueå
            break

    if res:
        break

print(A, B)

### FIXED CODE ###

import math
X = int(input())
res = False
for A in range(1,1000):
    for B in range(-1000, A):
        if math.pow(A, 5) - math.pow(B, 5) == X:
            res = True
            break

    if res:
        break

print(A, B)
x = int(input())
for i in range(x+1):
    for n in range(2,x+1):
        if i**n <= x:
            count = i**2
print(count)

### FIXED CODE ###

x = int(input())
count = 1
for i in range(1,x+1):
    for n in range(2,10):
        if i**n <= x:
            count = max(i**n,count)
print(count)
s = input()
if s = 'Sunny':
    ans = 'Cloudy'
elif s = 'Cloudy':
    ans = 'Rainy'
else:
    ans = 'Sunny'
print(ans)


### FIXED CODE ###

s = input()
if s == 'Sunny':
    ans = 'Cloudy'
elif s == 'Cloudy':
    ans = 'Rainy'
else:
    ans = 'Sunny'
print(ans)
h, n = input().split(' ')
as = list(map(int, input().split(' ')))

if sum(as) >= h:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

h, n = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
 
if sum(a) >= h:
  print('Yes')
else:
  print('No')
import math
N,M,X = map(int,input().split())
#a[i][0]:price of the i-th book
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int,input().split()))
a.sort()
#dp[j][k]:lowest amount of money needed to make j-th algorithm level k
dp = [[math.inf for k in range(X+1)] for j in range(M)]

for j in range(M):
    dp[j][0] = 0

for i in range(N):
    for j in range(M):
        for k in range(X,a[i][j+1],-1):
            dp[j][k] = min(dp[j][k],dp[j][k-a[i][j+1]] + a[i][0])
        for k in range(1,a[i][j+1]+1):
            dp[j][k] = min(dp[j][k],a[i][0])

#print(dp)
maximum = 0
for j in range(M):
    maximum = max(maximum,dp[j][X])
if maximum == math.inf:
    print(-1)
else:
    print(maximum)
            


### FIXED CODE ###

import math
N,M,X = map(int,input().split())
#a[i][0]:price of the i-th book
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int,input().split()))

def is_greater(b):
    for i in b:
        if i < X:
            return False
    return True 
    
cost = math.inf
for i in range(2**N):
    b = [0]*(M+1)
    for j in range(N):
        if ((i >> j)&1):
            for k in range(M+1):
                b[k] += a[j][k]
    if b[0] < cost and is_greater(b[1:]):
        cost = b[0]

if cost == math.inf:
    print(-1)
else:
    print(cost)
N = int(input())
A = list(map(int,input().split()))
cnt = [0]* (max(A)+1)
for i in range(N):
    if cnt[A[i]] == 0:
        cnt[A[i]] = 1
    else:
        print("NO")
        exit()
print("YES")

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if (A[i] in dic) == True:
        print("NO")
        exit()
    dic[A[i]] = "exist"
print("YES")
import numpy as np
N, K = (int(i) for i in input().split())  
A = [int(i) - 1 for i in input().split()] 
N = len(A)

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val][0]

now = 0
lis = []
p = {}
for i in range(N):
  now = A[now]
  if now in p:
    break
  
  p[now] = i
  lis.append(now)

if K < i:
  print(lis[i] + 1)
else:
  print(lis[(K-i-1) % (i - p[now]) + p[now]] + 1)
    
  

### FIXED CODE ###

import numpy as np
N, K = (int(i) for i in input().split())  
A = [int(i) - 1 for i in input().split()] 
N = len(A)

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val][0]

now = 0
lis = []
p = {}
for i in range(N):
  now = A[now]
  if now in p:
    break
  
  p[now] = i
  lis.append(now)

if K < i:
  print(lis[K-1] + 1)
else:
  print(lis[(K-i-1) % (i - p[now]) + p[now]] + 1)
n, a, b = list(map(int, input().split(' ')))
ab = ''

while len(ab) < n and a + b != 0:
    ab = ab + ('a' * a) + ('b' * b)

print(ab[:n].count('a'))


### FIXED CODE ###

n, a, b = list(map(int, input().split(' ')))
blueBall = 0
answer = []

if a == 0:
    print(a)
else:
    if n / (a + b):
        answer = divmod(n, (a + b))
        blueBall = answer[0] * a
        if answer[1] > a:
            blueBall = blueBall + a
        else:
            blueBall = blueBall + answer[1]

        print(blueBall)
    else:
        if n <= a:
            print(n)
        elif n <= b:
            print(a)
n,m=input().split()
n,m=int(n),int(m)
a=[]
for i in range(n):
    a.append(input())

b=[]
for i in range(m):
    b.append(input())

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
if c==m or (n==m and a==b):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n,m=input().split()
n,m=int(n),int(m)
a=[]
for i in range(n):
    a.append(input())

b=[]
for i in range(m):
    b.append(input())

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
#cが定義されない時(m==nでは)エラー
if a==b:
    print("Yes")
elif n==m:
    print("No")
elif c==m:
    print("Yes")
else:
    print("No")
N, M=map(int,input.split())
a=[map(int,input.split())]
if N-sum(a)>=0:
  print(N-sum(a))
else:
  print(-1)
  

### FIXED CODE ###

N, M=map(int,input().split())
a=list(map(int,input().split()))
if N-sum(a)>=0:
  print(N-sum(a))
else:
  print(-1)
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = zip(*[i for i in a if "#" in a])
a = zip(*[i for i in a if "#" in a])
for i in range(len(a)):
    print("".join(a[i]))

### FIXED CODE ###

H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = list(zip(*[i for i in a if "#" in i]))
a = list(zip(*[i for i in a if "#" in i]))
for i in range(len(a)):
    print("".join(a[i]))
S = input()
T = input()
if T not it S:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

S = input()
T = input()
if (T[:-1] == S):
  print("Yes")
else:
  print("No")
n=int(input())
if n//9==0:
  print(Yes)
else:
  print(No)

### FIXED CODE ###

x=list(input())
a=0
for i in x:
  a+=int(i)
if a%9==0:
  print("Yes")
else:
  print("No")
n = int(input())
cnt= [0]*100000
a = list(map(int, input().split()))
for v in a:
    cnt[v-1] += 1
    cnt[v] += 1
    cnt[v+1] += 1

print(max(cnt))

### FIXED CODE ###

n = int(input())
cnt= [0]*100002
a = list(map(int, input().split()))
for v in a:
    cnt[v-1] += 1
    cnt[v] += 1
    cnt[v+1] += 1

print(max(cnt))
import math

print(2 * math.pi * input())

### FIXED CODE ###

import math

R = input()

print(2 * float(R) * math.pi)
#!/usr/bin/python3
# abc060_b
"""
Choose Integers
"""

from math import gcd  # greatest common divisor, 最大公約数
test = False

def lcm(x, y):
    """
    最小公倍数 least common multiple
    """
    return (x * y) // gcd(x, y)

def answer():
    """
    Aの倍数の中に条件を満たすものがあるか調べる。
    """
    A, B, C = map(int, input().split())
    upper_limit = int(lcm(A, B) / A)
    if test:
        print(lcm(A, B), upper_limit)

    for i in range(1, upper_limit+1):
        if (A * i) % B == C:
            print(A * i)
            return 'YES'
    return 'NO'


def main():
    """
    main関数
    """
    print(answer())


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3
# abc060_b
"""
Choose Integers
"""

test = False


def answer():
    """
    Aの倍数の中に条件を満たすものがあるか調べる。
    """
    A, B, C = map(int, input().split())

    for i in range(1, A*B+1):
        if (A * i) % B == C:
            if test:
                print(A * i)
            return 'YES'
    return 'NO'


def main():
    """
    main関数
    """
    print(answer())


if __name__ == '__main__':
    main()
for i in range(10000):
    print("Case {}: {}".format(i+1, int(input()))


### FIXED CODE ###

for i in range(10000):
    x = int(input())
    print("Case {}: {}".format(i+1, x))
    if x == 0:
        break
S = input()
agct = ['A','G','C','T']
count = 0
max_count = 0
for i in len(S):
  if S[i] in agct:
    count += 1
  else:
    max_count = max(count,max_count)
print(max_count)

### FIXED CODE ###

L = ["A","T","C","G"]
S = input()
S += "B"
count = 0
maxcount = 0
for i in S:
  if i in L:
    count += 1
  else:
    maxcount = max(count,maxcount)
    count = 0
print(maxcount)
N = input()
a = []
for i in range(N):
    a.append(map(int, input().split()))



for i in range(N):
    v = a[i]
    j = i-1
    while j>=0 and a[j]>v:
        a[j+1] = a[j]
        j = j-1
        a[j+1] = v
    print(a) 


### FIXED CODE ###

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


for i in range(N):
    v = b[i]
    j = i-1
    while j>=0 and b[j]>v:
        b[j+1] = b[j]
        j = j-1
        b[j+1] = v
    print(" ".join([str(n) for n in b]))
A, B, C, K = map(int, input().split())
result = 0

if A >= K:
    print(K)
else:
    for i in range(K):
        if A > (i + 1):
            result += 1
            continue
        elif A == (i + 1):
            result += 1
            continue

        if B > (i + 1 - A):
            result += 0
            continue
        elif B == (i + 1 - A):
            result += 0
            continue

        if C > (i + 1 - A - B):
            result -= 1
            continue
        elif C == (i + 1 - A - B):
            result -= 1
            break
        else:
            break
    print(result)

### FIXED CODE ###

s = input()
t = input()

if t.startswith(s) and str.isalpha(t):
    if len(t) == (len(s) + 1):
        print('Yes')
else:
    print('No')
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
h,w=map(int,input().split())
a=[list(map(str,input())) for _ in range(h)]
b=deque()
n=[-1]*(h*w)
c=0
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
             b.append((i,j))
             n[i*w+j]=0
        else:
            continue
while b:
    z=b.popleft()
    i=z[0]
    j=z[1]
    if i<h-1 and a[i+1][j]=="." and n[(i+1)*w+j]==-1:
      n[(i+1)*w+j]=n[i*w+j]+1
      c=max(c,n[i*w+j]+1)
      b.append(((i+1),j))
      f=True
    if i>0 and a[i-1][j]=="." and n[(i-1)*w+j]==-1:
      n[(i-1)*w+j]=n[i*w+j]+1
      c=max(c,n[i*w+j]+1)
      b.append(((i-1),j))
      f=True
    if j<w-1 and a[i][j+1]=="." and n[i*w+(j+1)]==-1:
      f=True
      n[i*w+(j+1)]=n[i*w+j]+1
      c=max(c,n[i*w+j]+1)
      b.append((i,(j+1)))
    if j>0 and a[i][j-1]=="."  and n[i*w+(j-1)]==-1:
      f=True
      n[i*w+(j-1)]=n[i*w+j]+1
      c=max(c,n[i*w+j]+1)
      b.append((i,(j-1)))
    if not f:
      break
print(c)
        

### FIXED CODE ###

import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
h,w=map(int,input().split())
a=[list(map(str,input())) for _ in range(h)]
b=deque()
n=[-1]*(h*w)
c=0
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
             b.append((i,j))
             n[i*w+j]=0
        else:
            continue
p = [(1,0),(-1,0),(0,1),(0,-1)]

while b:
    i,j=b.popleft()
    for s,t in p:
      if 0 <= i+s <= h-1 and 0 <= j+t <= w-1:
        if n[(i+s)*w+(j+t)]==-1:
          n[(i+s)*w+(j+t)]=n[i*w+j]+1
          c=max(c,n[i*w+j]+1)
          b.append(((i+s),(j+t)))
    
print(c)
N = int(input())
b = [10**9] + list(map(int,input().split())) + [10**9]
a = []
a[0] = b[1]
for i in range(1,N-1):
  a[i] == min(b[i-1],b[i])
  
a[N] = b[N-1]

### FIXED CODE ###

N = int(input())
b = [10**9] + list(map(int,input().split())) + [10**9]
a = []

for i in range(N):
  a.append(min(b[i],b[i+1]))

print(sum(a))
s=I().strip()
arr=s.split("S")
ans=0
for i in arr:
    ans=max(ans,len(i))
print(ans)

### FIXED CODE ###

import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

#
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x





	

def main():
	s=I().strip()
	arr=s.split("S")
	ans=0
	for i in arr:
		ans=max(ans,len(i))
	print(ans)

	













	
	
	






		







		
		
	
		

	







		









if __name__ == '__main__':
	main()
def dfs(cost, N):
    if N<6 :
        return cost+N
    else:
        ret0 = 6 ** math.floor(math.log(N, 6))
        ret1 = 9 ** math.floor(math.log(N, 9))
        if (ret0>1) and (ret1>1):
            return min(dfs(cost+1, N-ret0), dfs(cost+1, N-ret1))
        else:
            ret = max(ret0, ret1)
            return dfs(cost+1, N-ret)

N = int(input())
print(dfs(0, N))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6) 

def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func

@memorize
def memDFS(n):
    if n==0:
        return 0
    else:
        res = n
        pow6 = 1
        while(pow6<=n):
            res = min(res, memDFS(n-pow6)+1)
            pow6 *= 6
        pow9 = 1
        while(pow9<=n):
            res = min(res, memDFS(n-pow9)+1)
            pow9 *= 9
        return res

N = int(input())
print(memDFS(N))