Harryxun/stf_run huggingface dataset:
#abc 042 c
def dfs(i,s):
    if i==n_keta:
        if s>=n:
            kouho.append(s)
        return 0
    for j in range(len(like)):
        dfs(i+1,s+like[j])
    return 0

n,k=input().split()
d=list(map(int,input().split()))
like=[]
for i in range(10):
    if i not in d:
        like.append(str(i))
kouho=[]
n_keta=len(n)
dfs(0,"")
if not kouho:
    n_keta+=1
    dfs(0,"")
print(min(kouho))


### FIXED CODE ###

#abc 042 c
def dfs(i,s):
    if i==n_keta:
        if s>=n:
            kouho.append(s)
        return 0
    for j in range(len(like)):
        dfs(i+1,s+like[j])
    return 0

n,k=input().split()
d=list(map(int,input().split()))
like=[]
for i in range(10):
    if i not in d:
        like.append(str(i))
kouho=[]
n_keta=len(n)
dfs(0,"")
ans=""
if kouho==[]:
    if like[0]=="0":
        ans+=like[1]
    else:
        ans+=like[0]
    for i in range(n_keta):
        ans+=like[0]
else:
    ans=min(kouho)
print(ans)
m = map(int,raw_input().split())
i = m[0]
count = 0
for i in xrange(m[1]):
 if m[2] % i == 0:
  count = count + 1

### FIXED CODE ###

m = map(int, raw_input().split())
c = 0


for i in xrange(m[0],m[1]+1):
  if m[2] % i == 0:
   c = c + 1
print c
n,s=open(0)
a=0
for i in range(int(n)):
 if N-i<a:break
 a+=s[i+1:].find(s[i-a:i+1])>=0
print(a)

### FIXED CODE ###

def Z(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = c = 0
    # c : 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

a = 0
n, s = open(0)
for i in range(int(n)):
    for j, l in enumerate(Z(s[i:])):
        a = max(a, min(l, j))
print(a)
a = int(input())
s = input()

if a >= 3200:
    print(s)
else:
    print(red)


### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
    print(s)
else:
    print("red")
INPUT = list(map(int, input().split))
A = INPUT[0]
B = INPUT[1]
C = INPUT[2]

if (B//A) > C:
    ANS = C
else:
    ANS = B//A

print(ANS)

### FIXED CODE ###

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

if (B//A) > C:
    ANS = C
else:
    ANS = B//A

print(ANS)
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N,M,K = map(int,input().split())
# lisA = list(map(int,input().split()))
arrA = np.array([0] + list(map(int,input().split())))
arrB = np.array([0] + list(map(int,input().split())))

arrA = np.cumsum(arrA,dtype="int64")
arrB = np.cumsum(arrB,dtype="int64")
print(arrA)
print(arrB)

memo = np.add.outer(arrA,arrB) <= K
print(memo)
j = M
ans = 0
for i in range(N+1):
    while j >= 0:
        if memo[i][j]:
            ans = max(i+j,ans)
            break
        j -= 1

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


### FIXED CODE ###

# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N,M,K = map(int,input().split())
# lisA = list(map(int,input().split()))
arrA = np.array([0] + list(map(int,input().split())))
arrB = np.array([0] + list(map(int,input().split())))

arrA = np.cumsum(arrA,dtype="int64")
arrB = np.cumsum(arrB,dtype="int64")

# memo = np.add.outer(arrA,arrB) <= K
j = M
ans = 0
for i in range(N+1):
    while j >= 0:
        if arrA[i]+arrB[j] <= K:
            ans = max(i+j,ans)
            break
        j -= 1

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
N=int(input())
if N%2=1:
  a=N+1/2
  print(a)
else:
  b=N/2
  print(N)

### FIXED CODE ###

N=int(input())
if N%2==0:
  a=N/2
  b=a/N
  print(b)
else:
  t=N+1
  c=t/2
  d=c/N
  print(d)
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = list(range(1, 100))
ll = []
if n ==0:
    print(x)
else:
    for i in p:
        l.remove(i)
    for j in range(100):
        if x-j in l:
            ll.append(x-j)
        if x+j in l:
            ll.append(x+j)
        if len(ll) != 0:
            print(min(ll))
            break

### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))
l = list(range(1, 100))

if n ==0:
    print(x)
else:
    for j in range(51):
        ll = []
        if not x-j in p:
            ll.append(x-j)
        if len(ll) != 0:
            print(min(ll))
            break
        if not x+j in p:
            ll.append(x+j)
        if len(ll) != 0:
            print(min(ll))
            break
a, b = map(int, input().split())

mean = (a + b) / 2

if mean % 1 == 0:
  print((mean)
else:
  print((a + b) // 2 + 1)

### FIXED CODE ###

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

if (a + b) % 2 == 0:
  print(int((a + b) / 2))
else:
  print(int((a + b + 1) / 2))
N,X,T = input(int()).split()

A = ((N // X) + 1 ) * T
print(A)

### FIXED CODE ###

N,X,T = input().split()

N = int(N)
X = int(X)
T = int(T)

if N % X != 0:
  A = ((N // X) + 1 ) * T
else:
  A = (N/X) * T
print(int(A))
n=int(input())
end=n**(1/2)
for i in range(end,1,-1):
  if n%i==0:
    j=n//i
    print(i*j-2)
    break

### FIXED CODE ###

n=int(input())
end=int(n**(1/2))
for i in range(end,0,-1):
  if n%i==0:
    j=n//i
    print(i+j-2)
    break
a=input()
if a='Sunny'
	print('Cloudy')
elif a='Cloudy'
	print('Rainy')
else a='Rainy'
	print('Sunny')


### FIXED CODE ###

a = input()
b = 'Sunny'
c = 'Cloudy'
d = 'Rainy'
if a == b:
 print(c)
if a == c:
 print(d)
if a == d:
 print(b)
h, w = map(int,input().split())

if h%3 ==0 or w % 3 == 0:
	print(0)
	exit()

x = w//4
Sb =max(x*h,h//2*(w-x),(h-h//2)*(w-x))
Ss =min(x*h,h//2*(w-x),(h-h//2)*(w-x))
ans1 =Sb-ss
x += 1
Sb =max(x*h,h//2*(w-x),(h-h//2)*(w-x))
Ss =min(x*h,h//2*(w-x),(h-h//2)*(w-x))
ans2 =Sb-ss
y = h//4
Sb =max(y*w,w//2*(h-y),(w-w//2)*(h-y))
Ss =min(y*w,w//2*(h-y),(w-w//2)*(h-y))
ans3 =Sb-ss
y += 1
Sb =max(y*w,w//2*(h-y),(w-w//2)*(h-y))
Ss =min(y*w,w//2*(h-y),(w-w//2)*(h-y))
ans4 =Sb-ss

print(min(ans1,ans2,ans3,ans4))

### FIXED CODE ###

H,W = map(int,input().split())

ans = min(H,W)
for h in range(H//3,H//3+3):
    w = W//2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))


for w in range(W//3,W//3+3):
    h = H//2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

if H%3 == 0 or W%3 == 0:
    ans = 0
print(ans)
import stdin from sys
x = []
for line in sys.stdin:
    h,w = line.split()
    h,w = int(h), int(w)
    if h == 0 and w== 0: break
    x.append([h,w])

for i in range(len(x)):
    h, w = x[i]
    s1 = '.#' * ((w+1)/2)
    s2 = '#.' * ((w+1)/2)
    for j in range(h):
        if (j & 1)==0: print s2[:w]
        else: print s1[:w]
    print

### FIXED CODE ###

x = []
s = ['','']
while True:
    h, w = map(int, raw_input().split())
    if h == 0 and w== 0: break
    tmp = (w+1)/2
    s[0] = ('#.' * tmp)[:w]
    s[1] = ('.#' * tmp)[:w]
    for j in range(h):
        print s[j % 2]
    print
n,m=map(int,input().split())
wa,ac=0,0
ac_number,last_wa=0,0
for i in range(m):
    p,s=input().split()
    if s=="WA":
        wa+=1
        wa_number=int(p)
    elif s=="AC" and ac_number!=int(p): #ac_numberは最後にacした問題の番号
        ac+=1
        ac_number=int(p)
    if wa_number==ac_number:
        last_wa+=wa
print(ac,last_wa)

### FIXED CODE ###

n,m=map(int,input().split())
acs=[0]*n
was=[0]*n
WA=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if acs[p-1]==0:
        if s=="AC":
            acs[p-1]=1
            WA+=was[p-1]
        else:
            was[p-1]+=1
print(sum(acs),WA)
a,b = map(int,input().spolit())
print(int(a*b))

### FIXED CODE ###

from decimal import Decimal
a,b = map(Decimal,input().split())

print(int(a*b))
s = input()
l = [chr(ord(a)+i) for i in range(5)]
print("vowel" if s in l else "consonant")

### FIXED CODE ###

s = input()
l = ["a", "i", "u", "e", "o"]
print("vowel" if s in l else "consonant")
import math

n = int(input())
ans = 0
m = math.floor(math.log(n,5))

if n%2 == 1:
  print(0)
else:
  for j in range(1,m+1):
    ans += n//((5**j)*2)
    
    
  print(ans)

### FIXED CODE ###

import math

n = int(input())
ans = 0
if n== 0:
  print(0)
  exit()
m = math.floor(math.log(n,5))

if n%2 == 1:
  print(0)
else:
  for j in range(1,m+1):
    ans += n//((5**j)*2)
    
    
  print(ans)
#C
# 7,77,777･･･=7*(1,11,111･･･)
# 7*(10^i)=7*(10^i-1)/10-1 = 7*(10^i-1)/9 がkで割れる
# 10^iを(9k,7の倍数だったら9k/7)で割ってあまりが１だったら良い
import sys
k=int(input())
if k%7==0:
    k/=7
k*=9
a=10%k
for i in range(k):
    a=a%k
    if a==1:
        print(i+1)
        sys.exit()
    a*=10
print(-1)


### FIXED CODE ###

#C
import sys
k=int(input())
s=0

for i in range(k):
    s=s*10+7
    if s%k!=0:
        s=s%k
    else:
        print(i+1)
        sys.exit()
print(-1)
sitaH = (H*60+M) / 720 * 2 * math.pi
sitaM =  M/60 * 2 * math.pi

posXH = A * math.cos(sitaH)
posYH = A * math.sin(sitaH)
posXM = B * math.cos(sitaM)
posYM = B * math.sin(sitaM)

delX = posXH - posXM
delY = posYH - posYM

d = (delX*delX + delY*delY)**(1/2)
print(d)

### FIXED CODE ###

import math
A, B, H, M = map(int, input().split())
sitaH = (H*60+M) / 720 * 2 * math.pi
sitaM =  M/60 * 2 * math.pi

posXH = A * math.cos(sitaH)
posYH = A * math.sin(sitaH)
posXM = B * math.cos(sitaM)
posYM = B * math.sin(sitaM)

delX = posXH - posXM
delY = posYH - posYM

d = (delX*delX + delY*delY)**(1/2)
print(d)
N = int(input())
a = input().split()
a_n = [int(s) for s in a]

max = max(a_n)
a_n_num = [0]*(max+1)
for i in range(len(a_n)):
    a_n_num[a_n[i]] += 1

counter = 0
for i in range(len(a_n_num)):
    if a_n_num[i] > i:
        counter += a_n_num[i] - i
    elif a_n_num[i] < i:
        counter += a_n_num[i]

print(counter)


### FIXED CODE ###

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

dict = {}
for i in range(N):
    if a_n[i] in dict:
        dict[a_n[i]] += 1
    else:
        dict[a_n[i]] = 1

cnt = 0
for i in dict:
    if dict[i] > i:
        cnt += dict[i] - i
    elif dict[i] < i:
        cnt += dict[i]
print(cnt)
N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
C = [int(i) for i in input().split()]
C.sort()

graph = [[] for _ in range(N)]
for u, v in Nodes:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

ret = [0] * N
def dfs(p, c):
    ret[c] = C.pop()
    for next_edge in graph[c]:
        if next_edge != p:
            dfs(c, next_edge)
dfs(p=-1, c=0)

print(str(sum(ret[1:])))
print(' '.join(map(str, ret)))


### FIXED CODE ###

def d_maximum_sum_of_minimum(N, Nodes, C):
    # 根から始め、巡回した葉にCの大きなものから順に書き込んで行く。
    import sys
    sys.setrecursionlimit(10**6)

    int_list = list(sorted(C))
    graph = [[] for _ in range(N)]
    for u, v in Nodes:  # 0-basedとする
        graph[u - 1].append(v - 1)
        graph[v - 1].append(u - 1)

    def traverse_tree(parent, current, ret=[0] * N):
        """各頂点にCの値が大きなもの順に書き込んでいく"""
        def dfs(p, c):
            ret[c] = int_list.pop()
            for next_edge in graph[c]:
                if next_edge != p:  # 木を「逆戻り」しない頂点だけ調べる
                    dfs(c, next_edge)
        dfs(parent, current)
        return ret
    tmp = traverse_tree(-1, 0)
    return str(sum(tmp[1:])) + '\n' + ' '.join(map(str, tmp))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
C = [int(i) for i in input().split()]
print(d_maximum_sum_of_minimum(N, Nodes, C))
N=int(input())
X=input()
X10=int(X,2)
one=X.count('1')
a=X10%(one-1)
b=X10%(one+1)
c=one-1
d=one+1
def popcount(n):
  c=format(n,'b').count('1')
  if c==0:
    print(n)
  return n%c
def f(n):
  count=0
  while n>0:
    n=popcount(n)
    count+=1
  return count

for i in range(N):
  if X[i]=='1':
    Y=(a-pow(2,N-i-1,c))%c
    print(f(Y)+1)
  if X[i]=='0':
    Y=(b+pow(2,N-i-1,d))%d
    print(f(Y)+1)
 

### FIXED CODE ###

N=int(input())
X=input()
X10=int(X,2)
one=X.count('1')
def popcount(n):
  c=format(n,'b').count('1')
  if c!=0:
    return n%c
  else:
    return 0
def f(n):
  count=0
  while n>0:
    n=popcount(n)
    count+=1
  return count
if one==1:
  e=X10%2
  for i in range(N):
    if X[i]=='0':
      Y=e+pow(2,N-i-1,2)
      print(f(Y)+1)
     
    elif X[i]=='1':
      print(0)
if one==0:
  for i in range(N):
    print(1)
if one>1:
  a=X10%(one-1)
  b=X10%(one+1)
  c=one-1
  d=one+1
  for i in range(N):
    if X[i]=='1':
      Y=(a-pow(2,N-i-1,c))%c
      print(f(Y)+1)
    if X[i]=='0':
      Y=(b+pow(2,N-i-1,d))%d
      print(f(Y)+1)
for i=1 in range(9):
    for j=1 in range(9):
        print(str(i) + 'x' + str(j) + '=' + str(i*j))

### FIXED CODE ###

for i in range(1, 10):
    for j in range(1,10):
        print(str(i) + 'x' + str(j) + '=' + str(i*j))
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
bit_num = len(bin(K))-2
arr = [[int(s) for s in format(val,'b').zfill(bit_num)] for val in As]
# ここか？
arr = [sum([arr[i][j] for i in range(len(arr))]) for j in range(len(arr[0]))]


### FIXED CODE ###

str_ = input().split()
x = int(str_[0])
t = int(str_[1])
print(x/t)
a = input()
b = input()
for i in range(0,3):
  if a[i] == 'S':
    a[i] = '1'
  elif a[i] == 'C':
    a[i] = '2'
  else:
    a[i] = '3'
for j in range(0,3):
  if b[j] == 'S':
    b[j] = '1'
  elif b[j] == 'C':
    b[j] = '2'
  else:
    b[j] = '3'
out = 0
for k in range(0,3):
  if int(a[k])-int(b[k]) == 0:
    out = out + 1
print(out)


### FIXED CODE ###

a = input()
b = input()
out=0
for i in range(0,3):
  if a[i] ==b[i]:
    out =out+1
print(out)
Taro = 0
Hanako = 0

n = int(input())

for i in range(n):
    T,H = map(str, input().split())
    if T > H:
        Taro += 3
    elif T = H:
        Taro += 1
        Hanako += 1
    else:
        Hanako += 3

print(Taro, Hanako)



### FIXED CODE ###


Taro = 0
Hanako = 0

n = int(input())

for i in range(n):
    T,H = map(str, input().split())
    if T > H:
        Taro += 3
    elif T == H:
        Taro += 1
        Hanako += 1
    else:
        Hanako += 3

print(Taro, Hanako)
import math

 

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

pair = {N:S,M:T}

def lcd(N,M):
    return int(M*N/math.gcd(N,M))
def prove(n,m):
    global pair
    mul = int(n/m)
    c = [pair[n][mul*(i-1)+1] for i in range(len(pair[m]))]
    if c== pair[m]:
        print (m)
    else:
        print (-1)
if max(N,M) % min(N,M) == 0:
    n = max(pair.keys())
    m = min(pair.keys())
    prove(n,m)
else:
    print(lcd(N,M))


### FIXED CODE ###

import math

 

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

pair = {N:S,M:T}


def lcd(n,m):
    return int(n * m / gcd(n,m))
def gcd(n,m):
    if n % m == 0:
        return m
    else:
        return gcd(m,n % m)
#    return int(m*n/math.gcd(n,m))
    
def prove(n,m):
    if gcd(n,m)==1:
        return lcd(n,m)
    global pair
    n_i = int(n/gcd(n,m))
    m_i = int(m/gcd(n,m))
    n_list = pair[n][::n_i]
    m_list = pair[m][::m_i]
#    print(c)
#    print(pair[m])
    if n_list[0:len(m_list)]==m_list:
        return lcd(n,m)
    else:
        return -1
n = max(pair.keys())
m = min(pair.keys())
if pair[N][0]!=pair[M][0]:
    print(-1)
elif N==M:
    if S==T:
        print(N)
    else:
        print(-1)
else:
    print(prove(n,m))
def main():
    n,x = map(int, input().split())
    l = list(map(int, input().split()))
    ans = 1
    
    while True:
        i = 0
        max += l[i]
        if max < x:
            ans += 1
            
        i += 1
        
    print(ans)

main()

### FIXED CODE ###

def main():
    n,x = map(int, input().split())
    l = list(map(int, input().split()))
    ans = 1
    max = 0

    #while True:
        #i = 0
        #max += l[i]
        #if max < x:
            #ans += 1
        #i += 1

    for i in range(len(l)):
        max += l[i]
        if max <= x:
            ans += 1
    print(ans)

main()
def countStep(n):
    global S, b
    if n==-1:
        return 0
    elif n==0:
        return 1
    elif str(n) in b:
        count = S[n]
        return count
    else:
        count1 = countStep(n-1)
        count2 = countStep(n-2)
        count = count1 + count2
        b.append(str(n))
        S[n] = count
        return count

N,M = map(int,input().split())
b = []
for _ in range(M):
  b.append(input())
S = [0] * (N+1)

print(countStep(N) % 1000000007)



### FIXED CODE ###

N,M = map(int,input().split())
a = [True] * (N+1)

for _ in range(M):
  a[int(input())] = False

S = [0] * (N+1)
S[0] = 1
for n in range(1, N+1):
    if a[n]==False:
        S[n] = 0
    elif n==1:
        S[n] = 1
    else:
        S[n] = (S[n-1] + S[n-2])%1000000007

print(S[n])
#for i in range(1,10000):
i = 1

while True:
    x = int(input())
    if x == 0:
        break:
    else:
        print("Case %d: %d" % (i, x))
        i++


### FIXED CODE ###

#
# 3b
#

def main():
    i = 1
    while True:
        x = int(input())
        if x == 0:
            break
        print(f"Case {i}: {x}")
        i += 1


if __name__ == '__main__':
    main()
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans
 
n = int(raw_input())
a = map(int, raw_input().split())
ans = min(map(how_many_times_divisible, a))
 
print(ans)

### FIXED CODE ###

def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans
 
n = int(input())
a = map(int, input().split())
ans = min(map(how_many_times_divisible, a))
 
print(ans)
from copy import deepcopy as dc
#n,x=map(int,input().split())
x=int(input()) #
a=list(map(int,input().split()))
n=len(a) #
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>=a[j][1]+x or (a[i][0]>=a[j][1] and a[j][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

### FIXED CODE ###

n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[[None for _ in [0]*n] for _ in [0]*n]

for i in range(n):
	m=a[i]
	for j in range(n):
		k=i-j
		if k<0:
			k+=n
		m=min(m,a[k])
		b[j][i]=m

m=10**15
for i,j in enumerate(b):
	m=min(m,sum(j)+x*i)
print(m)
import bisect
N=input()
S=list(input())
alphabet=[[] for _ in range(26)]
for i,s in enumerate(S):
    alphabet[ord(s)-ord('a')].append(i)
Q=int(input())
for _ in range(Q):
    Type,A,B=input().split()
    if Type=="1":
        A=int(A)
        s=S[A-1]
        o=ord(s)-ord("a")
        alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))
        index=bisect.bisect(alphabet[o],A-1)
        #alphabet[o]=alphabet[o][:index]+[A-1]+alphabet[o][index:]
        #bisect.insort(alphabet[o],A-1)
        alphabet[ord(B)-ord("a")].insert(index,A-1)
        S[A-1]=B
    else:
        A=int(A)
        B=int(B)
        ans=0
        for i in range(26):
            indexL=bisect.bisect_left(alphabet[i],A-1)
            #indexR=bisect.bisect_right(alphabet[i],B-1)
            #ans+=(indexL!=indexR)
            if indexL==len(alphabet[i]):
                continue
            ans+=(alphabet[i][indexL]<=B-1)
        print(ans)


### FIXED CODE ###

from bisect import bisect_left

n = int(input())
s = list(input())
q = int(input())
query = [input() for _ in range(q)]

p = [[] for _ in range(26)]

for i, x in enumerate(s):
    p[ord(x) - ord('a')].append(i)

for x in query:
    a, b, c = x.split()
    #print(c)
    if a == '1':
        b = int(b) - 1
        if s[b] == c:
            continue
        d = ord(s[b]) - ord('a')
        e = ord(c) - ord('a')
        temp = bisect_left(p[d], b)
        p[d].pop(temp)
        temp = bisect_left(p[e], b)
        p[e].insert(temp, b)
        s[b] = c
    else:
        b = int(b) - 1
        c = int(c) - 1
        #print(b, c)
        ans = 0
        for i in range(26):
            L = bisect_left(p[i], b)
            if L >= len(p[i]):
                continue
            if p[i][L] <= c:
                ans += 1
        print(ans)
import math
from functools import reduce

def gcd(*numbers):
   return reduce(math.gcd, numbers)

n=int(input())
al=input().split()
al_i = [int(s) for s in al]
m = max(al_i)
gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = gcd(*al_i)
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)

### FIXED CODE ###

import sys

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

if (n == 2):
   print(max(al_i[0],al_i[1]))
   sys.exit()

fg = [0] * n
bg = [0] * n

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1

for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n-1):
      g = fg[n-2]
   else:
      g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)
n, m = map(int, input().split())
vote = list(map(int, input().split()))

vote.sort(reverse=True)
popular = vote[0:m-1]
sum = sum(vote)

yes = True

for win in popular:
    if win < sum / (4*m):
        print('No')
        yes = False
        stop

if yes:
    print('Yes')

### FIXED CODE ###

n, m = map(int, input().split())
vote = list(map(int, input().split()))

vote.sort(reverse=True)
popular = vote[0:m]
sum = sum(vote)

yes = True

for win in popular:
    if win < sum / (4*m):
        print('No')
        yes = False
        break


if yes:
    print('Yes')
import math
import sys

sys.setrecursionlimit(10000)

n, q = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n - 1)]
pxL = [list(map(int, input().split(" "))) for _ in range(q)]

to = [[] for _ in range(200005)]
ans = [0 for _ in range(n + 1)]


def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)


for a, b in abL:
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for p, x in pxL:
    p -= 1
    ans[p] += x

dfs(0)

for a in ans[:n]:
    print(a)

### FIXED CODE ###

import math
import sys

sys.setrecursionlimit(200005)

n, q = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n - 1)]
pxL = [list(map(int, input().split(" "))) for _ in range(q)]

to = [[] for _ in range(200005)]
ans = [0 for _ in range(n + 1)]


def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)


for a, b in abL:
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for p, x in pxL:
    p -= 1
    ans[p] += x

dfs(0)

for a in ans[:n]:
    print(a)