stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

#define int long long

typedef long long ll;

using namespace std;

const int MOD = 1000000007;

const int INF = 1000000000000000000;

const double EPS = 1e-10;

const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



struct edge { int to, cost; };

vector<edge> g[110000];

int d[110000];

int v,e,s,t;



void dijkstra(int s, int d[], vector<edge> g[]){

  priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> que;

  fill(d,d+v+1, INF);d[s] = 0;que.push(pair<int,int>(0,s));

  while(!que.empty()){

    pair<int,int> p = que.top();que.pop();

    int v = p.second;

    if(d[v]<p.first)continue;

    rep(i,g[v].size()){

      edge e = g[v][i];

      if(d[e.to] > d[v] + e.cost){

        d[e.to] = d[v] + e.cost;

        que.push(pair<int,int>(d[e.to], e.to));

      }

    }

  }

}



signed main(){

  int x,y,z,k;cin>>x>>y>>z>>k;

  int a[1100], b[1100], c[1100];rep(i,x)cin>>a[i];rep(i,y)cin>>b[i];rep(i,z)cin>>c[i];

  vector<int> d(x*y);int ind = 0;

  rep(i,x){

    rep(j,y){

      d[ind] = a[i]+b[j];

      ind++;

    }

  }

  sort(d.begin(), d.end(),greater<int>());sort(c,c+z,greater<int>());

  deque<int> q;

  rep(i,z){

    rep(j,min(k,x*y)){

      q.push_back(c[i]+d[j]);

    }

  }

  sort(q.begin(), q.end(), greater<int>());

  rep(i,k){

    cout << q[i] << endl;

  }

}


// Faster C++ solution for the same problem (measured speedup: 3.682957124621603x):
#include <bits/stdc++.h>

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

#define int long long

typedef long long ll;

using namespace std;

const int MOD = 1000000007;

const int INF = 1010000000;

const double EPS = 1e-10;

const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



vector<int> init(int size){

  vector<int> par(size,-1);

  return par;

}



int root(int x, vector<int>& par){

  if(par[x] < 0){

    return x;

  }else{

    return par[x] = root(par[x],par);

  }

}



bool same(int x, int y, vector<int>& par){

  return root(x, par) == root(y, par);

}



void unite(int x, int y, vector<int>& par){

  x = root(x, par), y = root(y, par);

  if(same(x,y, par))return;

  par[x] += par[y];

  par[y] = x;

}



int size(int x, vector<int>& par){

  return -par[root(x, par)];

}



int pow(int x, int n){

  if(n == 0)return 1;

  if(n % 2 == 0)return pow(x * x % MOD, n/2);

  else return x * pow(x, n-1) % MOD;

}



signed main(){

  int x,y,z,k;cin>>x>>y>>z>>k;

  int a[1100], b[1100], c[1100];rep(i,x)cin>>a[i];rep(i,y)cin>>b[i];rep(i,z)cin>>c[i];

  sort(a,a+x,greater<int>());sort(b,b+y,greater<int>());sort(c,c+z,greater<int>());

  vector<int> v;

  rep(i,x){

    rep(j,y){

      rep(l,z){

        if((i+1)*(j+1)*(l+1) > k)break;

        v.push_back(a[i]+b[j]+c[l]);

      }

    }

  }

  sort(v.begin(), v.end(), greater<int>());

  rep(i,k)cout << v[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &another) const {

        return taste < another.taste;

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    priority_queue<P> pq;

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<vector<int>, int> cnt;

    cnt[{0, 0, 0}]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        // printf("taste=%d a=%d b=%d c=%d\n", q.taste, q.a, q.b, q.c);

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (q.a+1<X && cnt[{q.a + 1, q.b, q.c}] == 0) {

            // cout << "1だよ" << endl;

            pq.push(newq1);

            cnt[{q.a + 1, q.b, q.c}]++;

        }

        if (q.b+1<Y && cnt[{q.a, q.b + 1, q.c}] == 0) {

            // cout << "2だよ" << endl;

            pq.push(newq2);

            cnt[{q.a, q.b + 1, q.c}]++;

        }

        if (q.c+1<Z && cnt[{q.a, q.b, q.c + 1}] == 0) {

            // cout << "3だよ" << endl;

            pq.push(newq3);

            cnt[{q.a, q.b, q.c + 1}]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1239172339077177x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

using ll = long long;

using namespace std;



vector<ll> AB;

vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(all(C));

    reverse(all(C));



    rep(x, X) rep(y, Y) {

        AB.push_back(A[x] + B[y]);

    }

    sort(all(AB));

    reverse(all(AB));



    rep(i, min(X*Y, K)) rep(z, min(K, Z)) {

        ans.push_back(AB[i] + C[z]);

    }

    sort(all(ans));

    reverse(all(ans));



    rep(i, K) cout << ans[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &d) const {

        if (a == d.a && b == d.b && c == d.c) {

            return taste < d.taste;

        } else if (a != d.a) {

            return a < d.a;

        } else if (b != d.b) {

            return b < d.b;

        } else {

            return c < d.c;

        }

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    auto compare = [](P a, P b) {

      return a.taste < b.taste;

    };



    priority_queue<P,vector<P>,decltype(compare)> pq {compare};

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<P, int> cnt;

    cnt[init]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (cnt[newq1] == 0) {

            pq.push(newq1);

            cnt[newq1]++;

        }

        if (cnt[newq2] == 0) {

            pq.push(newq2);

            cnt[newq2]++;

        }

        if (cnt[newq3] == 0) {

            pq.push(newq3);

            cnt[newq3]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1170338455902402x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

using ll = long long;

using namespace std;



vector<ll> AB;

vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(all(C));

    reverse(all(C));



    rep(x, X) rep(y, Y) {

        AB.push_back(A[x] + B[y]);

    }

    sort(all(AB));

    reverse(all(AB));



    rep(i, min(X*Y, K)) rep(z, min(K, Z)) {

        ans.push_back(AB[i] + C[z]);

    }

    sort(all(ans));

    reverse(all(ans));



    rep(i, K) cout << ans[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &another) const {

        return taste < another.taste;

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    priority_queue<P> pq;

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<vector<int>, int> cnt;

    cnt[{0, 0, 0}]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        // printf("taste=%d a=%d b=%d c=%d\n", q.taste, q.a, q.b, q.c);

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (q.a+1<X && cnt[{q.a + 1, q.b, q.c}] == 0) {

            // cout << "1だよ" << endl;

            pq.push(newq1);

            cnt[{q.a + 1, q.b, q.c}]++;

        }

        if (q.b+1<Y && cnt[{q.a, q.b + 1, q.c}] == 0) {

            // cout << "2だよ" << endl;

            pq.push(newq2);

            cnt[{q.a, q.b + 1, q.c}]++;

        }

        if (q.c+1<Z && cnt[{q.a, q.b, q.c + 1}] == 0) {

            // cout << "3だよ" << endl;

            pq.push(newq3);

            cnt[{q.a, q.b, q.c + 1}]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1249514632004378x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

using ll = long long;

using namespace std;



vector<ll> AB;

vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(all(C),greater<ll>());



    rep(x, X) rep(y, Y) {

        AB.push_back(A[x] + B[y]);

    }

    sort(all(AB),greater<ll>());



    rep(i, min(X*Y, K)) rep(z, min(K, Z)) {

        ans.push_back(AB[i] + C[z]);

    }

    sort(all(ans),greater<ll>());



    rep(i, K) cout << ans[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &d) const {

        if (a == d.a && b == d.b && c == d.c) {

            return taste < d.taste;

        } else if (a != d.a) {

            return a < d.a;

        } else if (b != d.b) {

            return b < d.b;

        } else {

            return c < d.c;

        }

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    auto compare = [](P a, P b) {

      return a.taste < b.taste;

    };



    priority_queue<P,vector<P>,decltype(compare)> pq {compare};

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<P, int> cnt;

    cnt[init]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (cnt[newq1] == 0) {

            pq.push(newq1);

            cnt[newq1]++;

        }

        if (cnt[newq2] == 0) {

            pq.push(newq2);

            cnt[newq2]++;

        }

        if (cnt[newq3] == 0) {

            pq.push(newq3);

            cnt[newq3]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1180617407850246x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

using ll = long long;

using namespace std;



vector<ll> AB;

vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(all(C),greater<ll>());



    rep(x, X) rep(y, Y) {

        AB.push_back(A[x] + B[y]);

    }

    sort(all(AB),greater<ll>());



    rep(i, min(X*Y, K)) rep(z, min(K, Z)) {

        ans.push_back(AB[i] + C[z]);

    }

    sort(all(ans),greater<ll>());



    rep(i, K) cout << ans[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &another) const {

        return taste < another.taste;

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    priority_queue<P> pq;

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<vector<int>, int> cnt;

    cnt[{0, 0, 0}]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        // printf("taste=%d a=%d b=%d c=%d\n", q.taste, q.a, q.b, q.c);

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (q.a+1<X && cnt[{q.a + 1, q.b, q.c}] == 0) {

            // cout << "1だよ" << endl;

            pq.push(newq1);

            cnt[{q.a + 1, q.b, q.c}]++;

        }

        if (q.b+1<Y && cnt[{q.a, q.b + 1, q.c}] == 0) {

            // cout << "2だよ" << endl;

            pq.push(newq2);

            cnt[{q.a, q.b + 1, q.c}]++;

        }

        if (q.c+1<Z && cnt[{q.a, q.b, q.c + 1}] == 0) {

            // cout << "3だよ" << endl;

            pq.push(newq3);

            cnt[{q.a, q.b, q.c + 1}]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.124674187426089x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



vector<ll> AB;

vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(C));



    rep(x, X) rep(y, Y) {

        AB.push_back(A[x] + B[y]);

    }

    sort(rall(AB));



    rep(i, min(X*Y, K)) rep(z, min(K, Z)) {

        ans.push_back(AB[i] + C[z]);

    }

    sort(rall(ans));



    rep(i, K) cout << ans[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &d) const {

        if (a == d.a && b == d.b && c == d.c) {

            return taste < d.taste;

        } else if (a != d.a) {

            return a < d.a;

        } else if (b != d.b) {

            return b < d.b;

        } else {

            return c < d.c;

        }

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    auto compare = [](P a, P b) {

      return a.taste < b.taste;

    };



    priority_queue<P,vector<P>,decltype(compare)> pq {compare};

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<P, int> cnt;

    cnt[init]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (cnt[newq1] == 0) {

            pq.push(newq1);

            cnt[newq1]++;

        }

        if (cnt[newq2] == 0) {

            pq.push(newq2);

            cnt[newq2]++;

        }

        if (cnt[newq3] == 0) {

            pq.push(newq3);

            cnt[newq3]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1177861631756016x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



vector<ll> AB;

vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(C));



    rep(x, X) rep(y, Y) {

        AB.push_back(A[x] + B[y]);

    }

    sort(rall(AB));



    rep(i, min(X*Y, K)) rep(z, min(K, Z)) {

        ans.push_back(AB[i] + C[z]);

    }

    sort(rall(ans));



    rep(i, K) cout << ans[i] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



struct P {

    ll taste;

    int a;

    int b;

    int c;



    bool operator<(const P &another) const {

        return taste < another.taste;

    };

};



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X + 2000, -10000000000);

    vector<ll> B(Y + 2000, -10000000000);

    vector<ll> C(Z + 2000, -10000000000);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    priority_queue<P> pq;

    P init = {A[0] + B[0] + C[0], 0, 0, 0};

    pq.push(init);

    map<vector<int>, int> cnt;

    cnt[{0, 0, 0}]++;

    vector<ll> ans;



    while (!pq.empty() && ans.size() < K) {

        P q = pq.top();

        pq.pop();

        // printf("taste=%d a=%d b=%d c=%d\n", q.taste, q.a, q.b, q.c);

        ans.push_back(q.taste);

        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};

        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};

        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};



        if (q.a+1<X && cnt[{q.a + 1, q.b, q.c}] == 0) {

            // cout << "1だよ" << endl;

            pq.push(newq1);

            cnt[{q.a + 1, q.b, q.c}]++;

        }

        if (q.b+1<Y && cnt[{q.a, q.b + 1, q.c}] == 0) {

            // cout << "2だよ" << endl;

            pq.push(newq2);

            cnt[{q.a, q.b + 1, q.c}]++;

        }

        if (q.c+1<Z && cnt[{q.a, q.b, q.c + 1}] == 0) {

            // cout << "3だよ" << endl;

            pq.push(newq3);

            cnt[{q.a, q.b, q.c + 1}]++;

        }

    }

    rep(i, K) cout << ans[i] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1151979135114711x):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(), (x).rend()

using ll = long long;

using namespace std;



vector<ll> ans;



int main() {

    int X, Y, Z, K;

    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);

    vector<ll> B(Y);

    vector<ll> C(Z);

    rep(i, X) cin >> A[i];

    rep(i, Y) cin >> B[i];

    rep(i, Z) cin >> C[i];

    sort(rall(A));

    sort(rall(B));

    sort(rall(C));



    rep(i,X)rep(j,Y)rep(k,Z){

        if(i*j*k>K)break;

        ans.push_back(A[i]+B[j]+C[k]);

    }

    sort(rall(ans));

 

    rep(i, K) cout << ans[i] << endl;

}