#include #include #include using namespace std; using ll = long long; int unfairness(int p, int e, int a, int h) { int max = p; if (max < e) max = e; if (max < a) max = a; if (max < h) max = h; int min = p; if (min > e) min = e; if (min > a) min = a; if (min > h) min = h; return max - min; } int main() { int N; ll ans=0; cin >> N; vector P(N), E(N), A(N), H(N); for (int i = 0; i < N; i++) { cin >> P.at(i); } sort(P.begin(), P.end()); for (int i = 0; i < N; i++) { cin >> E.at(i); } sort(E.begin(), E.end()); for (int i = 0; i < N; i++) { cin >> A.at(i); } sort(A.begin(), A.end()); for (int i = 0; i < N; i++) { cin >> H.at(i); } sort(H.begin(), H.end()); for (int i = 0; i < N; i++) { ans += unfairness(P.at(i), E.at(i), A.at(i), H.at(i)); } cout << ans << endl; for (int i = 0; i < N; i++) { cout << P.at(i); if (i < N - 1) { cout << " "; } else { cout << endl; } } for (int i = 0; i < N; i++) { cout << E.at(i); if (i < N - 1) { cout << " "; } else { cout << endl; } } for (int i = 0; i < N; i++) { cout << A.at(i); if (i < N - 1) { cout << " "; } else { cout << endl; } } for (int i = 0; i < N; i++) { cout << H.at(i); if (i < N - 1) { cout << " "; } else { cout << endl; } } return 0; }