#include<bits/stdc++.h>
using namespace std;

 int main()
 {
    int num[4][5] = {0};
    for(int i = 0;i<4;i++)
    {
        for(int j = 0;j<5;j++)
        {
            cin>>num[i][j];
        }
    }
    int result[2][5] = {0};
    int j = 0,k=0;
    for(int i = 0;i<5;i++)
    {
        int num1 = INT_MIN;
        int num2 = INT_MIN;
        int k1 =0,k2=0;
        for(int j = 0;j<4;j++)
        {
            if(num[j][i]>num1)
            {
                num2 = num1;
                num1 = num[j][i];
                k2 = k1;
                k1 = j;
            }
            else if(num[j][i]>num2&&num[j][i]<=num1)
            {
                num2 = num[j][i];
                k2 = j;
            }
            else {
            continue;
            }
        }
        if(k1<k2)
        {
            result[j][k] = num1;
            result[j+1][k] = num2;
        }
        else 
        {
            result[j][k] = num2;
            result[j+1][k] = num1;
        }
        j = 0;k++;
    }
    for(int i = 0;i<2;i++)
    {
        for(int j = 0;j<5;j++)
        {
            cout<<result[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
 }