Harryxun/stf_run huggingface dataset:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

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

n = int(readline())
a = list(map(int, readline().split()))

counter = [0 for _ in range(n + 1)]
for i in a:
    counter[i] += 1

MAX = 10 ** 5
MOD = 10 ** 9 + 7
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod
comInit(MOD)

total = 0 
diff = [0 for _ in range(n + 1)]
for i, c in enumerate(counter):
    x = com(c, 2, MOD)
    total += x
    # if c - 1 <= 0:
    #     diff[i] = x
    # else:
    #     y = com(c - 1, 2, MOD)
    #     diff[i] = x - y

for i in range(n):
    print(total - diff[a[i]])

### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

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

n = int(readline())
a = list(map(int, readline().split()))

counter = [0 for _ in range(n + 1)]
for i in a:
    counter[i] += 1

total = 0 
diff = [0 for _ in range(n + 1)]
for i, c in enumerate(counter):
    x = c * (c - 1) // 2
    total += x
    if c - 1 <= 0:
        diff[i] = x
    else:
        y = (c - 1) * (c - 2) // 2
        diff[i] = x - y

for i in range(n):
    print(total - diff[a[i]])
N = int(input())
X = list(map(int, input().split()))
sum = 0
for x in X:
  sum = sum +(x-P)**2
print(sum)

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
  sum = 0
print(min_sum)
N = int(input())
H = list(map(int, input().split()))
max_count = 0
for i in range(N-1):
  tmp_count = 0
  for j in range(i+1, N-i):
  	if H[j-1] >= H[j]:
      tmp_count=tmp_count+1
  if tmp_count > max_count:
    max_count = tmp_count
print(max_count)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
tmp = 0
s = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    tmp += 1
    s = max(s, tmp)
  else:
    tmp = 0
    
print(s)
N = int(input())
A = list(map(int, input().split()))
count = [0] * N
last = [0] * N
used = [0] * N

if A == [1, 1, 1]:
  print(1)
  quit()

for i in range(3 * N):
  now = A[i] - 1
  count[now] += 1
  if count[now] == 3:
    last[now] = i
  #print(now)  
#print(count, last)    

score = 0
now = [A[0], A[1], A[2], A[3], A[4]]
for i in range(N - 1):
  L = [0] * 5
  for j in range(5):
    L[j] = [last[now[j] - 1], j, used[now[j] - 1]]
  L = sorted(L)
  #print(L)
  if L[1][0] == L[2][0]:
    if L[0][0] == L[1][0]:
      score += 1
      one, two = L[3][1], L[4][1]
    elif L[2][0] == L[3][0]:
      score += 1
      one, two = L[0][1], L[4][1]
    else:
      L = sorted(L, key = lambda x:x[2])
      one, two = L[0][1], L[1][1]
      used[L[0][2]] = 1
      used[L[0][3]] = 1
      used[L[0][4]] = 1
  elif (L[2][0] == L[3][0]) and (L[3][0] == L[4][0]):
    score += 1
    one, two = L[0][1], L[1][1]
  else:
    L = sorted(L, key = lambda x:x[2])
    one, two = L[0][1], L[1][1]
    used[L[0][2]] = 1
    used[L[0][3]] = 1
    used[L[0][4]] = 1
    
  if i != N - 2:
    now = [A[one], A[two], A[5 + 3 * i], A[6 + 3 * i], A[7 + 3 * i]]
  else:
    now = [A[one], A[two], A[-1]]
  
if now[0] == now[1] and now[1] == now[2]:
  score += 1
    
print(score)  
      
      
  
  
  
  
  
  
  
  
  
  
  
  





### FIXED CODE ###

#ABC176 #F 問題 (Question F) #解説方針 #提出参考
N = int(input())
A = list(map(int, input().split()))

#DP(動的計画法)用配列
ans = [[-N] * (N+1) for _ in range(N+1)]
#初期化 (Initialization)
a0, a1 = A[:2]
ans[a0][a1] = 0
ans[a1][a0] = 0

##最大値の管理
#ans[i] の最大値を集めた配列 (0 <= i <= N)
ma = [-N] * (N+1) 
#ans の初期化に合わせて初期化
ma[a0] = 0
ma[a1] = 0
#ansの全要素の最大値、0で初期化
all_max = 0

#3, 4, 5番目の数が等しいときに加算するための変数
add = 0

#DP部分 多分 O(N ** 2)
for i in range(N - 1): 
    #3, 4, 5番目の数を a, b, c とする
    a, b, c = A[3 * i + 2], A[3 * i + 3], A[3 * i + 4]
    #3つとも等しいとき、最後の三枚を消す
    if a == b == c:
        add += 1
        continue
    Q = []
    for _ in range(3):
        a, b, c = b, c, a
        # a, b, c から残す数を2つ選ぶ
        # ans[c][c] + 1 は [c,c,a,b,c]を想定
        # all_max は DP[i][k][l]の最大値で最大化するときに対応
        Q.append((a, b, max(all_max, ans[c][c] + 1)))
        
        # a, b, c から残す数を1つ選ぶ
        for j in range(1, N + 1):
            #これまでのDP[i][k][l] (k, lのうち片方の変数として見たとき) の最大値
            val = ma[j]
            #2つの数が等しいとき
            if b == c:
                val = max(val, ans[b][j] + 1)
            Q.append((a, j, val))
            
        #配列を使いまわしているので、DP[i + 1][k][l] を DP[i][k][l]で最大化し直す必要なし
        #もしDP[i][k][l]が最大なら、maxを取る過程でこれが残る
    for i, j, val in Q:
        #DP配列の更新
        ans[i][j] = max(ans[i][j], val)
        ans[j][i] = max(ans[j][i], val)
        #最大値の管理
        ma[i] = max(ma[i], val)
        ma[j] = max(ma[j], val)
        all_max = max(all_max, val)
        
#ans の中から最大の値を見つけ出す。O(N ** 2)        
answer = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        #最後に残った3枚が同じならもう1点加算
        if i == j == A[-1]:
            answer = max(answer, ans[i][j] + 1)
        else:
            answer = max(answer, ans[i][j])
            
print(answer + add)
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(lst!=[]):
    for a in lst:
         fl.append(int(a))
else:
    print(X)
for a in range(len(fl)):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break

### FIXED CODE ###

l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(N!=0):
    for a in lst:
         fl.append(int(a))
for a in range(101):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break
from itertools import permutations
N = int(input())
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
cnt = 0
for x in permutations(range(1,N+1),N):
    if P==x:
        indP = cnt
    elif Q==x:
        indQ = cnt
    cnt += 1
print(abs(indP-indQ))

### FIXED CODE ###

from itertools import permutations
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = []
for x in permutations(range(1,N+1),N):
    A.append(list(x))
A = sorted(A)
indP = A.index(P)
indQ = A.index(Q)
print(abs(indP-indQ))
def main():
    n = int(input())

    # for i in range(1, n + 1):
    #     if

    # i = 1
    # while i * i <= n:
    #     i += 1
    #
    # print((i - 1) ** 2)

    ans = [1]
    for i in range(2, n + 1):
        j = 2
        while i ** j <= n:
            ans.append(i ** j)
            j += 1

    print(max[ans])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())

    # for i in range(1, n + 1):
    #     if

    # i = 1
    # while i * i <= n:
    #     i += 1
    #
    # print((i - 1) ** 2)

    ans = [1]
    for i in range(2, n + 1):
        j = 2
        while i ** j <= n:
            ans.append(i ** j)
            j += 1

    print(max(ans))


if __name__ == '__main__':
    main()
N =int(input())
d = list(map(int,input().split()))

r  = 0
for i in range(N-1):
    for f in range(i + 1,N):
        r += d[i] * d[j]
print(r)

### FIXED CODE ###

N =int(input())
d = list(map(int,input().split()))

r  = 0
for i in range(N-1):
    for j in range(i + 1,N):
        r += d[i] * d[j]
print(r)
# B

s = input() # 1行読み込む（文字列）

min = 999
i = 0
while i + 3 < s.length:
    t = s[i:i+3]
    n = int(t) - 753
    if n < 0:
        n = n - 1
    if min > n:
        min = n

print(min)


### FIXED CODE ###

# B

s = input()

min = 999
i = 0
while i + 3 <= len(s):
    t = s[i:i+3]
    n = int(t) - 753
    if n < 0:
        n = -n
    if min > n:
        min = n
    i = i + 1

print(min)
i = input()

acc = 0
for j in range(len(i)//2):
	acc+=9*(10**(2*j))

if len(i)%2==0:
	print(acc)
else:
	addition = int(i[1:])+1 + (int(i[0])-1)*10**(len(i)-1)
	print(acc+addition)

### FIXED CODE ###

i = input()

acc = 0
for j in range(len(i)//2):
  acc+=9*(10**(2*j))

if len(i)%2==0:
  print(acc)
else:

  addition = (int(i[0])-1)*10**(len(i)-1)+1
  if len(i)>1:
    addition += int(i[1:])
  print(acc+addition)
from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


k = int(input())

graph = [[] for _ in range(k)]
for i in range(1, k):
    graph[i - 1].append((1, i + 1))
    graph[i].append((0, 10 * i % k))

dist = dijkstra(graph, k, 1)
ans = dist[0]
print(ans)


### FIXED CODE ###

from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


k = int(input())

graph = [[] for _ in range(k)]
for i in range(1, k):
    graph[i].append((1, (i + 1) % k))
    graph[i].append((0, 10 * i % k))

dist = dijkstra(graph, k, 1)
ans = dist[0] + 1
print(ans)
import sys

nm=input().split()
a=input()
n=int(nm[0])
m=int(nm[1])
lista=[]
for i in a:
  lista.append(int(i))
count=0
suma=sum(lista)
thre=suma/4/m
for i in lista:
  if i >= thre:
    count+=1
  if count >= m:
    print('Yes')
    sys.exit()
print('No')

### FIXED CODE ###

import sys
 
nm=input().split()
a=input().split()
n=int(nm[0])
m=int(nm[1])
lista=[]
for i in a:
  lista.append(int(i))
count=0
suma=sum(lista)
thre=suma/4/m
for i in lista:
  if i >= thre:
    count+=1
  if count >= m:
    print('Yes')
    sys.exit()
print('No')
a,b,c,d,e,f=map(int,input().split())
water=[]
sugar=[]
ans,ans_2,con=0,0,0
for i in range(f//100+1):#f//100+1によりTLEを解消
    for j in range(f//100+1):
        x=100*a*i+100*j*b
        if x<=f:
            water.append(x)
for i in range(f):
    for j in range(f):
        y=c*i+d*j
        if y<=f:
            sugar.append(y)
sugar=list(set(sugar))
for i in water:
    for j in sugar:
        if i+j<=f:
            f j<=(i//100)*e:
                now=(100*j)/(i+j)
                if con<=now:
                    ans=i+j
                    ans_2=j
                    con=now
print(ans,ans_2)


### FIXED CODE ###

a,b,c,d,e,f = map(int, input().split())

sugar = []
for i in range(f):
    for j in range(f):
        y = i*c + j*d
        if y <= f:
            sugar.append(y)

water = []
for i in range(0, f//100+1):
    for j in range(0, f//100+1):
        x = i*a*100 + j*b*100
        if x <= f:
            water.append(x)
max_concentration = 0
ans1, ans2 = 0, 0
for x in water:
    for y in sugar:
        if x == 0 and y == 0:
            continue
        elif e * (x // 100) < y:
            continue
        elif x + y > f:
            continue
        else:
            concentration = (100 * y) / (x+y)
            if max_concentration <= concentration:
                max_concentration = concentration
                ans1 = x+y
                ans2 = y
print("{} {}".format(ans1, ans2))
n,m=map(int,input().split())
food=list(range(1,m+1))
for i in range(n):
    k,*a=map(int,input().split())
    food &= set(a)
print(len(food))

### FIXED CODE ###

n,m=map(int,input().split())
food=set(range(1,m+1))
for i in range(n):
    k,*a=map(int,input().split())
    food &= set(a)
print(len(food))
import fractions

N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
    
print(ans)

### FIXED CODE ###

import fractions

N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(1, N):
    ans = fractions.gcd(ans, A[i])
    
print(ans)
list = str(input())

if list is "AAA" or list is "BBB" or len(list(list)) is not 3:
    print("No")
else : 
    print("Yes")


### FIXED CODE ###

list = str(input())

if list == 'AAA' or list == 'BBB' or len(list) != 3:
    print("No")
else : 
    print("Yes")
N = int(input())
s = str(input())
types = []
for i in range(len(s)-1):
    x = s[:i+1]
    y = s[i+1:]
    x.sort()
    y.sort()
    x_str = []
    y_str = []
    count = 0
    for j in range(len(x)):
        if j == 0:
            x_str.append(x[0])
        else:
            if x[j-1] != x[j]:
                x_str.append(x[j])
    for j in range(len(y)):
        if j == 0:
            y_str.append(y[0])
        else:
            if y[j-1] != y[j]:
                y_str.append(y[j])
    for j in range(len(x_str)):
        if x_str[j] in y_str:
            count += 1
    types.append(count)
print(max(types))

### FIXED CODE ###

N = int(input())
s = str(input())
types = []
for i in range(len(s)-1):
    x = list(s[:i+1])
    y = list(s[i+1:])
    x.sort()
    y.sort()
    x_str = []
    y_str = []
    count = 0
    for j in range(len(x)):
        if j == 0:
            x_str.append(x[0])
        else:
            if x[j-1] != x[j]:
                x_str.append(x[j])
    for j in range(len(y)):
        if j == 0:
            y_str.append(y[0])
        else:
            if y[j-1] != y[j]:
                y_str.append(y[j])
    for j in range(len(x_str)):
        if x_str[j] in y_str:
            count += 1
    types.append(count)
print(max(types))
H,W=map(int,input().split())
A=tuple(tuple(input()) for _ in range(H))
next_q=[]
L=[[0]*W for _ in range(H)]
for i,row in enumerate(A):
    for j,c in enumerate(row):
        if c=='#':
            next_q.append((i,j))
            L[i][j]=1
res=-1
while len(next_q)!=0:
    q,next_q=next_q[:],[]
    if len(q)==0:break
    while len(q)!=0:
        x,y=q.pop(0)
        if x>0 and L[x-1][y]==0:
            L[x-1][y]=1
            next_q.append((x-1,y))
        if x<W-1 and L[x+1][y]==0:
            L[x+1][y]=1
            next_q.append((x+1,y))
        if y>0 and L[x][y-1]==0:
            L[x][y-1]=1
            next_q.append((x,y-1))
        if y<H-1 and L[x][y+1]==0:
            L[x][y+1]=1
            next_q.append((x,y+1))
    res+=1
print(res)

### FIXED CODE ###

from collections import deque
import copy
H, W = map(int, input().split())
A = tuple(tuple(input()) for _ in range(H))
L=[[0]*W for _ in range(H)]
next_q=deque()

for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            L[i][j]=1
            next_q.append((i,j))

q=deque()

res = 0
while len(next_q) != 0:
    q=copy.copy(next_q)
    next_q.clear()
    while q:
        y, x = q.popleft()
        if y > 0 and L[y - 1][x] == 0:
            L[y - 1][x] = 1
            next_q.append((y - 1, x))
        if y < H - 1 and L[y + 1][x] == 0:
            L[y + 1][x] = 1
            next_q.append((y + 1, x))
        if x > 0 and L[y][x - 1] == 0:
            L[y][x - 1] = 1
            next_q.append((y, x - 1))
        if x < W - 1 and L[y][x + 1] == 0:
            L[y][x + 1] = 1
            next_q.append((y, x + 1))
    if len(next_q)==0: break
    res += 1
print(res)
a = int(input())
aa = list(str(a))
n = 0
for i in range(len(aa)):
	b = int(aa[i])
    if b == 7:
        n +=1
    else:
        n = n
if n > 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a = int(input())
aa = list(str(a))
n = 0
for i in range(len(aa)):
    b = int(aa[i])
    if b == 7:
        n +=1
    else:
        n = n
if n > 0:
    print("Yes")
else:
    print("No")
N,M = map(int,input().split())

A = [[0]]*(N+1)
A[N] = str("a")*50
B = [[0]]*M

for i in range(N):
    A[i] = input()
for j in range(M):
    B[j] = input()

judge = False 
count = 0   
for i in range(N-M+1):
    for j in range(M):
        if B[j]==A[i][i:i+M] and B[j+1]==A[i+1][i:i+M]:
            count += 1
            
            if count == M - 1:
                judge = True
                break
if judge == True:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

A = [[0]]*N
B = [[0]]*M

for i in range(N):
    A[i] = input()
for j in range(M):
    B[j] = input()

judge = False 

#行同士で比較していく
for k in range(N-M+1):
    for i in range(N-M+1):
        count = 0
        for j in range(M):
            if B[j]==A[j+i][k:k+M]:
                count += 1
                
                if count == M:
                    judge = True
                    break
            
if judge == True:
    print("Yes")
else:
    print("No")
input()
int_list = list(map(int, input().split()))
max_num = 10**18
ans = 1

if 0 in int_list:
   print(0)
   exit()
 
for i in int_list:
   ans *= i
   if ans > max_num:
       print(-1)
       break
else:
   print(ans)

### FIXED CODE ###

x, y = map(int, input().split())
print(x*y)
list = input().rstrip().split(" ")
kisu = int(list[1])
gusu = int(list[0])
#奇数奇数の場合
kiki = kisu * (kisu - 1
#偶数偶数の場合

### FIXED CODE ###

n, m = map(int, input().split())
print((n * ~-n // 2) + (m* ~-m // 2))#n * ~-n == n*(n-1)
def in(x):
	if x == 0:
		return 1
    if x == 1:
		return 0
x = int(input())
print(in(x))

### FIXED CODE ###

x = int(input())
if x == 0:
  print(1)
if x == 1:
  print(0)
s = str(input())


a, b = 0, 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        a, b = i+1, i+2
        break
    elif i != len(s)-1:
        if s[i] == s[i+2]:
            a, b = i+1, i+3
            break
        
if a == 0:
    print(-1, -1)
else:
    print(a, b)

### FIXED CODE ###

s = str(input())


a, b = 0, 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        a, b = i+1, i+2
        break
    elif i < len(s)-2:
        if s[i] == s[i+2]:
            a, b = i+1, i+3
            break
        
if a == 0:
    print(-1, -1)
else:
    print(a, b)
n, m, x = map(int,input().split())
a = list(map(int,input().split()))
ans1 = 0
ans2 = 0
aa = a
if x == 1 or x == n:
    print(0)
else:
    for i in range(1, x):
        if a[0] == i:
            ans1 += 1
            a.pop(0)
    if len(a) != 0:
        for i in range(x, n):
            if a[0] == i:
                ans2 += 1
                a.pop(0)
    ans = min(ans1, ans2)
    print(ans)

### FIXED CODE ###

n, m, x = map(int,input().split())
a = list(map(int,input().split()))
ans1 = 0
ans2 = 0
if x == 1 or x == n:
    print(0)
else:
    for i in range(1, x):
        if len(a) != 0:
            if a[0] == i:
                ans1 += 1
                a.pop(0)
    if len(a) != 0:
        for i in range(x, n):
            if len(a) != 0:
                if a[0] == i:
                    ans2 += 1
                    a.pop(0)
    ans = min(ans1, ans2)
    print(ans)
A,B=input().split()
A = int(A)

if isinstance(B,int):
    B = int(B)
else:
    B = float(B)
print(math.floor(A*B))



### FIXED CODE ###


import math
from decimal import *

A,B=input().split()
print(math.floor(Decimal(A)*Decimal(B)))
main()
import math
n,m=map(int,input().split())
def cc(n,r):
    return int(math.factorial(n)/(math.factorial(n-r)*math.factorial(r)))
if n>=2:
    if m>=2:
        print(cc(n,2)+cc(m,2))
    else:
        print(cc(n,2))
else:
    if m>=2:
        print(cc(m,2))
    else:
        print(0)

### FIXED CODE ###

import math
n,m=map(int,input().split())
def cc(n,r):
    return int(math.factorial(n)/(math.factorial(n-r)*math.factorial(r)))
if n>=2:
    if m>=2:
        print(cc(n,2)+cc(m,2))
    else:
        print(cc(n,2))
else:
    if m>=2:
        print(cc(m,2))
    else:
        print(0)
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())

list_cake_1 = list(map(int, input().split()))
list_cake_2 = list(map(int, input().split()))
list_cake_3 = list(map(int, input().split()))

list_cake_1 = sorted(list_cake_1, reverse=True)
list_cake_2 = sorted(list_cake_2, reverse=True)
list_cake_3 = sorted(list_cake_3, reverse=True)

list_total_sum = []

for i, cake_1 in enumerate(list_cake_1, 1):
	for j, cake_2 in enumerate(list_cake_2, 1):
		for k, cake_3 in enumerate(list_cake_3, 1):
			if i*j*k > K:
				break
			list_total_sum.append(cake_1 + cake_2 + cake_3)

for element in sorted(list_total_sum, reverse=True)[:K]:
	print(element)

### FIXED CODE ###

import sys

input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())

list_cake_1 = list(map(int, input().split()))
list_cake_2 = list(map(int, input().split()))
list_cake_3 = list(map(int, input().split()))

list_cake_1 = sorted(list_cake_1, reverse=True)
list_cake_2 = sorted(list_cake_2, reverse=True)
list_cake_3 = sorted(list_cake_3, reverse=True)

list_total_sum = []

for i, cake_1 in enumerate(list_cake_1, 1):
	for j, cake_2 in enumerate(list_cake_2, 1):
		for k, cake_3 in enumerate(list_cake_3, 1):
			if i*j*k > K:
				break
			list_total_sum.append(cake_1 + cake_2 + cake_3)

for element in sorted(list_total_sum, reverse=True)[:K]:
	print(element)
print((int(input())-1)*(int(input())-1))

### FIXED CODE ###

m,n=map(int,input().split());print((m-1)*(n-1))
n,k = map(int,input().split())
a = map(int,input().split())
a.sort()
print(sum(p[:k]))

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
print(sum(a[:k]))