Harryxun/stf_run huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    cnt = 0
    c_sum = [0]
    s = set()
    while cnt < k:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        now = p[now]
        cnt += 1
        if now in s:
            break
    if k <= cnt:
        ans = max(ans, max(c_sum[1: min(k + 1, len(c_sum))]))
    else:
        temp = c_sum[-1]
        q = k // cnt
        temp *= q
        q = k - q*cnt
        temp += max(c_sum[1:min(q + 1, len(c_sum))])
        ans = max(ans, temp, max(c_sum[1:]))
print(ans)




    

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    c_sum = [0]
    s = set()
    cnt = 0
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        cnt += 1
        now = p[now]
        if now in s:
            break
    c_sum = c_sum[1:]
    if k < cnt:
        ans = max(ans, max(c_sum[: k]))
    else:
        score = c_sum[-1]
        count = k // cnt
        k_ = k - count*cnt
        score *= count
        score_2 = score - c_sum[-1]
        score_2 += max(c_sum)
        if k_ > 0:
            score += max(0, max(c_sum[:k_]))
        ans = max(ans, score, max(c_sum), score_2)
print(ans)
l=input()
if l="RRR":
  print(3)
elif l="RRS" or "SRR":
  print(2)
elif l="SSS":
  print(0)
else:
  print(1)
    

### FIXED CODE ###

l=input()
for i in range(4):
  if "R"*i in l:
    ans=i
print(ans)
import math

a, b = map(int, input().split())
ans = (a * b) // math.gcd(a, b)
print(ans)

### FIXED CODE ###

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

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

a, b = map(int, input().split())
ans = lcm(a, b)
print(ans)
n=int(input())%500
a=int(input())
if a>=n:
  print('Yes')
else:
  ptint('No')


### FIXED CODE ###

n=int(input())%500
a=int(input())
print('Yes' if a>=n else 'No')
n,a,b = map(int,input().split())
c = 0
for k in range(a,b+1):
  if sum(list(map(int, list(str(k)))):
         c += 1
print(c)

### FIXED CODE ###

n,a,b = map(int,input().split())
s = 0
for k in range(1,n+1):
  x = sum(list(map(int, list(str(k))))) 
  if x >= a and x <= b:
         s += k 
print(s)
N,M,K = list(map(int,input().split()))

# DFSテンプレ、計算量=O(N+M)
# N:頂点の数
# M:辺の数

G = [[] for _ in range(N)]
# graphの入力
for _ in range(M):
    a,b = list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
# print("G:",G)

KG = [[] for _ in range(N)]
# block graphの入力
for _ in range(K):
    a,b = list(map(int,input().split()))
    KG[a-1].append(b-1)
    KG[b-1].append(a-1)
# print("KG:",KG)

# ここまでエラーなし。

def dfs(G,v):
    # global l
    # nを訪問済みにする
    seen[v] = 1
    # l += 1
    # print(v+1)
    seenV.append(v)
    # vから行ける各頂点next_vについて
    for next_v in G[v]:
        if seen[next_v] == 1:
            continue
        dfs(G,next_v)

# Adj_size = [0]*N
# 全頂点を未訪問に初期化。
Adj = [[] for _ in range(N)]
seen = [0]*N
Y = []
for v in range(N):
    # l = 0
    if seen[v] == 0:
        # 未探索ならdfs発動
        seenV = []
        dfs(G,v)
    
        for sv in seenV:
            Adj[sv] = seenV
    """
        print("dfs done !!!")
    print("v=",v+1,"seen:",seen)
    print("seenV:",seenV)
    print("Adj[",v,"] :",Adj[v])
    """
    
    # 出力
    # y = Adj_size[v] - len(G[v])-1
    y = len(Adj[v]) - len(G[v]) - 1
    for k in KG[v]:
        if k in Adj[v]:
            y += -1
    # print("v=",v+1,"y=",y)
    Y.append(str(y))
    # print("")

# print("ADj",Adj)
# print("Y",Y)
# print("G",G)

print(" ".join(Y))





### FIXED CODE ###

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
 
def unite(x,y):
  x,y=find(x),find(y)
  if x!=y:
    if x>y:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
    
def same(x,y):
  return find(x)==find(y)
 
def size(x):
  return-par[find(x)]
 
N,M,K = map(int,input().split())
par=[-1]*N
B = [set() for _ in range(N)]
FF = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    unite(a-1,b-1)
    FF[a-1] += 1
    FF[b-1] += 1
# print(F)
for j in range(K):
    a,b = map(int,input().split())
    B[a-1].add(b-1)
    B[b-1].add(a-1)

Y = []
for i in range(N):
    y = size(i) - FF[i] -1
    for b in B[i]:
        if same(i,b):
            y += -1
    Y.append(str(y))
print(" ".join(Y))
def R(xyzr1,xyzr2):
	x1,y1,z1,r1 = xyzr1
	x2,y2,z2,r2 = xyzr2
	return max(0,((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2)**0.5 - r1 - r2)

while 1:
	n = input()
	if n == 0: break
	xyzr = [map(float,raw_input().split()) for i in range(n)]
	ans = 1e10
	for i in range(n):
		for j in range(i+1,n):
			l = R(xyzr[i],xyzr[j])
			if l < ans:
				ans = l
				s = [i,j]
	chain = [xyzr.pop(s[1]),xyzr.pop(s[0])]
	while xyzr:
		pipe = 1e10
		for i in range(len(xyzr)):
			for j in range(len(chain)):
				l = R(xyzr[i],chain[j])
				if l < pipe:
					pipe = l
					p = i
		ans += pipe
		chain.append(xyzr.pop(p))
	print ans

### FIXED CODE ###

inf = 1 << 28
def calc(xyzr1,xyzr2):
    x1,y1,z1,r1 = xyzr1
    x2,y2,z2,r2 = xyzr2
    d = ((x1-x2)**2+(y1-y2)**2+(z1-z2)**2)**0.5
    return max(0, d-r1-r2)
    
while 1:
    n = int(raw_input())
    if n == 0: break
    xyzr = [map(float,raw_input().split()) for i in xrange(n)]
    
    cost = [[0]*n for i in xrange(n)]
    for i in xrange(n):
        for j in xrange(n):
            cost[i][j] = cost[j][i] = calc(xyzr[i],xyzr[j])
    
    mincost = [inf]*n
    used = [False]*n
    mincost[0] = 0
    ans = 0
    while 1:
        v = -1
        for u in xrange(n):
            if not used[u] and (v == -1 or mincost[u] < mincost[v]): v = u
        if v == -1: break
        used[v] = True
        ans += mincost[v]
        for u in xrange(n):
            mincost[u] = min(mincost[u], cost[v][u])
    
    print "%.3f"%ans
A,B,C = map(int,input().split())

r = B%A
s = (B-r)/A

print(min(C,s)


### FIXED CODE ###

A,B,C = map(int,input().split())

List=[B//A,C]
print(min(List))
N = int(input())
A = []
for i in range(0,N):
  B = int(input())
  A.append(B)

sum1 = float(1/A[0])

for i in range(0,N-1):
  sum1 = sum1 + 1/A[i+1]

result = 1/sum1
print(result)

### FIXED CODE ###

if __name__=="__main__":
    import sys
    a = int(input())
    s = input()

if a>=3200:
    print(s)
else:
    print('red')
import re
import numpy as np
_, q = input()
s = input()
qs = [input().split() for _ in range(q)]

def get_num_AC(s):
    count = len(re.split(r'AC', s)) - 1
    return count

def get_substr(s, smaller, larger)
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)

### FIXED CODE ###

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

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])
import math
from collections import Counter
M = 256

def entropy_if_smallest(ctr,bound):
    ret = 0
    for v in ctr.values():
        ret -= (v / N) * math.log2(v / N)
        if ret >= bound:
            return None
    return ret

def solve(src):
    ans_h = float('inf')
    ans = None
    for s in range(16):
        for a in range(16):
            for c in range(16):
                ctr = Counter()
                r = s
                for i in src:
                    r = (a*r + c) % M
                    o = (i + r) % M
                    ctr.update([o])
                h = entropy_if_smallest(ctr,ans_h)
                if h is not None:
                    ans = (s,a,c)
                    ans_h = h
                    if ans_h == 0:
                        return ans
    return ans

while True:
    N = int(input())
    if N == 0: break
    src = list(map(int,input().split()))
    print(' '.join(map(str,solve(src))))

### FIXED CODE ###

import math
M = 256

def entropy_if_smallest(ctr,bound):
    ret = 0
    for v in ctr:
        if v == 0: continue
        ret -= (v / N) * math.log2(v / N)
        if ret >= bound:
            return None
    return ret

def solve(src):
    ans_h = float('inf')
    ans = None
    for s in range(16):
        for a in range(16):
            for c in range(16):
                ctr = [0] * M
                r = s
                for i in src:
                    r = (a*r + c) % M
                    o = (i + r) % M
                    ctr[o] += 1
                h = entropy_if_smallest(ctr,ans_h)
                if h is not None:
                    ans = (s,a,c)
                    ans_h = h
                    if ans_h == 0:
                        return ans
    return ans

while True:
    N = int(input())
    if N == 0: break
    src = list(map(int,input().split()))
    print(' '.join(map(str,solve(src))))
l,r=map(int,input().split())
lst=list(range(l,r+1))
lst1=lst[:min(2020,r-l+2)]
def div(n):
  return n%2019
lst1=list(map(div,lst1))
lst1.sort()
print(lst1[0]*lst1[1])
  


### FIXED CODE ###

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

if 2018<=r-l:
  print(0)
  sys.exit()

L=l%2019
R=r%2019
m=2018

if L>R:
  print(0)
  sys.exit()

  
for i in range(L,R):
  for j in range(i+1,R+1):
    m=min((i*j)%2019,m)

print(m)
dgthd

### FIXED CODE ###

ls = {'A':'T','C':'G','T':'A','G':'C'}
print(ls[input()])
from math import ceil

def isOK(length):
  ans = 0
  for a in A:
    ans += ceil(a / length) - 1
  return ans <= k


n, k = map(int, input().split())
A = list(map(int, input().split()))

start, end = 0, 10**9 + 1
while True:
  mid = (start + end) // 2
  prev = mid - 1
  if isOK(mid):
    if isOK(prev):
      end = mid
    else:
      print(mid)
      exit()
  else:
    start = mid


### FIXED CODE ###

from math import ceil

def isOK(length):
  ans = 0
  for a in A:
    ans += ceil(a / length) - 1
  return ans <= k

n, k = map(int, input().split())
A = list(map(int, input().split()))

start, end = 0, 10**9 + 1
while True:
  mid = (start + end) // 2
  if mid == 1:
    print(mid)
    exit()
  prev = mid - 1
  if isOK(mid):
    if isOK(prev):
      end = mid
    else:
      print(mid)
      exit()
  else:
    start = mid
from functools import lru_cache
dan,ana=map(int,input().split())
l={int(input()) for _ in range(ana)}
@lru_cache(maxsize=100000000000000)
def f(x):
  global l
  if x in l:return 0
  elif x==1:return 1
  elif x==2:return f(1)+1
  else:return (f(x-1)+f(x-2))%(10**9+7)

print(f(dan))


### FIXED CODE ###

n,m=map(int,input().split())
l={int(input()) for i in range(m)}
dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(1,1+n):
    if i not in l:dp[i]+=dp[i-1]+dp[i-2];dp[i]%=10**9+7
print(dp[n])
l = input().split()
d = min(l)
e = max(l)
fl.remove(max(l), min(l))

print(str(d) + " " + f + " " + e)

### FIXED CODE ###

l = list(map(int, input().split()))
l.sort()
for i in range(len(l)):
    if i == len(l)-1:
        print(l[i])
    else:
        print(l[i], end = " ")
import sys
sys.setrecursionlimit(10**5)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(k,0,0)
for i in range(q):
    x, y = map(int,input().split())
    print(d[x]+d[y])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(k,0,0)
for i in range(q):
    x, y = map(int,input().split())
    print(d[x]+d[y])
n, m = map(int, input().split())
print(~-a*~-b)


### FIXED CODE ###

n, m = map(int, input().split())
print((n-1)*(m-1))
import sys
from math import factorial

def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 

def check(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp

    n = x - y
    x -= 2 * n

    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

# if not check(X, Y):
#     print(0)
#     exit(0)

m = int(1/3 * (2*Y - X))
n = int(Y - 2 * m)

if n < 0 or m < 0:
    print(0)
else:
    p = m if m < n else n
    print(ncr(n+m, p))


### FIXED CODE ###

import sys
from math import factorial

def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 

def check(x, y):
    if (x + y) % 3 == 0:
        return True
    else:
        return False
    

# Read
line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

if not check(X, Y):
    print(0)
    exit(0)

m = int(1/3 * (2*Y - X))
n = int(Y - 2 * m)

if n < 0 or m < 0:
    print(0)
else:
    print(ncr(n+m, n, 10**9+7))
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  

c=0
for i in range(n):
  l=[1]*n
  for j in range(i,n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=X[0][0]
      #l[b] *= Y[j][k]

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)  
   

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
N, C = map(int, input().split())
timeTable = [tuple(map(int, input().split())) for i in range(N)]
sutyoku =  [set() for i in range(20002)]

for s,t,c in timeTable:
    if s == 0:
        for i in range(2*t):
            sutyoku[i].add(c)
    else:
        for i in range(2*s-1,2*t):
            sutyoku[i].add(c)

ans = 0
for s in sutyoku:
    ans = max(ans, len(s))

print(ans)



### FIXED CODE ###

import numpy

N, C = map(int, input().split())
STC = [list(map(int, input().split())) for i in range(N)]
Channel = numpy.array([[0]*(2*10**5+1) for i in range(C+1)])

for s, t, c in STC:
    Channel[c][2*s-1] += 1
    Channel[c][2*t] -= 1
    
for i in range(len(Channel)):
    Channel[i] = numpy.cumsum(Channel[i])
bool_Channel = Channel.astype(numpy.bool_)

needs = numpy.sum(bool_Channel, axis=0)
print(needs.max())
num_n = input()
n = map(int, raw_input().split())
num_m = input()
m = map(int, raw_input().split())
    
def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(n):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - n[i])
   return res
     
for k in m:
   if solve(0, m[k]):
      print "yes"
   else:
      print "no"

### FIXED CODE ###

_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())

def exSearch(i, m):
    if m == 0:
        return True
    if i >= len(hoge) or m > sum(hoge):
        return False
    res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
    return res

if __name__ == '__main__':
    
    for val in (int(x) for x in input().split()):
        if exSearch(0, val):
            print ('yes')
        else:
            print ('no')
import math

a, b = map(int, input().split())  # 複数数値入力

A = list()
B = list()

for i in range(1, int(math.log2(b))+2):
    tmp = b // (2 ** i) * 2 ** (i - 1)

    if b % (2 ** i) < (2 ** (i-1)):
        plus = 0
    else:
        plus = b % (2 ** i) - 2 ** (i-1) + 1

    B.append(tmp+plus)
if a == 1:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

ans = 0
for i in range(0, int(math.log2(b)) + 1):
    if i >= len(A):
        ans += (B[i]) % 2 * 10 ** i
    else:
        ans += (B[i] - A[i]) % 2 * 10 ** i

print(int(str(ans), 2))


### FIXED CODE ###

import math

a, b = map(int, input().split())  # 複数数値入力

A = list()
B = list()

if b == 0:
    B = [0]
elif b == 1:
    B = [1]
else:
    for i in range(1, int(math.log2(b))+2):
        tmp = b // (2 ** i) * 2 ** (i - 1)

        if b % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = b % (2 ** i) - 2 ** (i-1) + 1

        B.append(tmp + plus)

if a == 0:
    A = [0]
elif a == 1:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

if b == 0:
    print(0)
else:
    ans = 0
    for i in range(0, int(math.log2(b)) + 1):
        if i >= len(A):
            ans += (B[i]) % 2 * 10 ** i
        else:
            ans += (B[i] - A[i]) % 2 * 10 ** i

    print(int(str(ans), 2))
r = int(input())
pi = 3.1415926535
print("%.5f %.5f" % (pi*r*r, 2*pi*r))

### FIXED CODE ###

r = float(input())
pi = 3.14159265358979323846264338
print("%.7f %.7f" % (pi*r*r, 2*pi*r))
n=int(input())
t,a=list(input().split())
H=list(input().split())
L=list()

for i in range(H):
  Ave_temparature=abs(float(a)-(float(t)-float(H[i])*0.006))
  L.append(Ave_temparature)
  
print(min(L))


### FIXED CODE ###

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

for i in range(0,len(H)):
  H[i]=abs(1000*a-t*1000+H[i]*6)
  
print(H.index(min(H))+1)
N,M=list(map(int,input().split()))

S=[]
s=0
for m in range(M):
    e = int(input())
    S.append(list(range(s,e)))
    s = e+1

e = int(N+1)
S.append(list(range(s,e)))

fibo=[0,1]
for n in range(2,N+1):
    fibo.append(fibo[n-2]+fibo[n-1])
    
ans=1
for s in S:
    ans=ans*fibo[len(s)]
print(ans%1000000007)

### FIXED CODE ###

N,M=list(map(int,input().split()))
 
S=[]
s=0
for m in range(M):
    e = int(input())
    S.append(list(range(s,e)))
    s = e+1

e = int(N+1)
S.append(list(range(s,e)))
 
fibo=[0,1]
for n in range(2,N+2):
    fibo.append(fibo[n-2]+fibo[n-1])
    
ans=1
for s in S:
    ans=ans*fibo[len(s)]
print(ans%1000000007)
N = input()
print(N**3)

### FIXED CODE ###

N =input()
print(int(N)**3)
N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append((b, c))
    D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 1)


def dfs(c, p, d):
    DS[c] = d
    for r in D[c]:
        if r[0] == p:
            continue
        dfs(r[0], c, d + r[1])


def main():
    dfs(K - 1, -1, 0)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(DS[x - 1] + DS[y - 1])


main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000001)

N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append((b, c))
    D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)


def dfs(c, p, d):
    DS[c] = d
    for r in D[c]:
        if r[0] == p:
            continue
        dfs(r[0], c, d + r[1])


def main():
    dfs(K - 1, -1, 0)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(DS[x - 1] + DS[y - 1])


main()
a,b=map(int,input().split())
from math import *
c=gcd(a,b)
d=0
for i in range(1,c+1):
    if c%i==0:
        c//=i
        d+=+1
print(d)

### FIXED CODE ###

def z(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a,b=map(int,input().split())
A=set(z(a))
B=set(z(b))
c=[i for i in A if i in B]
print(len(c)+1)
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y/2)**2 * x % mod

  
s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (power(3,q)+c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (power(3,q) + c*3) % mod
    q += 1
print(abc)


### FIXED CODE ###

s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (pow(3,q,mod) + c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (pow(3,q,mod) + c*3) % mod
    q += 1
print(int(abc))
for i in range(int(input())):
	c,a,n = map(int,input().split())
    cnt1 = min(c,a,n)
    c -= cnt1
    a -= cnt1
    cnt2 = min(c//2,a)
    c -= cnt2*2
    cnt3 = c//3
    print(cnt1+cnt2+cnt3)
    
#for i in range(int(input())):
#	c,a,n = map(int,input().split())
#	cnt = 0
#	while True:
#		if c<1 or a<1 or n<1:
#			break
#		c -= 1
#		a -= 1
#		n -= 1
#		cnt += 1
#	while True:
#		if c<2 or a<1:
#			break
#		c -= 2
#		a -= 1
#		cnt += 1
#	while True:
#		if c<3:
#			break
#		c -= 3
#		cnt += 1
#	print(cnt)

### FIXED CODE ###

for i in range(int(input())):
	c,a,n = map(int,input().split())
	cnt1 = min(c,a,n)
	c -= cnt1
	a -= cnt1
	cnt2 = min(c//2,a)
	c -= cnt2*2
	cnt3 = c//3
	print(cnt1+cnt2+cnt3)

#for i in range(int(input())):
#	c,a,n = map(int,input().split())
#	cnt = 0
#	while True:
#		if c<1 or a<1 or n<1:
#			break
#		c -= 1
#		a -= 1
#		n -= 1
#		cnt += 1
#	while True:
#		if c<2 or a<1:
#			break
#		c -= 2
#		a -= 1
#		cnt += 1
#	while True:
#		if c<3:
#			break
#		c -= 3
#		cnt += 1
#	print(cnt)
a,b = map(int, input().split())
tap = a
i = 1
while tap < b:
	tap = tap + a-1
	i += 1
return (i)


### FIXED CODE ###

a,b = map(int, input().split())
tap = a
i = 0
if b != 1:
	while tap < b:
		tap = tap + a-1
		i += 1
	print(i + 1)
else:
  	print(0)
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]

    ia = n-1
    res = n
    ib = 0
    time = sum(a)

    while(ia>=0 and ib<m):

      if(time > k):
            time -= (a[ia])
            res-=1
            ia-=1
        elif(time+b[ib]<=k):
            time += (b[ib])
            res+=1
            ib+=1
        else:
            break

    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    a = [0]+list(itertools.accumulate(a))
    b = [0]+list(itertools.accumulate(b))
    res = 0
    j = m
    best=0
    for i in range(n+1):
        if(a[i]>k):
            break
        while(b[j] > k-a[i]):
            j-=1
        res = max(res,i+j)
    print(res)


if __name__ == '__main__':
    main()