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

import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))

### FIXED CODE ###

import numpy as np

N,K = map(int,input().split(' '))
a = np.array(list(map(int,input().split(' '))))

cost = np.full(N,10**9)
cost[0] = 0
for i in range(1 , N):
    
    size =  min(i,K)
    cost[i] = (np.abs(a[i] - a[i-size:i]) + cost[i-size:i]).min()

print(int(cost[-1]))
### BUGGY CODE ###

from collections import defaultdict
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = 10 ** 13

def bfs(graph, N, M):
    que = []
    que.append([0, 0])
    visited = [-INF for x in range(MAX_N)]
    update_cnt = [0 for x in range(MAX_N)]
    result = -INF
    while (len(que) > 0):
        now = que[0]
        que.pop(0)

        pos = now[0]
        cost = now[1]



        if (pos == N - 1):
            result = max(result, cost)
            if (update_cnt[N - 1] >= MAX_N):
                return (0, False)

        for val in graph[pos]:
            nxt = val[0]
            nxt_cost = val[1]
            if (cost + nxt_cost > visited[nxt]):
                visited[nxt] = cost + nxt_cost
                update_cnt[nxt] += 1
                que.append([nxt, nxt_cost + cost])

    if (update_cnt[N - 1] >= MAX_N):
        return (0, False)
    return (result, True)


if __name__ == "__main__":
    N, M = map(int, input().split())
    graph = defaultdict(list)
    for x in range(M):
        a,b,c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append([b, c])
    res,ok = bfs(graph, N, M)
    if (not ok):
        print ('inf')
    else:
        print (res)


### FIXED CODE ###


MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = 10 ** 13

def bfs(graph, N, M):
    que = []
    que.append([0, 0])
    visited = [-INF for x in range(MAX_N)]
    update_cnt = [0 for x in range(MAX_N)]
    result = -INF
    while (len(que) > 0):
        now = que[0]
        que.pop(0)

        pos = now[0]
        cost = now[1]
        if (visited[pos] > cost):
            continue
        for val in graph[pos]:
            nxt = val[0]
            nxt_cost = val[1]

            if (cost + nxt_cost > visited[nxt] and update_cnt[nxt] < MAX_M):
                visited[nxt] = cost + nxt_cost
                update_cnt[nxt] += 1
                que.append([nxt, nxt_cost + cost])

    if (update_cnt[N - 1] >= MAX_N):
        return (0, False)
    return (visited[N - 1], True)


if __name__ == "__main__":
    N, M = map(int, input().split())
    graph = [[] for x in range(MAX_N)]
    for x in range(M):
        a,b,c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append([b, c])
    res,ok = bfs(graph, N, M)
    if (not ok):
        print ('inf')
    else:
        print (res)
### BUGGY CODE ###

s=input()
s=s[::-1]
md=[0]
ex10=1
tmp=0
mod=2019
for i in range(len(s)):
    tmp+=ex10*int(s[i])
    tmp%=mod
    md.append(tmp)
    ex10*=10
from collections import Counter

sc= Counter(md)
ans=0
for k in sc:
    sck=sc[k]
    ans+= sck*(sck-1)//2
print(ans)

### FIXED CODE ###


s=input()
s=s[::-1]
md=[0]
ex10=1
tmp=0
mod=2019
for i in range(len(s)):
    tmp+=ex10*int(s[i])
    tmp%=mod
    md.append(tmp)
    ex10*=10
    ex10%=mod
from collections import Counter

sc= Counter(md)
ans=0
for k in sc:
    sck=sc[k]
    ans+= sck*(sck-1)//2
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def slove():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A)
    ans = 0
    flag = False
    while len(A) != 0:
        ans += 1
        tmp = A.pop(0)
        #print(A)
        k = 0
        for i in range(len(A)):
            if A[i-k] % tmp == 0:
                if A[i-k] == tmp:
                    flag = True
                A.remove(A[i-k])
                k += 1
        if flag:
            ans -= 1
            flag = False
        
    print(ans)


if __name__ == "__main__":
    slove()


### FIXED CODE ###

import sys 
input = sys.stdin.readline

def slove():
    n = int(input())
    A = sorted(list(map(int,input().split())))
    a_max = A[-1]+1
    B = [0] * a_max
    for value in A:
        B[value] += 1
        for i in range(value*2,a_max,value):
            B[i] += 2
    #print(B)
    print(B.count(1))

if __name__ == "__main__":
    slove()

"""
import sys
input = sys.stdin.readline

def slove():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A)
    ans = 0
    flag = False
    while len(A) != 0:
        ans += 1
        tmp = A.pop(0)
        #print(A)
        k = 0
        for i in range(len(A)):
            if A[i-k] % tmp == 0:
                if A[i-k] == tmp:
                    flag = True
                A.remove(A[i-k])
                k += 1
        if flag:
            ans -= 1
            flag = False
        
    print(ans)


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

import numpy as np
from numpy import *

n, k, q = map(int, input().split())
a = np.array([])

for i in range(q):
  a = np.append(a, int(input()))

points = [k for i in range(n)]
points = np.array(points)
minus_ones = [-1 for i in range(n)]
minus_ones = np.array(minus_ones)

for i in range(len(a)):
    points += minus_ones
    points[a[i]-1] += 1

for i in range(n):
  if points[i] > 0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

n, k, q = map(int, input().split())
a = []

for i in range(q):
  a.append(int(input()))

points = [k for i in range(n)]
minus_ones = [-1 for i in range(n)]

for i in range(q):
    points[a[i]-1] += 1
  
for i in range(n):
    points[i] -= q

for i in range(n):
  if points[i] > 0:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###



def main():
    from fractions import gcd
    import sys
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = a[0]

    #mmm=10**9+7
    for i in range(1, n):
        ans = ans * a[i] // gcd(ans, a[i])

    result=0
    for item in a:
      result=(result+ans//item)%(10**9+7)

    print(result)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    from fractions import gcd
    import sys
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = 1

    mmm=10**9+7
    for i in a:
        ans = ans *i // gcd(ans, i)

    result=0
    for item in a:
      result+=ans//item

    print(result%mmm)

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

k,s = map(int,input().split())

ans = 0

for i in range(k+1):
    for j in range(k+1):
        for c in range(k+1):
            if i + j + c == s:
                ans += 1
print(ans)

### FIXED CODE ###

k,s = map(int,input().split())

ans = 0

for i in range(k+1):
    for j in range(i,k+1):
        c = s-i-j
        if k >= c and c >=j:
            if i == j and j == c:
                ans += 1
            elif i!=j and j!=c and c!=j:
                ans += 6
            else:
                ans += 3
        
print(ans)
### BUGGY CODE ###

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

dp = [0] * (N+1)

mvlst = list()
for i in range(K):
    l, r = list(map(int, input().split()))
    for j in range(l, r+1):
        mvlst.append(j)

dp[1] = 1
for i in range(1, N+1):
    for j in range(len(mvlst)):
        if i-mvlst[j]<1: continue
        dp[i] += dp[i-mvlst[j]]
        dp[i] = dp[i] % MOD

print(dp[N] % MOD)


### FIXED CODE ###

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

a = [0] * (N+1)
f = [0] * (N+1)
mv = list()
for i in range(K):
    mv.append(list(map(int, input().split())))

def solve(N, a, f):
    for i in range(1, N+1):
        f[i] = (f[i-1] + a[i]) % MOD
        for j in range(len(mv)):
            l, r = mv[j]
            if i+l < N+1: a[i+l] = (a[i+l] + f[i]) % MOD
            if i+r+1 < N+1: a[i+r+1] = (a[i+r+1] - f[i]) % MOD

a[1] = 1
mv.sort()
solve(N, a, f)

print(a[N])
### BUGGY CODE ###

n,q = map(int,input().split())
S = list(input())
a = [0]*n

for i in range(n-1):
    if (S[i]=='A')and(S[i+1]=='C'):
        a[i] = 1

for i in range(q):
    l,r = map(int,input().split())
    ans = 0
    for k in range(l-1,r-1):
        ans += a[k]
    print(ans)


### FIXED CODE ###

n,q = map(int,input().split())
S = list(input())
a = [0]*n

for i in range(1,n):
    a[i] = a[i-1]
    if (S[i-1]=='A')and(S[i]=='C'):
        a[i] += 1 
for i in range(q):
    l,r = map(int,input().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

# ABC149c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    x = int(input())

    if x == 2:
        print(2)
        exit(0)

    def prime_numbers(right):
        pn = [2]
        for L in range(3, right):
            chk = True
            for L2 in pn:
                if L % L2 == 0:
                    chk = False
            if chk == True:
                pn.append(L)
                if L >= x:
                    print(L)
                    exit(0)
        return pn

    l = prime_numbers(x*x)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# ABC149c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    x = int(input())

    def prime_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

    for i in range(x, x * x):
        if len(prime_factorize(i)) < 2:
            print(i)
            exit(0)


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

def main():
  import sys
  input=sys.stdin.readline
  h,w,k=map(int,input().split())
  sx,sy,tx,ty=map(int,input().split())
  calc=lambda x,y:x*1000007+y
  b=[[-1]*(w+2)]
  for i in range(h):
    s=input()
    bb=[-1]
    for j in s:
      if j==".":bb.append(0)
      else:bb.append(-1)
    bb.append(-1)
    b.append(bb)
  b.append([-1]*(w+2))
  from collections import deque
  d=deque()
  d.append((sx,sy))
  s=set()
  while d:
    x,y=d.popleft()
    if calc(x,y)in s:
      s.discard(calc(x,y))
      continue
    if x==tx and y==ty:
      exit(print(b[x][y]))
    for i in range(1,k+1):
      if b[x-i][y]<=b[x][y] and b[x-i][y]!=0:break
      d.append((x-i,y))
      if b[x-i][y]!=0:
        s.add(calc(x-i,y))
      b[x-i][y]=b[x][y]+1
    for i in range(1,k+1):
      if b[x+i][y]<=b[x][y] and b[x+i][y]!=0:break
      d.append((x+i,y))
      if b[x+i][y]!=0:
        s.add(calc(x+i,y))
      b[x+i][y]=b[x][y]+1
    for j in range(1,k+1):
      if b[x][y-j]<=b[x][y] and b[x][y-j]!=0:break
      d.append((x,y-j))
      if b[x][y-j]!=0:
        s.add(calc(x,y-j))
      b[x][y-j]=b[x][y]+1
    for j in range(1,k+1):
      if b[x][y+j]<=b[x][y] and b[x][y+j]!=0:break
      d.append((x,y+j))
      if b[x][y+j]!=0:
        s.add(calc(x,y+j))
      b[x][y+j]=b[x][y]+1
  print(-1)
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
si,sj,ti,tj=map(int,input().split())
si-=1
sj-=1
ti-=1
tj-=1
b=[input()for _ in range(h)]
ans=[[-1]*w for _ in range(h)]
ans[si][sj]=0
from collections import deque
d=deque()
d.append((si,sj))
while d:
  x,y=d.popleft()
  if x==ti and y==tj:
    exit(print(ans[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or b[xx][yy]=="@":break
      if 0<=ans[xx][yy]<=ans[x][y]:break
      if ans[xx][yy]==-1:d.append((xx,yy))
      ans[xx][yy]=ans[x][y]+1
print(-1)
### BUGGY CODE ###

# https://atcoder.jp/contests/agc005/tasks/agc005_a
# 半分はS, 半分はTからなる文字列
# STを取り除く，どうなるか (無限回)

X = input()
j = len(X) - 1
i = X.find("ST")

while i >= 0:
    X = X[:i] + X[i + 2:]
    i = X.find("ST")

print(len(X))

### FIXED CODE ###

# https://atcoder.jp/contests/agc005/tasks/agc005_a
#
# Stackでやる

from collections import deque

stack = deque([])
X = input()

for ch in X:
    if ch == 'S':
        stack.append(ch)
    elif ch == 'T':
        if len(stack) == 0:
            stack.append(ch)
        elif stack[-1] == 'T':
            stack.append(ch)
        elif stack[-1] == 'S':
            stack.pop()

print(len(stack))
### BUGGY CODE ###

S=input()
b=1
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        S=c+S if (int(f)-1)^b else S+c 
print(S if b else S[::-1])

### FIXED CODE ###

S=input()
b=1
x=''
y=''
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        if (int(f)-1)^b:x=c+x
        else:y=y+c
S=x+S+y
print(S if b else S[::-1])
### BUGGY CODE ###

h,w,k = map(int, input().split())
sx,sy,gx,gy = map(lambda x: int(x)-1, input().split())
board = [list(map(lambda x: int(x=="."), input())) for i in range(h)]
inf = 1<<30
DP = [[inf for j in range(w)] for i in range(h)]
DP[sx][sy] = 0

que = [(sx,sy)]
dxdy = [(0,1),(1,0),(0,-1),(-1,0)]
for x,y in que:
    for dx,dy in dxdy:
        nx,ny = x,y
        for i in range(k):
            nx += dx
            ny += dy
            if not(0<=nx<h and 0<=ny<w and board[nx][ny] and DP[nx][ny] >= DP[x][y]+1):
                break
            if DP[nx][ny] > DP[x][y]+1:
                DP[nx][ny] = DP[x][y]+1
            que.append((nx,ny))
ans = DP[gx][gy]
if ans == inf:
    ans = -1
print(ans)


### FIXED CODE ###

h,w,k = map(int, input().split())
sx,sy,gx,gy = map(lambda x: int(x)-1, input().split())
board = [list(map(lambda x: int(x=="."), input())) for i in range(h)]
inf = 1<<30
DP = [[inf for j in range(w)] for i in range(h)]
DP[sx][sy] = 0

from collections import deque
que = deque([(sx,sy)])

dxdy = [(0,1),(1,0),(0,-1),(-1,0)]
while que:
    x,y = que.popleft()
    for dx,dy in dxdy:
        nx,ny = x,y
        for i in range(k):
            nx += dx
            ny += dy
            if not(0<=nx<h and 0<=ny<w and board[nx][ny] and DP[nx][ny] >= DP[x][y]+1):
                break
            # コストが変わらない場合は無視か...
            if DP[nx][ny] == DP[x][y]+1:
                continue
            DP[nx][ny] = DP[x][y]+1
            que.append((nx,ny))
ans = DP[gx][gy]
if ans == inf:
    ans = -1
print(ans)
### BUGGY CODE ###

import string

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

while True:
	try:
		sentence = raw_input()
		while 'the' not in sentence or 'that' not in sentence or 'this' not in sentence:
			sentence = sentence.translate(tbl)
		print sentence
	except EOFError:
		break

### FIXED CODE ###

import string, sys

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

for s in sys.stdin:
	while not('the' in s or 'that' in s or 'this' in s):
		s = s.translate(tbl)
	print s[:-1]
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
mod = 1000000007
a = list(int(input()) for _ in range(m))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, n+1):
    if i not in a: dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%mod)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
mod = 1000000007
a = set(int(input()) for _ in range(m))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, n+1):
    if i not in a: dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%mod)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def is_prime3(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False


if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    if is_prime3(M):
        print(1)
        exit()
    for i in range(M):
        if M%(N+i) == 0:
            print(int(M/(N+i)))
            exit()
        if M/(N+i) < 2:
            print(1)
            exit()


### FIXED CODE ###


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    list = []
    for i in range(1,int(math.sqrt(M)+1)):
        if M%i == 0:
            list.append(i)
    for i in range(len(list)):
        list.append(int(M/list[i]))
    print(max([i for i in list if i <= M // N]))
### BUGGY CODE ###

s=input()
q=int(input())

flg=True #正順
for i in range(q):
    qi=list(map(str,input().split()))
    if qi[0]=="1":
        flg=not flg
    else:
        f,c=qi[1],qi[2]
        if f=="1":
            if flg:
                s=c+s
            else:
                s=s+c
        else:
            if not flg:
                s=c+s
            else:
                s=s+c
                

if flg:
    s=s
else:
    s=s[::-1]
    
print(s)




### FIXED CODE ###

s=input()
q=int(input())
l=""
r=""
flg=True

for i in range(q):
    p=list(map(str,input().split()))
    if p[0]=="1":
        flg=not flg
    else:
        z,f,c=p
        if f=="1":
            if flg:
                l=c+l
            else:
                r=r+c
        else:
            if not flg:
                l=c+l
            else:
                r=r+c
s=l+s+r

if flg:
    ans=s
else:
    ans=s[::-1]
print(ans)
### BUGGY CODE ###

s = list(input())

a = []
k = 0
for z in s:
  if z == "T":
    a += [k]
    k = 0
  else:
    k += 1
a += [k]
# print(a)

l = [a[0]]
for k in a[2::2]:
  l = [t+k for t in l] + [t-k for t in l]

m = [0]
for k in a[1::2]:
  m = [t+k for t in m] + [t-k for t in m]

x,y = map(int,input().split())
print("Yes" if x in l and y in m else "No")


### FIXED CODE ###

s = list(input())

a = []
k = 0
for z in s:
  if z == "T":
    a += [k]
    k = 0
  else:
    k += 1
a += [k]
# print(a)

l = [a[0]]
for k in a[2::2]:
  if k == 0:
    continue
  l = [t+k for t in l] + [t-k for t in l]
  l = list(set(l))

m = [0]
for k in a[1::2]:
  if k == 0:
    continue
  m = [t+k for t in m] + [t-k for t in m]
  m = list(set(m))

x,y = map(int,input().split())
print("Yes" if x in l and y in m else "No")
### BUGGY CODE ###

import sys
n = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


dp = [[0 for i in range(n)] for j in range(n)]
#初期条件
for j in range(n):
    if S[0] == S[j]:
        dp[0][j] = 1
    else:
        dp[0][j] = 0

#print(dp)

for i in range(n):
    for j in range(n):
        if S[i] ==S[j]:
            dp[i][j] = min(dp[i-1][j-1] +1, n//2)
        else:
            dp[i][j] = 0

maxp = 0
for i in range(n):
    for j in range(n):
        if maxp < dp[i][j] and i !=j:
            maxp = dp[i][j]
#print(dp)
print(maxp)

### FIXED CODE ###

import sys
n = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


dp = [[0 for i in range(n)] for j in range(n)]
#初期条件
for j in range(1, n):
    if S[0] == S[j]:
        dp[0][j] = 1

#print(dp)

for i in range(1, n-1):
    for j in range(i+1, n):
        if S[i] ==S[j]:
            dp[i][j] = min(dp[i-1][j-1] +1, j-i)

maxp = 0
for i in range(n-1):
    for j in range(i+1, n):
        if maxp < dp[i][j]:
            maxp = dp[i][j]
#print(dp)
print(maxp)
### BUGGY CODE ###

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

for i in range(N):
    A[i] = int(input())


for i in range(N):
    if i == 0:
        print(max(A[1:N]))
    elif i == N-1:
        print(max(A[0:N-1]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))


### FIXED CODE ###

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

for i in range(N):
    A[i] = int(input())

mx = max(A)
mxi = A.index(max(A))

for i in range(N):
    if i != mxi:
        print(mx)
    elif i == 0:
        print(max(A[1:N]))
    elif i == N-1:
        print(max(A[0:N-1]))
    else:
        print(max(max(A[0:i]),max(A[i+1:N])))
### BUGGY CODE ###

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

list=[]

while N not in list:
    list.append(N)
    N=abs(N-K)

print(min(list))


### FIXED CODE ###

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

print(min(N%K,K-N%K))
### BUGGY CODE ###

a, b, n = map(int, input().split())
t = n // b
if t == 0:
    ans = int(a * n / b) - a * int(n / b)
else:
    ans = 0
    for i in range(t):
        x = b * i + (b - 1)
        if x > n:
            x = n
        else:
            pass
        
        tmp = int(a * x / b) - a * int(x / b)
        if tmp > ans:
            ans = tmp
        else:
            pass

print(ans)

### FIXED CODE ###

a, b, n = map(int, input().split())
t = n // b

if t == 0:
    ans = int(a * n / b) - a * int(n / b)
else:
    ans = 0
    for i in range(t):
        x = b * i + (b - 1)
        if x > n:
            x = n
        else:
            pass
        
        tmp = int(a * x / b) - a * int(x / b)
        
        if tmp > ans:
            ans = tmp
        else:
            break

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

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

for i in range(n):
  tmp = copy.deepcopy(a)
  tmp[i] = 0
  print(max(tmp))
  tmp = a

### FIXED CODE ###

n = int(input())
a  =[]
for i in range(n):
  x = int(input())
  a.append(x)
ma = max(a)
b = sorted(a)
for i in range(n):
  if a[i] != ma:
    print(ma)
  else:
    print(b[-2])
### BUGGY CODE ###

n=int(input())
s=list(input())

ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                if j-i!=k-j:
                    ans+=1

print(ans)

### FIXED CODE ###

n=int(input())
s=list(input())

ans=0
a=0
b=0
c=0
for i in range(n):
    if s[i]=="R":
        a+=1
    if s[i]=="G":
        b+=1
    if s[i]=="B":
        c+=1
ans=a*b*c

for i in range(n):
    for j in range(i+1,n):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
            ans=ans-1
    

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

K, S = map(int, input().split())
    
ans = 0
for i in range(K+1):
    for j in range(K+1):
        for f in range(K+1):
            if i + j + f == 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):
        Z = S - X - Y
        if 0 <= Z and Z <= K:
            ans += 1
print(ans)
### BUGGY CODE ###

import heapq
n, m = map(int, input().split())
jobs = [[int(x) for x in input().split()] for _ in range(n)]
jobs = sorted(jobs, key=lambda x:x[0], reverse=True)
ans = 0
q = []

for i in range(m+1):
    tmp = reversed(jobs[:])
    for job in tmp:
        if job[0] <= i:
            heapq.heappush(q, -jobs.pop()[1])
        else:
            break
    if q:
        ans += -heapq.heappop(q)
print(ans)


### FIXED CODE ###

import heapq
n, m = map(int, input().split())
jobs = [[int(x) for x in input().split()] for _ in range(n)]
jobs = sorted(jobs, key=lambda x:x[0], reverse=True)
r_jobs = list(reversed(jobs[:]))
ans = 0
q = []
cnt = 0
l = len(jobs)
for i in range(m+1):
    while cnt < l:
        if r_jobs[cnt][0] == i:
            heapq.heappush(q, -jobs.pop()[1])
            cnt += 1
        else:
            break

    if q:
        ans += -heapq.heappop(q)

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

from collections import Counter
N = int(input())
S = []
cnt = []
for i in range(N):
    S.append(input())
    S[i] = list(S[i])
    cnt.append(Counter(S[i]))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if cnt[i] == cnt[j]:
            ans += 1

print(ans)
#print("cnt = {}".format(cnt))

### FIXED CODE ###

from collections import Counter
from math import factorial
N = int(input())
S = []
for i in range(N):
    tmp = input()
    tmp = sorted(list(tmp))
    S.append("".join(tmp))

cnt = Counter(S)
ans = 0
for i in cnt:
    if cnt[i] > 1:
        ans += factorial(cnt[i]) // (factorial(cnt[i] - 2) * factorial(2))

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

N = int(input())
P = list(map(int, input().split()))
result = 0

for i, p in enumerate(P):
    subary = P[:i+1]
    if (min(subary) >= p):
        result += 1

print(result)


### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
result = 0

minValue = P[0]

for i, p in enumerate(P):
  if (minValue >= p):
    result += 1
    minValue = p

print(result)