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

import copy

h, w = map(int, input().split())
s = [input() for _ in range(h)]
canlight = [[int(c == '.') for c in s[y]] for y in range(h)]
leftbeam = copy.deepcopy(canlight)
rightbeam = copy.deepcopy(canlight)
downbeam = copy.deepcopy(canlight)
upbeam = copy.deepcopy(canlight)

for y in range(h):
    for x in range(w - 1):
        leftbeam[y][x + 1] = (leftbeam[y][x] + 1) * canlight[y][x + 1]
        rightbeam[y][-(x + 2)] = (rightbeam[y][-(x + 1)] + 1) * canlight[y][-(x + 2)]

for x in range(w):
    for y in range(h - 1):
        downbeam[y + 1][x] = (downbeam[y][x] + 1) * canlight[y + 1][x]
        upbeam[-(y + 2)][x] = (upbeam[-(y + 1)][x] + 1) * canlight[-(y + 2)][x]

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)
print(ans)

### FIXED CODE ###

h, w = map(int, input().split())
s = [input() for _ in range(h)]
leftbeam = [[0 for _ in range(w)] for _ in range(h)]
rightbeam = [[0 for _ in range(w)] for _ in range(h)]
downbeam = [[0 for _ in range(w)] for _ in range(h)]
upbeam = [[0 for _ in range(w)] for _ in range(h)]

def can_light(y, x):
    return (0 <= y < h) and (0 <= x < w) and s[y][x] == '.'

for y in range(h):
    beamlen = 0
    for x in range(w):
        if can_light(y, x):
            beamlen += 1
        else:
            beamlen = 0
        leftbeam[y][x] = beamlen

for y in range(h):
    beamlen = 0
    for x in range(w):
        if can_light(y, w - x - 1):
            beamlen += 1
        else:
            beamlen = 0
        rightbeam[y][w - x - 1] = beamlen


for x in range(w):
    beamlen = 0
    for y in range(h):
        if can_light(y, x):
            beamlen += 1
        else:
            beamlen = 0
        downbeam[y][x] = beamlen

for x in range(w):
    beamlen = 0
    for y in range(h):
        if can_light(h - y - 1, x):
            beamlen += 1
        else:
            beamlen = 0
        upbeam[h - y - 1][x] = beamlen

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)

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

n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
for i in range(1,n):
  ans=abs(2*sum(a[:i])-suma)
  if ans < minans:
    minans = ans
    
print(minans)


### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
#print(minans)

mydata=0
for i in range(0,n-1):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)
### BUGGY CODE ###

s = list(input())
q = int(input())
rv = False
fr = []
re = []
for i in range(q):
    t = input().split(' ')
    if t[0] == '1':
        rv = True if not rv else False
    else:
        if t[1] == '1' and not rv or t[1] == '2' and rv:
            fr.insert(0, t[2])
        else:
            if t[1] == '1' and rv or t[1] == '2' and not rv:
                re.append(t[2])
if rv:
    re.reverse()
    s.reverse()
    fr.reverse()
    print(''.join(re + s + fr))
else:
    print(''.join(fr + s + re))

### FIXED CODE ###

from collections import deque
s = list(input())
q = int(input())
rv = False
fr = deque()
re = []
for i in range(q):
    t = input().split(' ')
    if t[0] == '1':
        rv = True if not rv else False
    else:
        if t[1] == '1' and not rv or t[1] == '2' and rv:
            fr.appendleft(t[2])
        else:
            if t[1] == '1' and rv or t[1] == '2' and not rv:
                re.append(t[2])
if rv:
    re.reverse()
    s.reverse()
    fr.reverse()
    print(''.join(re + s) + ''.join(fr))
else:
    print(''.join(fr) + ''.join(s + re))
### BUGGY CODE ###

h,w,m=map(int,input().split())
H=[0]*(3*10**5+1)
W=[0]*(3*10**5+1)
M=[]
for i in range(m):
    h,w=map(int,input().split())
    M.append([h,w])
    H[h]+=1
    W[w]+=1

p=max(H)
q=max(W)

X=[i for i in range(3*10**5+1) if H[i]==p]
Y=[i for i in range(3*10**5+1) if W[i]==q]

cnt=1
flag=True
for x in X:
    if flag:
        for y in Y:
            if not [x,y] in M:
                cnt=0
                flag=False
                break

print(p+q-cnt)

### FIXED CODE ###

h,w,m=map(int,input().split())
H=[0]*(3*10**5+1)
W=[0]*(3*10**5+1)
M=[]
for i in range(m):
    h,w=map(int,input().split())
    M.append([h,w])
    H[h]+=1
    W[w]+=1

p=max(H)
q=max(W)

X=set([i for i in range(3*10**5+1) if H[i]==p])
Y=set([i for i in range(3*10**5+1) if W[i]==q])

cnt=0
for i in range(m):
    if M[i][0] in X and M[i][1] in Y:
        cnt+=1

if cnt==len(X)*len(Y):
    print(p+q-1)
else:
    print(p+q)
### BUGGY CODE ###

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations
def main():
    n, *a = map(int, read().split())
    large_p = 10 ** 9 + 7

    com = tuple(combinations(a, 2))
    r = 0
    for come in com:
        r += (come[0] * come[1]) % large_p
        r = r % large_p

    print(r)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n, *a = map(int, read().split())
    large_p = 10 ** 9 + 7
    aac = tuple(accumulate(a))
    r = 0
    for i1 in range(n):
        t1 = aac[-1] - aac[i1]
        r += (t1 * a[i1]) % large_p
    r = r % large_p
    print(r)


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

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

t = n

while True:
  n = abs(n - k)
  if n > t:
    break
  t = n
    
print(t)

### FIXED CODE ###

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

t = n

if n % k == 0:
  print(0)
else:
  if n < k:
    a = abs(n - k)
    b = abs(a-k)
    if a < b:
      print(a)
    else:
      print(b)
  else:
  	x = n % k
  	print(k - x)
### BUGGY CODE ###

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

mod = 10**9+7
ans = 0

for i in range(60):
  B = [0]*N
  one = 0
  for j in range(N):
    B[j] = A[j]%pow(2,(i+1))//pow(2,i)
    one += B[j]
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
import numpy as np
mod = 10**9+7
ans = 0
A = np.array(A)
for i in range(60):
  one = np.count_nonzero(A>>i&1)
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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

n = int(input())
s = input()
r = min(s.count('#'), s.count('.'))
for i in range(n-1):
  r = min(r, s[:i+1].count('#') + s[i+1:].count('.')) 
print(r)

### FIXED CODE ###

n = int(input())
s = input()
w = s.count('.')
b = 0
r = w 
for i, x in enumerate(s):
  if x == '#':
    b += 1
  else:
    w -= 1
    r = min(r, b + w)
print(r)
### BUGGY CODE ###

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

for i in range(1,n):
    while True:
        if a[i] >= a[i-1]:
            break
        else:
            a[i] += 1
            l[i] += 1
print(sum(l))



### FIXED CODE ###

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

for i in range(1,n):
    if a[i] >= a[i-1]:
        continue
    else:
        step = a[i-1] - a[i]
        a[i] += step
        ans += step
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
def ans(l):
    max = 0
    for i in l:
        s = l.count(i)
        if s>max:
            max = s
    return n/2 - max
if a.count(a[0])==n:
    p = int(n/2)
else:
    p = int(ans(a[::2]) + ans(a[1::2]))
print(p)


### FIXED CODE ###

from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = a[0]
        count00, count01 = int(n/2), 0
    else:
        c = Counter(a[::2])
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = a[1]
        count10, count11 = int(n/2), 0
    else:
        c = Counter(a[1::2])
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
minus = 0
plus = 0
fact = [0] * (N+1)
fact[0] = 1
pow_fact = [0] * (N+1)
pow_fact[0] = 1
fa = 1
for i in range(1, N+1):
    fa *= i
    fact[i] = fa
    pow_fact[i] = pow(fa, mod-2, mod)
b = pow_fact[K-1]
for i in range(N-K+1):
    a = fact[N-i-1]
    c = pow_fact[N-i-K]
    comb = (a*b*c) % mod
    minus += (A[i] * comb)
    plus += (A[-i-1] * comb)
print((plus - minus) % mod)

### FIXED CODE ###

import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
minus = 0
plus = 0
fact = [0] * (N+1)
fact[0] = 1
pow_fact = [0] * (N+1)
pow_fact[0] = 1
fa = 1
for i in range(1, N+1):
    fa *= i
    fa %= mod
    fact[i] = fa
    pow_fact[i] = pow(fa, mod-2, mod)
b = pow_fact[K-1]
for i in range(N-K+1):
    a = fact[N-i-1]
    c = pow_fact[N-i-K]
    comb = (a*b*c) % mod
    minus += (A[i] * comb) % mod
    plus += (A[-i-1] * comb) % mod
print((plus - minus) % mod)
### BUGGY CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

@lru_cache(maxsize=None)
def temp(n):
    return 10**i%2019

s = list(map(int,list(input())[:-1]))
n=len(s)
right = [0] * (n + 1)
for i in range(n):
    right[-i - 2] = (right[-i - 1] + s[-i-1] * temp(i)) % 2019
log = defaultdict(lambda: 0)
ans=0
for i in range(n + 1):
    log[right[-i - 1]] += 1
    value = log[right[-i - 1]]
    if value!=1:
        ans+=2*(value-1)-1
print(ans)

### FIXED CODE ###

'''
1~9の文字列で構成されたSの中で
i文字目からj文字目までが2019の倍数になっているものの個数を求めよ

terms:
    1<=|S|<=2*10**5

input:
    1817181712114

output:
    3
'''
from collections import defaultdict
import sys
input = sys.stdin.readline
s = input()[:-1]
n=len(s)
arr = [int(s[i]) for i in range(n)]
ans = 0
dic = defaultdict(int)
dic[0] = 1
now = 0
for i in range(n - 1, -1, -1):
    now += arr[i] * pow(10, n - i - 1, 2019)
    now %= 2019
    ans += dic[now]
    dic[now] += 1
print(ans)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce
import numpy as np

def gcd_list(numbers):
    return reduce(gcd, numbers)
  
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
g = gcd_list(A)
A = np.array(A)
A //= g
A = A.tolist()
l = lcm_list(A)
if l%2 == 0:
  print(0)
else:
  print(((m//(l*g))+1)//2)

### FIXED CODE ###

from fractions import gcd
from functools import reduce

def lcm(x, y):
  g = gcd(x, y)
  x //= g
  y //= g
  if x&y&1:
    l = x*y*g
    if l > 10**9:
      return 0
    return l
  return 0
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
k = reduce(lcm, A)
if k == 0:
  print(0)
else:
  print(((m//k)+1)//2)
### BUGGY CODE ###

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

dp = [1,1]
temp = 1
if 1 in a: dp[1] = 0
for i in range(2,n+1):
  dp.append(dp[i-1] + dp[i-2])
  if i in a: dp[i] = 0

print(dp[n]%1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
 
dp = [0, 1]
for i in range(N):
    if i+1 in A: dp.append(0)
    else: dp.append(dp[i]+dp[i+1])
print(dp[N+1]%1000000007)
### BUGGY CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * pow(2, i, MOD)
    print(ans % MOD)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * pow(2, i, MOD)
    print(ans % MOD)


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

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    s=[sorted(list(input())) for i in range(n)]
    cnt=0
    for i in range(n):
        for j in range(i+1,n):
            if s[i]==s[j]:
                cnt+=1
    print(cnt)
resolve()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    s=[sorted(list(input())) for i in range(n)]
    s.sort()
    ans=0
    cnt=1
    for i in range(n-1):
        if s[i]==s[i+1]:
                cnt+=1
                if i ==n-2:
                    ans+=cnt*(cnt-1)//2
        else:
            if cnt>=2:
                ans += cnt * (cnt - 1) // 2
                cnt=1
    print(ans)
resolve()
### BUGGY CODE ###

#方針　もっとも近い敵でない島の集まりを調べると区間スケジュール問題となる。
#一列に並んでいるので飛んだ島とは繋げない
#橋の取り壊しの最小値というが、分割としてはもっとも番号の若いものまでしか無理である。
#最近接の敵である島の数字をもつ配列を考える。
N,M = (int(_) for _ in input().split())
mostNeightborOpponent = [N+1 for _ in range(N)]
#print(mostNeightborOpponent)
for i in range(M):
    a,b = (int(_) for _ in input().split())
    if mostNeightborOpponent[a-1] > b:
        mostNeightborOpponent[a-1] = b
#print(mostNeightborOpponent)
#island:・・・島|島・・・の右の島のindex
island = 1
bridgeWillBreak = 0

while island < N:
    minOpIsland = mostNeightborOpponent[island-1]
    for i in range(island-1,N):
        if minOpIsland > mostNeightborOpponent[i]:
            minOpIsland=mostNeightborOpponent[i]
    #print(minOpIsland)
    island = minOpIsland
    if island > N:
        break
    bridgeWillBreak += 1

print(bridgeWillBreak)


### FIXED CODE ###

#TLEした
#方針　もっとも近い敵でない島の集まりを調べると区間スケジュール問題となる。
#一列に並んでいるので飛んだ島とは繋げない
#橋の取り壊しの最小値というが、分割としてはもっとも番号の若いものまでしか無理である。
#最近接の敵である島の数字をもつ配列を考える。

#TLEの解決さく最小値順に初めから並べ替えておく。そのとき島の位置がindexkara
#測れないのでtupleを作っていく。

from operator import itemgetter
N,M = (int(_) for _ in input().split())
mostNeightborOpponent = [(N+1,i+1) for i in range(N)]
#print(mostNeightborOpponent)
for i in range(M):
    a,b = (int(_) for _ in input().split())
    if mostNeightborOpponent[a-1][0] > b:
        mostNeightborOpponent[a-1] = (b,a) #tupleを作るsortは第一引数を考えるので順序はこの順
#print(mostNeightborOpponent)
#island:・・・島|島・・・の右の島のindex
island = 1
bridgeWillBreak = 0

sortedOpponent = sorted(mostNeightborOpponent,key = itemgetter(0))

for b,a in sortedOpponent:
    if a < island :
        continue
    island = b
    if island > N :
        break
    bridgeWillBreak += 1

print(bridgeWillBreak)
### BUGGY CODE ###

import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
from collections import Counter
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


import numpy as np


def main():
    n, k = geta(int)
    p = [0] + list(geta(int))
    c = [0] + list(geta(int))

    inf = 1 << 32

    used = [False] * (n + 1)

    ans = -inf

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

        if used[i]:
            continue
        else:
            used[i] = True

        c_loop = []
        j = p[i]
        c_loop += [c[j]]

        while j != i:
            used[j] = True
            j = p[j]
            c_loop += [c[j]]

        n_loop = len(c_loop)
        c_loop = np.array(c_loop + c_loop)
        cs_loop = np.cumsum(c_loop)
        tot_loop = cs_loop[n_loop - 1]

        _jmax = k if k < n_loop else n_loop

        _ans = -inf
        _len = 0
        for _i in range(n_loop):
            for _j in range(1, _jmax + 1):
                _tmp = cs_loop[_j + _i] - cs_loop[_i]

                if tot_loop > 0 and k > _j:
                    _tmp += (k - _j) // n_loop * tot_loop

                if _ans < _tmp:
                    _ans = _tmp

        if ans < _ans:
            ans = _ans

    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
from collections import Counter
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def accumurate(l):
    ret = [0] * len(l)
    ret[0] = l[0]

    for i in range(1, len(l)):
        ret[i] = ret[i - 1] + l[i]

    return ret


def main():
    n, k = geta(int)
    p = [0] + list(geta(int))
    c = [0] + list(geta(int))

    inf = 1 << 32

    used = [False] * (n + 1)

    ans = -inf

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

        if used[i]:
            continue
        else:
            used[i] = True

        c_loop = []
        j = p[i]
        c_loop += [c[j]]

        while j != i:
            used[j] = True
            j = p[j]
            c_loop += [c[j]]

        n_loop = len(c_loop)
        c_loop += c_loop
        cs_loop = accumurate(c_loop)
        tot_loop = cs_loop[n_loop - 1]

        _jmax = k if k < n_loop else n_loop

        _ans = -inf
        _len = 0
        for _i in range(n_loop):
            for _j in range(1, _jmax + 1):
                _tmp = cs_loop[_j + _i] - cs_loop[_i]

                if tot_loop > 0 and k > _j:
                    _tmp += (k - _j) // n_loop * tot_loop

                if _ans < _tmp:
                    _ans = _tmp

        if ans < _ans:
            ans = _ans

    print(ans)


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

N = int(input())
count = 1+N
for i in range(1,N):
  if N % i == 0:
    if i + N/i < count:
      count = i+ N/i
count = int(count)
print(count-2)


### FIXED CODE ###

N = int(input())
count = 1+N
for i in range(1,int(N**0.5)+1):
  if N % i == 0 and i + N/i < count:
    count = i+ N/i
count = int(count)
print(count-2)
### BUGGY CODE ###

n, h = list(map(int, input().split(' ')))
k = [list(map(int, input().split(' '))) for _ in range(n)]
a = []
b = []
for i in range(n):
    a.append(k[i][0])
    b.append(k[i][1])

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        h -= a[x]
        count += 1
print(count)

### FIXED CODE ###

n, h = list(map(int, input().split(' ')))
k = [list(map(int, input().split(' '))) for _ in range(n)]
a = []
b = []
for i in range(n):
    a.append(k[i][0])
    b.append(k[i][1])

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        count += h//a[x]
        if h%a[x] != 0:
            count += 1
        h = 0
print(count)
### BUGGY CODE ###

x,y,z,k=map(int,input().split())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
c=tuple(map(int,input().split()))
 
def f(p,q):
    return sorted([i+j for j in q for i in p])[::-1][:k]
 
if x+y<y+z:
    for i in sorted(f(c,f(a,b)))[::-1][:k]:
        print(i)
elif x+z<y+z:
    for i in sorted(f(b,f(a,c)))[::-1][:k]:
        print(i)
else:
    for i in sorted(f(a,f(b,c)))[::-1][:k]:
        print(i)

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
 
AB = sorted([a + b for a in A for b in B])[-1:-K-1:-1]
ABC = sorted([ab + c for ab in AB for c in C])[-1:-K-1:-1]
print('\n'.join(map(str, ABC)))
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))
for i in range(N - 1):
    for j in range(i + 1, N):
        if H[i] > H[j] + 1:
            print('No')
            quit()
print('Yes')

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
I = [H[i + 1] - H[i] for i in range(N - 1)]
N = len(I)
for i in range(N):
    if I[i] >= 0:
        continue
    elif I[i] < -1:
        print('No')
        quit()
    else:
        if i == N - 1:
            continue
        for j in range(i + 1, N):
            if I[j] >= 1:
                break
            elif I[j] <= -1:
                print('No')
                quit()
            else:
                continue
print('Yes')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from itertools import permutations
def inpl(): return tuple(map(int, input().split()))
N, M, R = inpl()
inf = float("inf")
G = [[inf for _ in range(N+1)] for _ in range(N+1)]
D = inpl() # destination

for _ in range(M):
    a, b, c = inpl()
    G[a][b] = c
    G[b][a] = c

for n in range(N+1):
    G[n][n] = 0

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            G[j][k] = min(G[j][k], G[j][i] + G[i][k])

res = inf
for C in permutations(D, len(D)):
    res = min(res, sum([G[C[i]][C[i+1]] for i in range(len(D)-1)]))

print(res)

### FIXED CODE ###

# -*- coding: utf-8 -*-
from itertools import permutations, product
def inpl(): return tuple(map(int, input().split()))
N, M, R = inpl()
inf = float("inf")
G = [[inf for _ in range(N+1)] for _ in range(N+1)]
D = inpl() # destination

for _ in range(M):
    a, b, c = inpl()
    G[a][b] = c
    G[b][a] = c

for n in range(N+1):
    G[n][n] = 0

for i ,j, k in product(range(1, N+1), repeat=3):
    G[j][k] = min(G[j][k], G[j][i] + G[i][k])

res = inf
for C in permutations(D, len(D)):
    res = min(res, sum([G[C[i]][C[i+1]] for i in range(len(D)-1)]))

print(res)