Problem:
Score: 400 points

Problem Statement

The Patisserie AtCoder sells cakes with number-shaped candles.
There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.
Each cake has an integer value called deliciousness, as follows:

The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.

The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.

The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.

Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.

There are X \times Y \times Z such ways to choose three cakes.

We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.

Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

Constraints

1 \leq X \leq 1 \ 000

1 \leq Y \leq 1 \ 000

1 \leq Z \leq 1 \ 000

1 \leq K \leq \min(3 \ 000, X \times Y \times Z)

1 \leq A_i \leq 10 \ 000 \ 000 \ 000

1 \leq B_i \leq 10 \ 000 \ 000 \ 000

1 \leq C_i \leq 10 \ 000 \ 000 \ 000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

Output

Print K lines. The i-th line should contain the i-th value stated in the problem statement.

Sample Input 1

2 2 2 8
4 6
1 5
3 8

Sample Output 1

19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:

(A_2, B_2, C_2): 6 + 5 + 8 = 19

(A_1, B_2, C_2): 4 + 5 + 8 = 17

(A_2, B_1, C_2): 6 + 1 + 8 = 15

(A_2, B_2, C_1): 6 + 5 + 3 = 14

(A_1, B_1, C_2): 4 + 1 + 8 = 13

(A_1, B_2, C_1): 4 + 5 + 3 = 12

(A_2, B_1, C_1): 6 + 1 + 3 = 10

(A_1, B_1, C_1): 4 + 1 + 3 = 8

Sample Input 2

3 3 3 5
1 10 100
2 20 200
1 10 100

Sample Output 2

400
310
310
301
301

There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.
However, they are different ways of choosing cakes, so 301 occurs twice in the output.

Sample Input 3

10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736

Sample Output 3

23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547

Note that the input or output may not fit into a 32-bit integer type.

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

public class Program
{
    public static readonly int Mod = 1000000007;

    public static void Main(string[] args)
    {
        int X = Scanner.Int;
        int Y = Scanner.Int;
        int Z = Scanner.Int;
        int K = Scanner.Int;

        var A = Enumerable.Range(0, X).Select(i => Scanner.Long).ToArray(); //.OrderByDescending(i => i).ToArray();
        var B = Enumerable.Range(0, Y).Select(i => Scanner.Long).ToArray(); //.OrderByDescending(i => i).ToArray();
        var C = Enumerable.Range(0, Z).Select(i => Scanner.Long).ToArray(); //.OrderByDescending(i => i).ToArray();

        var AB = A.SelectMany(a => B.Select(b => a + b)).ToList();// .OrderByDescending(i => i).Take(Math.Min(3000, X * Y));
        AB.Sort();
        AB.Reverse();
        var ANS = AB.Take(Math.Min(3000, X * Y)).SelectMany(ab => C.Select(c => ab + c)).ToList();//.OrderByDescending(i => i);
        ANS.Sort();
        ANS.Reverse();
        foreach(long ans in ANS.Take(K))
        {
            Console.WriteLine(ans);
        }

        Console.WriteLine();
        Console.ReadLine();
    }
}

/// <summary>
/// スキャナ
/// </summary>
public static class Scanner
{
    public static char[] separator = new char[] { ' ' };

    private static IEnumerator<string> enumerator = Enumerator();
    private static IEnumerator<string> Enumerator()
    {
        while (true)
        {
            foreach (string s in Console.ReadLine().Split(separator))
            {
                yield return s;
            }
        }
    }

    public static IEnumerable<string> StringLine
    {
        get
        {
            return Console.ReadLine().Split(separator);
        }
    }
    public static IEnumerable<int> IntLine
    {
        get
        {
            return StringLine.Select(int.Parse);
        }
    }
    public static IEnumerable<long> LongLine
    {
        get
        {
            return StringLine.Select(long.Parse);
        }
    }
    public static IEnumerable<double> DoubleLine
    {
        get
        {
            return StringLine.Select(double.Parse);
        }
    }
    public static IEnumerable<char> CharLine
    {
        get
        {
            return StringLine.Select(char.Parse);
        }
    }

    public static string String
    {
        get
        {
            return enumerator.Next();
        }
    }
    public static int Int
    {
        get
        {
            return String.Int();
        }
    }
    public static long Long
    {
        get
        {
            return String.Long();
        }
    }
    public static double Double
    {
        get
        {
            return String.Double();
        }
    }
    public static char Char
    {
        get
        {
            return char.Parse(String);
        }
    }

    public static Tuple<int, int> IntTuple
    {
        get
        {
            return new Tuple<int, int>(Int, Int);
        }
    }

}

/// <summary>
/// Linq拡張
/// </summary>
public static class LinqExtension
{
    /// <summary>
    /// 二分探索
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="self"></param>
    /// <param name="solve"></param>
    /// <param name="min"></param>
    /// <param name="max"></param>
    /// <returns></returns>
    public static T LeftBinarySearch<T>(this IEnumerable<T> self, Func<T, bool> solve, T min, T max)
    {
        int index = self.LeftBinarySearchIndex(solve);

        return self.Get(index, min, max);
    }

    /// <summary>
    /// 二分探索
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="self"></param>
    /// <param name="solve"></param>
    /// <param name="min"></param>
    /// <param name="max"></param>
    /// <returns></returns>
    public static T RightBinarySearch<T>(this IEnumerable<T> self, Func<T, bool> solve, T min, T max)
    {
        int index = self.RightBinarySearchIndex(solve);

        return self.Get(index, min, max);
    }

    /// <summary>
    /// <para>二分探索</para>
    /// <para>渡されたラムダ式の条件を満たすものの中で、一番左側のもの(インデックスが小さい)</para>
    /// </summary>
    /// <typeparam name="T">IEnumerable</typeparam>
    /// <param name="solve"></param>
    /// <returns>一番左側のインデックス</returns>
    public static int LeftBinarySearchIndex<T>(this IEnumerable<T> self, Func<T, bool> solve)
    {
        int ng = -1;
        int ok = self.Count();

        while (Math.Abs(ok - ng) > 1)
        {
            int mid = (ok + ng) / 2;

            if (solve(self.ElementAt(mid)))
            {
                ok = mid;
            }
            else
            {
                ng = mid;
            }
        }

        return ok;
    }

    /// <summary>
    /// <para>二分探索</para>
    /// <para>渡されたラムダ式の条件を満たすものの中で、一番右側のもの(インデックスが大きい)</para>
    /// </summary>
    /// <typeparam name="T">IEnumerable</typeparam>
    /// <param name="solve"></param>
    /// <returns>一番右側のインデックス</returns>
    public static int RightBinarySearchIndex<T>(this IEnumerable<T> self, Func<T, bool> solve)
    {
        int ng = self.Count();
        int ok = -1;

        while (Math.Abs(ok - ng) > 1)
        {
            int mid = (ok + ng) / 2;

            if (solve(self.ElementAt(mid)))
            {
                ok = mid;
            }
            else
            {
                ng = mid;
            }
        }

        return ok;
    }

    /// <summary>
    /// OutOfRange対応
    /// </summary>
    /// <typeparam name="T">型T</typeparam>
    /// <param name="self">IEnumerable</param>
    /// <param name="index">対象のインデックス</param>
    /// <param name="min">0未満のインデックスの時</param>
    /// <param name="max">配列のサイズ以上の時</param>
    /// <returns>型Tの値</returns>
    public static T Get<T>(this IEnumerable<T> self, int index, T min, T max)
    {
        if (index < 0) return min;
        if (index >= self.Count()) return max;

        return self.ElementAt(index);
    }

    /// <summary>
    /// リストを埋める
    /// </summary>
    /// <typeparam name="T">型T</typeparam>
    /// <param name="self">リスト</param>
    /// <param name="func">(index) => T</param>
    /// <returns>リストの参照</returns>
    public static IList<T> Fill<T>(this IList<T> self, Func<int, T> func)
    {
        for (int i = 0; i < self.Count; i++)
        {
            self[i] = func(i);
        }

        return self;
    }

    /// <summary>
    /// リストを埋める
    /// </summary>
    /// <typeparam name="T">型T</typeparam>
    /// <param name="self">リスト</param>
    /// <param name="value">型Tの値</param>
    /// <returns>リストの参照</returns>
    public static IList<T> Fill<T>(this IList<T> self, T value)
    {
        for (int i = 0; i < self.Count; i++)
        {
            self[i] = value;
        }

        return self;
    }

    public static T Next<T>(this IEnumerator<T> self)
    {
        self.MoveNext();
        return self.Current;
    }

    public static void Write(this IEnumerable<bool> self)
    {
        StringBuilder sb = new StringBuilder();
        foreach(bool b in self)
        {
            sb.Append(b ? "□" : "■");
        }
        Console.WriteLine(sb.ToString());
    }
}

/// <summary>
/// Int拡張
/// </summary>
public static class IntExtensiton
{
    /// <summary>
    /// 階上
    /// </summary>
    /// <param name="self"></param>
    /// <returns></returns>
    public static long Factorial(this int self)
    {
        if (self == 1) return 1L;
        return self * (self - 1).Factorial();
    }

    /// <summary>
    /// 階上
    /// </summary>
    /// <param name="self"></param>
    /// <returns></returns>
    public static long Factorial(this int self, int c)
    {
        if (c == 0 || self == 1) return 1L;
        return self * Factorial(self - 1, c - 1);
    }

    public static int BitCount(this int bit, int digit = 32)
    {
        int count = 0;
        for (int i = (digit - 1); i >= 0; i--)
        {
            if (bit.GetBit(i)) count++;
        }
        return count;
    }

    public static bool GetBit(this int bit, int digit)
    {
        int mask = (1 << digit);
        return (bit & mask) == mask;
    }

    public static int SetBit(this int bit, int digit)
    {
        return (bit | (1 << digit));
    }

    public static string BitToString(this int bit, int digit = 32)
    {
        StringBuilder sb = new StringBuilder();

        for (int i = (digit - 1); i >= 0; i--)
        {
            sb.Append(bit.GetBit(i) ? "1" : "0");
        }

        return sb.ToString();
    }

    public static bool IsDivisor(this int self, int target)
    {
        return self % target == 0;
    }

    public static IEnumerable<int> Divisors(this int self)
    {
        for (int i = 1; i * i <= self; i++)
        {
            if (self % i == 0)
            {
                yield return i;
                if (i * i != self) yield return self / i;
            }
        }
    }

    public static bool NeighboringBit(this int self, int digit = 32)
    {
        if (digit < 2) return false;
        return Enumerable.Range(0, digit - 1).Where(j => self.GetBit(j) && self.GetBit(j + 1)).Any();
    }
}

/// <summary>
/// Long拡張
/// </summary>
public static class LongExtensition
{
    public static long BitCount(this long bit, int digit = 64)
    {
        long count = 0;
        for (int i = (digit - 1); i >= 0; i--)
        {
            if (bit.GetBit(i)) count++;
        }
        return count;
    }

    public static bool GetBit(this long bit, int digit)
    {
        long mask = (1L << digit);
        return (bit & mask) == mask;
    }

    public static long SetBit(this long bit, int digit)
    {
        return bit | (1L << digit);
    }

    public static string BitToString(this long bit, int digit = 64)
    {
        StringBuilder sb = new StringBuilder();

        for (int i = (digit - 1); i >= 0; i--)
        {
            sb.Append(bit.GetBit(i) ? "1" : "0");
        }

        return sb.ToString();
    }

    public static bool IsDivisor(this long self, int target)
    {
        return self % target == 0;
    }
}

/// <summary>
/// String拡張
/// </summary>
public static class StringExtensiton
{
    public static void Print(this string str) => Console.WriteLine(str);
    public static int Int(this string str) => int.Parse(str);
    public static long Long(this string str) => long.Parse(str);
    public static double Double(this string str) => double.Parse(str);
}

/// <summary>
/// 便利関数
/// </summary>
public static class F
{
    public static void ChMax<T>(ref T x, T y) where T : IComparable
    {
        if (x.CompareTo(y) < 0)
        {
            x = y;
        }
    }

    public static void ChMin<T>(ref T x, T y) where T : IComparable
    {
        if (x.CompareTo(y) > 0)
        {
            x = y;
        }
    }

    public static void Swap<T>(ref T x, ref T y)
    {
        T tmp = x;

        x = y;
        y = tmp;
    }
}