Harryxun/stf_run huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1

a.sort()

b = a[n/2]

for i in range(n):
    a[i] = abs(a[i]-b)
print(sum(a))


### FIXED CODE ###

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

a.sort()

b = a[n//2]

for i in range(n):
    a[i] = abs(a[i]-b)
print(sum(a))
xyzk_, a_, b_, c_ = [input() for _ in range(4)]

x, y, z, k = [int(w) for w in xyzk_.split()]
a_nums = [int(n) for n in a_.split()]
b_nums = [int(n) for n in b_.split()]
c_nums = [int(n) for n in c_.split()]

a_nums.sort(reverse=True)
b_nums.sort(reverse=True)
c_nums.sort(reverse=True)

p, q, r = 0, 0, 0
now = a_nums[p] + b_nums[q] + c_nums[r]

for (p+1) * (q+1) * (r+1) < k:
    print(a_nums[p] + b_nums[q] + c_nums[r])
    if a_nums[p+1] >= max(b_nums[q+1], c_nums[r+1]):
        p += 1
    elif b_nums[q + 1] >= c_nums[r + 1]:
        q += 1
    else:
        r += 1

a_nums = a_nums[:p]
b_nums = b_nums[:q]
c_nums = c_nums[:r]

sums.sort(reverse=True)

sums = []
for a in a_nums:
    for b in b_nums:
        for c in c_nums:
            sums.append(a + b + c)

for n in sums[:k]:
    print(n)


### FIXED CODE ###

xyzk_, *nums_ = [input() for _ in range(4)]

*le, k = [int(w) for w in xyzk_.split()]
abc = [sorted((int(n) for n in w.split()), reverse=True) for w in nums_]

p = [0, 0, 0]
pool = [0, sum(abc[i][p[0]] for i in range(3))]
for _ in range(k):
    max_pool = max(pool)
    max_t = 0
    for i in range(3):
        if p[i] + 1 == le[i]:
            continue
        t = abc[i][p[i] + 1] + abc[(i + 1) % 3][0] + abc[(i + 2) % 3][0]
        if t > max_t:
            max_t = t
            max_3 = i
    if max_pool < max_t:
        p[max_3] = min(p[max_3] + 1, le[max_3] - 1)
        j, k = (max_3 + 1) % 3, (max_3 + 2) % 3
        for n1 in abc[j][:p[j] + 1]:
            for n2 in abc[k][:p[k] + 1]:
                pool.append(n1 + n2 + abc[max_3][p[max_3]])
    print(pool.pop(pool.index(max(pool))))
def get_order(numbers, originals):
    
    from math import factorial
    from copy import copy
    numbers = copy(numbers)
    originals = copy(originals)
    
    total = 0
    while numbers:
        number = numbers.pop(0)
        number_index = originals.index(number)
        originals.pop(number_index)
        count = (number_index ) * factorial(len(originals))
        total += count
    return total
        
def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def main(print=__builtins__.print):
    n = get_next_int()
    
    a = get_next_ints()
    b = get_next_ints()
    originals = list(map(int, range(n)))
    print(get_order(a, originals) - get_order(b, originals))

if __name__ == '__main__':
    main()
    

### FIXED CODE ###

def get_order(numbers, originals):
    
    from math import factorial
    from copy import copy
    numbers = copy(numbers)
    originals = copy(originals)
    
    total = 0
    while numbers:
        number = numbers.pop(0)
        number_index = originals.index(number)
        originals.pop(number_index)
        count = (number_index ) * factorial(len(originals))
        total += count
    return total
        
def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def main(print=__builtins__.print):
    n = get_next_int()
    
    a = list(get_next_ints())
    b = list(get_next_ints())
    originals = list(map(int, range(1, n+1)))
    print(abs(get_order(a, originals) - get_order(b, originals)))

if __name__ == '__main__':
    main()
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())

for i in range(N):
    ax, ay, ar, bx, by, br = map(float, input().split())

    between_center = math.hypot(ax - bx, ay - by)

    # ????????£????????????
    if between_center > ar + br:
        print(0)

    # ????????????????????¨
    else:
        # B in A
        if ar > between_center + br:
            print(2)

        # A in B
        elif br > between_center + ar:
            print(-2)

        else:
            print(1)

### FIXED CODE ###

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

import sys
import os


def max_seq(A):
    s = []
    s.append(A[0])
    for i in range(1, len(A)):
        v = max(A[i], A[i] + s[i-1])
        s.append(v)
    return max(s)

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    print(max_seq(A))
import math
a, b = int(input())
print(int(math.ceil((a+b)/2)))


### FIXED CODE ###

import math
a, b = map(int, input().split())
print(int(math.ceil((a+b)/2)))
d, n = map(int, input().split())

c = 100　** d

a = c * n

print(a)


### FIXED CODE ###

d, n = map(int, input().split())

c = pow(100, d)

if n  != 100:
    a = c * n
else:
    a = c * (n+1)

print(a)
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] >= p[i] and r[k] >= q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] > r[k]:
                countA += 1
                ans += p[i]
                i += 1
            elif q[j] > r[i]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]

    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y-(countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])

    return out


if __name__ == '__main__':
    # main()
    print(main())

### FIXED CODE ###

import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)

    p = p[:X]
    q = q[:Y]
    pqr = p + q + r
    pqr.sort(reverse = True)
    return sum(pqr[:X+Y])




if __name__ == '__main__':
    # main()
    print(main())
a = input().split(" ")
if a[0] < a[1] and a[1] < a[2]:
    print("Yes")
else:
    print("No")a = input().split(" ")
if a[0] < a[1] and a[1] < a[2]:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

a = input().split(" ")
if a[0] < a[1] and a[1] < a[2]:
    print("Yes")
else:
    print("No")
#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, N: int):
    # max_pos = 0
    # max_v = 0
    # for x in range(1, B):
    #     v = math.floor(A*x/B) - A*math.floor(x/B)
    #     if v > max_v:
    #         max_v = v
    #         max_pos = x
    #p = max([math.floor(A*x/B) - A*math.floor(x/B) for x in range(1, B+1)])

    print(max([math.floor(A*x/B) - A*math.floor(x/B) for x in range(1, min(B, N+1))]))

    #r = A % B
    #print(max([A//B * x + math.floor((r * x)/B) for x in range(1, min(B+1, N+1))]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()



### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, N: int):
    x = min(B-1, N)
    print(math.floor(A*x/B) - A*math.floor(x/B))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()
N = int(input())
A = list(map(int, input().split()))
a = A[int(N/2)]
b = A[int(n/2)+1]
print(b-a)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
a = A[int(N/2)-1]
b = A[int(N/2)]
print(b-a)
while True:
    s = input()
    if s == '_': 
        break

   m = int(input())
   for mi in range(m):
       h = int(input())
       s = s[:index] + s[:index]


   print(s)

### FIXED CODE ###

while True:
    s =input()
    if s =='-':   break
    loop=int(input())
    for i in range(loop):
        ch=int(input())
 
        s = s[ch:]+s[:ch]
    print(s)
A = int(input())
B = int(input())
C = int(input())
print(C, A, B)

### FIXED CODE ###

A,B,C= map(int,input().split())
print(C,A,B)
import math
import itertools as p
l = int(input())
r = int(input())
d = int(input())
count = 0
for i in range(l,r+1):
	if i%d == 0:
		count+=1
print(count)

### FIXED CODE ###

import math
import itertools as p
l,r,d = map(int,input().split())
count = 0
for i in range(l,r+1):
	if i%d == 0:
		count+=1
print(count)
a,b =map(int(),input().split())
if a>=10 b>10 :
  print("-1")
else :
  print(a*b)

### FIXED CODE ###

a,b=map(int,input().split())
if a>=10 or b>=10:
  print(-1)
else:
  print(a*b)
n,m = map(int,input().split())

v = [-1] * (n + 1)
x = [[] for _ in range(n + 1)]

for _ in range(m):
    a,b = map(int,input().split())
    x[a].append(b)

def dfs(i):
    if v[i] != -1:
        return v[i]

    rt = 0
    for node in x[i]:
        tmp = dfs(node) + 1
        if rt < tmp:
            rt = tmp

    #メモ化再帰
    v[i] = rt
    return rt

ans = 0

for k in range(1,n+1):
    tmp2 = dfs(k)

    if tmp2 > ans:
        ans = tmp2

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

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

v = [-1] * (n + 1)
x = [[] for _ in range(n + 1)]

for _ in range(m):
    a,b = map(int,input().split())
    x[a].append(b)

def dfs(i):
    if v[i] != -1:
        return v[i]

    rt = 0
    for node in x[i]:
        tmp = dfs(node) + 1
        if rt < tmp:
            rt = tmp

    #メモ化再帰
    v[i] = rt
    return rt

ans = 0

for k in range(1,n+1):
    tmp2 = dfs(k)

    if tmp2 > ans:
        ans = tmp2

print(ans)
if S[2] == S[3] and S[4] == S[5]:
  print("Yes")
else:
  print("No")
  

### FIXED CODE ###

S = input()

if S[2] == S[3] and S[4] == S[5]:
  print("Yes")
else:
  print("No")
*t,s=open(0).read().split()
n,k,r,s,p=map(int,t)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(s[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)

### FIXED CODE ###

*n,t=open(0).read().split()
n,k,r,s,p=map(int,n)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(t[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)
N, K = map(int,input().split())
hs = [int(i) for i in input().split()]

dp = [1000000]*N
dp[0] = 0
for i in range(1,N):
    min_ind = max(0, i-K)
    dp[i] = min(dp[i], dp[min_ind]+abs(hs[min_ind]-hs[i]))
    for k in range(1,K+1):
        dp[i] = min(dp[i], dp[i-k]+abs(hs[i-k]-hs[i]))

print(dp[-1])

### FIXED CODE ###

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

dp = [1000000]*N
dp[0] = 0
for i in range(1,N):
    # for k in range(K+1):
    x = max(0, i-K)
    # dp[i] = min(dp[i], dp[min_ind]+abs(hs[min_ind]-hs[i]))
    dp[i] = min([dpj + abs(hs[i] - hj) for hj, dpj in zip(hs[x:i], dp[x:i])])
# print(dp)
print(dp[-1])
s = input()
t = input()
ss = sorted(s)
tt = sorted(t)
print("Yes" if ss < tt[::-1] else "No")


### FIXED CODE ###

a,b =map(int,input().split())
print(-(-(a+b)//2))
from itertools import combinations
N = int(input())

X_Y = [0] * N

for i in range(N):
    X_Y[i] = tuple(map(int, input().split()))
    
combo = list(combinations(X_Y, 2))
diff = [0] * (len(combo))

for i, item in enumerate(combo):
    x_dif = item[0][0] - item[1][0]
    y_dif = item[0][1] - item[1][1]
    diff[i] = [x_dif, y_dif]

count_list = [0] * len(diff)
for k, d in enumerate(diff):
    p = d[0]
    q = d[1]
    count = 0
    for i in range(0, len(X_Y) - 1):
        if (X_Y[i][0] == X_Y[i + 1][0] + p) and X_Y[i][1] == X_Y[i + 1][1] + q:
            count += 0
        else:
            count += 1
    count_list[k] = count
print(min(count_list) + 1)

### FIXED CODE ###

from itertools import combinations
import sys

N = int(input()) 
X_Y = [0] * N

for i in range(N):
    X_Y[i] = tuple(map(int, input().split()))


if N == 1:
    print(1)
    sys.exit()

combo = list(combinations(X_Y, 2))
diff = [0] * (len(combo))

dict_diff = {}

for i, item in enumerate(combo):
    x_dif = item[0][0] - item[1][0]
    y_dif = item[0][1] - item[1][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1
    
    x_dif = item[1][0] - item[0][0]
    y_dif = item[1][1] - item[0][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1

print((N) - max(dict_diff.values()))
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
print(abs(A.index(map(int,input().split()))-A.index(map(int,input().split())))


### FIXED CODE ###

import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q)))
N, a, b = map(int, input().split())

sum = pow(2, N)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
X = 2 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, X + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ax = cmb(N, a, mod)
bx = cmb(N, b, mod)

print((sum - ax - bx - 1)%(10**9+7))

### FIXED CODE ###

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

MOD = 10**9+7

def modcmb(n, r, m):
    x = 1
    y = n
    for i in range(2,r+1):
        x *= i
        x %= MOD
        y *= n-i+1
        y %= MOD
    return y * pow(x, m-2, m) % m

ans = pow(2, N, MOD) - modcmb(N, a, MOD) - modcmb(N, b, MOD) - 1
print(ans % MOD)
A, B, C, D = map(int, input().split())

a = "%d+%d+%d+%d=7" % (A, B, C, D)
b = "%d+%d+%d-%d=7" % (A, B, C, D)
c = "%d+%d-%d+%d=7" % (A, B, C, D)
d = "%d-%d+%d+%d=7" % (A, B, C, D)
e = "%d+%d+%d+%d=7" % (A, B, C, D)
f = "%d-%d+%d-%d=7" % (A, B, C, D)
g = "%d-%d-%d+%d=7" % (A, B, C, D)
h = "%d-%d-%d-%d=7" % (A, B, C, D)

if A + B + C + D == 7:
    print(a)
elif A + B + C - D == 7:
    print(b)
elif A + B - C + D == 7:
    print(c)
elif A - B + C + D == 7:
    print(d)
elif A + B - C - D == 7:
    print(e)
elif A - B + C - D == 7:
    print(f)
elif A - B - C + D == 7:
    print(g)
elif A - B - C - D == 7:
    print(h)



### FIXED CODE ###

inp = str(input())

A = int(inp[0])
B = int(inp[1])
C = int(inp[2])
D = int(inp[3])

a = "%d+%d+%d+%d=7" % (A, B, C, D)
b = "%d+%d+%d-%d=7" % (A, B, C, D)
c = "%d+%d-%d+%d=7" % (A, B, C, D)
d = "%d-%d+%d+%d=7" % (A, B, C, D)
e = "%d+%d-%d-%d=7" % (A, B, C, D)
f = "%d-%d+%d-%d=7" % (A, B, C, D)
g = "%d-%d-%d+%d=7" % (A, B, C, D)
h = "%d-%d-%d-%d=7" % (A, B, C, D)

if A + B + C + D == 7:
    print(a)
elif A + B + C - D == 7:
    print(b)
elif A + B - C + D == 7:
    print(c)
elif A - B + C + D == 7:
    print(d)
elif A + B - C - D == 7:
    print(e)
elif A - B + C - D == 7:
    print(f)
elif A - B - C + D == 7:
    print(g)
elif A - B - C - D == 7:
    print(h)
L,R=map(int,input().split())

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)

ans=min(D)

print(ans)

### FIXED CODE ###

L,R=map(int,input().split())

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)
    ans=min(D)

print(ans)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
dishes = [a,b,c,d,e]
n = []
ans = 0
for i in range(5):
  if dishes[i]%10==0:
    ans += dishes[i]//10
  else:
    ans += dishes[i]//10+1
    n.append(dishes[i]%10)
if len(n)==0:
  print(ans*10)
else:
ans = ans*10-10+min(n)
print(ans)


### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
dishes = [a,b,c,d,e]
n = []
ans = 0
for i in range(5):
  if dishes[i]%10==0:
    ans += dishes[i]//10
  else:
    ans += dishes[i]//10+1
    n.append(dishes[i]%10)
if len(n)==0:
  print(ans*10)
else:
  ans = ans*10-10+min(n)
  print(ans)
print 2

### FIXED CODE ###

day = input()
if day == "SUN":
  print(7)
elif day=="MON":
  print(6)
elif day=="TUE":
  print(5)
elif day=="WED":
  print(4)
elif day=="THU":
  print(3)
elif day=="FRI":
  print(2)
elif day=="SAT":
  print(1)
#!/usr/bin/env python


N = input()
N = int(N)

A = []
A = input().split()
A = [int(n) for n in A]

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)

#print('N=',N)
#print('A=',A)
#print('B=',B)

monster = 0

for i in range(N+1) :
	if A[i] < B[i] :
		monster = monster + A[i]
		B[i+1] = B[i] - A[i]
	if A[i] >= B[i] :
		monster = monster + B[i]

print(monster)









### FIXED CODE ###

#!/usr/bin/env python

N = input()
N = int(N)

A = []
A = input().split()
A = [int(n) for n in A]
#A.append(0)

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
#B.append(0)

#print('N=',n)
#print('A=',A)
#print('B=',B)

monster = 0

for i in range(N) :
	if A[i] < B[i] :
		monster = monster + A[i]
		B[i] = B[i] - A[i]
		if A[i+1] < B[i] :
			monster = monster + A[i+1]
			A[i+1] = 0
		elif A[i+1] >= B[i] :
			monster = monster + B[i]
			A[i+1] = A[i+1] - B[i]
	elif A[i] >= B[i] :
		monster = monster + B[i]

print(monster)
n=int(input())
n=3**n
a=list(map(int,input().split()))

a=[2 if i%2==0 for i in a else 1]

cnt=1

for i in a:
  cnt*=i
  
  
print(n-cnt)


### FIXED CODE ###

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

a=[2 if i%2==0 else 1 for i in a]

cnt=1

for i in a:
  cnt*=i
  
  
print(n-cnt)
N = int(input())

def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors



facts = factorize(N)
fs = set(facts)

from collections import Counter
fc = Counter(facts)
divisiors = sorted(make_divisors(N))
fms = max([v for k,v in fc.items()])
fm = max(max(facts), fms) 
ans = 0

# print(facts)
# print(divisiors)
done = set()

for d in divisiors:
    if d == 1:
        continue
    if N % d == 0:
        N //= d
        ans += 1

print(ans)



### FIXED CODE ###

N = int(input())

def factorize(n):
     a = []
     # 2で割り切れるまでnを割り続ける
     while n % 2 == 0:
         a.append(2)
         n //= 2
     f = 3
     # 3からはじめて各奇数で割り切れるまでnを割り続ける
     # nの最大約数は√nなので、f*fで計算
     while f * f <= n:
         if n % f == 0:
             a.append(f)
             n //= f
         else:
             f += 2
     if n != 1:
         a.append(n)
     return a
    
fs = factorize(N)

from collections import Counter
fc = Counter(fs)

ans = 0
i = 1
for k, v in fc.items():
    # print(k, v)
    k2, v2 = k,v
    while v2 >= i:
        # print(k, v, i)
        ans += 1
        v2 -= i  
        i += 1
    i = 1

print(ans)
from math import factorial

modulo = 10 ** 9 + 7

N, K = map(int, input().split())
adj = {a: [] for a in range(1, N + 1)}
for i in range(N - 1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)

def P(n, k):
    return factorial(n) // factorial(n - k) if n >= k else 0

visited = set()

def ncoloring(root, d):
    """the number of coloring of a subtree at depth d
       when the color of the root has been decided."""
    visited.add(root)
    children = [s for s in adj[root] if s not in visited]
    remainingcolors = K - 2 if d > 0 else K - 1

    # coloring of the children
    p = P(remainingcolors, len(children)) % modulo

    # coloring of the subtrees
    for c in children:
        p = p * ncoloring(c, d + 1) % modulo
    return p

print(ncoloring(1, 0) * K % modulo)

### FIXED CODE ###

from collections import deque

modulo = 10 ** 9 + 7

N, K = map(int, input().split())
adj = {a: [] for a in range(1, N + 1)}
for i in range(N - 1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)

def P(n, k):
    if n < k:
        return 0
    f = 1
    for i in range(n, n - k, -1):
        f = f * i % modulo
    return f

visited = set()
q = deque([1])
ncoloring = K  # num of coloring of the root

while len(q) > 0:
    u = q.popleft()
    visited.add(u)

    # coloring of the children
    children = [c for c in adj[u] if c not in visited]
    ncoloring *= P(K - 1 if u == 1 else K - 2, len(children))
    ncoloring %= modulo

    q.extend([c for c in children])

print(ncoloring)
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)

### FIXED CODE ###

n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)