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

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

#print(a)

for i in range(n):
    temp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = temp

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

max_val = max(a)
max_total = a.count(max_val) - 1

for i in range(n):
    if max_val > a[i]:
        print(max_val)

    elif max_val == a[i] and max_total != 0:
        print(max_val)
        max_total -= 1
    else:
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp
### BUGGY CODE ###

N = int(input())
n = len(str(N)) - 1
ans = 0
for i in range(3, n+1):
  ans += 3**i - (2**i)*3 + 3

t = 3**n - 2**(n+1) + 1

if int(str(N)[0]) == 3:
  for i in range(3*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('5' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 4:
  ans += t
elif int(str(N)[0]) == 5:
  ans += 3**n - (2**n)*3 + 3 + 2**n - 2
  for i in range(5*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('3' in s) and ('7' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) == 6:
  ans += 2*t
elif int(str(N)[0]) == 7:
  ans += 2*t
  for i in range(7*(10**n), N+1):
    s = set([j for j in str(i)])
    if ('3' in s) and ('5' in s) and (len(s)==3):
      ans += 1
elif int(str(N)[0]) > 7:
  ans += 3*t
print(ans)

### FIXED CODE ###

N = int(input())

def dfs(n):
  if int(n) > N:
    return 0
  if ('3' in n) and ('5' in n) and ('7' in n):
    ret = 1
  else:
    ret = 0
  for c in '357':
    ret += dfs(n+c)
  return ret

print(dfs('0'))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
s = input() #sys.stdin.readlineは最後が改行

r = [0]*n
g = [0]*n
b = [0]*n

for i in range(n):
    if s[i] == 'R':r[i]+=1
    elif s[i] == 'G':g[i]+=1
    else: b[i]+=1

from itertools import accumulate
r_nokori = list(reversed(r))
r_nokori = list(reversed(list(accumulate(r_nokori))))
g_nokori = list(reversed(g))
g_nokori = list(reversed(list(accumulate(g_nokori))))
b_nokori = list(reversed(b))
b_nokori = list(reversed(list(accumulate(b_nokori))))

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]: continue

        if (s[i]=='R' and s[j]=='G') or (s[i]=='G' and s[j]=='R'):
            ans += b_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'B': ans-= 1

        if (s[i]=='G' and s[j]=='B') or (s[i]=='B' and s[j]=='G'):
            ans += r_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'R': ans-= 1

        if (s[i]=='B' and s[j]=='R') or (s[i]=='R' and s[j]=='B'):
            ans += g_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'G': ans-= 1

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
s = input() #sys.stdin.readlineは最後が改行

r = [0]*n
g = [0]*n
b = [0]*n

for i in range(n):
    if s[i] == 'R':r[i]+=1
    elif s[i] == 'G':g[i]+=1
    else: b[i]+=1

from itertools import accumulate
r_nokori = list(reversed(r))
r_nokori = list(reversed(list(accumulate(r_nokori))))
g_nokori = list(reversed(g))
g_nokori = list(reversed(list(accumulate(g_nokori))))
b_nokori = list(reversed(b))
b_nokori = list(reversed(list(accumulate(b_nokori))))

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]: continue

        if (s[i]=='R' and s[j]=='G') or (s[i]=='G' and s[j]=='R'):
            ans += b_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'B': ans-= 1

        if (s[i]=='G' and s[j]=='B') or (s[i]=='B' and s[j]=='G'):
            ans += r_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'R': ans-= 1

        if (s[i]=='B' and s[j]=='R') or (s[i]=='R' and s[j]=='B'):
            ans += g_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'G': ans-= 1

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

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

for i in range(N):
    tmp = A.copy()
    tmp.pop(i)
    print(max(tmp))

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N) ]
left = []
right = []
left_max = 0
right_max = 0
for i in range(N):
    if i == 0:
        left.append(0)
    else:
        left.append(max(left_max, A[i-1]))
    
    if (A[i-1] > left_max) and i != 0:
        left_max = A[i-1]
        
for i in range(N-1, -1, -1):
    if i == N-1:
        right.append(0)
    else:
        right.append(max(right_max, A[i+1]))
    
    if i != N-1:
        if A[i+1] > right_max:
            right_max = A[i+1]
right.reverse()

for i in range(N):
    print(max(left[i],right[i]))
### BUGGY CODE ###

b = list(map(int, input()))
cnt = 0
i = 0
while len(b) > 1:
    
    if len(list(set(b))) == 1:
        break
    if b[i] != b[i + 1]:
        b.pop(i)
        b.pop(i)
        cnt += 1
        i = 0
        continue
    i += 1
    
print(cnt*2)


### FIXED CODE ###

s = input()
zom = min(s.count("1"),s.count("0"))
if len(set(list(s))) == 1:
    zom = 0
print(zom*2)
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
for i in range(min(n,k)):
  a.pop(0)
print(sum(a))

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
del a[:min(n,k)]
print(sum(a))
### BUGGY CODE ###

n=int(input())
x=[0]*1010
for i in list(map(int,input().split())):x[i]+=1
ans=0
for a in range(1,1001):
  for b in range(a,1001):
    for c in range(b,1001):
      if a<b+c and b<c+a and c<a+b:
        if a==b==c:ans+=x[a]*(x[b]-1)*(x[c]-2)//6
        elif a==b:ans+=x[a]*(x[b]-1)*x[c]//2
        elif b==c:ans+=x[a]*x[b]*(x[c]-1)//2
        else:ans+=x[a]*x[b]*x[c]
print(ans)

### FIXED CODE ###

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

import re
cnt = 0
n = input()
while True:
    cnt += len(re.findall(r"(01|10)", n))
    n = re.sub(r"(01|10)", "", n)
    m = re.search(r"(01|10)", n)
    if m is None:
        break
print(cnt*2)

### FIXED CODE ###

s = input()
zom = min(s.count("1"),s.count("0"))
if len(set(list(s))) == 1:
    zom = 0
print(zom*2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

s = input()
s = s[0:len(s)-1]
Q = int(input())
lq = [input().split() for _ in range(Q)]

flg = 0 # 0:sonomama 1:gyakuten
for q in lq:
    if q[0] == "1":
        if flg == 0:
            flg = 1
        else:
            flg = 0
    elif q[0]=="2":
        tmp = q[2]
        if (q[1] == "1" and flg ==0) or (q[1] == "2" and flg ==1):
            tmp += s
            s = tmp
        elif (q[1] == "2" and flg == 0) or (q[1] == "1" and flg == 1):
            s += tmp

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


### FIXED CODE ###

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

    s = input()
    s = s[0:len(s)-1]
    Q = int(input())
    head = []
    tail = []

    flg = 0 # 0:sonomama 1:gyakuten
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            if flg == 0:
                flg = 1
            else:
                flg = 0
        elif q[0]=="2":
            index,tmp = q[1],q[2]
            if (index == "1" and flg ==0) or (index == "2" and flg ==1):
                head.append(tmp)
            elif (index == "2" and flg == 0) or (index == "1" and flg == 1):
                tail.append(tmp)

    s1 = "".join(head)
    s1 = s1[::-1]
    s2 = "".join(tail)
    ans = s1 + s + s2
    if flg == 1:
        ans = ans[::-1]

    print(ans)

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

import sys
from collections import deque

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,m,k = map(int, input().split())
f = [[] for _ in range(n)]
g = [[] for _ in range(n)]

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

for _ in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    g[c].append(d)
    g[d].append(c)

d = {}
parent = [-1] * n
seen = [False] * n

# DFS
for i in range(n):
    if seen[i]:
        continue
    stack = deque()
    # グループは集合で管理
    d[i] = set([i])
    stack = [i]
    while stack:
        v = stack.pop()
        seen[v] = True
        # 親を設定して同じ連結成分であることを判別する
        parent[v] = i
        for nv in f[v]:
            if seen[nv]:
                continue
            # 集合に追加する
            d[i].add(nv)
            stack.append(nv)

ans = [0] * n
for i in range(n):
    # 連結成分ごとに集合を取り出す
    group = d[parent[i]]
    # 集合の全要素数 - 友達 - ブロック - 自分
    sum = len(group) - len(f[i]) - len(set(g[i]) & group) - 1
    ans[i] = sum

print(*ans)


### FIXED CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,m,k = map(int, input().split())
f = [[] for _ in range(n)]
g = [[] for _ in range(n)]

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

for _ in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    g[c].append(d)
    g[d].append(c)

d = {}
parent = [-1] * n
seen = [False] * n

for i in range(n):
    if seen[i]:
        continue
    stack = deque()
    d[i] = set([i])
    stack = [i]
    while stack:
        v = stack.pop()
        seen[v] = True
        parent[v] = i
        for nv in f[v]:
            if seen[nv]:
                continue
            d[i].add(nv)
            stack.append(nv)

ans = [0] * n
for i in range(n):
    group = d[parent[i]]
    tmp = len(group) - len(f[i]) - 1
    for j in g[i]:
        if j in group:
            tmp -= 1
    ans[i] = tmp

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

import itertools

def main():
    n = int(input())
    l = map(int, input().split())
    ts = set()
    for a,b,c in itertools.combinations(l, 3):
        if a < b+c and b < c+a and c < a+b:
            ts.add((a,b,c))
    print(len(ts))
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import bisect

def main():
    n = int(input())
    l = sorted(list(map(int, input().split())))
    count = 0
    for i in range(n-2):
        a = l[i]
        for j in range(i+1, n-1):
            b = l[j]
            kmax = bisect.bisect_left(l, a+b)
            #print("k", kmax, "j", j, "k-j", kmax-(j+1), a, b)
            count += max(kmax-(j+1),0)
    print(count)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
d = {}
for i in l:
    d[i]=l.count(i)
cp = 0
for i in d.values():
    cp+= i*(i-1)//2
for i in l:
    print(cp-d[i]+1)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
d = {}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1
cp = 0
for i in d.values():
    cp+= i*(i-1)//2
for i in l:
    print(cp-d[i]+1)
### BUGGY CODE ###

N,Ma,Mb=map(int,input().split())

A,B,C = [],[],[]
for i in range(N):
    a,b,c=map(int,input().split())
    A += [a]
    B += [b]
    C += [c]

dp = [[10**18 for _ in range(401)] for _ in range(401)]

dp[0][0]=0
for i in range(N):
    for ca in range(361, -1, -1):
        for cb in range(361, -1, -1):
            dp[ca+A[i]][cb+B[i]] = min(dp[ca+A[i]][cb+B[i]],dp[ca][cb]+C[i])

ans = 10**18
for ca in range(401):
    for cb in range(401):
        if not ca*Mb == cb*Ma or ca == 0:
            continue
        if ans > dp[ca][cb]:
            ans = dp[ca][cb]
        
if ans == 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

N,Ma,Mb=map(int,input().split())

dp = [[10**18 for _ in range(401)] for _ in range(401)]

dp[0][0]=0
for i in range(N):
    a,b,c=map(int,input().split())
    for ca in range(i * 10, -1, -1):
        for cb in range(i * 10, -1, -1):
            dp[ca+a][cb+b] = min(dp[ca+a][cb+b],dp[ca][cb]+c)

ans = 10**18
for ca in range(401):
    for cb in range(401):
        if not ca*Mb == cb*Ma or ca == 0:
            continue
        if ans > dp[ca][cb]:
            ans = dp[ca][cb]
        
if ans == 10**18:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import bisect
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
BC = []
for j in range(m):
    b, c = map(int, input().split())
    BC.append((b, c))
BC = sorted(BC, key=lambda x : x[1], reverse=True)
for b, c in BC:
    i = bisect.bisect_left(A,c)
    if i == 0:
        break
    else:
        start = min(i, b)
        A = A[start:]
        for j in range(start):
            bisect.insort_right(A,c)
print(sum(A))

### FIXED CODE ###

n, m = map(int, input().split())
A = sorted(map(int, input().split()))
BC = []
for j in range(m):
    b, c = map(int, input().split())
    BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
D = []
for b, c in BC:
    D.extend([c for i in range(b)])
    if len(D) >= n:
        D = D[:n]
        break
for x in range(len(D)):
    if A[x] > D[x]:
        break
else:
    x += 1
print(sum(A[x:]) + sum(D[:x]))
### BUGGY CODE ###

from sys import stdin

N = int(stdin.readline())
A = [None]*N
B = [None]*N
for i in range(N):
    A[i], B[i] = map(int, stdin.readline().split())

now = 0
for i in range(N):
    job = B.index(min(B))
    now += A[job]
    deadline = B[job]
    B[job] = 10000000000
    if now > deadline:
        print("No")
        quit()
else:
    print("Yes")

### FIXED CODE ###

from sys import stdin

N = int(stdin.readline())
Job = [None]*N
for i in range(N):
    Job[i] = tuple(map(int, stdin.readline().split()))[::-1]

Job.sort()

Now = 0
for i in range(N):
    Deadline = Job[i][0]
    Now += Job[i][1]
    if Now > Deadline:
        print("No")
        quit()

else:
    print("Yes")
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    results = tuple(map(int, input().split()))

    products = 1
    for result in results[:k]:
        products *= result
    for i in range(n-k):
        new_products = products * results[i+k] / results[i]
        if products < new_products:
            print('Yes')
        else:
            print('No')
        products = new_products


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    results = tuple(map(int, input().split()))

    for i in range(n-k):
        print('Yes' if results[i] < results[i+k] else 'No')



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

def examA():
    N = I()
    H = LI()
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(N-1):
        dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
        if i<N-2:
            dp[i + 2] = min(dp[i + 2], dp[i]+abs(H[i + 2] - H[i]))
    ans = dp[-1]
    print(ans)
    return

def examB():
    N, K = LI()
    H = LI()
    dp = [inf]*N
    dp[0] = 0
    for i in range(N):
        for k in range(1,K+1):
            if i+k>=N:
                break
            if dp[i+k]>dp[i]+abs(H[i+k]-H[i]):
                dp[i+k] = dp[i]+abs(H[i+k]-H[i])
    ans = dp[-1]
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

### FIXED CODE ###

N,K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*N
ans = int(0)
c = int(0)
if N < K:
    c = N-1
else:
    c = K
for i in range(c):
    dp[i+1] = abs(h[i+1]-h[0])

for i in range(2,N):
    if i<K:
        c = i
    else:
        c = K
    dpcandi = [0] * c
    for j in range(c):
        dpcandi[j] = dp[i-j-1] + abs(h[i]-h[i-j-1])
    dp[i] = min(dpcandi)

ans = dp[N-1]

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

N = int(input())

x = [i + 1 for i in range(N)]

print(sum(x) - N)


### FIXED CODE ###

N = int(input())


print(N*(N + 1) // 2 - N)
### BUGGY CODE ###

import sys
import numpy as np
from collections import defaultdict

input = sys.stdin.buffer.readline
MOD = 1000000007
N = int(input())
dd = defaultdict(list)
count = 1
iwashi = np.array([list(map(int, input().split())) for _ in range(N)])


gcd = np.gcd(iwashi[:, 0], iwashi[:, 1])
iwashi = iwashi // np.array([gcd, gcd]).T
checked = [False] * N
zeros = 0
for i in range(N):
    if checked[i]:
        continue
    if iwashi[i][0] == iwashi[i][1] == 0:
        zeros += 1
        continue
    parallel = [i]
    vertical = []
    for j in range(i + 1, N):
        if checked[j]:
            continue
        if iwashi[j][0] == iwashi[j][1] == 0:
            zeros += 1
            checked[j] = True
            continue
        if np.dot(iwashi[i], iwashi[j]) == 0:
            vertical.append(j)
            checked[j] = True
        elif (iwashi[i] == iwashi[j]).all() or (iwashi[i] == iwashi[j] * (-1)).all():
            parallel.append(j)
            checked[j] = True
    p = len(parallel)
    v = len(vertical)
    count *= (pow(2, p, MOD) - 1) + (pow(2, v, MOD) - 1) + 1
    count %= MOD
count -= 1
count += zeros
print(count % MOD)


### FIXED CODE ###

import sys
import math
from collections import defaultdict

input = sys.stdin.buffer.readline
MOD = 1000000007
N = int(input())
dd = defaultdict(int)
count = 1
iwashi = [list(map(int, input().split())) for _ in range(N)]


checked = defaultdict(bool)
zeros = 0

for i in range(N):
    if iwashi[i][0] == iwashi[i][1] == 0:
        zeros += 1
        continue
    iw = iwashi[i]
    gcd_iw = math.gcd(iw[0], iw[1])
    if gcd_iw != 0:
        iw = list(map(lambda x: x // gcd_iw, iw))
    if iw[0] < 0:
        iw = list(map(lambda x: -x, iw))
    if iw[0] == 0 and iw[1] < 0:
        iw = list(map(lambda x: -x, iw))
    dd[tuple(iw)] += 1

for key, val in dd.items():
    if checked[key]:
        continue
    vert_key = (key[1], -key[0]) if key[1] > 0 else (-key[1], key[0])
    vert_val = dd[vert_key] if vert_key in dd else 0
    count *= (pow(2, val, MOD) - 1) + (pow(2, vert_val, MOD) - 1) + 1
    count %= MOD
    checked[vert_key] = True

# 0匹入れる場合を除外
count -= 1

count += zeros
print(count % MOD)
### BUGGY CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    ans[i]=10**10
    for j in range(max(0,i-K),i):
        ans[i]=min(abs(h[i]-h[j])+ans[j],ans[i])
print(ans[-1])

### FIXED CODE ###

def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()
### BUGGY CODE ###

def isprime(x):
    for i in range(2 , int(x**0.5)+1):
        if x%i == 0:
            return False
    return True
N = 10**5
lst = []
for x in range(2,N):
    if isprime(x):
        lst.append(x)

q = int(input())
ans = []

for i in range(q):
    cnt = 0
    l,r = map(int,input().split())
    for j in range(l,r+1,2):
        if j != 1 and j in lst and int((j+1)/2) in lst:
            cnt += 1
    ans.append(cnt)

for i in range(q):
    print(ans[i])

### FIXED CODE ###


import math
def eratosthenes(n):
    prime = []
    limit = math.sqrt(n)
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e%p != 0]

_primes = eratosthenes(10**5)
primes = [False] * (10**5+1)

for p in _primes:
    primes[p] = True

like_2017 = [False] * (10**5+1)
for p in _primes:
    if primes[(p+1)//2]:
        like_2017[p] = True

c = 0
C = [0]
for i in range(1,10**5+1):
    if like_2017[i]:
        c += 1
    C.append(c)

q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(C[r] - C[l-1])
### BUGGY CODE ###

import itertools

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)
B = [int(x) for x in input().split()]
B.sort(reverse=True)
C = [int(x) for x in input().split()]
C.sort(reverse=True)
 
list_ = [b+c for (b,c) in itertools.product(B, C)]
list_.sort(reverse=True)
 
list__ = [ab+c for (ab,c) in itertools.product(list_[:K], A)]
list__.sort(reverse=True)
for N in list__[:K]:
  print(N)

### FIXED CODE ###

import itertools

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
 
list_ = [b+c for (b,c) in itertools.product(B, C)]
list_.sort(reverse=True)
 
list__ = [ab+c for (ab,c) in itertools.product(list_[:K], A)]
list__.sort(reverse=True)
for N in list__[:K]:
  print(N)
### BUGGY CODE ###

#!/usr/bin/env python3
import numpy as np
N = int(input())
A = list(map(int, input().split()))

A_diff = np.array([a - i for i, a in enumerate(A, 1)])

ans = float("inf")
for i in range(N):
    A_diff_cp = A_diff.copy()
    A_diff_cp += -1 * A_diff[i]
    ans = min(ans, sum(np.abs(A_diff_cp)))

print(ans) # O(N ** 2なので無理ぽい)

### FIXED CODE ###

#!/usr/bin/env python3

import numpy as np
N = int(input())
A = list(map(int, input().split()))

A_diff = np.array([a - i for i, a in enumerate(A, 1)])
my_median = np.median(A_diff)

print(int(np.sum(np.abs(A_diff * -1 + my_median))))
### BUGGY CODE ###

n = int(input())
score = list(map(int, input().split()))
sum_score = sum(score)
target = list(map(int, input().split()))
sum_target = sum(target)
sub = list(map(lambda x: score[x] - target[x], range(n)))
cnt = sum(1 for x in sub if x < 0)
sub.sort()
sub.reverse()

sub_new = [0]
for i in range(n):
    sub_new.append(sub_new[i] + sub[i])

if(sum_score > sum_target):
    if(cnt > 0):
        a, b, ans = 0, 0, 1
        tmp = sub_new[1+a]
        while sum(1 for x in sub if x < 0) > 0:
            if(tmp + sub[-(b+1)] >= 0): 
                tmp += sub[-(b+1)]
                sub[-(b+1)] = 0
                b+=1
            else: 
                sub[-(b+1)] -= tmp
                a+=1
                tmp = sub_new[1+a]
                ans += 1
            #print(tmp, sub, ans)
        print(cnt + ans)
    else: print(0)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
score = list(map(int, input().split()))
target = list(map(int, input().split()))

sub = [score[i] - target[i] for i in range(n)]
ans = 0

if sum(score) < sum(target): ans = -1
else:
    minus = []
    plus = []
    for i in range(n):
        if(sub[i] < 0): minus.append(-sub[i])
        elif(sub[i] > 0): plus.append(sub[i])
    plus = sorted(plus, reverse = True)
    sum_minus = sum(minus)

    ans += len(minus)
    while sum_minus > 0:
        if sum_minus <= plus[0]:
            plus[0] = 0
            sum_minus = 0
        else:
            sum_minus -= plus.pop(0)
        ans += 1

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

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

ans = 0

while True:
    if N == 0 or M == 1 or M == 0:
        break

    N -= 1
    M -= 2
    ans += 1

if N == 0:
    while True:
        M -= 4
        if M >= 0:
            ans += 1
        else:
            break

print(ans)


### FIXED CODE ###

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

ans = 0

if N*2 <= M:
    ans += N
    M -= 2*N
    N = 0
    if M >= 4:
        ans += math.floor(M / 4)
else:
    ans += M/2
print(int(ans))
### BUGGY CODE ###

import collections

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

c = collections.Counter(A)

i = 0
ans = 0
for num, cnt in c.most_common()[::-1]:
    if i >= len(set(A)) - K:
        break
    ans += cnt
    i += 1

print(ans)

### FIXED CODE ###

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)