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

a,b,q = map(int,input().split())
inf = 10 ** 18
s = [-inf]
for _ in range(a):
  s.append(int(input()))
s.append(inf)
t = [-inf]
for _ in range(b):
  t.append(int(input()))
t.append(inf)
import bisect
st = [inf]
for i in range(1,a+1):
  here = bisect.bisect_left(t,s[i])
  st.append(min(abs(t[here-1]-s[i]),abs(t[here]-s[i])))
st.append(inf)
ts = [inf]
for j in range(1,b+1):
  here = bisect.bisect_left(s,t[j])
  ts.append(min(abs(s[here-1]-t[j]),abs(s[here]-t[j])))
ts.append(inf)
for _ in range(q):
  now = int(input())
  shere = bisect.bisect_left(s,now)
  there = bisect.bisect_left(t,now)
  z1 = abs(now-s[shere-1]) + st[shere-1]
  z2 = abs(now-s[shere  ]) + st[shere  ]
  z3 = abs(now-t[there-1]) + ts[there-1]
  z4 = abs(now-t[there  ]) + ts[there  ]
  print(min(z1,z2,z3,z4))

### FIXED CODE ###

#22:10
a,b,q = map(int,input().split())
s = []
for _ in range(a):
  s.append(int(input()))
t = []
for _ in range(b):
  t.append(int(input()))
import bisect
st = []
for i in range(a):
  tmp = bisect.bisect_left(t,s[i])
  if tmp == 0:
    st.append(abs(s[i]-t[tmp]))
  elif tmp == b:
    st.append(abs(s[i]-t[tmp-1]))
  else:
    st.append(min(abs(s[i]-t[tmp-1]),abs(s[i]-t[tmp])))
ts = []
for j in range(b):
  tmp = bisect.bisect_left(s,t[j])
  if tmp == 0:
    ts.append(abs(t[j]-s[tmp]))
  elif tmp == a:
    ts.append(abs(t[j]-s[tmp-1]))
  else:
    ts.append(min(abs(t[j]-s[tmp-1]),abs(t[j]-s[tmp])))
'''
print(s)
print(t)
print(st)
print(ts)
'''
for _ in range(q):
  x = int(input())
  can = []
  xs = bisect.bisect_left(s,x)
  xt = bisect.bisect_left(t,x)
  try:
    can.append(abs(x-s[xs-1]) + st[xs-1])
  except:
    pass
  try:
    can.append(abs(x-s[xs])   + st[xs])
  except:
    pass
  try:
    can.append(abs(x-t[xt-1]) + ts[xt-1])
  except:
    pass
  try:
    can.append(abs(x-t[xt])   + ts[xt])
  except:
    pass
  print(min(can))
### BUGGY CODE ###

from collections import defaultdict
n = int(input())
m = n//2
INF = 10**18
dp = [defaultdict(lambda: -INF)for _ in range(n+2)]
for i, a in enumerate(map(int, input().split()), 2):
    for j in range(1, -(-i//2)+1):
        if j-1 == 0:
            dp[i-2][j-1] = 0
        dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+a)

print(dp[n+1][m])


### FIXED CODE ###

from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
m = n//2
INF = 10**18
dp = [defaultdict(lambda: -INF) for _ in range(n+1)]
for i in range(1, n+1):
    L = i//2-1
    R = (i+1)//2+1
    for j in range(L, R):
        if j == 1:
            dp[i][j] = max(dp[i-1][j], A[i-1])
        elif 0 <= i-2 and 0 <= j <= m:
            dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+A[i-1])
print(dp[-1][m])
### BUGGY CODE ###

def main():
    n,q = map(int, input().split())
    S = list(input())
    array = [list(map(int,input().split())) for _ in range(q)]

    for i in range(q):
        count = 0
        S_temp = S[array[i][0]-1:array[i][1]]
        S_temp_len = len(S_temp)
        for j in range(S_temp_len):
            if j == S_temp_len-1:
                break
            if S_temp[j] == 'A':
                if S_temp[j+1] == 'C':
                    count += 1
        print(count)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n,q = map(int, input().split())
    S = input()
    N = [0]*(n+1)

    for i in range(n):
        N[i+1] += N[i]
        if S[i:i+2] == 'AC':
            N[i+1] += 1
    for i in range(q):
        l,r = map(int,input().split())
        print(N[r-1]-N[l-1])


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

x,y,z,k = map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
c= list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

ansListab=ansListab[:min(3001,x*y*z+1)]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[i])


### FIXED CODE ###

x,y,z,k = map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
c= list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[i])
### BUGGY CODE ###

#%%
h, w, d = map(int, input().split())
a = [0] * h
for i in range(h):
    a[i] = list(map(int, input().split()))
q = int(input())
l, r = [0] * q, [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())

pos = [[0] for _ in range(h*w+1)]
for i in range(h):
    for j in range(w):
        pos[a[i][j]] = [i+1, j+1]
#print(pos)

cost = [[0]*(h*w+1) for i in range(h*w+1)]
#print(cost)

for i in range(1, len(cost)):
    for j in range(i, len(cost)):
        pos1 = pos[i]
        pos2 = pos[j]
        dist = abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])
        cost[i][j] = dist

import numpy as np
##print(np.array(cost))


for i in range(q):
    tmp = 0
    while l[i] != r[i]:
        tmp += cost[l[i]][l[i]+d]
        l[i] += d
    print(tmp)


### FIXED CODE ###

#%%
h, w, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
q = int(input())
l, r = [0] * q, [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())

reach = [0] * (w * h)
for i in range(h):
    for j in range(w):
        reach[a[i][j] - 1] = [i, j]
#print(reach)

count = [0] * (w * h)
for i in range((w * h)):
    if i - d < 0 : 
        pass
    else:
        count[i] = count[i - d] + (abs(reach[i][0] - reach[i - d][0]) + abs(reach[i][1] - reach[i - d][1]))
#print(count)

for i in range(q):
    print(count[r[i] - 1] - count[l[i] - 1])
### BUGGY CODE ###

input_list = list(input())

height_list = [0]
height = 0
for d in input_list:
    if d == '\\':
        height += -1
        height_list.append(height)
    if d == '/':
        height += 1
        height_list.append(height)
    if d == '_':
        height_list.append(height)

highest = max(height_list)
lowest = min(height_list)
flag = False
left_side_index = 0
right_side_index = 0
left_and_right_dict = {} # key = left_side_index, value = right_side_index
skip_indices = []
while highest != lowest:
    for i in range(len(height_list)):
        if i in skip_indices:
            continue
        else:
            if height_list[i] != highest:
                continue
            else:
                if i != len(height_list) - 1 and input_list[i] == '\\':
                    for k in range(i + 1, len(height_list)):
                        if height_list[k] != highest:
                            continue
                        else:
                            if input_list[k-1] == '/':
                                left_side_index = i
                                right_side_index = k
                                flag = True
                                break
                # Get the width of a puddle
                if flag:
                    left_and_right_dict[left_side_index] = right_side_index
                    for j in range(left_side_index, right_side_index):
                        skip_indices.append(j)
                    flag = False
    highest += -1

area_list = []
for left in sorted(left_and_right_dict.keys()):
    area = 0
    surface = height_list[left]
    for i in range(left, left_and_right_dict[left]):
        if input_list[i] == '\\':
            area += abs(surface - height_list[i+1]) - 0.5
        if input_list[i] == '/':
            area += abs(surface - height_list[i]) - 0.5
        if input_list[i] == '_':
            area += abs(surface - height_list[i])
    area_list.append(int(area))

print(sum(area_list))
if area_list != []:
    print(len(area_list), end = ' ')
    print(*area_list)
else:
    print(0)


### FIXED CODE ###

string = input()
height = 0
height_list = [[0, False]]
for s in string:
    if s == '\\':
        height += -1
    elif s == '/':
        height += 1
    else:
        pass
    height_list.append([height, False])

highest = 0
for i in range(1, len(height_list)):
    if height_list[i-1][0] < height_list[i][0] <= highest:
        height_list[i][1] = True
    highest = max(highest, height_list[i][0])

puddles = []
area = 0
surface_level = None

for i in range(len(height_list)-1, -1, -1):
    if surface_level != None:
        area += surface_level - height_list[i][0]
        if surface_level == height_list[i][0]:
            puddles += [area]
            surface_level = None
            area = 0
    if surface_level == None and height_list[i][1]:
        surface_level = height_list[i][0]

puddles = puddles[::-1]
print(sum(puddles))
print(len(puddles), *puddles)
### BUGGY CODE ###

#!/usr/bin/env python3
#from bisect import bisect_left

n, k = map(int, input().split())
*a, = map(int, input().split())
# def is_ok(arg):
#     # 条件を満たすかどうか？問題ごとに定義
#     return sum(-(-i // arg) - 1 for i in a) <= k
# 
# 
# def meguru_bisect(ng, ok):
#     '''
#     初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
#     まずis_okを定義すべし
#     ng ok は  とり得る最小の値-1 とり得る最大の値+1
#     最大最小が逆の場合はよしなにひっくり返す
#     '''
#     while (abs(ok - ng) > 1):
#         mid = (ok + ng) // 2
#         if is_ok(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok
# print(meguru_bisect(0, max(a)))
import math
import heapq
b = [(-i,1) for i in a]
heapq.heapify(b)
for _ in range(k):
    p, q = heapq.heappop(b)
    heapq.heappush(b, (p*q/(q+1),q+1))
print(math.ceil(-heapq.heappop(b)[0]))


### FIXED CODE ###

#!/usr/bin/env python3
from bisect import bisect_left

n, k = map(int, input().split())
*a, = map(int, input().split())
def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    return sum(-(-i // arg) - 1 for i in a) <= k


def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
print(meguru_bisect(0, max(a)))
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline

N = int(input())
P = [int(x) for x in input().split()]

count = 0
for i in range(len(P)):
	if min(P[:i+1]) == P[i]:
		count += 1

print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
P = [int(x) for x in input().split()]

l = []
for x in P:
	if not l or l[-1] > x:
		l.append(x)
	else:
		l.append(l[-1])

print(len(set(l)))
### BUGGY CODE ###

import numpy as np
N = int(input())
S = input()

A = np.zeros(N+1)
for i,s in enumerate(S):
    if s=='.':
        A[-i-1:] += 1
    else:
        A[:N-i] += 1

print(int(np.min(A)))

### FIXED CODE ###

N = int(input())
S = input()

A = [None]*(N+1)
A[0] = 0
cnt = 0
for i,s in enumerate(S[::-1]):
    if s=='.':
        A[i+1] = A[i]+1
    else:
        A[i+1] = A[i]-1
        cnt += 1
print(min(A)+cnt)
### BUGGY CODE ###

a,b,k=map(int,input().split())
lst=[]
for i in range(a,b+1):
  if a<=i<=k+a-1 or b-k+1<=i<=b:
    lst.append(i)
for j in range(len(lst)):
  print(lst[j])

### FIXED CODE ###

a,b,k=map(int,input().split())
lst=[]
for i in range(a,min(a+k, b)):
  lst.append(i)
  print(i)
for j in range(max(a, b-k+1),b+1):
  if j not in lst:
    print(j)
### BUGGY CODE ###

S = input()

count = 0
for times in range(1, 101):
    num = 2019 * times
    num_length = len(str(num))
    for i in range(len(S) - 3):
        for j in range(i + 3, len(S)):
            if j-i+1 != num_length:
                continue
            sub_S = int(S[i:j+1])
            if num == sub_S:
                count += 1

print(count)

### FIXED CODE ###

S = list(input())
N = len(S)
# N 文字の文字列 S から、長さ N+1 の ---累積和--- s[0], s[1], ..., s[N] を作る
# これを 2019 で割ったあまりで分類する (具体的には counter[ r ] := あまりが r のやつが何個あるか)
# 各 r ごとに、counter[r] 個から 2 個選ぶ方法の数を、足し上げる

counter = [0] * 2019
k = 10
for i in range(N + 1):
    if i == 0:
        sub = 0
    elif i == 1:
        sub = int(S[N - 1])
    else:
        sub += int(S[N - i]) * k
        k *= 10
        k %= 2019
    rest = sub % 2019
    counter[rest] += 1

ans = 0
for r in counter:
    ans += r * (r - 1) // 2
print(ans)
### BUGGY CODE ###

def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

    INF = 10 ** 9 + 10

    N, M, K = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())

    def rec(t, ai, bi):
        if t > K: return -INF

        ac, bc = INF, INF
        if ai < len(A): ac = A[ai]
        if bi < len(B): bc = B[bi]

        return max(
            0,
            rec(t + ac, ai + 1, bi) + 1,
            rec(t + bc, ai, bi + 1) + 1
        )

    print(rec(0, 0, 0))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, M, K = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *P, = accumulate(A)
    *Q, = accumulate(B)

    ans = 0
    j = len(Q) - 1
    for i, x in enumerate(P):
        while j > 0 and x + Q[j] > K:
            j -= 1
        if x + Q[j] <= K:
            ans = max(ans, i + j)
    print(ans)


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

# -*- coding: utf-8 -*-
import sys
# 12:55~
sys.setrecursionlimit(10**9)

N,M = map(int,input().split())
uv = [list(map(int,input().split())) for _ in range(M)]
S,T = map(int,input().split())

S -= 1
T -= 1
#%%
adj_list = [[] for _ in range(N)]
for u,v in uv:
    adj_list[u-1].append(v-1)

INF = 10**9+7
dist = [INF]*N
dist[S] = 0

def dfs(vartex, count):
    nxt_v = adj_list[vartex]
    if count%3==2:
        for nv in nxt_v:
            if dist[nv]>(count+1)//3:
                dist[nv] = min(dist[nv],(count+1)//3)
                dfs(nv,count+1)                
    else:
        for nv in nxt_v:
            dfs(nv,count+1)
    
dfs(S,0)
if dist[T]==INF:
    ans = -1
else:
    ans = dist[T]
print(ans)
            
        
        
        
    





### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from queue import Queue
# 12:55~
sys.setrecursionlimit(10**9)

N,M = map(int,input().split())
uv = [list(map(int,input().split())) for _ in range(M)]
S,T = map(int,input().split())

S -= 1
T -= 1
#%%
adj_list = [[[] for _ in range(3)] for _ in range(N)]
for u,v in uv:
    for i in range(3):
        adj_list[u-1][i].append([v-1,(i+1)%3])


INF = 10**9+7
dist = [[INF]*3 for _ in range(N)]
dist[S][0] = 0

stack = Queue()
stack.put([S,0])
while not stack.empty():
    v,c = stack.get()
    nxt_v = adj_list[v][c]
    for nv,nc in nxt_v:
        if dist[nv][nc]==INF:
            dist[nv][nc] = dist[v][c] + 1
            stack.put([nv,nc])
            
            
if dist[T][0]==INF:
    ans = -1
else:
    ans = dist[T][0]//3
print(ans)
### BUGGY CODE ###

def z_algorithm(s):
    n = len(s)
    z = [0] * n
    z[0] = n

    i = 1
    lcp = 0
    while i < n:
        while i+lcp < n and s[i+lcp] == s[lcp]:
            lcp += 1
        z[i] = lcp

        if lcp == 0:
            i += 1
            continue

        k = 1
        while i+k < n and k+z[k] < lcp:
            z[i+k] = z[k]
            k += 1
        i += k
        lcp -= k

    return z

from collections import deque
def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for c, v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for c, v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res

s = input()
t = input()

n0 = len(s)
m = len(t)

s = s * ((n0 + m) // n0 + 1)

idx = s.find(t)

if idx >= 0:
    z = z_algorithm(s[idx:])
    # print(z)

    graph = [[] for _ in range(n0)]
    for i in range(n0):
        if i >= idx and z[i-idx] >= m:
            graph[i].append( (1, (i + m) % n0) )

    ts = topological_sort(graph, n0)
    if len(ts) != n0:
        ans = -1
    else:
        # print(ts)
        ans = 0
        path = [0] * n0
        for i in range(n0):
            ans = max(ans, path[ts[i]])
            for _, j in graph[ts[i]]:
                path[j] = path[ts[i]] + 1
else:
    ans = 0

print(ans)


### FIXED CODE ###

def z_algorithm(s):
    n = len(s)
    z = [0] * n
    z[0] = n

    i = 1
    lcp = 0
    while i < n:
        while i+lcp < n and s[i+lcp] == s[lcp]:
            lcp += 1
        z[i] = lcp

        if lcp == 0:
            i += 1
            continue

        k = 1
        while i+k < n and k+z[k] < lcp:
            z[i+k] = z[k]
            k += 1
        i += k
        lcp -= k

    return z

from collections import deque
def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res

import sys

def main():
    input = sys.stdin.readline
    s = input().rstrip()
    t = input().rstrip()

    n0 = len(s)
    m = len(t)

    s = s * (m // n0 + 2)


    z = z_algorithm(t + '*' + s)
    z = z[m+1:]
    # print(z)

    graph = [[] for _ in range(n0)]
    for i in range(n0):
        if z[i] >= m:
            graph[i].append( (i + m) % n0 )

    ts = topological_sort(graph, n0)
    if len(ts) != n0:
        ans = -1
    else:
        # print(ts)
        ans = 0
        path = [0] * n0
        for i in range(n0):
            ans = max(ans, path[ts[i]])
            for j in graph[ts[i]]:
                path[j] = path[ts[i]] + 1

    print(ans)

main()
### BUGGY CODE ###

X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
for i in r:
    p_min = p[X - 1]
    q_min = q[Y - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        p.pop()
        p.insert(0, i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        q.pop()
        q.insert(0, i)
 
print(sum(p) + sum(q))

### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
colored_p = []
colored_q = []
 
for i in r:
    p_min = p[len(p) - 1] if len(p) > 0 else colored_p[len(colored_p) - 1]
    q_min = q[len(q) - 1] if len(q) > 0 else colored_q[len(colored_q) - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        if len(p) > 0:
            p.pop()
        colored_p.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        if len(q) > 0:
            q.pop()
        colored_q.append(i)
 
print(sum(p) + sum(q) + sum(colored_p) + sum(colored_q))
### BUGGY CODE ###

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

r = min(r, r+4038)

min = 99999999
for i in range(l,r):
  for j in range(i+1,r+1):
    value = (i*j)%2019
    if min > value:
      min = value
print(min)

### FIXED CODE ###

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

r = min(r, l+4038)

min = 99999999
for i in range(l,r):
  for j in range(i+1,r+1):
    value = (i*j)%2019
    if min > value:
      min = value
print(min)
### BUGGY CODE ###

import sys
import collections
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
cost = collections.deque([])
tree = collections.deque([])
level = collections.deque([])
parent = collections.deque([])
for i in range(210000):
    tree.append(collections.deque([]))
    level.append(-1)
    parent.append(-1)
    cost.append(0)

for loop in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for loop in range(q):
    p, x = map(int, input().split())
    cost[p] += x

def make_level(index, lev, pp):
    level[index] = lev
    parent[index] = pp
    for next in tree[index]:
        if level[next] != -1:
            continue
        cost[next] += cost[index]
        make_level(next, lev + 1, index)

make_level(1, 0, -1)

res = list(map(str, cost))
print(" ".join(res[1:n+1]))

### FIXED CODE ###

edge = []
n, q = map(int, input().split())
for _ in range(n+100):
    edge.append([])
for _ in range(n-1):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
res = [0] * (n+1)
cost = [0] * (n+1)
for _ in range(q):
    a,b = map(int, input().split())
    res[a] += b

import collections
q = collections.deque([[1, 0]])
used = [False] * (n+1)
while len(q) > 0:
    #print(q)
    curnode, cost = q.popleft()
    res[curnode] += cost
    used[curnode] = True
    for i in range(len(edge[curnode])):
        nnext = edge[curnode][i]
        if used[nnext] is True:
            continue
        else:
            q.append([nnext, res[curnode]])
res=res[1:]
print(" ".join(list(map(str, res))))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
 
for i in range(N):
  print(A.count(i+1))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
x = [0]*(2*10**5+1)
for i in range(N-1):
    x[A[i]] += 1
for i in range(1,N+1):
    print(x[i])
### BUGGY CODE ###

num, track = [int(x) for x in input().split()]
hoge_l = list()
for _ in range(num):
    hoge_l.append(int(input()))
hoge_i = sum(hoge_l)
if hoge_i % track == 0:
    hoge_i = hoge_i // track
else:
    hoge_i = hoge_i // track + 1

while True:
    tmp = 0
    c = 1
    for v in hoge_l:
        tmp += v
        if tmp > hoge_i:
            c += 1
            tmp = 0
            tmp += v
    if c == track:
        break
    elif c > track:
        hoge_i += 1
max_num = max(hoge_l)
if max_num > hoge_i:
    hoge_i = max_num
print (hoge_i)


### FIXED CODE ###

def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True

num, track = [int(x) for x in input().split()]
hoge_l = list()
for _ in range(num):
    hoge_l.append(int(input()))
left = 0
right = 100000 * 10000

while left < right :
    mid = (right + left) // 2
    if imas(hoge_l, mid, track):
        right = mid 
    else:
        left = mid + 1
        
max_num = max(hoge_l)
if max_num > right:
    right = max_num
print (right)
### BUGGY CODE ###

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    for i in range(n):
        x = 0
        a[i], x = x, a[i]
        print(max(a))
        a[i], x = x, a[i]

main()

### FIXED CODE ###

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    a_copy = sorted(a)
    a_max = a_copy[-1]
    a_second = a_copy[-2]
    for i in range(n):
        if a[i] == a_max:
            print(a_second)
        else:
            print(a_max)


main()