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

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

a,b=[0],[0]
for i in range(N):
    a.append(a[i] + A[i])
    for  i in range(M): 
        b.append(b[i] + B[i])

ans,j=0,M
for  i in range(N + 1): 
    if a[i]>K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

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

SumA=[0 for _ in range(N+1)]
SumB=[0 for _ in range(M+1)]
for i in range(1,N+1):
    SumA[i]=SumA[i-1]+A[i-1]
for i in range(1,M+1):
    SumB[i]=SumB[i-1]+B[i-1]

def binary_search(Time,IndexA):
    if Time>K:
        return 0 
    l=0
    r=M
    c=(l+r)//2
    while r-l>1:
        if Time+SumB[c]>K: r=c
        if Time+SumB[c]<=K: l=c
        c=(l+r)//2
    if Time+SumB[r]>K: IndexB=l
    else: IndexB=r
    NumOfBooks=IndexA+IndexB
    return NumOfBooks

MaxNumOfBooks=0
for IndexA in range(N+1):
    NumOfBooks=binary_search(SumA[IndexA],IndexA)
    if MaxNumOfBooks<NumOfBooks: MaxNumOfBooks=NumOfBooks
print(MaxNumOfBooks)
### BUGGY CODE ###

k,s=map(int,input().split())
ans=0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:
                ans+=1
print(ans)

### FIXED CODE ###

k,s=map(int,input().split())
ans=0
for x in range(k+1):
    for y in range(k+1):
        if 0<=s-x-y<=k:
            ans+=1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split( )))
ans = 0
mod = 10**9+7
Bit = [0 for j in range(60)]# for i in range(n+1)

for i in range(1,n):##1から
    for j in range(60):
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j]<<j
            ans %=mod
        else:
            ans += (i-Bit[j])<<j
            ans %= mod
    
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split( )))
ans = 0
mod = 10**9+7
Bit = [0 for j in range(60)]# for i in range(n+1)
for j in range(60):#ループ交換
    for i in range(1,n):##1から
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j]<<j
            ans %=mod
        else:
            ans += (i-Bit[j])<<j
            ans %= mod
    
print(ans)
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import dijkstra

N, X, Y = list(map(int, input().split()))

# N = 2000
# X = 100
# Y = 1900


X -= 1
Y -= 1

# @profile


def main(N, X, Y):
    ans = [0]*N
    graph = np.zeros((N, N))
    # np.fill_diagonal(graph[1:, :], 1)
    np.fill_diagonal(graph[:, 1:], 1)
    graph[X, Y] = 1
    # graph[Y, X] = 1
    dist_matrix = dijkstra(graph, directed=False)
    # print(dist_matrix)

    for i in range(1, N):
        print(np.count_nonzero(dist_matrix == i)//2)


main(N, X, Y)


### FIXED CODE ###


N, X, Y = list(map(int, input().split()))

# N = 2000
# X = 100
# Y = 1900


X -= 1
Y -= 1

# @profile


def main(N, X, Y):
    ans = [0]*N
    for i in range(N):
        for j in range(i+1, N):
            d = min(j-i, abs(X-i)+abs(Y-j)+1)
            ans[d] += 1

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


main(N, X, Y)
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
res = 0
for i in range(n):
    for j in range(i+1, n, 1):
        a = l[i]
        b = l[j]
        ab = a + b
        for k in range(j+1, n, 1):
            if l[k] < ab:
                res += 1
            else:
                break
print(res)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)
### BUGGY CODE ###

S = input()
S_list = list(S)

while len(S_list) >= 5 :
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if len(S_list) >= 6 :
            if S_list[5] == 'r' :
                del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if len(S_list) >= 8 :
            if S_list[5:8] == ['e', 'r', 'a'] :
                del S_list[0:5]
        elif len(S_list) >= 7 :
            if S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')


### FIXED CODE ###

S = input()
S_list = list(S)

while len(S_list) >= 5 :
    a = len(S_list)
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if a >= 6 :
            if S_list[5] == 'r' :
                del S_list[0:6]
            else:
                del S_list[0:5]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if a >= 8 :
            if S_list[5:8] == ['e', 'r', 'a'] :
                del S_list[0:5]
            elif S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
            else :
                del S_list[0:5]
        elif a >= 7 :
            if S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
            else:
                del S_list[0:5]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')
### BUGGY CODE ###

def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num, logs):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(logs):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      if half_num != 1:
        count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a > K:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2)
    elif half_num != 1 and count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # count_aが最大になれば終了
      return half_num
      break

N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max)

### FIXED CODE ###

def round_up_division(num1, num2):
# 切り上げ除算
  div = -(-num1 // num2)
  return div

def binary_search(search_range, max_num, logs):
  search_min = 1
  search_max = search_range
  # 二分探索
  while True:
    # max_numを超えない最大回数にする
    count_a = 0
    # count_aより1短い長さ
    count_b = 0
    # 最小値と最大値の中間の値を出す
    half_num = (search_min + search_max - 1) // 2 + 1
    for i in range(logs):
      # 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
      count_a += round_up_division(A[i], half_num) - 1
      if half_num != 1:
        count_b += round_up_division(A[i], half_num - 1) - 1
    if count_a > K:
      # 多ければ長い半分で探索
      search_min = round_up_division(search_min + search_max, 2)
    elif half_num != 1 and count_b <= K:
      # 少なければ短い半分で探索
      search_max = half_num - 1
    else:
      # count_aが最大になれば終了
      return half_num
      break

N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
cons = (10**9+7)
if N == M:
    s = 1
    for i in range(2, N+1):
        s *= i%cons
    print((s**2*2)%cons)

elif abs(N-M) == 1:
    N = max(N, M)
    s = 1
    for i in range(2, N+1):
        s *= i%cons
    print((s*(s//N)%cons))
else:
    print(0)


### FIXED CODE ###

import math

N, M = list(map(int, input().split()))
cons = (10**9+7)
if N == M:
    s = math.factorial(N)
    print((s**2*2)%cons)

elif abs(N-M) == 1:
    N = min(N, M)
    s = math.factorial(N)
    print((s*(s*(N+1))%cons))
else:
    print(0)
### BUGGY CODE ###

N = int(input())
sd = []
cnt = 0
for i in range(N):
    str = ','.join(sorted(input()))
    cnt += sd.count(str)
    sd.append(str)
print(cnt)



### FIXED CODE ###

N = int(input())
sd = {}
cnt = 0
for i in range(N):
    str = ','.join(sorted(input()))
    if str in sd:
        sd[str] += 1
        cnt += sd[str]
    else:
        sd[str] = 0
print(cnt)
### BUGGY CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0

#a<=b<=c とする
#a,b 固定
#cf : http://drken1215.hatenablog.com/entry/2019/10/20/032700
for i in range(N):
 for j in range(i,N):
   if(i != j):
    a,b = L[i],L[j]
    a_plus_b = a+b
    k = bisect.bisect_left(L,a+b)
    tmp = max(0, k-(j+1))
    count += tmp
    
print(count)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0

#a<=b<=c とする
#a,b 固定
#cf : http://drken1215.hatenablog.com/entry/2019/10/20/032700
for i in range(N):
 for j in range(i,N):
   if(i != j):
    a,b = L[i],L[j]
    a_plus_b = a+b
    k = bisect.bisect_left(L,a+b)
    tmp = max(0, k-(j+1))
    count += tmp
    
print(count)
### BUGGY CODE ###

from collections import deque
from typing import List


def main():
    h, w = map(int, input().split())
    g = []
    for _ in range(h):
        r = list(input())
        g.append(r)
    print(mm(h, w, g))


def mm(h: int, w: int, g: List[List[str]]) -> int:
    ret = 0
    for i in range(h):
        for j in range(w):
            if (g[i][j] == '#'):
                continue
            q = deque([(i, j, 0)])
            v = [[0] * w for _ in range(h)]
            while q:
                ii, jj, cnt = q.popleft()
                v[ii][jj] = 1
                ret = max(ret, cnt)
                # ↓
                if ii < h - 1 and g[ii + 1][jj] == '.' and v[ii + 1][jj] == 0:
                    q.append((ii + 1, jj, cnt + 1))
                # →
                if jj < w - 1 and g[ii][jj + 1] == '.' and v[ii][jj + 1] == 0:
                    q.append((ii, jj + 1, cnt + 1))
                # ↑
                if ii > 0 and g[ii - 1][jj] == '.' and v[ii - 1][jj] == 0:
                    q.append((ii - 1, jj, cnt + 1))
                # ←
                if jj > 0 and g[ii][jj - 1] == '.' and v[ii][jj - 1] == 0:
                    q.append((ii, jj - 1, cnt + 1))
    return ret


if __name__ == '__main__':
    main()


### FIXED CODE ###

import queue


def get_longest(s_tmx, i, j, h, w):
    q = queue.Queue()
    q.put((i, j))
    dist_mtx = [[-1] * w for a in range(h)]
    dist_mtx[i][j] = 0
    while not q.empty():
        pnt = q.get()
        y = pnt[0]
        x = pnt[1]
        if x - 1 >= 0 and dist_mtx[y][x-1] == -1 and s_mtx[y][x-1] == 1:
            dist_mtx[y][x-1] = dist_mtx[y][x] + 1
            q.put((y, x-1))
        if y - 1 >= 0 and dist_mtx[y-1][x] == -1 and s_mtx[y-1][x] == 1:
            dist_mtx[y-1][x] = dist_mtx[y][x] + 1
            q.put((y-1, x))
        if x < w - 1 and dist_mtx[y][x+1] == -1 and s_mtx[y][x+1] == 1:
            dist_mtx[y][x+1] = dist_mtx[y][x] + 1
            q.put((y, x+1))
        if y < h - 1 and dist_mtx[y+1][x] == -1 and s_mtx[y+1][x] == 1:
            dist_mtx[y+1][x] = dist_mtx[y][x] + 1
            q.put((y+1, x))
    ret = 0
    for item in dist_mtx:
        for item_item in item:
            if item_item > ret:
                ret = item_item
    return ret


h, w = map(int, input().split())
s_mtx = []

for i in range(h):
    s_list = [0] * w
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            s_list[j] = 1
        else:
            s_list[j] = 0
    s_mtx.append(s_list)

ret = 0

for i in range(h):
    for j in range(w):
        if s_mtx[i][j] == 1:
            tmp = get_longest(s_mtx, i, j, h, w)
            if tmp > ret:
                ret = tmp

print(ret)
### BUGGY CODE ###

import sys
def input():
	return sys.stdin.readline()[:-1]
	
class BellmanFord():
	def __init__(self, adj, start):
		self.adj = adj
		self.start = start
		self.size = len(adj)
		self.dist = [10**30 for _ in range(self.size)]
		self.dist[self.start] = 0

	def solve(self):
		for _ in range(self.size-1):
			for x in range(self.size):
				for y, w in self.adj[x]:
					if self.dist[y] > self.dist[x] + w:
						self.dist[y] = self.dist[x] + w
		return

	#負閉路のせいでgoalへの距離が-infになるか
	def NegativeCycleToGoal(self, goal):
		res = self.dist[goal]
		for _ in range(self.size):
			for x in range(self.size):
				for y, w in self.adj[x]:
					if self.dist[y] > self.dist[x] + w:
						self.dist[y] = self.dist[x] + w
			if res != self.dist[goal]:
				return True
		return False

	def GetDistance(self, goal):
		return self.dist[goal]

n, m, p = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
	a, b, c = map(int, input().split())
	adj[a-1].append((b-1, -c+p))

bf = BellmanFord(adj, 0)
bf.solve()
if bf.NegativeCycleToGoal(n-1):
	print("-1")
else:
	print(max(-bf.GetDistance(n-1), 0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**4)
def input():
	return sys.stdin.readline()[:-1]

class BellmanFord():
	def __init__(self, adj, start, size):
		self.adj = adj
		self.start = start
		self.size = size
		self.dist = [10**30 for _ in range(self.size)]
		self.dist[self.start] = 0

	def solve(self):
		for _ in range(self.size-1):
			for x in range(self.size):
				for y, w in self.adj[x]:
					if s_reachable[x] and s_reachable[y] and g_reachable[x] and g_reachable[y]:
						if self.dist[y] > self.dist[x] + w:
							self.dist[y] = self.dist[x] + w
		for x in range(self.size):
			for y, w in self.adj[x]:
				if s_reachable[x] and s_reachable[y] and g_reachable[x] and g_reachable[y]:
					if self.dist[y] > self.dist[x] + w:
						return False

		return True

	def GetDistance(self, goal):
		return self.dist[goal]

n, m, p = map(int, input().split())
adj = [[] for _ in range(n)]
adj_rev = [[] for _ in range(n)]

for _ in range(m):
	a, b, c = map(int, input().split())
	adj[a-1].append((b-1, -c+p))
	adj_rev[b-1].append(a-1)

s_reachable = [False for _ in range(n)]
s_reachable[0] = True
g_reachable = [False for _ in range(n)]
g_reachable[n-1] = True

def dfs_s(x):
	for v, w in adj[x]:
		if not s_reachable[v]:
			s_reachable[v] = True
			dfs_s(v)
	return

def dfs_g(x):
	for v in adj_rev[x]:
		if not g_reachable[v]:
			g_reachable[v] = True
			dfs_g(v)
	return

dfs_s(0)
dfs_g(n-1)

bf = BellmanFord(adj, 0, n)
if not bf.solve():
	print(-1)
else:
	print(max(-bf.GetDistance(n-1), 0))
### BUGGY CODE ###

n,x,y = map(int, input().split())
import collections

g = [[] for i in range(n)]
for i in range(n):
    if i != 0:
        g[i].append(i-1)
    if i != n-1:
        g[i].append(i+1)
g[x-1].append(y-1)
g[y-1].append(x-1)

inf = 10**5
dp = [[inf for i in range(n)] for j in range(n)]
todo = collections.deque()

for i in range(n):
    dp[i][i] = 0
    for j in g[i]:
        todo.append(j)
    while len(todo) > 0:
        now = todo.popleft()
        leng = inf
        for j in g[now]:
            if dp[i][j] == inf:
                todo.append(j)
            else:
                tem = dp[i][j] + 1
                if tem < leng:
                    leng = tem
        dp[i][now] = leng

for i in range(1,n):
    ans = 0
    for j in range(n):
        for k in range(n):
            if j < k:
                if dp[j][k] == i:
                    ans += 1
    print(ans)

### FIXED CODE ###

n,x,y = map(int, input().split())

ans = [0]*(n-1)
for j in range(1, n+1):
    for i in range(1, j):
        dis = min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        ans[dis-1] += 1

for i in ans:
    print(i)
### BUGGY CODE ###

import sys

file_input = sys.stdin

NM = file_input.readline()

import itertools

while NM != '0 0\n':
    N, M = map(int, NM.split())
    P = [int(file_input.readline()) for i in range(N)]
    P.append(0)
    P = list(set(P))
    P.sort()
    scores = map(sum, itertools.combinations_with_replacement(P, 4))
    print(max(filter(lambda x: x <= M, scores)))
    NM = file_input.readline()

### FIXED CODE ###

import sys

file_input = sys.stdin

NM = file_input.readline()

import itertools, bisect

while NM != '0 0\n':
    N, M = map(int, NM.split())
    P = [int(file_input.readline()) for i in range(N)]
    P.append(0)
    scores = map(sum, itertools.combinations_with_replacement(P, 2))
    scores = filter(lambda x: x <= M, scores)
    scores = list(set(scores))
    scores.sort()
    print(max(s + scores[bisect.bisect_right(scores, M - s) - 1] for s in scores))
    NM = file_input.readline()
### BUGGY CODE ###

n = int(input())

for i in range(2, 10**9, 2):
    if i % n == 0:
        print(i)


### FIXED CODE ###

n = int(input())

if n % 2 == 0:
    print(n)
else:
    print(n*2)
### BUGGY CODE ###

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

nx = 0
for i in range(a-b+1):
  x = 0
  for j in range(b):
  	x += (c[i+j]+1) / 2
  nx = max(nx,x) 

print('{:.12f}'.format(nx))

### FIXED CODE ###

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

x = [(e + 1) / 2 for e in c]

t = sum(x[0:b])
res = t
for i in range(a - b):
  t -= x[i]
  t += x[i+b]
  res = max(res,t)

print('{:.12f}'.format(res))
### BUGGY CODE ###

from sys import setrecursionlimit


def f(u, l, r, a, dp):
    if l > r:
        return (0, 0)
    if dp[l][r] is not None:
        return dp[l][r]
    t0 = None
    x, y = f(u ^ 1, l + 1, r, a, dp)
    if u == 0:
        t0 = (x + a[l], y)
    else:
        t0 = (x, y + a[l])
    t1 = None
    x, y = f(u ^ 1, l, r - 1, a, dp)
    if u == 0:
        t1 = (x + a[r], y)
    else:
        t1 = (x, y + a[r])
    if t0 is None:
        result = t1
    elif t1 is None:
        result = t0
    else:
        if t0[u] - t0[u ^ 1] > t1[u] - t1[u ^ 1]:
            result = t0
        else:
            result = t1
    dp[l][r] = result
    return result


setrecursionlimit(1000000)

N = int(input())
a = list(map(int, input().split()))

dp = [[None] * N for _ in range(N)]
t = f(0, 0, N - 1, a, dp)
print(t[0] - t[1])


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]
for l in range(1, N + 1):
  for i in range(N + 1 - l):
    j = i + l
    if (N - l) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
print(dp[0][N])
### BUGGY CODE ###

N, X = map(int, input(). split())
ban = [0]
patty = [1]

B = [1]
for i in range(N):
    B = ban + B + patty + B + ban

print(sum(B[:X]))

### FIXED CODE ###

N, X = map(int, input(). split())
a, p = [1], [1]

for n in range(N):
    a.append(a[n]*2 + 3)
    p.append(p[n]*2 + 1)

def xmas(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return xmas(N-1, X-1)
    else :
        return p[N-1] + 1 + xmas(N-1, X-(a[N-1]+2))

print(xmas(N, X))
### BUGGY CODE ###

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

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

### FIXED CODE ###

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

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)
### BUGGY CODE ###

n,m=(int(x) for x in input().split())
import math as math
import numpy as np

ans = 0
A = [int(x) for x in input().split()]

for i in range(m):
    A.sort()
    A [-1] = A[-1]/2
for i in range(n):
   A[i] =  math.floor(A[i]) 
   ans += A[i]
print(ans)


### FIXED CODE ###

#キューを使っている。ところどころマイナスにしているのはキューの性質のため。実行時間が全然違うのはソートが早いから
n,m = map(int,input().split())
a = list(map(lambda x: -int(x) ,input().split()))

import heapq
heapq.heapify(a)
for _ in range(m):
  tmp = -heapq.heappop(a)
  tmp //= 2
  heapq.heappush(a,-tmp)
print(-sum(a))
### BUGGY CODE ###

S=list(map(str,input()))
N=len(S)
M=(N//10+1)*10
Q=[0]*N
for i in range(N):
  p=i
  for j in range(M):
    if S[p]=="R":
      p=p+1
      if S[p]=="L" and j%2!=0:
        break
    else:
      p=p-1
      if S[p]=="R" and j%2!=0:
        break
  Q[p]=Q[p]+1
print(*Q)

### FIXED CODE ###

S=list(map(str,input()))
N=len(S)
Q=[0]*N
R=[]
R1=[0]*N
L1=[0]*N
L=[]
V=[0]*N
for i in range(0,N):
  if S[i]=="R" and S[i+1]=="L":
    R.append(i)
  elif S[i]=="L" and S[i-1]=="R":
    L.append(i)
  else: V[i]=1

for i in R+L:
  Q[i]=1

x=0
for r in R:
  while x!=r:
    R1[x]=r
    x=x+1
x=N-1
for l in reversed(L):
  while x!=l:
    L1[x]=l
    x=x-1

for i in range(N):
  if V[i]==1:
    if S[i]=="R":
      if (R1[i]-i)%2==0:
        Q[R1[i]]=Q[R1[i]]+1
      else:
        Q[R1[i]+1]=Q[R1[i]+1]+1
    else:
      if (i-L1[i])%2==0:
        Q[L1[i]]=Q[L1[i]]+1
      else:
        Q[L1[i]-1]=Q[L1[i]-1]+1

print(*Q)
### BUGGY CODE ###

import itertools
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 8 * K
for v in itertools.permutations(x, K):
  v = list(v)
  v.sort()
  a = abs(v[0]) + abs(v[-1] - v[0])
  b = abs(v[-1]) + abs(v[-1] - v[0])
  if min(a, b) < ans:
    ans = min(a, b)
print(ans)

### FIXED CODE ###

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

ans = float('inf')
for i in range(n-k+1):
    l, r = X[i], X[i+k-1]
    if r <= 0:
        ans = min(abs(l), ans)
    elif 0 <= l:
        ans = min(abs(r), ans)
    else:
        dist = min(abs(l), abs(r))*2+max(abs(l), abs(r))
        ans = min(dist, ans)
print(ans)
### BUGGY CODE ###

import sys
a=int(input())
i=0
j=1
t=True
while i**5<=a:
  if a-i**5>=0:
    if int((a-i**5)**0.2)==(a-i**5)**0.2:
      print(i,int((-1)*(a-i**5)**0.2))
      sys.exit()
  else:
    if int((-a+i**5)**0.2)==(-a+i**5)**0.2:
      print(i,int((-a+i**5)**0.2))
      sys.exit()
  i+=1
while t:
  if i**5-j**5>a:
    j+=1
  elif i**5-j**5<a:
    i+=1
  else:
    print(i,j)
    sys.exit()

### FIXED CODE ###

import sys
a=int(input())
for i in range(151):
  b=i**5-a
  c=abs(b)
  j=0
  while j**5<=c:
    if j**5==c:
      if b>=0:
        print(i,j)
        sys.exit()
      else:
        print(i,-j)
        sys.exit()
    j+=1
### BUGGY CODE ###

s = list(input().rstrip())
n = len(s)
m = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    c = -1 if s[i] == '?' else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
        for j in range(13):
            dp[i + 1][j] %= m
print(dp[n][5])


### FIXED CODE ###

s = list(input().rstrip())
n = len(s)
m = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    c = -1 if s[i] == '?' else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
        for j in range(13):
            dp[i + 1][j] %= m
print(dp[n][5])
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for j in range(N):
    if (A[j] != max(A)):
        print(max(A))
    elif(A.count(A[i]) > 1):
        print(A[i])
    else:
        print(sorted(A)[-2])

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
maxA = max(A)
secondA = sorted(A)[-2]
for j in range(N):
    if (A[j] != maxA):
        print(maxA)
    else:
        print(secondA)