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

import sys
input = sys.stdin.readline
n = int(input())
A = []
for i in range(n):
    rs = list(map(int, input().split()))
    rs = [r-1 for r in rs]
    A.append(rs)

cnts = [0] * n
days = 1
while True:
    tekis = []
    # print("Day",days, cnts)
    fin = 0
    for cnt,a in zip(cnts, A):
        if cnt == n-1: 
            tekis.append(-1)
            fin += 1
        else: 
            tekis.append(a[cnt])
    if fin == n: 
        print(days-1)
        exit()
    # 敵の敵が自分だったらマッチング成立
    flg = False
    matched = [False] * n
    for i,teki in enumerate(tekis):
        if matched[teki] or teki==-1:continue
        if tekis[teki] == i:
            cnts[i] += 1
            matched[i] = True
            cnts[teki] += 1
            matched[teki] = True
            flg = True
            # print("{}vs{}".format(i,teki))
    # マッチングが一つも成立しない
    if not flg or days > 1000*1001//2:
        print(-1)
        exit()
    days += 1

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict, deque
n = int(input())
X = 10000
INF = 1 << 50
edges = defaultdict(list)
edges_r = defaultdict(list)
def topological_sort(G):

    cnt_in = defaultdict(int)
    for k in G.keys():
        for v in G[k]:
            cnt_in[v] += 1
    # print(cnt_in)
    res = []
    # 入次数==0
    q = deque([i for i in list(G.keys()) if cnt_in[i]==0])
    while len(q) > 0:
        v = q.popleft()
        res.append(v)
        for next_v in G[v]:
            # 入次数を下げていく
            cnt_in[next_v] -= 1
            # 入次数が0に残ったところを次に追加
            if cnt_in[next_v] == 0:
                q.append(next_v)
    # トポソ不可能！
    if len(G) != len(res):
        print(-1)
        exit()
    return res

for i in range(n):
    r = list(map(int, input().split()))
    # 初期
    mn = min(i, r[0]-1)
    mx = max(i, r[0]-1)
    prev = mn * n + mx
    for e in r[1:]:
        e -= 1
        mn = min(i,e)
        mx = max(i,e)
        now = mn*n+mx
        edges[prev].append(now)
        edges_r[now].append(prev)
        prev = now
vs = topological_sort(edges)

# トポソの順番で経路長を入れていく
used = [0] * n**2
# for V in vs:
#     if used[V]: continue
#     used[V] = 1
#     q = deque([V])
#     while len(q) > 0:
#         v = q.popleft()
#         for u in edges[v]: 
#             if used[u] <= used[v]:
#                 q.append(u)
#                 used[u] = max(used[u], used[v] + 1)

for V in vs:
    if used[V]:continue
    used[V] = 1
    mx = 1
    for b in edges_r[V]:
        mx = max(mx, used[b]+1)
    used[V] = mx
# print(used)
print(max(used))
### BUGGY CODE ###

from sys import stdin
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = "@"
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        ccnt = data[2]
        if data[1] == "1":
            if cnt % 2 == 0:
                s = "".join([ccnt,s])
            else:
                s = "".join([s,ccnt])  
        else:
            if cnt % 2 == 0:
                s = "".join([s,ccnt])
            else:
                s = "".join([ccnt,s])
    else:
        cnt += 1
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)

### FIXED CODE ###

from sys import stdin
from collections import deque
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = deque(["@"])
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        if data[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(data[2])
            else:
                s.append(data[2])
        else:
            if cnt % 2 == 0:
                s.append(data[2])
            else:
                s.appendleft(data[2])
    else:
        cnt += 1
s = "".join(s)
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)
### 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):
        if len(S)-i+1 < num_length:
            break
        for j in range(i + 3, len(S)):
            if j-i+1 > num_length:
                break
            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 ###

import itertools

n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
mod=10**9+7

dp=[0]*(2**n)
dp[0]=1
visited=[False]*(2**n)
visited[0]=True

for i in range(1,n+1):
    for lst in itertools.permutations(['1']*i+['0']*(n-i),n):
        lst2=''.join(lst)
        if visited[int(lst2,base=2)]:
          continue
        visited[int(lst2,base=2)]=True

        for j in range(n):
            if lst[-j-1]=='1':
                if a[i-1][j]==1:
                    dp[int(lst2,base=2)]+=dp[int(lst2,base=2)-2**j]
                    dp[int(lst2,base=2)]%=mod



print(dp[-1])

### FIXED CODE ###

n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
mod=10**9+7

dp=[0]*(2**n)
dp[0]=1

for i in range(1,2**n):
    x=bin(i)[2:]
    y=x.count('1')
    for j in range(len(x)):
      if x[-j-1]=='1':
        if a[y-1][j]==1:
            dp[i]+=dp[i-(2**j)]
            dp[i]%=mod


print(dp[-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
o = []

for i in range(n):
  o.append(a.index(i + 1) + 1)

print(" ".join(str(e) for e in o))


### FIXED CODE ###

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

o = sorted(range(len(a)), key=lambda k: a[k])

print(" ".join(str(e+1) for e in o))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
 
n,k = map(int, input().split())
 
################
p = 10**9 + 7
def comb(n,k,p):
  ans = 1
  for i in range(1,k+1):
    ans = ans * (n - (i-1)) % p
    ans = ans * pow(i, p-2, p)
  return ans
################
 
if k >= n:
  ans = comb(2*n-1, n, p) % p
else:
  ans = 0
  for i in range(0,k+1):
    temp = (comb(n-1, i, p) % p) * (comb(n, i, p) % p) % p
    ans = (ans + temp) % p
    
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

MOD = 10**9 +7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret *= kaijo(n)
  ret %= MOD;
  ret *= gyaku_kaijo(r)
  ret %= MOD;
  ret *= gyaku_kaijo(n-r)
  ret %= MOD;
  return ret




 
n,k = map(int, input().split())
 
################
#p = 10**9 + 7
#def comb(n,k,p):
#  ans = 1
#  for i in range(1,k+1):
#    ans = ans * (n - (i-1)) % p
#    ans = ans * pow(i, p-2, p)
#  return ans
################
 
if k >= n:
  ans = nCr(2*n-1, n) % MOD
else:
  ans = 0
  for i in range(0,k+1):
    temp = (nCr(n-1, i) % MOD) * (nCr(n, i) % MOD) % MOD
    ans = (ans + temp) % MOD
    
print(ans)
### BUGGY CODE ###

n = int(input())
p = [int(s) for s in input().split()]
count = 0
for a in range(n):
     i = p[a]
     s = p[0:(a+1)]
     if min(s)>=i:
         count+=1
print(count)

### FIXED CODE ###

n = int(input())
p = [int(s) for s in input().split()]
count = 0
M = p[0]
for a in range(n):
     i = p[a]
     if M >=i :
          count+=1
          M = i
print(count)
### BUGGY CODE ###

N = int(input())
A = [list(map(int, input().split())) for n in range(N)]
P = [0] * N


def get_num(i):
    return A[i][P[i]] - 1


def update(mem, K):
    for i in mem:
        P[i] += 1
        if P[i] == N - 1:
            K.remove(i)


def f():
    K = {i for i in range(N)}
    mem = set()
    for t in range(N * (N - 1) // 2 + 1):
        if len(K) == 0:
            return t

        for i in K:
            if i in mem:
                continue

            j = get_num(i)
            if j in mem:
                continue

            if i == get_num(j):
                mem.add(i)
                mem.add(j)

        if len(mem) == 0:
            return -1

        update(mem, K)
        mem = set()

    return -2

print(f())


### FIXED CODE ###

N = int(input())
A = [list(map(int, input().split())) for n in range(N)]
P = [0] * N


def get_num(i):
    return A[i][P[i]] - 1


def update(mem, K):
    for i in mem:
        P[i] += 1
        if P[i] == N - 1:
            K.remove(i)


def f():
    K = {i for i in range(N)}
    L = {i for i in range(N)}
    mem = set()
    for t in range(N * (N - 1) // 2 + 1):
        if len(K) == 0:
            return t

        for i in L:
            if i in mem:
                continue

            j = get_num(i)
            if j in mem:
                continue

            if i == get_num(j):
                mem.add(i)
                mem.add(j)

        if len(mem) == 0:
            return -1
        update(mem, K)
        L = K & mem
        mem.clear()

    return -2

print(f())
### BUGGY CODE ###

import math
import numpy as np
import itertools

N = int(input())
prime_factor = []
for i in range(2,int(math.sqrt(N))+1):
  while N%i == 0:
    prime_factor.append(i)
    N/=i
    
if N > 1:
  prime_factor.append(N)
  prime_factor.append(1)

  
prime_factor = np.array(prime_factor)
prime_len = len(prime_factor) // 2
comb = set(range(0,len(prime_factor)))

min_root = -1

for i in range(1,(prime_len+1)):
  for sets in itertools.combinations(list(comb),i):
    sets = set(sets)
    sets_c = comb - sets
    min_cand = prime_factor[list(sets)].prod() + prime_factor[list(sets_c)].prod()
    if min_cand < min_root or min_root < 0:
      min_root = min_cand
      
print(int(min_root - 2))

### FIXED CODE ###

import math
 
N = int(input())
 
min_cand = 10**12
 
for i in range(1,(int(math.sqrt(N))+1)):
  if N % i == 0 and min_cand > (i + (N // i)):
    min_cand = (i + (N // i))
    
print(min_cand - 2)
### BUGGY CODE ###

import numpy as np

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] >= tmax:
        tmax = t[i]

c_timeline = np.array([[0 for _ in range(C)] for _ in range(2*tmax + 1)])
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i]-1
    for j in range(2*S-1, 2*T+1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = np.sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

### FIXED CODE ###

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)
### BUGGY CODE ###

n = int(input())
l = []
for i in range(n):
    x = input()
    if x not in l:
        l.append(x)
print(len(l))

### FIXED CODE ###

n = int(input())
l = []
for i in range(n):
    x = input()
    l.append(x)
ans = n
l.sort()
for i in range(1,n):
    if l[i] == l[i-1]:
        ans -= 1
print(ans)
### BUGGY CODE ###

import sys
from math import gcd
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。
    計算量は「調和級数」になるのがミソ。具体的には
        N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N)
                                       = N * loglog(√N) (素数の逆数和の発散スピードがこれ)
                                       = N(loglogN - log2)
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return [0] * (n + 1)
    prime = [1] * (n + 1)
    prime[0] = prime[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not prime[i]: continue
        for j in range(i * 2, n + 1, i):
            prime[j] = 0
    return prime


def main():
    N = int(input())
    A = list(map(int, input().split()))
    all_gcd = A[0]
    for a in A:
        all_gcd = gcd(all_gcd, a)
    if all_gcd != 1:
        print("not coprime")
        return

    prod = A[0]
    for i, a in enumerate(A):
        if i == 0: continue
        if gcd(prod, a) != 1:
            print("setwise coprime")
            return
        prod *= a
    print("pairwise coprime")




if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from math import gcd
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A =list(map(int, input().split()))

    all_gcd = A[0]
    max_num = A[0]
    for a in A:
        all_gcd = gcd(all_gcd, a)
        max_num = max(max_num, a)
    if all_gcd != 1:
        print("not coprime")
        return

    # エラトステネスの篩でprimes[i] = (iを割り切る最小の素数)を記録する
    min_prime = [i for i in range(max_num + 1)]
    for p in range(2, int(max_num**0.5) + 1):
        if min_prime[p] != p: continue
        for i in range(2, max_num // p + 1): min_prime[i * p] = p

    used = [0] * (max_num + 1)
    for a in A:
        while a > 1:
            p = min_prime[a]
            if used[p]:
                print("setwise coprime")
                return
            while a % p == 0: a //= p
            used[p] = 1
    print("pairwise coprime")




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

X = int(input())
flag = 0
A = 0
B = 0
for a in range(100000):
    for b in range(100000):
        if (a-10)**5 - (b-10)**5 == X:
            flag = 1
            A = a-10
            B = b-10
            break
        else:
            pass
    if flag == 1:
        break

print(A,B)

### FIXED CODE ###

import time
X = int(input())
flag = 0
T_0 = time.time()

A = 0
B = 0
for a in range(2000):
    for b in range(2000):
        if (a-1000)**5 - (b-1000)**5 == X:
            flag = 1
            A = a-1000
            B = b-1000
            break
        else:
            pass
    if flag == 1:
        break
T_1 = time.time()

print(A,B)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
result=[1]
temp=1
i=0
while i<k or temp not in result:
  temp=a[temp-1]
  result.append(temp)
  i=i+1
result.append(temp)
l=len(result)
temp=result.index(result[l-1])
if k<l:
  print(result[k+1])
else:
  l2=l-1-temp
  print(result[temp+(k-temp)%l2])

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
result=[1]
temp=1
for i in range(n):
  temp=a[temp-1]
  result.append(temp)
temp=result.index(result[len(result)-1])
c=len(result)-temp-1
if k<n:
  print(result[k])
else:
  print(result[temp+(k-temp)%c])
### BUGGY CODE ###

a, b, c = map(int, input().split())
k = int(input())
while k:
    if not a < b:
        b *= 2
        k -= 1
        continue
    elif not b < c:
        c *= 2
        k -= 1


if a < b < c:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

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

while k:
    if not a < b:
        b *= 2
        k -= 1
        continue
    elif not b < c:
        c *= 2
        k -= 1
        continue
    else:
        break


if a < b < c:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

n, K = map(int, input().split())
As = list(map(int, input().split()))

# doubling
m = 0
while 2**m < K:
    m += 1
d = [[0] * n for i in range(m)]
for i in range(n):
    d[0][i] = As[i] - 1 

for k in range(m-1):
    for i in range(n):
        d[k+1][i] = d[k][d[k][i]]

now = 0
for k in range(m):
    if (K >> k) & 1:
        now = d[k][now]

print(now+1)


### FIXED CODE ###

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

visited = [-1] * n
cnt = 0
n = 0
while True:
    visited[n] = cnt
    nx = As[n] - 1
    cnt += 1
    # ループ入った場合
    if visited[nx] != -1:
        first = visited[nx]
        if k <= first:
            for i,v in enumerate(visited):
                if v == k:
                    print(i+1)
                    exit()    
        a = (k-first)%(cnt-first)
        loop = [v-first for v in visited]
        for i,x in enumerate(loop): 
            if x == a:
                print(i+1)
                exit()
        break
    n = nx
### BUGGY CODE ###

x = int(input())

# 素因数分解
def prime_factorization(n):
    prime = {}
    tmp = n
    for i in range(2, int(n**0.5)+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if i in prime:
                prime[i] += cnt
            else:
                prime[i] = cnt
    if tmp != 1:
        if tmp in prime:
            prime[tmp] += 1
        else:
            prime[tmp] = 1
    return prime

if x == 1:
    print(0, -1)
else:
    p = prime_factorization(x)
    m = min(p.keys())
    a = 0
    while True:
        b = a - m
        if a ** 5 - b ** 5 == x:
            print(a, b)
            break
        if a > 0:
            a = -a
        else:
            a = -a + 1


### FIXED CODE ###

x = int(input())

for a in range(-200, 200):
    for b in range(-200, 200):
        if a**5 - b**5 == x:
            print(a, b)
            exit()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  print(a[i:].count(i+1))


### FIXED CODE ###


n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(n-1):
  if a[i] in d:
    d[a[i]]+=1
  else:
    d[a[i]]=1

for i in range(1,n+1):
  if i in d:
    print(d[i])
  else:
    print(0)
### BUGGY CODE ###

N = int(raw_input())
X = map(int, raw_input().split())

for i in range(N):
    print(sorted(X[:i] + X[i+1:])[(N-1)/2])


### FIXED CODE ###

N = int(raw_input())
X = map(int, raw_input().split())

sortedX = sorted(X)
medSmall = sortedX[N/2-1]
medLarge = sortedX[N/2]

#print medSmall, medLarge

for i in range(N):
    if(X[i] <= medSmall):
        print(medLarge)
    else:
        print(medSmall)
### BUGGY CODE ###

n,m=map(int,input().split())
A=[]
for i in range(m):
    A.append(int(input()))

x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1

for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=x[j-1]+x[j-2]

print(x[n]%1000000007)

### FIXED CODE ###

n,m=map(int,input().split())
A=set(int(input()) for i in range(m))
 
x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1
 
for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=(x[j-1]+x[j-2])%(10**9+7)
        
 
print(x[n])
### BUGGY CODE ###

n=int(input())
a=input()
ans=0
def nanka(m,c):
  global a,n,ans
  b=c
  for i in range(n-m):
    if not a[i+m] in b:
      ans+=1
      b.append(a[i+m])
      if n>i+m+1:nanka(m+i+1,b)
      del b[len(b)-1]
nanka(0,[])
print(ans)

### FIXED CODE ###

from collections import Counter
n,s=int(input()),input();c=[s[i]for i in range(n)];a=Counter(c);ans=1
for i in a:ans*=a[i]+1
print((ans-1)%(10**9+7))
### BUGGY CODE ###

def main():
    s = input()
    t = list(reversed(list(input())))

    for T in t:
        if T not in s:
            print(-1)
            return

    for loop in range(10**100):
        for idx in range(len(s)):
            if s[idx] == t[-1]:
                t.pop()
                if len(t) == 0:
                    print(idx+1+loop*len(s))
                    return

    print(-1)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys


def main():
    t = input()
    s = input()

    appear_pos = {}  # 文字が出てくる場所
    for idx, T in enumerate(t):
        if T not in appear_pos:
            appear_pos[T] = [idx]
        else:
            appear_pos[T].append(idx)

    search_idx = {}
    for key in appear_pos.keys():
        search_idx[key] = -1

    loop_count = 0
    find_idx = -1
    for S in s:
        if S not in appear_pos:
            print(-1)
            sys.exit()

        while True:
            search_idx[S] += 1
            if len(appear_pos[S]) == search_idx[S]:
                # 次のループに移動する
                loop_count += 1
                for key in appear_pos.keys():
                    search_idx[key] = -1
                find_idx = appear_pos[S][0]
                break

            idx_new = appear_pos[S][search_idx[S]]
            if idx_new > find_idx:
                find_idx = idx_new
                break

    print(find_idx+loop_count*len(t)+1)


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

N = int(input())
numbers = []
for i in range(N):
    numbers.append(int(input()))
    
aaa = max(numbers)
    
for n in numbers:
    if aaa == n:
        print(sorted(numbers)[-2])
    else:
        print(aaa)

### FIXED CODE ###

N = int(input())
numbers = []
for i in range(N):
    numbers.append(int(input()))
    
    
aaa = max(numbers)
bbb = sorted(numbers)[-2]

for n in numbers:
    if aaa == n:
        print(bbb)
    else:
        print(aaa)
### BUGGY CODE ###

import numpy as np

N=int(input())
alist=list(map(int,input().split()))
arr=np.array(alist)

matrix=[]
for i in range(N-1):
  array=[0]*i + [1/2,1/2] + [0]*(N-i-2)
  matrix.append(array)
matrix.append([1/2]+[0]*(N-2)+[1/2])

#print(matrix)
mat = np.matrix(matrix)
#print(mat)
mat_rev=mat**-1
#print(mat_rev)

prod=np.dot(mat_rev,arr)
prod_list=prod.tolist()

prod_list_int=[]
for p in prod_list[0]:
  prod_list_int.append(str(int(p)))
  
#print(prod_list_int)
print(" ".join(prod_list_int))

### FIXED CODE ###

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

asum=sum(alist)
ans_list=[-1]*N

minus_even=sum(alist[1:N:2])
minus_odd=sum(alist[2:N:2])

for i in range(N//2):
  ans_list[2*i] = asum-2*minus_even
  ans_list[2*i+1] = asum-2*minus_odd
  
  minus_even += alist[(2*i+N)%N]-alist[(2*i+1)%N]
  minus_odd += alist[(2*i+N+1)%N]-alist[(2*i+2)%N]
  
ans_list[-1]=asum-2*minus_even
  
ans_list_str=map(str,ans_list)  
print(" ".join(ans_list_str))