Harryxun/stf_run huggingface dataset:
import sys
input=sys.stdin.readline

check=dict()
N,b,d=0,[],0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d

    #-1ずつしていく場合
    check[0]=min(check[n]+n*d,check[0])

    x1,x2,x3=n//ttf,n%ttf,x2*d
    x3=x2*d
    if ttf-x2>=x2:
        if x1==0:
            if x1 in check:
                if check[x1]>check[n]+x3:
                    check[x1]=check[n]+x3
            else:
                check[x1]=check[n]+x3
        else:
            if x1 in check:
                if check[x1]>check[n]+x3+cha:
                    check[x1]=check[n]+x3+cha
                    dfs(x1)
            else:
                check[x1]=check[n]+x3+cha
                dfs(x1)

    x1,x2,x3=n//ttf+1,ttf-n%ttf,x2*d
    if ttf-x2>x2:
        if x1 in check:
            if check[x1]>check[n]+x3+cha:
                check[x1]=check[n]+x3+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x3+cha
            dfs(x1)


def dfs(n):
    global b,check,d
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])

### FIXED CODE ###

import sys
check=dict()
N,a,b,c,d=0,0,0,0,0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d
    if 0 in check:
        check[0]=min(check[n]+n*d,check[0])
    else:
        check[0]=check[n]+n*d
    if n//ttf==0:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d:
                check[n//ttf]=check[n]+(n%ttf)*d
        else:
            check[n//ttf]=check[n]+(n%ttf)*d
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global check,a,b,c,d
    dfs_sub(n,2,a)
    dfs_sub(n,3,b)
    dfs_sub(n,5,c)

t=int(input())
ans=[0]*t
for i in range(t):
    N,a,b,c,d=map(int,input().split())
    check={N:0}
    dfs(N)
    ans[i]=check[0]
for i in range(t):
    print(ans[i])
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d=0,0
def kaijyou(x):
  y=1
  for i in range(1,x+1):
    y*=i
  return y
for i in range(n):
  c+=kaijyou(n-i-1)*(max(0,a[i]-1))
for i in range(n):
  d+=kaijyou(n-i-1)*(max(0,b[i]-1))
print(abs(a-b))

### FIXED CODE ###

import itertools
n=int(input())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
lst=[i for i in itertools.permutations(range(1,n+1))]
cnt=0
for i in lst:
  if a==i:
    a=cnt
  if b==i:
    b=cnt
  cnt+=1
print(abs(a-b))
memo = {}

def gcd(a, b):
    if (a, b) in memo.keys():
        return memo.get[(a, b)]
    if b == 0:
        return a
    return gcd(b, a % b)

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i in xrange(1, n):
        if i == exclude:
            continue
        g_new = gcd(g, a_list[i])
        memo[(g, a_list[i])] = g_new
        g = g_new
        if g <= max_g:
            break
    if g > max_g:
        max_g = g
print(max_g)


### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    g = gcd(b, a % b)
    return g

n = input()
a_list = map(int, raw_input().split())

gs1 = [None] * n
gs1[0] = a_list[0]
for i in xrange(1, n):
    gs1[i] = gcd(gs1[i - 1], a_list[i])

gs2 = [None] * n
gs2[n - 1] = a_list[n - 1]
for i in reversed(xrange(n - 1)):
    gs2[i] = gcd(gs2[i + 1], a_list[i])

max_g = 0
for exclude in xrange(n):
    if exclude == 0:
        g = gs2[1]
    elif exclude == n - 1:
        g = gs1[n - 2]
    else:
        g = gcd(gs1[exclude - 1], gs2[exclude + 1])
    if g > max_g:
        max_g = g
print(max_g)
N = int(input())
s = [int(input()) for i in range(N)]

s_max=max(s)

for i in range(N):
  if s[i]<s_max:
    print(s_max)
  else:
	print(max([s[x] for x in range(i)]+[s[x] for x in range(i+1, N)]))


### FIXED CODE ###

N=int(input())
s=[int(input()) for i in range(N)]

temp=s.copy()
s_max=max(temp)
temp.remove(s_max)
s_max2=max(temp)

for i in range(N):
  if s[i]<s_max:
    print(s_max)
  else:
    print(s_max2)
import numpy as np
K = int(input())

sum = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    s += np.gcd(i,j)
    for k in range(1,K+1):
      sum += np.gcd(s,k)
      
print(sum)

### FIXED CODE ###

from math import gcd
K = int(input())
sum = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(gcd(i,j),k)
      
print(sum)
N, L = map(int, input().split())
s = []
for i in range(N):
    line = input()
    s.append(line)
s.sort()
print("".join(s))

### FIXED CODE ###

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

arr = [A, B, C]
fives = 0
sevens = 0

for num in arr:
    if num == 5:
        fives += 1
    if num == 7:
        sevens += 1

if fives == 2 and sevens == 1:
    print("YES")
else:
    print("NO")
n,a,b = map(int,input().split())

mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fac = [0]*(n+1)
fac[0] = 1
fac[1] = 1
for i in range(2,n+1):
    fac[i] = fac[i-1] * i % mod

c = 0
if n % 2 == 0:
    for i in range(1,n//2 ):
        c += ( fac[n] * modinv(fac[i]) )%mod * modinv(fac[n-i]) % mod
    c *= 2
    c += ( fac[n] * modinv(fac[n//2]) )%mod * modinv(fac[n-n//2]) % mod
    c -= ( fac[n] * modinv(fac[a]) )%mod * modinv(fac[n-a]) % mod
    c -= (fac[n] * modinv(fac[b])) % mod * modinv(fac[n-b]) % mod
    c += 1
    c = c % mod
else:
    for i in range(1, n // 2 + 1):
        c += (fac[n] * modinv(fac[i])) % mod * modinv(fac[n - i]) % mod
    c *= 2
    c -= (fac[n] * modinv(fac[a])) % mod * modinv(fac[n - a]) % mod
    c -= (fac[n] * modinv(fac[b])) % mod * modinv(fac[n - b]) % mod
    c += 1
    c = c % mod

print(c)

### FIXED CODE ###

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

mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def com(n,k,mod=10**9+7):
    u = 1
    s = 1
    for i in range(n,n-k,-1):
        u = u*i % mod
    for i in range(k,0,-1):
        s = s*i % mod
    return u * modinv(s)

c = pow(2,n,mod)
c -= 1
c -= com(n,a)
c -= com(n,b)
print(c%mod)
import math
n=int(input())
h=[]
for i in range(n):
    w=list(map(int,input().split()))
    h.append(w)
for i in range(n):
    a,b,c,d=h[i][0],h[i][1],h[i][2],h[i][3]
    if(b>a or b>d):
        print("No")
        continue
    if(b<=c):
        print("Yes")
        continue
    if(b-math.gcd(b,d)+a%math.gcd(b,d)<=c):print("Yes")
    else:print("No")

### FIXED CODE ###

from fractions import gcd
n=int(input())
h=[]
for i in range(n):
    w=list(map(int,input().split()))
    h.append(w)
for i in range(n):
    a,b,c,d=h[i][0],h[i][1],h[i][2],h[i][3]
    if(b>a or b>d):
        print("No")
        continue
    if(b<=c):
        print("Yes")
        continue
    if(b-gcd(b,d)+a%gcd(b,d)<=c):print("Yes")
    else:print("No")
    continue
from fractions import gcd
from bisect import bisect_left

N, M = map(int, input().split())
S = input()
T = input()
 
if N > M:
    N, M = M, N
    S, T = T, S

L = N*M // gcd(N, M)
 
a = G//N
b = G//M
 
X = [a*i for i in range(N)]
Y = [b*j for j in range(M)]
 
for i, x in enumerate(X):
    j = bisect_left(Y, x)
    if j < M and Y[j] == x:
        if S[i] != T[j]:
            print(-1)
            break
else:
    print(L)

### FIXED CODE ###

from fractions import gcd
from bisect import bisect_left
 
N, M = map(int, input().split())
S = input()
T = input()
 
if N > M:
    N, M = M, N
    S, T = T, S

G = N*M // gcd(N, M)
 
a = G//N
b = G//M
 
X = [a*i for i in range(N)]
Y = [b*j for j in range(M)]
 
for i, x in enumerate(X):
    j = bisect_left(Y, x)
    if j < M and Y[j] == x:
        if S[i] != T[j]:
            print(-1)
            break
else:
    print(G)
N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[]           
seen = {}
k=A[0]
for i in range (K):
  if not k in seen.keys():
      l.append(k)
      seen[k]=i
      k=A[k-1]

  else:
    r_start=seen[k]
    roop=i-r_start
    break
c=K//roop
K=K-roop*c
ans=l[K-1]
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
l=[1]           
seen={}
k=1
for i in range (K):
  if not k in seen.keys():
      seen[k]=i
      k=A[k-1]
      l.append(k)
  else:
    r_start=seen[k]
    roop=i-r_start
    K=(K-r_start)%roop+r_start
    break
ans=l[K]
print(ans)
a=int(input())
b=int(input())
if a > b:
  print("a > b")
elif a < b:
   print("a < b")
else:
    print("a == b")


### FIXED CODE ###

n=input().split()
a=int(n[0])
b=int(n[1])
if a > b:
    print("a > b")
elif a < b:
    print("a < b")
else:
    print("a == b")
import math
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // math.gcd(x,y)
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))

### FIXED CODE ###

import fractions
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // fractions.gcd(x,y)
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))
cs = [ int(x) for x in input().split() ]
    n = cs[0] * 100 + cs[1] * 10 + cs[2]
    if n % 4 == 0 :
        print("YES")
    else :
        print("NO")

### FIXED CODE ###

cs = [ int(x) for x in input().split() ]
n = cs[0] * 100 + cs[1] * 10 + cs[2]
if n % 4 == 0 :
            print("YES")
else :
            print("NO")
n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
for _ in range(n):
    s = [list(map(int, input().split())) for _ in range(n)]
    for i in range(101):
        for j in range(101):
            h = -1
            ok = 1
            for t in s:
                if h == -1:
                    h = abs(t[0] - i) + abs(t[1] - j) + t[2]
                else:
                    h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                    if h == h0:
                        ok += 1
            if ok == n:
                print(i, j, h)
                exit()

### FIXED CODE ###

n = int(input())
if n == 1:
    x, y, h = map(int, input().split())
    print(x, y, h)
    exit()
s = [list(map(int, input().split())) for _ in range(n)]
for i in range(101):
    for j in range(101):
        h = -1
        ok = 1
        for t in s:
            if t[2] == 0:
                ok += 1
            elif h == -1:
                h = abs(t[0] - i) + abs(t[1] - j) + t[2]
            else:
                h0 = abs(t[0] - i) + abs(t[1] - j) + t[2]
                if h == h0:
                    ok += 1
        if ok == n:
            for t in s:
                if abs(t[0] - i) + abs(t[1] - j) <= h:
                    if not h == abs(t[0] - i) + abs(t[1] - j) + t[2]:
                        ok = 0
                else:
                    if not t[2] == 0:
                        ok = 0
            if ok == n:
                print(i, j, h)
                exit()
N, K = map(int, input().split())
import math

ttl = 0
l = []
for i in range(K):
  a = math.factorial(i+1+N-K)/((math.factorial(N-K+1))*(math.factorial(i)))
  b = math.factorial(K-1+i-1)/((math.factorial(K-1))*(math.factorial(i-1)))
  ans = a*b
  l.append(ans)

for j in l:
  print(int(j%(10^9+7)))


### FIXED CODE ###

N, K = map(int, input().split())
import math
mod =10**9+7

l = []
l.append(N-K+1)
for i in range(1, K):
  a = l[i-1] * (N-K-i+1) * (K-i) // ((i+1)*i)
  l.append(int(a))

for j in l:
  print(j%mod)
L, N = map(int, input().split())

C = [input() for i in range(N)]

C.sort()

i=0

while i < N:
    print(C[i] , end ="")
    i += 1

### FIXED CODE ###

N, L = map(int, input().split())
 
C = [input() for i in range(N)]
 
C.sort()
 
i=0
 
while i < N:
    print(C[i] , end ="")
    i += 1
N = input()
pi = 3.141592653589

S = round(N**2*pi, 6)
R = round(2*pi*N, 6)

print(S, R)

### FIXED CODE ###

import math

r = float(input())

s = r*r*math.pi
v = 2*math.pi*r

S = round(s, 6)
V = round(v, 6)

print(S, V)
n,k=map(int,input().split())
a=list(map(int,input().split()))
town=[1]
cnt=0
loop=0
index=0
while(len(town) <= k):
    town.append(a[town[-1]-1])
    cnt+=1
    index=town.index(town[-1])
    if cnt != index:
        loop = cnt - index
        town.pop(-1)
        break

if k<index:
    print(town[k])
else:
    for i in range(0,index):
        town.pop(0)
    print(town[(k-index)%loop])

### FIXED CODE ###

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

s=[]
ordn=[]
for i in range(n+1):
    ordn.append(-1)

v=1
while(ordn[v] == -1):
    ordn[v]=len(s)
    s.append(v)
    v=a[v-1]

c=len(s)-ordn[v]
l=ordn[v]

if k<l:
    print(s[k])
else:
    k -= l
    k%=c
    print(s[l+k])
n,m=(int(i) for i  in input().split())
#print(n,m)
mtrx=[[int(i)-1 for i in input().split()] for j in range(m)]
#print(mtrx)
adjacent=[[i] for i in range(n)]
#print(adjacent)
for i in range(n):
    adjacent[mtrx[i][0]]+=[mtrx[i][1]]
    adjacent[mtrx[i][1]]+=[mtrx[i][0]]
#print(adjacent)

cnt=[]
def dfs(goal,path):
    p=path[-1]
    if p==goal:
        cnt.append(len(set(path)))
        return
    else:
        for x in adjacent[p]:
            if x in path:
                continue
            else:
                path.append(x)
                dfs(goal,path)
                path.pop()

for i in range(1,n):
    dfs(i,[0])                
if m==0:
  print(0)
else:
  print(cnt.count(n))

### FIXED CODE ###

n,m=(int(i) for i in input().split())
mtrx=[[int(i) for i in input().split()] for j in range(m)]
#print(mtrx)
mtrx+=[[mtrx[i][1],mtrx[i][0]] for i in range(m)]
#print(mtrx)
mylist=[10*mtrx[i][0]+mtrx[i][1] for i in range(len(mtrx))]
#print(mylist)
# 順列を格納するリスト
perm = []
cnt=[]
# 順列の生成
def make_perm(n, m = 0):
    if n == m and perm[0]==1:
        flag=1
        for i in range(len(perm)-1):
            myval=10*perm[i]+perm[i+1]
            myval1=mylist.count(myval)
            flag=flag*myval1
        cnt.append(flag)
        
    else:
        for x in range(1, n + 1):
            if x in perm: continue
            perm.append(x)
            make_perm(n, m + 1)
            perm.pop()
            
make_perm(n)
print(sum(cnt))
n=input()
if [i for i in [int(input()) for _ in range(n)] if i % 2]:
  print('first')
 else:
  print('second')

### FIXED CODE ###

n=int(input())
if [i for i in [int(input()) for _ in range(n)] if i % 2]:
    print('first')
else:
    print('second')
X=int(input())
print(X//500*1000+X%500//5*5)

### FIXED CODE ###

s=input()
if s[2]==s[3] and s[4]==s[5]:
  ans="Yes"
else:
  ans="No"
print(ans)
A=int(input())
B=int(input())
if (A+B)>=(A-B) and (A+B)>=(A*B):
  print(A+B)
elif (A-B)>=(A+B) and (A-B)>=(A*B):
  print(A-B)
else (A*B)>=(A+B) and (A*B)>=(A-B):
  print(A*B)

### FIXED CODE ###

A,B=map(int,input().split())
print(max(A+B,A-B,A*B))
import sys
from functools import reduce
X, Y = map(int, input().split())
mod = 10**9 + 7

if (X+Y)%3 != 0:
    print(0)
    sys.exit()

if 2 * min(X, Y) < max(X, Y):
    print(0)
    sys.exit()

def f(n, A):
    bunsi = reduce(lambda x, y: x*y%mod, range(n, n-A, -1))
    bunbo = reduce(lambda x, y: x*y%mod, range(1, A+1))
    return bunsi * pow(bunbo, mod-2, mod) % mod

ans = 0
r, d = 0, 0
if X == Y:
    r, d = X//3, Y//3
    ans = f(r+d, d)%mod
else:
    r = abs(X-Y) + ((X+Y) - 3*abs(X-Y))//6
    d = ((X+Y) - 3*abs(X-Y))//6
    ans = f(r+d, d)%mod

print(ans)

### FIXED CODE ###

import sys
from functools import reduce
X, Y = map(int, input().split())
mod = 10**9 + 7

if (X+Y)%3 != 0:
    print(0)
    sys.exit()

if 2 * min(X, Y) < max(X, Y):
    print(0)
    sys.exit()

def f(n, A):
    bunsi = reduce(lambda x, y: x*y%mod, range(n, n-A, -1))
    bunbo = reduce(lambda x, y: x*y%mod, range(1, A+1))
    return bunsi * pow(bunbo, mod-2, mod) % mod

ans = 0
r, d = 0, 0
if X == Y:
    r, d = X//3, Y//3
    ans = f(r+d, d)%mod
else:
    r = abs(X-Y) + ((X+Y) - 3*abs(X-Y))//6
    d = ((X+Y) - 3*abs(X-Y))//6
    if d == 0:
        print(1)
        sys.exit()
    ans = f(r+d, d)%mod

print(ans)
a,b,c,x = map(int,input().strip())


count=0

for a_num in range(a+1):
  for b_num in range(b+1):
    for c_num in range(c+1):
      if a*500+b*100+c*50==x:
        count+=1

print(str(count))


### FIXED CODE ###

print((int(input())-int(input()))%int(input()))
from fractions import gcd
def lcm(a, b):
    return a*b//gcd(a, b)
n = input()
arr = input().split(' ')
arr = [int(a) for a in arr]
tmp = arr[0]
for i in range(len(arr)-1):
    tmp = lcm(tmp,arr[i+1])
ans = sum([tmp/a for a in arr])
ans = int(ans % (1e+9+7))
print(ans)


### FIXED CODE ###

import sys
from fractions import gcd
input = sys.stdin.readline

n = input()
arr = list(map(int, input().split()))
tmp = arr[0]
for i in arr:
    tmp = tmp*i//gcd(tmp,i)
print(sum(tmp//a for a in arr) % (10**9+7))
import math
dishes = [int(input()) for _ in range(5)]
lead_times = [int(math.ceil(t/10))*10 - t in dishes]
max_idx = lead_times.index(max(lead_times))
result = 0
for i in range(5):
  result += dishes[i]
  if i != max_idx:
    result += lead_times[i]
print(result)

### FIXED CODE ###

import math
dishes = [int(input()) for _ in range(5)]
lead_times = [int(math.ceil(t/10))*10 - t for t in dishes]
max_idx = lead_times.index(max(lead_times))
result = 0
for i in range(5):
  result += dishes[i]
  if i != max_idx:
    result += lead_times[i]
print(result)
a,b,c=map(int,input(),split())
if a+b+c>=22:
    print("bust")
else:
    print("win")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a+b+c>=22:
    print("bust")
else:
    print("win")
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
    e += c[i]
    if e <= b:
        d += 1
print(d)
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
    e += c[i]
    if e <= b:
        d += 1
    else:
        break
print(d)


### FIXED CODE ###

a, b = map(int, input().split())
d = 0
e = 1
for i in list(map(int, input().split())):
    d += i
    if d > b:
        break
    e += 1
print(e)
s=list(map(str,input().split()))
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    b = 0
    if S[0] == S[-1]:
        if S[-2] == S[0] or S[1] == S[0]:
            b = 0
        else:
            b = 1

    print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    A = set(list(S))
    if len(S) == 1:
        print(K // 2)
        return

    elif len(A) == 1:
        if len(S) % 2 == 1:
            a = K % 2
            print(len(S) * (K // 2) + (len(S) // 2) * a)
        else:
            a = K % 2
            print(len(S) * (K // 2) + (len(S) // 2) * a)
    else:
        for s in S:
            if s == last:
                a += 1
                last = ""
            else:
                last = s
        if S[0] != S[-1]:
            print(a * K)
        elif len(S) == 2:
            print(a * K)
        else:
            x = 0
            y = 0
            for i in range(len(S) // 2):
                if S[i] == S[0]:
                    x += 1
            for j in range(len(S) // 2):
                if S[len(S) - j - 1] == S[-1]:
                    y += 1

            if x % 2 == 1 and y % 2 == 1:
                b = 1
            else:
                b = 0

            print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()
# 27
n,x = list(map(int, input().split()))
aa = list(map(int, input().split()))
aa.sort()
ans = 0
for a in aa:
    if x<a:
        break
    ans+=1
    x-=ai
else:
    if x>0:
        ans-=1
print(num)

### FIXED CODE ###

# 27
n,x = map(int, input().split())
aa = list(map(int, input().split()))
aa.sort()
ans = 0
for a in aa:
    if x<a:
        break
    ans+=1
    x-=a
else:    #for else文 - breakすると入らないことを利用=ループ完遂した場合の終端処理
    if x>0:
        ans-=1
print(ans)
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    if n == 2:
        print(1)
        sys.exit()
    r = 0
    x = 2
    while x != 1:
        r += 1
        x = a.index(x) + 1
        if x == 2:
            r = -1
            break
    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

n = int(input())
a = [0]
tmp = [int(input()) for _ in range(n)]
a = a + tmp

r = -1
cnt = 1
next = a[1]
while cnt < n:
  if next == 2:
    r = cnt
    break
  else:
    next = a[next]
    cnt += 1
print(r)
n=int(input())
d=sorted(list(map(int, input().split())))
num=[]

for i in range(max(d)+1):
    count=d.count(i)
    num.append(count)
ans=1
if d[0]!=0:
    print(0)
else:
    for i in range(1, max(d)+1):
        ans*=num[i-1]**num[i]
    print(ans)


### FIXED CODE ###

n=int(input())
if n%2 == 0:
    print((n>>1)-1)
else:
    print(n>>1)
S = input()
alp = "abcdefghijklmnopqrstuvwxyzC"
ans = "AC"
if S[0] != "A":
    ans = "WA"
flag = 0
for C in S[2:-1]:
    if C == "C":
        flag+=1
    if not c in alp:
        ans = "WA"
if flag != 1:
    ans = "WA"
if not S[1] in alp[:-1]:
    ans = "WA"
if not S[-1] in alp[:-1]:
    ans = "WA"

print(ans)


### FIXED CODE ###

S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpC = "abcdefghijklmnopqrstuvwxyzC"

ans = "AC"
if S[0] != "A":
    ans = "WA"
countC = 0
for i in S[2:-1]:
    if i == "C":
        countC += 1
    if not i in alpC:
        ans = "WA"
if countC != 1:
    ans = "WA"
if not S[1] in alp:
    ans = "WA"
if not S[-1] in alp:
    ans = "WA"
print(ans)
s = input()
if s == 'AAA' and S == 'BBB':
    print('No')
else:
    print('Yes')

### FIXED CODE ###

s = input()
if s == 'AAA'or s == 'BBB':
    print('No')
else:
    print('Yes')
def rightMinNumber(L):
    min = L[len(L)-1]
    min_index = len(L) - 1
    for i in range(len(L)-2,-1,-1):
        if L[i] < min:
            min = L[i]
            min_index = i
    lL = L[:min_index]
    rL = L[min_index+1:]
    a.append(min)
    rightMinNumber(rL)
    rightMinNumber(lL)


N = int(input())
B = (int(i) for i in input().split())
#出力
a = []
#Bのエンコーダを作る

#Bの正当性を調べる。
for i in range(N):
    if B[i] > i:
        x = -1
        break
if x == -1:
    print(x)
else :
    rightMinNumber(B)
    for i in range(N):
        print(a[i])


### FIXED CODE ###

def main():
    N = int(input())
    B = [int(_) for _ in input().split()]

    #出力用
    outs = []

    for i in range(N):
        for k in range(N-1-i,-1,-1):
            if B[k] == k+1:
                del B[k]
                outs.insert(0,k+1)
                break
        else:
            print(-1)
            return

    for out in outs:
        print(out)

if __name__ == '__main__':
    main()
n,k = map(int,input().split())
list=[]
for i in range(k):
    d = int(input())
    sunuke = map(int,input().split())
    for j in sunuke:
        if j not in list:
            list.append(j)
print(str(n - len(list)))

### FIXED CODE ###

s = input()

if s == 'ABC':
    print('ARC')
if s == 'ARC':
    print('ABC')