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

import copy
s=int(input())
list1=[input() for _ in range(s)]
for i in range(len(list1)):
  list2=copy.copy(list1)
  list2.remove(list2[i])
  list2=sorted(list2,key=lambda x:-int(x))
  print(list2[0])


### FIXED CODE ###

import copy
s=int(input())
list1=[input() for _ in range(s)]
list2=copy.copy(list1)
list2=sorted(list2,key=lambda x:-int(x))
for i in list1:
    if list2[0]==i:
      print(list2[1])
    else:
      print(list2[0])
### BUGGY CODE ###

N = int(input())
a = [int(c) for c in input().split()]

dp = [[-1] * N for _ in range(N)]
for i in range(N):
    for L in range(N):
        for R in range(L, N):
            if L == R:
                dp[L][R] = a[L]
            else:
                dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1])


print(dp[0][N-1])


### FIXED CODE ###

N = int(input())
a = [int(c) for c in input().split()]

dp = [[-1] * N for _ in range(N)]
for L in range(N, -1, -1):
    for R in range(L, N):
        if L == R:
            dp[L][R] = a[L]
        else:
            dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1])


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

s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        s_new = ''
        for i in range(len(s)):
            s_new += s[len(s)-1-i]
        s = s_new
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
print(s)

### FIXED CODE ###

from collections import deque

s = deque(input())
n = int(input())
q_list = [input().split() for i in range(n)]
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if count == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])
if count != 1:
    s.reverse()
print(*s, sep='')
### BUGGY CODE ###

# https://drken1215.hatenablog.com/entry/2020/03/22/224200

def main():
    MOD = 998244353

    N, S = map(int, input().split())
    *A, = map(int, input().split())

    dp = [[[0] * 3 for _ in range(S + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 1

    for i, a in enumerate(A, start=1):
        for j in range(S + 1):
            not_opened = dp[i - 1][j][0]
            opened = dp[i - 1][j][1]
            closed = dp[i - 1][j][2]

            dp[i][j][0] = (dp[i][j][0] + not_opened) % MOD
            dp[i][j][1] = (dp[i][j][1] + opened) % MOD
            dp[i][j][2] = (dp[i][j][2] + closed) % MOD

            if (nj := j + a) <= S:
                dp[i][nj][1] = (dp[i][nj][1] + not_opened * i + opened) % MOD
                dp[i][nj][2] = (dp[i][nj][2] + not_opened * i * (N - i + 1) + opened * (N - i + 1)) % MOD

    ans = dp[-1][-1][2]
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# https://atcoder.jp/contests/abc159/submissions/11139734

def main():
    MOD = 998244353

    N, S = map(int, input().split())
    *a, = map(int, input().split())

    dp = [0] * (S + 1)

    ret = 0
    for i, x in enumerate(a):
        dp[0] += 1
        if x > S: continue
        ret = (ret + dp[S - x] * (N - i)) % MOD
        for k in range(S - 1, x - 1, -1):
            dp[k] = (dp[k] + dp[k - x]) % MOD

    print(ret)


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

N, M = map(int, input().split())
ceil = M / N
tmp = 1
mx = 0
while ceil >= tmp:
    if (M - tmp * (N - 1)) % tmp == 0:
        mx = tmp
    tmp += 1

print(mx)


### FIXED CODE ###

N, M = map(int, input().split())
ceil = M // N
for i in range(1,ceil+1)[::-1]:
    tmp = M - i * (N - 1)
    if tmp > 0 and tmp % i == 0:
        print(i)
        break
### BUGGY CODE ###

import math
from functools import reduce

K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += gcd(i,j,k)
      # print(f'i,j,k:{i},{j},{k}, ans:{gcd(i,j,k)}')
print(ans)

### FIXED CODE ###

import math
from functools import reduce

K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i == j  == k:
        ans += gcd(i,j,k)
      elif i == j or j == k:
        ans += 3*gcd(i,j,k)
      else:
        ans += 6*gcd(i,j,k)
      # print(f'i,j,k:{i},{j},{k}, ans:{gcd(i,j,k)}')
print(ans)
### BUGGY CODE ###

import sys
import math
import itertools
n = int(input())
ans = 0
for i in range(1, n + 1):
    ans+=i
print(ans-n)

### FIXED CODE ###

import sys
import math
import itertools
n = int(input())
if(n%2==0):
    print((n + 1) * (n // 2) - n)
else:
    print((n + 1) * ((n-1) // 2) +(n+1)//2- n)
### BUGGY CODE ###

X = int(input())
#print(X)
n = X
div = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    div.append(i)
    if i != n // i:
      div.append(n//i)
#print(div)

for i in div:
  for a in range(-i, i+1): 
    b = a - i
    #print(a, b)
    if a**5 - b**5 == X:
      print(a, b)
      break
  else:
    continue
  break
   
    

### FIXED CODE ###

X = int(input())
#print(X)
n = X
div = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    div.append(i)
    if i != n // i:
      div.append(n//i)
#print(div)

for i in div:
  for a in range(0, 10001): 
    b = a - i
    #print(a, b)
    if a**5 - b**5 == X:
      print(a, b)
      break
  else:
    continue
  break
### BUGGY CODE ###

import numpy as np
def code(n,p):
    curmin = np.inf
    ans = 0
    for idx in range(1,len(p)+1):
        curmin = np.min(p[:idx])
        if curmin == p[idx-1]:
          ans+=1
    
    return ans

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

idx = code(n,p)
if idx == None:
    print(n)
else:
    print(idx)


### FIXED CODE ###

n=int(input())
plist = list(map(int,input().split()))
cnt = 0
pmax=plist[0]
for i in range(n):
    if plist[i]<=pmax:
        pmax=plist[i]
        cnt += 1
print(cnt)
### BUGGY CODE ###

S = input()
Q = int(input())
q = [list(input().split()) for _ in range(Q)]
r = 0


for i in range(Q):
    if q[i][0] == "1":
        r += 1
    else:
        if (q[i][1] == "1" and r%2==0)or (q[i][1] == "2" and r%2==1 ):
            S = q[i][2] + S
        else:
            S = S + q[i][2]

if r%2==1:
    S = S[::-1]
print(S)


### FIXED CODE ###

from collections import deque

S = deque(list(input()))
Q = int(input())
q = [list(input().split()) for _ in range(Q)]
r = 0


for i in range(Q):
    if q[i][0] == "1":
        r += 1
    else:
        if (q[i][1] == "1" and r%2==0)or (q[i][1] == "2" and r%2==1 ):
            S.appendleft(q[i][2])
        else:
            S.append(q[i][2])

S = "".join(S)
if r%2==1:
    S = S[::-1]
print(S)
### BUGGY CODE ###

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

l = range(n+1)

c = 0

for i in range(k, n+2):
    mn = sum(l[:i])
    mx = sum(l[-i:])
    c = c + mx - mn + 1

print(c%(10**9+7))

### FIXED CODE ###


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

l = range(n+1)

c = 0

for i in range(k, n+2):
    mn = (i-1)*i//2
    mx = (2*n+1-i)*i//2
    c = c + mx - mn + 1

print(c%(10**9+7))
### BUGGY CODE ###

# E - Balanced Path

H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]

assert all(len(row) == W for row in A)
assert all(len(row) == W for row in B)

# そのマスを通過したときの赤・青の差 (の絶対値)
table = [[set() for j in range(W)] for i in range(H)]

table[0][0].add(abs(A[0][0] - B[0][0]))

for i in range(H):
    for j in range(W):
        prev  = table[i - 1][j] if i > 0 else set()
        prev |= table[i][j - 1] if j > 0 else set()
        for pdiff in prev:
            diff = A[i][j] - B[i][j]
            table[i][j].add(abs(pdiff + diff))
            table[i][j].add(abs(pdiff - diff))

m = min(diff for diff in table[H - 1][W - 1])
print(m)


### FIXED CODE ###

# E - Balanced Path

H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]

assert all(len(row) == W for row in A)
assert all(len(row) == W for row in B)

# そのマスを通過したときの赤・青の差 (の絶対値)
table = [[set() for j in range(W)] for i in range(H)]

table[0][0].add(abs(A[0][0] - B[0][0]))

for i in range(H):
    if i >= 2:
        table[i - 2] = None
    for j in range(W):
        prev  = table[i - 1][j] if i > 0 else set()
        prev |= table[i][j - 1] if j > 0 else set()
        for pdiff in prev:
            diff = A[i][j] - B[i][j]
            table[i][j].add(abs(pdiff + diff))
            table[i][j].add(abs(pdiff - diff))

m = min(diff for diff in table[H - 1][W - 1])
print(m)
### BUGGY CODE ###

N = int(input())

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


for i in range(1,N):
    print(A.count(i))
    
print(0)

### FIXED CODE ###

import collections

N = int(input())

A = list(map(int, input().split()))
c = collections.Counter(A)


for i in range(1,N):
    print(c[i])
    
print(0)
### BUGGY CODE ###

from collections import defaultdict

N, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 19

acc = defaultdict(int)

for x, y in xy:
	acc[(x, y)] = 1

x = [-INF] + [e for e, _ in xy]
y = [-INF] + [e for _, e in xy]
x.sort()
y.sort()

for i in range(N):
	for j in range(N + 1):
		acc[(x[i+1], y[j])] += acc[(x[i], y[j])]

for j in range(N):
	for i in range(N + 1):
		acc[(x[i], y[j+1])] += acc[(x[i], y[j])]

ans = INF
for i in range(1, N + 1):
	for j in range(i + 1, N + 1):
		for k in range(1, N + 1):
			for l in range(k + 1, N + 1):
				cnt = acc[(x[j], y[l])] - acc[(x[j], y[k-1])] - acc[(x[i-1], y[l])] + acc[(x[i-1], y[k-1])]
				if cnt >= K:
					sq = (x[j] - x[i]) * (y[l] - y[k])
					ans = min(ans, sq)

print(ans)


### FIXED CODE ###

from collections import defaultdict

N, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 19

acc = defaultdict(int)

x = [-INF]
y = [-INF]

for ex, ey in xy:
	acc[(ex, ey)] = 1
	x.append(ex)
	y.append(ey)

x.sort()
y.sort()

for i in range(N):
	for j in range(N + 1):
		acc[(x[i+1], y[j])] += acc[(x[i], y[j])]

for j in range(N):
	for i in range(N + 1):
		acc[(x[i], y[j+1])] += acc[(x[i], y[j])]

ans = INF
for i in range(1, N + 1):
	for j in range(i + 1, N + 1):
		for k in range(1, N + 1):
			for l in range(k + 1, N + 1):
				cnt = acc[(x[j], y[l])] - acc[(x[j], y[k-1])] - acc[(x[i-1], y[l])] + acc[(x[i-1], y[k-1])]
				if cnt >= K:
					sq = (x[j] - x[i]) * (y[l] - y[k])
					ans = min(ans, sq)

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

n = int(input())
ans = 0
lis = []
for i in range(n):
    s = input()
    s_lis = [s[j] for j in range(10)]
    lis.append(s_lis)
for i in range(n-1):
    for j in range(i+1,n):
        s_i = set(lis[i])
        s_j = set(lis[j])
        if s_i == s_j:
            same = True
            for k in range(10):
                if lis[i].count(lis[i][k]) == lis[j].count(lis[i][k]):
                    continue
                else:
                    same = False
                    break
            if same == True:
                ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
ans = 0
dic = {}
for i in range(n):
    sorted_s = sorted(input())
    s = ""
    for j in range(10):
        s = s + sorted_s[j]
    
    if s not in dic:
        dic[s] = 1
    else:
        ans += dic[s]
        dic[s] = dic[s] + 1
print(ans)
### BUGGY CODE ###

#coding: utf-8
#a, b = map(int, input().split())
#a, b, c, x = map(int, [input() for i in range(4)])

N, M = map(int, input().split())
L = []
R = []
LR_and = []
sum_list = []

for i in range(M):
    LR = input().split()
    L.append(int(LR[0]))
    R.append(int(LR[1]))

for i in range(M):
    for j in range(R[i] - L[i] + 1):
        LR_and.append(L[i] + j)

for i in range(len(LR_and)):
    if LR_and.count(LR_and[i]) == M:
        sum_list.append(str(LR_and[i]))

final_list = list(set(sum_list))

print(len(final_list))

### FIXED CODE ###

N, M = map(int, input().split())
L = []
R = []
LR_and = []
sum_list = []

for i in range(M):
    LR = input().split()
    L.append(int(LR[0]))
    R.append(int(LR[1]))

max_L = max(L)
min_R = min(R)

if max_L <= min_R:
    print(min_R - max_L + 1)
else:
    print(0)
### BUGGY CODE ###

import numpy as np
H,W=map(int,input().split())
S=list(list(input()) for _ in range(H))
ans=0
for i in range(H):
    for j in range(W):
        if S[i][j]!='#' and j!=W-1:
            ans+=1
        elif S[i][j]!='#'and j==W-1 :
            for k in range(ans+1):
                S[i][j-k]=ans+1
            ans=0
        else:
            for k in range(1,ans+1):
                S[i][j-k]=ans
            ans=0
q=list()
S_t=list(map(list,zip(*S)))
ans=0
for i in range(W):
    for j in range(H):
        if S_t[i][j]!='#' and j!=H-1:
            ans+=1
        elif S_t[i][j]!='#'and j==H-1 :
            for k in range(ans+1):
                q.append(ans+1+int(S_t[i][j-k]))
            ans=0
        else:
            for k in range(1,ans+1):
                q.append(ans+int(S_t[i][j-k]))
            ans=0
c=0
print(max(q)-1)

### FIXED CODE ###

H,W=map(int,input().split())
S=list(list(input()) for _ in range(H))
ans=0
for i in S:
    for j in range(W):
        if i[j]!='#' and j!=W-1:
            ans+=1
        elif i[j]!='#'and j==W-1 :
            for k in range(ans+1):
                i[j-k]=ans+1
            ans=0
        else:
            for k in range(1,ans+1):
                i[j-k]=ans
            ans=0
S_t=list(map(list,zip(*S)))
ans=0
for i in S_t:
    for j in range(H):
        if i[j]!='#' and j!=H-1:
            ans+=1
        elif i[j]!='#'and j==H-1 :
            for k in range(ans+1):
                i[j-k]+=ans+1
            ans=0
        else:
            for k in range(1,ans+1):
                i[j-k]+=ans
            ans=0
            i[j]=0
c=0
for i in S_t:
    c=max(c,max(i))
print(c-1)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = sum([max(0, a[i] - mid // f[i]) for i in range(n)])
    if ck <= k: right = mid
    else: left = mid

print(right)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

left, right = -1, a[-1] * f[0]

while right - left > 1:
    mid = (left + right) // 2
    ck = 0
    for i in range(n): ck += max(0, a[i] - mid // f[i])
    if ck <= k: right = mid
    else: left = mid

print(right)
### BUGGY CODE ###

s = input()
t = len(s)

m = [0]
a = 0
for i in reversed(range(0, t)):
    a += 10**(t-i-1) * int(s[i])
    a = a % 2019
    m.append(a)

n = sorted(m)

c = 0
d = 0

for i in range(t-1):
    if n[i] == n[i+1]:
        c += 1
        d += c
    else:
        c = 0

print(d)



### FIXED CODE ###

s = input()
t = len(s)

x = []
y = 0

while 10 ** y % 2019 not in x:
    x.append(10 ** y % 2019)
    y += 1

z = len(x)

m = [0 for i in range(2019)]
m[0] = 1
a = 0
for i in reversed(range(0, t)):
    a += x[(t-i-1) % z] * (int(s[i]) % 2019)
    a = a % 2019
    m[a] += 1

def triangle(n):
    if n > 1:
        return n * (n-1) // 2
    else:
        return 0

p = list(map(triangle, m))
# print(p)
print(sum(p))
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = [list(map(int,input().split())) for _ in range(N)]
    MOD = 10**9+7
    
    dp = [1] + [0 for _ in range(1<<N)]

    for i in range(N):
        use = [0 for _ in range((1<<N)+1)]
        for s in range(1<<N):
            if dp[s] == 0:
                continue
            for j in range(N):
                jb = 1<<j
                if not (s&jb) and a[i][j]:
                    use[s^jb] += dp[s]
                    use[s^jb] %= MOD
        dp = use
    
    print(dp[(1<<N)-1])
        
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = [list(map(int,input().split())) for _ in range(N)]
    MOD = 10**9+7
    
    dp = [1] + [0 for _ in range(1<<N)]

    for i in range(N):
        use = [0 for _ in range((1<<N)+1)]
        for s in range(1<<N):
            if dp[s] == 0:
                continue
            for j in range(N):
                jb = 1<<j
                if not (s&jb) and a[i][j]:
                    use[s^jb] += dp[s]
        dp = use
    
    print(dp[(1<<N)-1]%MOD)

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

def main():
    from collections import defaultdict
    n, m, *ab, = map(int, open(0).read().split())
    f = defaultdict(lambda: set())
    for i, j in zip(ab[::2], ab[1::2]):
        f[i].add(j)
        f[j].add(i)

    group = []
    i = 1
    g = {i}
    nx = {i}
    checked = set()
    while i <= n:
        if i in checked:
            i += 1
            continue
        checked |= g
        tmp = set()
        for j in list(nx):
            tmp |= f[j]
        tmp -= checked

        if len(tmp) == 0:
            group.append(g)
            i += 1
            g = {i}
            continue
        else:
            g |= tmp
            nx = tmp

    ans = max(list(map(len, group)))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, m, *ab, = map(int, open(0).read().split())
    p = [-1] * (n + 1)

    def find(x):
        while p[x] > 0:
            x = p[x]
        return x

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi == pj:
            return
        if p[pi] < p[pj]:
            pi, pj = pj, pi
            i, j = j, i
        p[pi] += p[pj]
        p[pj] = pi
        reconnect(j, pi)

    def reconnect(i, j):
        while p[i] > 0:
            k = p[i]
            p[i] = j
            i = k

    for i, j in zip(ab[::2], ab[1::2]):
        union(i, j)

    print(-min(p))


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

from itertools import*
import sys
input=sys.stdin.readline
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
d=[[],[],[]]
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        d[(i+j+2)%3].append(v-1)
ans=[]
for cmb in permutations(range(c),3):
    ans.append(sum(sum(cost[i][cmb[dindex]]for i in d[dindex])for dindex in range(3)))
print(min(ans))

### FIXED CODE ###

from itertools import*
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
d=[[0]*c for i in range(3)]
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        d[(i+j)%3][v-1]+=1
print(min(sum(cost[j][cmb[i]]*d[i][j]for j in range(c)for i in range(3))for cmb in permutations(range(c),3)))
### BUGGY CODE ###

import sys
import numpy as np
input = sys.stdin.readline

n = int(input())
L = np.array(list(map(int, input().split())))
s = 0
f = True
while True:
    minL = np.min(L[s:])
    m_idx = np.where(L==minL)[0][-1]
    for i in range(s, m_idx):
        if L[i] - minL >=2:
            print('No')
            f = False
            break
    s = m_idx+1
    
    if s==n or f ==False:
        break

if f ==True:
    print('Yes')

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n = int(input())

L = np.array(list(map(int, input().split())))

for i in range(n-1, 0, -1):
    if L[i]-L[i-1] ==-1:
        L[i-1] -=1

if np.all(L ==sorted(L)):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

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

#n = 5
#a = [3,3,4,2,4]

a.insert(0,0)

i = 1
pushed = [1]
ans = 0
while(1):
  ans += 1
  if a[i] == 2:
    break
  if a[i] in pushed:
    ans = -1
    break
  else:
    pushed.append(a[i])
    i = a[i]

print(ans)

### FIXED CODE ###

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

#n = 10
#a = [10,0,2,3,4,5,6,7,8,9]

a.insert(0,0)
i = 1
ans = 0
for _ in range(n+1):
  ans += 1
  i = a[i]
  if i == 2:
    break
else:
  ans = -1

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

import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()

a.sort()
b.sort()
c.sort()

ans = 0
for i in range(n):
    x = bisect.bisect_left(b, c[i])
    for j in range(x-1, -1, -1):
        y = bisect.bisect_left(a, b[j])
        ans += y

print(ans)
















### FIXED CODE ###

import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()

a.sort()
b.sort()
c.sort()

ans = 0
for tmp in b:
    top = bisect.bisect_left(a, tmp)
    bottom = bisect.bisect_right(c, tmp)
    ans += top * (n-bottom)

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

n_people, full_p, n_ques = map(int, input().split())

point = [full_p]*n_people

for i in range(n_ques):
  people = int(input())
  for j in range(n_people):
    if (j+1) != people: point[j] -= 1
      
for i in range(n_people):
  if point[i]>0: print('Yes')
  else: print('No')

### FIXED CODE ###

n_people, full_p, n_ques = map(int, input().split())

count = [0]*n_people

for i in range(n_ques):
  people = int(input())
  count[people-1] += 1

     
for i in range(n_people):
  if count[i] > n_ques-full_p:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
D=[]
for i in range(min(K,X)):
    for j in range(min(K,Y)):
        D.append(A[X-1-i]+B[Y-1-j])
D.sort()
ans=[]
for i in range(min(K,len(D))):
    for j in range(min(K,Z)):
        ans.append(D[len(D)-1-i]+C[Z-1-j])
ans.sort()
for i in range(K):
    print(ans[len(ans)-1-i])

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            else:
                ans.append(A[i]+B[j]+C[k])
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])