Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import heapq as h
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = [(-b[i],i) for i in range(n)]
q.sort()
cnt = 0
while q:
  v,i = h.heappop(q)
  v *= -1
  u = b[(i-1)%n] + b[(i+1)%n]
  if v < u or a[i] >= v: continue
  t = (v-a[i])//u
  cnt += t
  b[i] -= t*u
  if b[i] > a[i]:
    h.heappush(q,(-b[i],i))
print(cnt if a==b else -1)

### FIXED CODE ###

import heapq as h
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
e6 = 10**6
q = [-b[i]*e6-i for i in range(n)]
h.heapify(q)
cnt = 0
while q:
  w = -h.heappop(q)
  v,i = w//e6, w%e6
  u = b[(i-1)%n] + b[(i+1)%n]
  if v < u or a[i] == v: continue
  elif a[i] > v: print(-1); exit(0)
  t = (v-a[i])//u
  if not t: print(-1); exit(0)
  cnt += t
  b[i] -= t*u
  if b[i] > a[i]:
    h.heappush(q,-b[i]*e6-i)
print(cnt if a==b else -1)
### BUGGY CODE ###

L, R = map(int, input().split())
ans = 2019
for i in range(L, R+1):
  for j in range(i+1, R+1):
    ans = min(ans, i * j % 2019)
    if i * j % 2019 == 0:
      break
print(ans)

### FIXED CODE ###

L, R = map(int, input().split())
ans = 2019
for i in range(L, R+1):
  for j in range(i+1, R+1):
    ans = min(ans, i * j % 2019)
    if i * j % 2019 == 0:
      break
  else:
    continue
  break
print(ans)
### BUGGY CODE ###

def BFS(y,x):
    z= [[False for _ in range(W)] for _ in range(H)]
    v=deque( [[y,x]] )
    d[y][x]=0
    z[y][x]=True
    
    while v:
        a=v.popleft()
        for mv in move:
            s=a[0]+mv[0]
            t=a[1]+mv[1]
            if 0<=s<H and 0<=t<W:
                if z[s][t]==False:
                    z[s][t]=True
                    d[s][t]=min(d[s][t], d[a[0]][a[1]]+1)
                    v.append([s,t])
                    
    
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]


for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
                BFS(i,j)
                
#print(d)
maxi=0
for i in d:
    for j in i:
        maxi=max(maxi,j)
print(maxi)

### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]
z= [[False for _ in range(W)] for _ in range(H)]
ans=0

v=deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            v.append( [i,j] )
            z[i][j]=True
            d[i][j]=0
while v:
    a=v.popleft()
    #print(a,v)
    for mv in move:
        s=a[0]+mv[0]
        t=a[1]+mv[1]
        if 0<=s<H and 0<=t<W:
            if z[s][t]==False:
                z[s][t]=True
                d[s][t]=d[a[0]][a[1]]+1
                v.append([s,t])
                ans=max(ans,d[s][t])
#print(d)
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
hs = sorted([int(input()) for _ in range(N)])

min_diff = 10 ** 10
for i in range(N-K+1):
    tmp = hs[i:i+K]
    min_diff = min(min_diff, tmp[-1] - tmp[0])

print(min_diff)


### FIXED CODE ###

N, K = map(int, input().split())
hs = sorted([int(input()) for _ in range(N)])

min_diff = 10 ** 10
for i in range(N-K+1):
    min_diff = min(min_diff, hs[i+K-1] - hs[i])

print(min_diff)
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = Counter((list(map(int, input().split(' ')))))
ans = 0
for i in A:
    flg = True
    if A[i] > 1:
        continue
    for j in range(1,int(pow(i,0.5))+2):
        if not i%j:
            if A[j] and i != j:
                flg = False
                break
            if j != i//j and A[i//j] and i//j != i:
                    flg = False
                    break
    if flg:
        ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split(' '))))
ans = 0
m = max(A.keys())
L = [1]*(10**6+1)
for i in sorted(A.keys()):
    if not L[i]:
        continue
    if A[i] == 1:
        ans += 1
    for j in range(i,m+1,i):
        L[j] = 0
print(ans)
### BUGGY CODE ###

h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w
d=[I]*I
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if~d[t]-I:q+=t,
   d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)

### FIXED CODE ###

import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
dp[x1-1][y1-1]=0
#kの更新が遅い
def bfs(d):
    global h,w,k,dp,now,x2,y2
    l=len(now)
    if l==0:
        return
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub.append([x,y+j,d])
                #dp[x][y+j]=d
                cand.add((x,y+j))
                #now.append([x,y+j])
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub.append([x,y-j,d])
                #dp[x][y-j]=d
                cand.add((x,y-j))
                #now.append([x,y-j])
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub.append([x+j,y,d])
                #dp[x+j][y]=d
                cand.add((x+j,y))
                #now.append([x+j,y])
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub.append([x-j,y,d])
                #dp[x-j][y]=d
                cand.add((x-j,y))
                #now.append([x-j,y])
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now.append(i)
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)
### BUGGY CODE ###

s = raw_input()
while 1:
    result = s.replace("ST", "")
    if result == s:
        s = result
        break
    else: s = result
print len(s)


### FIXED CODE ###

s = raw_input()
T = S = 0
for i in s:
    if i == "T":
        if S: S -= 1
        else: T += 1
    elif i == "S":
        S += 1
print T + S
### BUGGY CODE ###

import sys
from itertools import permutations
N, C = map(int, sys.stdin.readline().rstrip().split())

d = []
for _ in range(C):
    d.append(tuple(map(int, sys.stdin.readline().rstrip().split())))

r_0 = []
r_1 = []
r_2 = []
for i in range(N):
    g = list(map(int, sys.stdin.readline().rstrip().split()))
    for j in range(N):
        if (i + j + 2) % 3 == 0:
            r_0.append(g[j])
        elif (i + j + 2) % 3 == 1:
            r_1.append(g[j])
        else:
            r_2.append(g[j])

ans = 10**18
for c_1, c_2, c_3 in permutations(range(1, C + 1), 3):
    total = 0
    for r in r_0:
        total += d[r - 1][c_1 - 1]
    for r in r_1:
        total += d[r - 1][c_2 - 1]
    for r in r_2:
        total += d[r - 1][c_3 - 1]
    ans = min(ans, total)
print(ans)

### FIXED CODE ###

import sys
from itertools import permutations
N, C = map(int, sys.stdin.readline().rstrip().split())

d = []
for _ in range(C):
    d.append(tuple(map(int, sys.stdin.readline().rstrip().split())))

r_0 = []
r_1 = []
r_2 = []
for i in range(N):
    g = list(map(int, sys.stdin.readline().rstrip().split()))
    for j in range(N):
        if (i + j) % 3 == 0:
            r_0.append(g[j])
        elif (i + j) % 3 == 1:
            r_1.append(g[j])
        else:
            r_2.append(g[j])

def get_cost(r):
    cost = [0] * (C + 1)
    for c in range(1, C + 1):
        for i in r:
            cost[c] += d[i - 1][c - 1]

    return cost

cost_0 = get_cost(r_0)
cost_1 = get_cost(r_1)
cost_2 = get_cost(r_2)

ans = 10**18
for c_0, c_1, c_2 in permutations(range(1, C + 1), 3):
    total = cost_0[c_0] + cost_1[c_1] + cost_2[c_2]
    ans = min(ans, total)
print(ans)
### BUGGY CODE ###

class Okojo:
    def __init__(self, line):
        self.line = line
        self.l = []
        self.r = []
        self.get_lr()

    def get_lr(self):
        for i in range(len(self.line)):
            if self.line[i] == 'L':
                self.l.append(i)
            else:
                self.r.append(i)

    def get_next(self, state):
        nex = [0] * len(self.line)
        for i in range(len(self.l)):
            nex[self.l[i] - 1] += state[self.l[i]]
        for i in range(len(self.r)):
            nex[self.r[i] + 1] += state[self.r[i]]
        return nex


def resolve():
    line = input()

    okojo = Okojo(line)

    now = [1] * len(line)
    before1 = now
    for i in range(10 ** 100):
        before2 = before1
        before1 = now
        now = okojo.get_next(before1)
        if before1 == now:
            break
        elif before2 == now:
            if i % 2 == 0:
                now = before1
            break

    print(*now)


resolve()


### FIXED CODE ###

def resolve():
    line = input()
    result = [0] * len(line)

    r_odd = 0
    r_even = 0
    for i in range(len(line)):
        if line[i] == 'L':
            if i % 2 == 0:
                result[i] += r_even
                result[i-1] += r_odd
            else:
                result[i] += r_odd
                result[i-1] += r_even
            r_odd = 0
            r_even = 0
        elif line[i] == 'R':
            if i % 2 == 0:
                r_even += 1
            else:
                r_odd += 1
    l_odd = 0
    l_even = 0
    for i in range(len(line)-1, -1, -1):
        if line[i] == 'R':
            if i % 2 == 0:
                result[i] += l_even
                result[i+1] += l_odd
            else:
                result[i] += l_odd
                result[i+1] += l_even
            l_odd = 0
            l_even = 0
        elif line[i] == 'L':
            if i % 2 == 0:
                l_even += 1
            else:
                l_odd += 1

    print(*result)
    
resolve()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_d
import sys
#import collections

n= int(input())

tmp = input().split()
s = list(map(lambda a: int(a), tmp))

total=0
a=[]
b=[]
c=[]
for i in range(0,60):
	a.append(0)

for i in range(0,n):
	tmp = s[i]
	for j in range(0,60):
		if(tmp==0):
			break
		if(tmp%2==1):
			a[j]+=1
		tmp=tmp//2

total=0
for j in range(60,0,-1):
	total*=2
	total=total+(a[j-1])*(n-a[j-1])
#	print(total)

total=total%1000000007

print(total)

### FIXED CODE ###

# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_d
import sys
#import collections

n= int(input())

tmp = input().split()
s = list(map(lambda a: int(a), tmp))

total=0
a=[]
for i in range(0,60):
	a.append(0)

for i in range(0,n):
	tmp = s[i]
	for j in range(0,60):
		if(tmp==0):
			break
		if(tmp%2==1):
			a[j]+=1
		tmp=tmp//2

total=0
for j in range(60,0,-1):
	total*=2
	if(a[j-1]>0):
		total=total+(a[j-1])*(n-a[j-1])
	if(total>1000000007):
		total=total%1000000007
total=total%1000000007

print(total)
### BUGGY CODE ###

# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_np =np.array(A,dtype=np.int64)
Q = int(input())
S =[0]*Q
for i in range(Q):
    b,c = (int(i) for i in input().split())
    A_np =np.where(A_np ==b,c,A_np)
    S[i] =np.sum(A_np)
    #print(A_np)


print(*S,sep='\n')

### FIXED CODE ###

# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_c =Counter(A)
Q = int(input())
S =[0]*Q
bc =[]
for i in range(Q):
    x,y = (int(i) for i in input().split())
    bc.append((x,y))
    #print(A_np)
sum_A =[0]*(Q+1)
sum_A[0] =sum(A)
ind =0
for k,v in bc:
    sum_A[ind+1] =sum_A[ind] -A_c[k] *k +A_c[k] *v
    A_c[v] +=A_c[k]
    A_c[k] =0
    #print(A_c)
    print(sum_A[ind +1])
    ind +=1
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from functools import lru_cache
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    S = [0] * (n + 1)
    for i in range(n):
        S[i + 1] = S[i] + A[i]

    @lru_cache(None)
    def dfs(l, r):
        # base case
        if r - l == 1:
            return 0
        # recursion
        return min(dfs(l, m) + dfs(m, r) + S[r] - S[l] for m in range(l + 1, r))

    print(dfs(0, n))
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n): S[i+1]=S[i]+A[i]
    dp=[[INF]*(n+1) for _ in range(n+1)]

    def dfs(L,R):
        if(R-L==1): return 0
        if(dp[L][R]!=INF): return dp[L][R]
        res=INF
        for h in range(L+1,R):
            res=min(res,dfs(L,h)+dfs(h,R)+S[R]-S[L])
        dp[L][R]=res
        return res

    print(dfs(0,n))
resolve()
### BUGGY CODE ###

import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, M = mi()
    g = 1
    for i in range(1, M//N+1):
        if M%i==0:
            g = i
    print(g)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, math
from functools import lru_cache
from collections import deque
from bisect import bisect_left
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, M = mi()

    d = []
    i = 1
    while i*i <= M:
        if M%i == 0:
            d.append(i)
            d.append(M//i)
        i += 1

    d.sort()

    for v in d:
        if v <= M//N:
            ans = v
        else:
            break

    print(ans)

    



if __name__ == '__main__':
    main()
### BUGGY CODE ###

n=int(input())
l=[0]*(n+1)
for x in range(1,n):
    for y in range(1,n-x):
        for z in range(1,n-x-y):
            value=x*x+y*y+z*z+x*y+y*z+z*x
            if value>n:
                continue
            l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(l[i])

### FIXED CODE ###

n=int(input())
l=[0]*10**7
s=int(n**0.7)+10
for x in range(1,s):
    for y in range(1,s-x):
        for z in range(1,s-x-y):
            l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(l[i])
### BUGGY CODE ###

x = int(input())
val = 1
for index in range(1,x+1):
    val = val*index
print(val %(10**9 + 7))

### FIXED CODE ###

x = int(raw_input())
a = 1L
for i in range(1, x+1):
 a = a * i
 a = a % 1000000007
print(a)
### BUGGY CODE ###

n,a,b=map(int,input().split())
aa=n//(a+b)
ss=n%(a+b)
ans=0
for i in range(aa):
    ans+=a
if ss>a:
    ans+=a
else:
    ans+=ss

print(ans)

### FIXED CODE ###

n,a,b=map(int,input().split())
aa=n//(a+b)
ss=n%(a+b)
ans=0
ans=ans+aa*a
if ss>a:
    ans+=a
else:
    ans+=ss

print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
aa=[]
ans=0
for i in range(0,1000):
    i=str(i).zfill(3)
    for a in range(len(s)-2):
        if i[0]==s[a]:
            for b in range(a+1,len(s)-1):
                if i[1]==s[b]:
                    for c in range(b+1,len(s)):
                        if i[2]==s[c]:
                            ans+=1
                            aa.append(i)
                            break
                        if c==len(s)-1 and i[2]!=str(c):
                            break
                if b==len(s)-2 and i[1]!=str(b):
                    break
        if a==len(s)-3 and i[0]!=str(a):
            break

print(len(list(set(aa))))

### FIXED CODE ###

n=int(input())
S = input()
 
ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
k = 0 
for i in range(N-1,-1,-1):
    if A[i] % B[i] == 0 :
        continue
    else :
        c = (B[i] - A[i] % B[i])
        k += c
        for j in range(i):
            A[j] += c

print(k)

### FIXED CODE ###

N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
k = 0 
for i in range(N-1,-1,-1):
    A[i] += k
    if A[i] % B[i] == 0 :
        pass
    else :
        c = (B[i] - A[i] % B[i])
        k += c

print(k)
### BUGGY CODE ###

N = int(input())

i = 1
AC = 0
WA = 0
TLE = 0
RE = 0
list = []
for i in range(N):
    list.append(str(input()))
    a = list.count("AC")
    b = list.count("WA")
    c = list.count("TLE")
    d = list.count("RE")

print("AC x",str(a))
print("WA x" , str(b))
print("TLE x" , str(c))
print("RE x" ,str(d))


### FIXED CODE ###

N = int(input())

list = []
for i in range(N):
    list.append(str(input()))
a = list.count("AC")
b = list.count("WA")
c = list.count("TLE")
d = list.count("RE")

print("AC x",a)
print("WA x" ,b)
print("TLE x" ,c)
print("RE x" ,d)
### BUGGY CODE ###

import numpy as np
N, K = map(int, input().split())


A_list = list(map(int, input().split()))
A_list = np.array(A_list) - 1
#A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0
while k > 0:
  town = A_list[town]
                     
  if town in path:
    #print("town is {}".format(town))
    #print("path is {}".format(path))
    first_visit = path.index(town)
    loop_size = j - first_visit + 1
    #print("loop_size is {}".format(loop_size))
    #print("k is {}".format(k))
    k = (k-1) % loop_size 
    #print("k is now {}".format(k))
    town = path[first_visit + k]
    break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

### FIXED CODE ###

N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0

while k > 0:
  town = A_list[town]
   
  if k % 10000 == 0:
    if town in path:
      #print("town is {}".format(town))
      #print("path is {}".format(path))
      first_visit = path.index(town)
      loop_size = j - first_visit + 1
      #print("loop_size is {}".format(loop_size))
      #print("k is {}".format(k))
      k = (k-1) % loop_size 
      #print("k is now {}".format(k))
      town = path[first_visit + k]
      break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)
### BUGGY CODE ###

n = int(input())
a_lst = list(map(int, input().split()))

res = 0
for i in range(n):
  for j in range(i+1, n):
    res += (a_lst[i] ^ a_lst[j])
print(res % (10 ** 9 + 7))

### FIXED CODE ###

import numpy as np
n=int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10**9+7
sm=0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    sm += 2 ** i * c1 * (n-c1)
    arr >>= 1

print(sm%mod)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)

for i in range(N):
  if i == A.index(max(A)):
    print(B[1])
  else:
    print(B[0])

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
x = B[1]
y = B[0]
m = A.index(max(A))

for i in range(N):
  if i == m:
    print(x)
  else:
    print(y)
### BUGGY CODE ###

N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
amax = max(A)

B = []
for i in range(N):
    B = A[:]
    bi = B.pop(i)
    if bi == amax:
        B.sort()
        print(B.pop())
    else:
        print(amax)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)
### BUGGY CODE ###

n = int(input())
s = list(input())

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        temp = 0
        for k in range(j - i):
            if j + k >= n:
                break
            if s[i+k] == s[j+k]:
                temp += 1
        ans = max(temp, ans)

print(ans)


### FIXED CODE ###

n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k]:
                k += 1
            p[i] = k
            j = i
    p[0] = len_str
    return p

ans = 0
for x in range(n):
    temp = [] + z_algorithm(s[x:])
    for y in range(n - x):
        z = min(temp[y], y)
        ans = max(ans, z)

print(ans)
### BUGGY CODE ###

import numpy as np
s = input()
p = 10 ** 9 + 7
dp = np.zeros((len(s)+1, 13), dtype=np.int64)
dp[0][0] = 1
for cnt, i in enumerate(reversed(s)):
	if i == "?":
		for f in range(10):
			k = pow(10, cnt, 13)*f%13
			for j in range(13):
				dp[cnt+1][(j+k)%13] = (dp[cnt+1][(j+k)%13] + dp[cnt][j])%p
	else:
		targ = int(i)
		k = pow(10, cnt, 13)*targ%13
		for j in range(13):
			dp[cnt+1][(j+k)%13] = (dp[cnt+1][(j+k)%13] + dp[cnt][j])%p
#print(dp)
print(dp[len(s)][5])

### FIXED CODE ###

from collections import defaultdict
s = input()
lens = len(s)
"""
1, 10, 100～900に対して13で割って5余るものは存在する？
"""
modl = [[] for i in range(len(s))]
modl[0] = [i for i in range(10)]
for i in range(1, len(s)):
	modl[i] = [(modl[i-1][j]*10)%13 for j in range(10)]
mod = 10**9+7

unta = defaultdict(lambda: 0)
unta[0] += 1
for i, j in enumerate(s[::-1]):
	newunta = defaultdict(lambda: 0)
	if j != "?":
		a = modl[i][int(j)]
		for k in range(13):
			newunta[(k+a)%13] = (newunta[(k+a)%13] + unta[k]) % mod
	else:
		for l in range(10):
			a = modl[i][l]
			for k in range(13):
				newunta[(k+a)%13] = (newunta[(k+a)%13] + unta[k]) % mod
	unta = newunta

print(unta[5] % mod)