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

import itertools
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in list(itertools.combinations(a,3)):
  if i[0] < i[1] + i[2] and i[1] < i[2] + i[0] and i[2] < i[0] + i[1]:
    ans += 1
print(ans)

### FIXED CODE ###

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

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

k = M // N + 1
ans = 1
for i in reversed(range(1, k+1)):
    if ans > i:
        break
    tmp = max(M - (N-1)*i, 1)
    if tmp % i == 0:
        ans = max(ans, i)

print(ans)


### FIXED CODE ###

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

k = M // N + 1
ans = 1
for i in reversed(range(1, k+1)):
    if ans > i:
        break
    tmp = max(M - (N-1)*i, 1)
    if tmp % i == 0:
        ans = max(ans, i)

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

n = int(input())
P = list(map(float, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
  for j in range(n+1):
    if j==0:
      dp[i+1][j] = dp[i][j]*(1-P[i])
    else:
      dp[i+1][j] = dp[i][j-1]*P[i] + dp[i][j]*(1-P[i])
print(sum(dp[n][1+n//2:]))

### FIXED CODE ###

n = int(input())
P = list(map(float, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
  for j in range(n+1):
    if j==0:
      dp[i+1][j] = dp[i][j]*(1-P[i])
    else:
      dp[i+1][j] = dp[i][j-1]*P[i] + dp[i][j]*(1-P[i])
print(sum(dp[n][1+n//2:]))
### BUGGY CODE ###

N = int(input())
list_P = [int(x) for x in input().split()]

ans = 0

for i in range(len(list_P)) :
    out = 0
    for j in range(i) :
        if list_P[i] > list_P[j] :
            out = 1
    if out == 0 :
        ans += 1

print(ans)


### FIXED CODE ###

N = int(input())
list_P = [int(x) for x in input().split()]

ans = 0
min = N+1

for i in list_P :
    if i < min :
        ans += 1
        min = i

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

n = int(input())
a = [int(i) for i in input().split(" ")]

a.sort()
dp = [True for i in range(n)]

for i in range(n):
    if dp[i]:
        for j in range(i + 1, n):
            if not a[j] % a[i]:
                dp[j] = False
            if a[j] == a[i]:
                dp[i] = False

print(dp.count(True))

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split(" ")]

a.sort()
dp = [True for i in range(a[-1]+1)]
count=0

for i in range(n):
    if dp[a[i]]:
        count+=1
        for j in range(1,n-i):
            if a[i]!=a[i+j]:
                break
            elif j==1:
                count-=1
            dp[a[i+j]]=False
        for j in range(a[i], a[-1]+1, a[i]):
            dp[j]=False
        # for j in range(i + 1, n):
        #     if not a[j] % a[i]:
        #         dp[j] = False
        #     if a[j] == a[i]:
        #         dp[i] = False

#print(dp.count(True))
print(count)
### BUGGY CODE ###

import operator
import numpy as np
n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

sa1 = np.argsort(xy[:,0])
sa2 = np.argsort(xy[:,1])

s1 = xy[sa1,0]
s2 = xy[sa2,1]
c1 = s1[1:] - s1[:-1]
c2 = s2[1:] - s2[:-1]

c = [(c, (sa1[i], sa1[i+1])) for i, c in enumerate(c1)] + [(c, (sa2[i], sa2[i+1])) for i, c in enumerate(c2)]
c = sorted(c, key=operator.itemgetter(0))

total_cost = 0
sg = {}
for cost, verts in c:
    vf1 = sg.get(verts[0])
    vf2 = sg.get(verts[1])
    if vf1 and vf2:
        if vf1 == vf2: continue
        total_cost += cost
        vf1.update(vf2)
        for v in vf2: sg[v] = vf1
    else:
        total_cost += cost
        if vf1:
            vf1.add(verts[1])
            sg[verts[1]] = vf1
        elif vf2:
            vf2.add(verts[0])
            sg[verts[0]] = vf2
        else:
            sg[verts[0]] = sg[verts[1]] = set(verts)
print(total_cost)

### FIXED CODE ###

import operator
import numpy as np
n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

sa1 = np.argsort(xy[:,0])
sa2 = np.argsort(xy[:,1])

s1 = xy[sa1,0]
s2 = xy[sa2,1]
c1 = s1[1:] - s1[:-1]
c2 = s2[1:] - s2[:-1]

c = [(c, (sa1[i], sa1[i+1])) for i, c in enumerate(c1)] + [(c, (sa2[i], sa2[i+1])) for i, c in enumerate(c2)]
c = sorted(c, key=operator.itemgetter(0))

total_cost = 0
sg = {}
for cost, verts in c:
    vf1 = sg.get(verts[0])
    vf2 = sg.get(verts[1])
    if vf1 and vf2:
        if vf1 is vf2: continue
        if len(vf1) < len(vf2): vf1, vf2 = vf2, vf1
        total_cost += cost
        vf1.update(vf2)
        for v in vf2: sg[v] = vf1
    else:
        total_cost += cost
        if vf1:
            vf1.add(verts[1])
            sg[verts[1]] = vf1
        elif vf2:
            vf2.add(verts[0])
            sg[verts[0]] = vf2
        else:
            sg[verts[0]] = sg[verts[1]] = set(verts)
print(total_cost)
### BUGGY CODE ###

import numpy as np
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
mod = 10**9+7

ans = 0
one = np.zeros(60, dtype=int)

for i in range(n):
    b = bin(a[i])[2:].zfill(60)

    for j in range(60):
        if b[j] == "1":
            ans += pow(2, 60-j-1, mod)*(i-one[j])
        else:
            ans += pow(2, 60-j-1, mod) * one[j]
        ans %= mod

    one += np.array(list(map(int, list(b))))

print(ans)


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

bit = [0] * 60
for a in A:
    i = 0
    while a > 0:
        bit[i] += a & 1
        i += 1
        a >>= 1

ans = 0
for i, x in enumerate(bit):
    x = x*(n-x)
    for _ in range(i):
        x *= 2
        x %= mod
    ans += x
    ans %= mod
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop

N,Q=map(int, sys.stdin.readline().split())

RW=[]	#  Roadwork: 道路工事を行っている場所　(開始時間、終了時間、x座標)
for _ in range(N):
	s,t,x=map(int, sys.stdin.readline().split())
	RW.append( (max(0,s-x) , max(0,t-1-x),x) )
RW.sort()

D=[ int(sys.stdin.readline().strip()) for _ in range(Q) ]	# Q人の歩き出す時刻
D.sort()


d=0
for d in D:
	hq=[]
	for s,t,x in RW:
		if s<=d<=t:
			heappush(hq, x)

	try:
		print hq[0]
	except:
		print -1


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right

N,Q=map(int, sys.stdin.readline().split())

S=[]
event=[]	#x, s, t
for _ in range(N):
	s,t,x=map(int, sys.stdin.readline().split())
	heappush( event, (x, max(0,s-x) , max(0,t-1-x)) )


D=[ int(sys.stdin.readline().strip()) for _ in range(Q) ]
D.sort()
ans=[ float("inf") for _ in range(Q) ]

Next=[ i+1 for i in range(Q) ]	#Next


while event:
	x,s,t=heappop(event)
	start=bisect_left(D,s)
	end=bisect_right(D,t)

	i=start
	while i<end:
		ans[i]=min(ans[i],x)
		next=Next[i]
		Next[i]=end
		i=next

for x in ans:
	if x==float("inf"):
		print -1
	else:
		print x
### BUGGY CODE ###

n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0

from heapq import heappush, heappop
for i in range(1, k+1):
  for j in range(1, i+1):
    for k in range(0, j+1):
      minus = []
      l = min(n, k)
      r = min(n-l, j-l)
      cur = 0
      for ll in range(l):
        cur += v[ll]
        if v[ll]<0:
          heappush(minus, v[ll])
      for rr in range(r):
        cur += v[n-rr-1]
        if v[n-rr-1]<0:
          heappush(minus, v[n-rr-1])
      rm = i-l-r
      while rm>0 and len(minus)>=rm:
        rm -= 1
        t = heappop(minus)
        cur -= t
      ans = max(ans, cur)
print(ans)

### FIXED CODE ###

n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
ls = [0 for i in range(n+1)]
rs = [0 for i in range(n+1)]
for i in range(n):
  ls[i+1] = ls[i]+v[i]
  rs[i+1] = rs[i]+v[n-i-1]

from heapq import heappush, heappop
for i in range(1, k+1):
  for j in range(1, i+1):
    for k in range(0, j+1):
      menus = []
      l = min(n, k)
      r = min(n-l, j-l)
      for ll in range(l):
        if v[ll]<0:
          heappush(menus, v[ll])
      for rr in range(r):
        if v[n-rr-1]<0:
          heappush(menus, v[n-rr-1])
      cur = ls[l] + rs[r]
      rm = i-l-r
      while rm>0 and len(menus)>=rm:
        rm -= 1
        t = heappop(menus)
        cur -= t
      ans = max(ans, cur)
print(ans)
### BUGGY CODE ###

n,k = list(map(int,input().split()))
m = 10**9+7
for i in range(1,k+1):
  a = 1
  for j in range(i-1):
    a *= k-1-j
    a //= j+1
  b = 1
  for j in range(i):
    b *= n-k+1-j
    b //= j+1
  a %= m
  b %= m
  print(a*b%m)

### FIXED CODE ###

n,k = list(map(int,input().split()))
m = 10**9+7
a = 1
b = n-k+1
print(a*b%m)
for i in range(2,k+1):
  a *= k+1-i
  a //= i-1
  at = a%m
  b *= n-k+2-i
  b //= i
  bt = b%m
  print(at*bt%m)
### BUGGY CODE ###

from pprint import pprint
import queue


def solve(n, q, a, b, p, x):
    counter = [0] * n
    q_sum = [0] * n
    for i in range(q):
        q_sum[p[i]] += x[i]
    # pprint(q_sum)

    edges = {}
    for i in range(n-1):
        if a[i] not in edges:
            edges[a[i]] = []
        edges[a[i]].append(b[i])
    # pprint(edges)

    counter[0] = q_sum[0]
    children = queue.Queue()
    for child in edges[0]:
        counter[child] = q_sum[0]
        children.put(child)
    while not children.empty():
        child = children.get()
        counter[child] += q_sum[child]
        # print("child")
        # print(child, counter[child])
        if child in edges:
            for c in edges[child]:
                counter[c] = counter[child]
                # print("c")
                # print(c, counter[c])
                children.put(c)

    print(" ".join(list(map(str, counter))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    a = []
    b = []
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        a.append(a_i - 1)
        b.append(b_i - 1)

    p = []
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p.append(p_i-1)
        x.append(x_i)
    solve(n, q, a, b, p, x)

### FIXED CODE ###

from collections import deque


def solve(n, q, a, b, p, x):
    counter = [0] * n
    q_sum = [0] * n
    for i in range(q):
        q_sum[p[i]] += x[i]
    # pprint(q_sum)

    edges = {}
    for i in range(n-1):
        if a[i] not in edges:
            edges[a[i]] = []
        edges[a[i]].append(b[i])
    # pprint(edges)

    counter[0] = q_sum[0]
    children = deque()
    for child in edges[0]:
        counter[child] = q_sum[0]
        children.append(child)
    while children:
        child = children.popleft()
        counter[child] += q_sum[child]
        # print("child")
        # print(child, counter[child])
        if child in edges:
            for c in edges[child]:
                counter[c] = counter[child]
                # print("c")
                # print(c, counter[c])
                children.append(c)

    print(" ".join(list(map(str, counter))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    a = []
    b = []
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        a.append(a_i - 1)
        b.append(b_i - 1)

    p = []
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p.append(p_i-1)
        x.append(x_i)
    solve(n, q, a, b, p, x)
### BUGGY CODE ###

S = input()
Q = int(input())
quer = [input().split() for _ in range(Q)]

hanten = 0
t = 0
for i in quer:
    quary = i
    if quary[0]=='1':
        #S = S[::-1]
        hanten = hanten ^ 1
    else:
        t = (int(quary[1])-1) ^ hanten
        if t:
            S = S + quary[2]
        else:
            S = quary[2] + S
    #print(S)
if hanten:
    S = S[::-1]
print(S)

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
quer = [input().split() for _ in range(Q)]

hanten = 0
t = 0
d = deque(S)
for i in quer:
    quary = i
    if quary[0]=='1':
        #S = S[::-1]
        hanten = hanten ^ 1
    else:
        t = (int(quary[1])-1) ^ hanten
        if t:
            #S = S + quary[2]
            d.append(quary[2])
        else:
            #S = quary[2] + S
            d.appendleft(quary[2])
    #print(S)
if hanten:
    d.reverse()
s = ''.join(list(d))
print(s)
### BUGGY CODE ###

n = int(input())
a = [int(s) for s in input().split()]
b = a.copy()
max_index = a.index(max(a))
count = 0
last_index = len(a)
while(last_index > 0):
    b[max_index: last_index] = [a[max_index]] * (last_index - max_index)
    last_index = max_index
    if last_index == 0:
        break
    max_index = a.index(max(a[:last_index]))

for i in range(len(a)):
    count += b[i] - a[i]
print(count)

### FIXED CODE ###

n = int(input())
a = [int(s) for s in input().split()]
count = 0
max = a[0]
for i in range(1, len(a)):
    if max >  a[i]:
        if a[i - 1] > max:
            max = a[i - 1]
        count += max - a[i]
    else:
        max = a[i]
print(count)
### BUGGY CODE ###

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
memo = []
memo_cir = []
index = 0
flag = True
while flag:
    if index in memo:
        flag = False
    else:
        memo.append(index)
        index = a[index] - 1
flag = False
for i_ in memo:
    if i_ == index:
        flag = True
    if flag:
        memo_cir.append(i_)
if k + 1 >= (len(memo) - len(memo_cir)):
    k -= (len(memo) - len(memo_cir) - 1)
    print(memo_cir[(k % len(memo_cir)) - 1] + 1)
else:
    print(memo[k] + 1)


### FIXED CODE ###

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
memo = []
memo_cir = []
visited = [False] * n
index = 0
flag = True
while flag:
    if visited[index]:
        flag = False
    else:
        memo.append(index)
        visited[index] = True
        index = a[index] - 1
flag = False
for i_ in memo:
    if i_ == index:
        flag = True
    if flag:
        memo_cir.append(i_)
if k + 1 >= (len(memo) - len(memo_cir)):
    k -= (len(memo) - len(memo_cir) - 1)
    print(memo_cir[(k % len(memo_cir)) - 1] + 1)
else:
    print(memo[k] + 1)
### BUGGY CODE ###

# coding: utf-8

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

answer = 0
num[0] -= num[1]
answer += num[1]

while num[0]>num[2]:
    num[0] -= num[2] + num[1]
    answer += num[1]
if num[0]<0:
    answer -= 0 - num[0]
    
print(answer)

### FIXED CODE ###

# coding: utf-8

num = input().split()
N, b, r = [int(N) for N in num]

n = N % (b+r)
if n>b:
    print(int(N / (b+r)) * b + b)
else:
    print(int(N / (b+r)) * b + n)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]

a_ = [0]

for i in range(n):
    a_.append(a_[i] + a[i])

cnt = 0
x = []

for i in a_:
    if i in x:
        cnt += x.count(i)
    x.append(i) 

print(cnt)

### FIXED CODE ###

from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]

a_ = [0]

for i in range(n):
    a_.append(a_[i] + a[i])

cnt = 0

def sum(i):
    return int((i + 1) / 2 * i)

for i in Counter(a_).values():
    cnt += sum(i-1)

print(cnt)
### BUGGY CODE ###

import copy
N = int(input())
X = [int(i) for i in input().split()]


c = int(N/2)

for i in range(N):
    Y = copy.deepcopy(X)
    Y[i:i+1] = []
    Y = sorted(Y, key= lambda x: -x)
    print(Y[c-1])

### FIXED CODE ###

import copy
N = int(input())
X = [int(i) for i in input().split()]
Y = copy.deepcopy(X)
Y = sorted(Y, key= lambda x: -x)

c = int(N/2)

for i in range(N):
    a = X[i]
    if a >= Y[c-1]:
        print(Y[c])
    else:
        print(Y[c-1])
### BUGGY CODE ###

n=int(input())
for i in range(1,n+1):
  ans=0
  for x in range(1,int(i**(1/2))):
    for y in range(x,int(i**(1/2))):
      for z in range(y,int(i**(1/2))):
        if (x+y)**2+(y+z)**2+(z+x)**2==2*i:
          if x==y==z:
            ans+=1
          elif (x==y and y!=z) or (x!=y and y==z):
            ans+=3
          elif x!=y and y!=z:
            ans+=6
  print(ans)

### FIXED CODE ###

n=int(input())
ans=[0 for i in range(10050)]
for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v=i*i+j*j+k*k+i*j+i*k+j*k
      if v<10050:
        ans[v]+=1
for i in range(n):
  print(ans[i+1])
### BUGGY CODE ###

N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while ct<M:
    min_id=l.index(min(l))
    for i in range(ab[min_id][1]):
        money+=l[min_id]
        ct+=1
        if ct==M:
            break
    ab[min_id][0]=100000000000
    l[min_id]=100000000000
    if ct==M:
        break
print(money)



### FIXED CODE ###

N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
ct1=0
ct2=0
money=0
l=[]
id=[]
for i in range(N):
    l.append(ab[i][0])
id=sorted(range(len(l)),key=lambda k: l[k])
l.sort()
while ct<M:
    while ct2<ab[id[ct1]][1]:##
        money+=l[ct1] #l[ct1]
        #print(money,l[ct1])
        ct+=1
        ct2+=1
        if ct==M:
            break
    ct1+=1
    ct2=0
print(money)
### BUGGY CODE ###

n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
ans = 0
for i in T:
	if i in S:
		ans += 1
print ans

### FIXED CODE ###

n = int(raw_input())
S = set(raw_input().split())
q = int(raw_input())
T = set(raw_input().split())
print len(S&T)
### BUGGY CODE ###

H,W=map(int, input().split())
S=[input() for i in range(H)]
l=[[0]*W for i in range(H)]
r=[[0]*W for i in range(H)]
t=[[0]*W for i in range(H)]
b=[[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w]=='.':
            l[h][w]=l[h][w-1]+1
            t[h][w]=t[h-1][w]+1
        if S[h][W-w-1]=='.':
            r[h][W-w-1]=r[h][-w]+1
        if S[H-h-1][w]=='.':
            b[H-h-1][w]=b[-h][w]+1
ans=0
for h in range(H):
    for w in range(W):
        ans=max(ans,l[h][w]+r[h][w]+t[h][w]+b[h][w]-3)
print(ans)

### FIXED CODE ###

H,W=map(int, input().split())
S=[input() for i in range(H)]
l=[[0]*W for i in range(H)]
r=[[0]*W for i in range(H)]
t=[[0]*W for i in range(H)]
b=[[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w]=='.':
            l[h][w]=l[h][w-1]+1
            t[h][w]=t[h-1][w]+1
        if S[h][W-w-1]=='.':
            r[h][W-w-1]=r[h][-w]+1
        if S[H-h-1][w]=='.':
            b[H-h-1][w]=b[-h][w]+1
ans=0
for h in range(H):
    for w in range(W):
        ans=max(ans,l[h][w]+r[h][w]+t[h][w]+b[h][w]-3)
print(ans)
### BUGGY CODE ###

def grid_bfs(h,w,start,maze,visit):
#    debug_print(maze)
    INF = 10**9+7
    distance = [[INF for _ in range(w)] for _ in range(h)]
    visited = visit
    def bfs():
        queue = []
        for s in start:
            queue.append(s)
            distance[s[0]][s[1]] = 0
        while len(queue):
            y, x = queue.pop()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (0<= nx <w and 0<= ny <h and maze[ny][nx] != '#' and distance[ny][nx] == INF):
                    queue.insert(0, (ny, nx))
                    distance[ny][nx] = distance[y][x] + 1
                    visited.append([ny,nx])
        return distance, visited
    return bfs()
def examA():
    H, W = LI()
    A = [SI() for _ in range(H)]
    start = []
    for i in range(H):
        for j in range(W):
            if A[i][j]=="#":
                start.append([i,j])
    V = start
    D, V = grid_bfs(H,W,start,A,V)
#    print(D,V)
    ans = 0
    for v in D:
        ans = max(ans,max(v))
    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()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


### FIXED CODE ###

def grid_bfs(h,w,start,maxD):
    INF = 10**9+7
    distance = [[INF for _ in range(w)] for _ in range(h)]
    queue = deque()
    for s in start:
        queue.append(s)
        distance[s[0]][s[1]] = 0
    while len(queue):
        y, x = queue.popleft()
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            if (0 <= nx < w and 0 <= ny < h):
                if (distance[ny][nx] > distance[y][x] + 1):
                    queue.append([ny, nx])
                    distance[ny][nx] = distance[y][x] + 1
                    if maxD<distance[ny][nx]:
                        maxD = distance[ny][nx]
    return maxD
def examA():
    H, W = LI()
    A = [[1 if a == "#" else 0 for a in SI()] for _ in range(H)]
    start = []
    for i in range(H):
        for j in range(W):
            if A[i][j]==1:
                start.append([i,j])
    ans = grid_bfs(H,W,start,0)
#    print(D,V)
    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()
mod = 10**9 + 7
inf = float('inf')

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

import sys,queue,math,copy,itertools,bisect,collections
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

X,Y,Z,K = LI()
A = LI()
B = LI()
C = LI()

if len (C) > len(A) and len(C) > len(B):
    A,C = C,A
elif len(B) > len(A) and len(B) > len(C):
    A,B = B,A

AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
C.sort(reverse=True)
max_abc = AB[0] + C[0]

l = 0
h = max_abc

while h > l+1:
    m = (h+l) // 2

    num = 0
    for i in AB:
        j = len(C) - 1
        while i + C[j] < m:
            j -= 1
            if j < 0: break
        else:
            num += j + 1
            continue
        break
    if num > K:
        l = m
    else:
        h = m

ans = []
for i in AB:
    j = len(C) - 1
    while i + C[j] < l:
        j -= 1
        if j < 0: break
    else:
        for k in range(j+1):
            ans.append(i+C[k])
ans.sort(reverse=True)
print (*ans[:K],sep='\n')



### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

X,Y,Z,K = LI()
A = LI()
B = LI()
C = LI()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = A[0] + B[0] + C[0]
l = 0
while h > l+1:
    m = (h+l) // 2

    num = 0
    for a in A:
        j = len(C) - 1
        for i in B:
            while i + C[j] < m - a:
                j -= 1
                if j < 0: break
            else:
                num += j + 1
                continue
            break
    if num > K:
        l = m
    else:
        h = m

ans = []
cnt = 0
for a in A:
    j = len(C) - 1
    last_cnt = cnt
    for i in B:

        while i + C[j] <= l - a:
            j -= 1
            if j < 0: break
        else:
            for k in range(j+1):
                ans.append(a+i+C[k])
                cnt += 1
            continue
        break
ans.sort(reverse=True)
for _ in range(K-len(ans)):
    ans.append(l)
print (*ans[:K],sep='\n')