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

n,k=map(int,input().split())
arr=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(arr[1]-arr[0])
for i in range(2,n):
	mn=99999999999999
	for j in range(1,k+1):
		if i-j>=0 and mn>dp[i-j]+abs(arr[i]-arr[i-j]):
			mn=dp[i-j]+abs(arr[i]-arr[i-j])
	dp[i]=mn
# print(dp)
print(dp[n-1])


### FIXED CODE ###

n,k=map(int,input().split())
arr=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(arr[1]-arr[0])
for i in range(2,n):
	mn=99999999999999
	for j in range(1,k+1):
		if i-j>=0 and mn>dp[i-j]+abs(arr[i]-arr[i-j]):
			mn=dp[i-j]+abs(arr[i]-arr[i-j])
	dp[i]=mn
# print(dp)
print(dp[n-1])
### BUGGY CODE ###

import copy
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    xi = copy.deepcopy(x)
    xi.pop(i)
    xi = sorted(xi,reverse=True)
    print(xi[(n-2)//2])

### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
x_sort = sorted(x)
med_l = x_sort[n//2-1]
med_r = x_sort[n//2]
for i in range(n):
    x[i]
    if x[i] <= med_l:
        print(med_r)
    else:
        print(med_l)
### BUGGY CODE ###

n = int(input())

def fac(n):
    arr = []
    temp = n
    a = 1
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    
    for i in arr:
        a = a * (i[1] + 1)
    return a * n


ans = 0
for i in range(1, n+1):
    ans += fac(i)
print(ans - 1)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n + 1):
    y = n // i
    ans += y * (y + 1) * i // 2
print(ans)
### BUGGY CODE ###

A,B,K=map(int,input().split())
L=list(i for i in range(A,B+1))
for i in range(B-A+1):
    if L[i] in L[:K] or L[i] in L[-K:]:
        print(L[i])

### FIXED CODE ###

a,b,k=map(int,input().split())
r1=[i for i in range(a,min(b+1,a+k))]
r2=[i for i in range(max(a,b-k+1),b+1)]
r1.extend(r2)
result=set(r1)
for i in sorted(result):
    print(i)
### BUGGY CODE ###

N, M = map(int, input().split())
friend = [0 for i in range(N)]
k = []

for i in range(M):
    A, B = map(int, input().split())
    x = min(A, B)
    y = max(A, B)
    if [x, y] not in k:
        friend[A-1] += 1
        friend[B-1] += 1
        k.append([x, y])

print(max(friend)+1)

### FIXED CODE ###

def find(n):
    if parent[n] < 0:
        return n
    else:
        parent[n] = find(parent[n])
        return parent[n]


def union(x, y):
    root_x = find(x)
    root_y = find(y)
    if root_x == root_y:
        return
    if parent[root_x] > parent[root_y]:
        root_x, root_y = root_y, root_x
    parent[root_x] += parent[root_y]
    parent[root_y] = root_x


def get_size(x):
    return -parent[find(x)]


n, m = map(int, input().split())
parent = [-1 for _ in range(n)]

for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    union(a, b)
ans = 0
for i in range(n):
    ans = max(ans, get_size(i))
print(ans)
### BUGGY CODE ###

S = input()
s = len(S)
ans = 0
for i in range(0, s-3):
  for j in range(i+3, s+1):
    if int(S[i:j]) % 2019 == 0:
      ans += 1
print(ans)
     


### FIXED CODE ###

S = input()
amari = [0]*2019
ans = 0
amari[0] = 1
A = 0
for i in range(len(S)):
    A += pow(10, i, 2019)*(int(S[len(S)-1-i]))
    amari[A % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(int(ans))
### BUGGY CODE ###

numbers =input().rstrip().split(" ")
prices=input().rstrip().split(" ")
noa =int(numbers[0])
noc =int(numbers[1])
for i in range(noa):
  prices[i] =int(prices[i])
#sort max//2を求めてからsort repeat
#loop content
prices=sorted(prices ,reverse=True)
#print(prices)
for i in range(noc):
  prices[0]=prices[0]//2
  prices=sorted(prices ,reverse=True)
#print(prices)
answer=0
for i in range(noa):
  answer=answer+prices[i]
print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
#from math import floor, ceil
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7

n,m=MI()
As=LI()
for i in range(n):
    As[i]*=-1
    
#print(As)

heapify(As)
for i in range(m):
    mn=heappop(As)
    mn=(abs(mn)//2)*(-1)
    heappush(As,mn)

print(-sum(As))
### BUGGY CODE ###

from statistics import mode
import copy
N = int(input())
v = list(map(int,input().split()))
values = list(set(v))
d = {}
for i in range(len(values)):
    number  = v.count(values[i])
    d[values[i]] = number
d  = sorted(d.items(), key=lambda x: x[1],reverse=True)

most_common = d[0][0]
#v_ = [i for i in v if i != most_common]
try:
    second_common = d[1][0]
except:
    second_common = most_common + 1
#print(v)
vv = copy.deepcopy(v)
cnt = 0
for j in range(N):
    if j % 2 != 0:
        if v[j] != most_common:
            v[j] = most_common
            cnt += 1
    else:
        if v[j] != second_common:
            v[j] = second_common
            cnt += 1
ccnt = 0
for j in range(N):
    if j % 2 != 0:
        if vv[j] != second_common:
            vv[j] = second_common
            ccnt += 1
    else:
        if vv[j] != most_common:
            vv[j] = most_common
            ccnt += 1
#print(v,cnt)
#print(vv,ccnt)
print(min(cnt,ccnt))

### FIXED CODE ###

from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = Counter(v[::2]).most_common()
o.append((0,0))
e = Counter(v[1::2]).most_common()
e.append((0,0))
if o[0][0] == e[0][0]:
    ans = min(n - o[0][1] - e[1][1], n - o[1][1] - e[0][1])
else:
    ans = n - o[0][1] - e[0][1]
print(ans)
### BUGGY CODE ###

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

MOD = 10**9+7
fact = [1 for i in range(N*M+1)]
for i in range(2, N*M+1):
    fact[i] = fact[i-1] * i

def comb(n, r):
    return fact[n] // fact[n-r] // fact[r]

p = comb(N*M-2, K-2)
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        #print(i, j, calc_rec_num(N, M, 0, 0, i, j))
        cnt = (N-i) * (M-j)
        if i != 0 and j != 0:
            cnt *= 2
        ans += d * cnt
        #if ans > DIV:
        #    ans %= DIV
        #print(ans)

print((ans*p)%MOD)


### FIXED CODE ###

from math import factorial
N, M, K = map(int, input().split())

MOD = 10**9+7

fact = [1] * (N*M+1)
for i in range(2, N*M+1):
    fact[i] = fact[i-1] * i % MOD

def comb(n, r):
    r = n-r if n-r < r else r
    return fact[n] * pow(fact[r], MOD-2, MOD) * pow(fact[n-r], MOD-2, MOD) % MOD

p = comb(N*M-2, K-2)
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        cnt = (N-i) * (M-j)
        if i != 0 and j != 0:
            cnt *= 2
        ans += d * cnt % MOD
ans = ans * p % MOD

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

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

A_list = []
for a in A:
  A_list.append(a)
  A_list.append(a+1)
  A_list.append(a-1)

A_unique = list(set(A_list))
A_dict = {}

for a_unique in A_unique:
  count = 0
  for a in A:
    if a_unique == a or a_unique == (a-1) or a_unique == (a+1):
      count +=1
  A_dict[a_unique] = count

ans = max(A_dict.values())
print(ans)


### FIXED CODE ###

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

A_dict = {}
for a in A:
  A_dict[a] = A_dict.get(a,0) + 1
  A_dict[a+1] = A_dict.get(a+1,0) + 1
  A_dict[a-1] = A_dict.get(a-1,0) + 1

ans = max(A_dict.values())
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
count = 0
for i in range(1,n+1):
  flag = True
  for j in range(m):
    if not lr[j][0] <= i <= lr[j][1]:
      flag = False
      break
  if flag:
    count += 1
print(count)
  
      
      
      
      
           
  

### FIXED CODE ###

n, m = map(int, input().split())
lll = []
rrr = []
for _ in range(m):
  lr = list(map(int, input().split()))
  lll.append(lr[0])
  rrr.append(lr[1])
maxl = max(lll)
minr = min(rrr)
count = 0
for i in range(1,n+1):
  if maxl <= i <= minr:
    count += 1
print(count)
### BUGGY CODE ###

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

jumps = []
for i in range(K):
    l, r = map(int, input().split())
    jumps += list(range(l, r + 1))

a = [0] * (N + 1)

a[1] = 1
for i in range(2, N + 1):
    for j in jumps:
        if i > j:
            a[i] = (a[i] + a[i - j]) % m
print(a[N])


### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353


@njit((i8, i8[:]), cache=True)
def main(N, LR):
    L, R = LR[::2], LR[1::2]
    K = len(L)
    F = np.zeros(N + 10, np.int64)
    F[0] = 1
    for n in range(1, N + 10):
        F[n] += F[n - 1]
        for k in range(K):
            l, r = L[k], R[k] + 1
            if n - l >= 0:
                F[n] += F[n - l]
            if n - r >= 0:
                F[n] -= F[n - r]
        F[n] %= MOD
    ans = F[N - 1] - F[N - 2]
    return ans % MOD


N, K = map(int, readline().split())
LR = np.array(read().split(), np.int64)

print(main(N, LR))
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = 1
for i in range(n):
    cnt*=a[i]
    if i>=k:
        m = cnt//a[i]
        cnt//=a[i-k]
        if cnt>m: print('Yes')
        else: print('No')

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    if i>=k:
      if a[i]>a[i-k]: print('Yes')
      else: print('No')
### BUGGY CODE ###

import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
n=int(input())
a=1
for i in range(1,n+1):
	a=a*i
	
print(a%1000000007)

### FIXED CODE ###

import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
n=int(input())
a=1
for i in range(1,n+1):
	a=a*i%1000000007
	
print(a)
### BUGGY CODE ###

from collections import Counter, defaultdict

s = input()
ls = []
for i in range(1, len(s)+1):
    ls.append(int(s[len(s)-i:]))

a = defaultdict(int)
a[0] += 1
for i in range(len(s)):
    a[ls[i]%2019] += 1

def comb(a):
    return a*(a-1)//2

ans = 0
for x in a.values():
    ans += comb(x)
print(ans)

### FIXED CODE ###

from collections import Counter, defaultdict
a = defaultdict(int)
a[0] += 1
s = input()[::-1]
cur = 0
for i, x in enumerate(s):
    cur += (int(x)*pow(10, i, 2019))%2019
    cur %= 2019
    a[cur] += 1

def comb(a):
    return a*(a-1)//2

ans = 0
for x in a.values():
    if x >= 2:
        ans += comb(x)
print(ans)
### BUGGY CODE ###

import array

def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    rcount = 0
    merged = array.array('i', [])  # List is too slow, so use array instead
    len_left = len(left)
    len_right = len(right)
    while lpos < len_left and rpos < len_right:
        if left[lpos] < right[rpos]:
            merged.append(left[lpos])
            lpos += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += len(left[lpos:])
    
    if left[lpos:]:
        merged.extend(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
    
    return merged, rcount
    
if __name__ == '__main__':
    n = int(raw_input())
    A = array.array('i', map(int, raw_input().split()))
    
    sorted, count = merge_sort(A)
    #print ' '.join(str(x) for x in sorted)
    print count

### FIXED CODE ###

from array import array

def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    rcount = 0
    merged = array('I', [])  # List is too slow. Use an array instead.
    len_left = len(left)
    len_right = len(right)
    while lpos < len_left and rpos < len_right:
        if left[lpos] < right[rpos]:
            merged.append(left[lpos])
            lpos += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            #rcount += len(left[lpos:])
            rcount += len_left - lpos
    
    if left[lpos:]:
        merged.extend(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
    
    return merged, rcount
    
if __name__ == '__main__':
    n = int(raw_input())
    A = array('I', map(int, raw_input().split()))
    
    sorted, count = merge_sort(A)
    #print ' '.join(str(x) for x in sorted)
    print count
### BUGGY CODE ###

n, W = map(int, input().split())
dp = [W + 1] * (1010 * (n + 1))

dp[0] = 0
v_max = 0
for i in range(n):
    w, v = map(int, input().split())
    v_max += v
    for j in range(v_max, v - 1, -1):
        dp[j] = min(dp[j - v] + w, dp[j])

ans = 0
for i in range(v_max, -1, -1):
    if dp[i] <= W:
        ans = max(ans, i)
print(ans)

### FIXED CODE ###

n, W = map(int, input().split())
dp = [W + 1] * (1010 * (n + 1))

dp[0] = 0
v_max = 0
for i in range(n):
    w, v = map(int, input().split())
    v_max += v
    for j in range(v_max, v - 1, -1):
        dp[j] = min(dp[j - v] + w, dp[j])

ans = 0
for i in range(v_max, -1, -1):
    if dp[i] <= W:
        ans = max(ans, i)
print(ans)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def main():
  s = input().strip()
  p = 13
  dp = [[0]*p for _ in range(len(s))]
  if s[-1] == '?':
    dp[0][:10] = [1] * 10
  else:
    dp[0][int(s[-1])] = 1
  for i, c in enumerate(s[::-1][1:], 1):
    if c == '?':
      for c in range(10):
        for j in range(p):
          dp[i][(int(c) * (10 ** i) + j) % p] += (dp[i-1][j] % MAX)
    else:
      for j in range(p):
        dp[i][(int(c) * (10 ** i) + j) % p] += (dp[i-1][j] % MAX) 
  print(dp[-1][5] % MAX)
  
if __name__=='__main__':
  main()



### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def main():
  s = input().strip()
  p = 13
  dp = [[0]*p for _ in range(len(s))]
  remains = [[0]*p for _ in range(6)]
  for i in range(6):
    for j in range(p):
      remains[i][j] = ((10 ** i) * j) % p
    
  if s[-1] == '?':
    dp[0][:10] = [1] * 10
  else:
    dp[0][int(s[-1])] = 1
    
  for i, c in enumerate(s[::-1][1:], 1):
    if c == '?':
      for c in range(10):
        for j in range(p):
          dp[i][(remains[i%6][c] + j) % p] += (dp[i-1][j] % MAX) 
    else:
      c = int(c)
      for j in range(p):
        dp[i][(remains[i%6][c] + j) % p] += (dp[i-1][j] % MAX) 
        
  print(dp[-1][5] % MAX)
  
if __name__=='__main__':
  main()
### BUGGY CODE ###

N, M = map(int,input().split())
ferris = [list(map(int, input().split())) for i in range(M)]

f1 =[]
fN = []
flag = 0

for f in ferris:
    if f[0]==1:
        f1.append(f)
    if f[1]==N:
        fN.append(f)

for f_1 in f1:
    if flag==0:
        for f_N in fN:
            if f_1[1]==f_N[0]:
                print('POSSIBLE')
                flag = 1
                break
            else:
                pass

if flag==0:
    print('IMPOSSIBLE')


### FIXED CODE ###

N, M = map(int, input().split())
ferry = [list(map(int, input().split())) for i in range(M)]

from_1 = [0 for i in range(N)]
to_N = [0 for i in range(N)]

for f in ferry:
    if f[0]==1:
        from_1[f[1]-1] = 1
    if f[1]==N:
        to_N[f[0]-1] = 1


flag = 0

for k in range(N):
    if from_1[k]==1 and to_N[k]==1:
        print('POSSIBLE')
        flag = 1
        break

if flag==0:
    print('IMPOSSIBLE')
### BUGGY CODE ###

#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=deque([0]*(n+1))
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=deque([1])
done=[0]*(n+1)
while h:
    a=h.popleft()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
counter.popleft()
print(*counter)

### FIXED CODE ###

#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])
### BUGGY CODE ###

import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
BC = []
for b in B:
    C2 = C[:]
    ok = bisect.bisect(C2,b)
    if ok!=N:
        bisect.insort(C2,b)
        for _ in range(N-ok):
            BC.append(C2[ok:])
for a in A:
    for bc in BC:
        if bisect.bisect(bc,a)==0:
            ans += 1
print(ans)

### FIXED CODE ###

import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    if ok_a!=0 and ok_c!=N:
        ans += ok_a*(N-ok_c)
print(ans)
### BUGGY CODE ###

import sys
from collections import defaultdict
K = int(input())
n = len(str(K))

r = 7 % K
# dict = defaultdict(bool)  # int/bool/list....
# dict[r] = True
orgr = r
d = 1
while r > 0:
    d += 1
    r = (10 * r + 7) % K
    # if dict[r]:
    if r == orgr:
        print(-1)
        sys.exit()

print(d)

### FIXED CODE ###

import sys
from collections import defaultdict
K = int(input())
n = len(str(K))

r = 7 % K
dict = defaultdict(bool)  # int/bool/list....
dict[r] = True
orgr = r
d = 1
for _ in range(K + 1):
    if r == 0:
        print(d)
        break
    d += 1
    r = (10 * r + 7) % K
    if dict[r]:
        print(-1)
        sys.exit()
    dict[r] = True
### BUGGY CODE ###

from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    return l[arg] < l[i] + l[j]

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n = INT()
l = sorted(LIST())

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += meguru_bisect(n, j) - j
print(ans)

### FIXED CODE ###

from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
l = sorted(LIST())

ans = 0
for i in range(n-2):
    right = i + 2
    for j in range(i+1, n-1):
        left = j + 1
        while right < n-1 and l[right] < l[i] + l[j]:
            right += 1
        ans += right - left
        if l[right] < l[i] + l[j]:
            ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1,n+1,2):
    i = list(str(i))
    if "1" not in i:
        if "2" not in i:
            if "3" in i:
                if "4" not in i:
                    if "5" in i:
                        if "6" not in i:
                            if "7" in i:
                                if "8" not in i:
                                    if "9" not in i:
                                        if "0" not in i:
                                            ans += 1
print(ans)

### FIXED CODE ###

import itertools
ans = 0
n = int(input())

for k in range(1,10):
    s = itertools.product(["3","5","7"], repeat=k)
    for seq in s:
        x = set()
        for i in seq:
            x.add(i)
        if len(x) != 3:
            continue
        t = "".join(seq)
        if 1 <= int(t) <= n:
            ans += 1
print(ans)
### BUGGY CODE ###

def main():
    from sys import stdin
    input = stdin.readline

    n = int(input())
    ab = [list(input().split()) for _ in [0]*(2*n)]
    ab = [(a, int(b)-1) for a, b in ab]
    dct = {(a, b): i for i, (a, b) in enumerate(ab)}

    dp = [[10**9]*(n+1) for _ in [0]*(n+1)]  # dp[i][j] = Bをi個、Wをj個置くための最小手数
    dp[0][0] = 0

    # 左i個にあるj以上のボールの数
    lb = [[0]*(n+1) for _ in [0]*(2*n)]
    lw = [[0]*(n+1) for _ in [0]*(2*n)]

    for j in range(n):
        cnt1, cnt2 = 0, 0
        for i, (a, b) in enumerate(ab):
            lb[i][j] = cnt1
            lw[i][j] = cnt2
            if a == "B":
                if b >= j:
                    cnt1 += 1
            else:
                if b >= j:
                    cnt2 += 1

    for i in range(n+1):
        try:
            t = dct[("B", i)]
        except:
            pass
        for j in range(n+1):
            d = dp[i][j]
            try:
                dp[i+1][j] = min(dp[i+1][j], d+lb[t][i]+lw[t][j])
            except:
                pass
            try:
                t2 = dct[("W", j)]
                dp[i][j+1] = min(dp[i][j+1], d+lb[t2][i]+lw[t2][j])
            except:
                pass
    print(dp[n][n])


main()


### FIXED CODE ###

def main():
    from sys import stdin
    input = stdin.readline

    n = int(input())
    ab = [list(input().split()) for _ in [0]*(2*n)]
    ab = [(a == "B", int(b)-1) for a, b in ab]
    dct_b = [0]*n
    dct_w = [0]*n
    for i, (a, b) in enumerate(ab):
        if a:
            dct_b[b] = i
        else:
            dct_w[b] = i

    dp = [[10**9]*(n+1) for _ in [0]*(n+1)]  # dp[i][j] = Bをi個、Wをj個置くための最小手数
    dp[0][0] = 0

    # 左i個にあるj以上のボールの数
    lb = [[0]*(n+1) for _ in [0]*(2*n)]
    lw = [[0]*(n+1) for _ in [0]*(2*n)]

    for j in range(n):
        cnt1, cnt2 = 0, 0
        for i, (a, b) in enumerate(ab):
            lb[i][j] = cnt1
            lw[i][j] = cnt2
            if a:
                if b >= j:
                    cnt1 += 1
            else:
                if b >= j:
                    cnt2 += 1

    dp = [[10**9]*(n+1) for _ in [0]*(n+1)]  # dp[i][j] = Bをi個、Wをj個置くための最小手数
    dp[0][0] = 0

    for i in range(n+1):
        dp1 = dp[i]
        if i < n:
            dp2 = dp[i+1]
            t = dct_b[i]
        for j in range(n+1):
            d = dp1[j]
            if i < n:
                dp2[j] = min(dp2[j], d+lb[t][i]+lw[t][j])
            if j < n:
                t2 = dct_w[j]
                dp1[j+1] = min(dp1[j+1], d+lb[t2][i]+lw[t2][j])
    print(dp[n][n])


main()
### BUGGY CODE ###

import copy
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    x = copy.copy(a)
    x.pop(i)
    print(max(x))

### FIXED CODE ###

import copy
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = copy.copy(a)
a.sort(reverse=True)
for i in range(n):
    if b[i] == a[0]:
        print(a[1])
    else:
        print(a[0])