#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()

vector<int> sumrow(5), sumcol(5);
bitset<32> visited(0);
vector<int> idxRow, idxCol;
int result[7][7];
int ans[7][7];

void sort_idx(vector<int> &idx, vector<int> &v)
{
    idx.resize(v.size());
    iota(all(idx), 0);
    stable_sort(all(idx), [&](const int &i1, const int &i2) { return v[i1] < v[i2]; });
}

inline void printResult()
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            printf("%d ", ans[i][j]);
        }
        printf("\n");
    }
}
bool stop = false;
void solution(int k)
{
    if(stop) return;
    if(k == 25)
    {
        for(int i = 0; i < 5; i++)
        {
            for(int j = 0; j < 5; j++)
            {
                int oldX = idxRow[i];
                int oldY = idxCol[j];
                ans[oldX][oldY] = result[i][j];
            }
        }
        printResult();
        stop = true;
        return;
    }

    int x = k / 5;
    int y = k % 5;

    int L = 1, R = 25;
    int c1 = sumrow[x];
    int c2 = sumcol[y];
    if(y == 4) L = R = c1;
    else if(x == 4)
        L = R = c2;
    else
    {
        int a1 = 0, a2 = 0;
        int b1 = 0, b2 = 0;
        int maxx = max(5 - (x + 1), 5 - (y + 1));
        for(int i = 25, cnt1 = 0, cnt2 = 0; i >= 1 && cnt1 < maxx && cnt2 < maxx; --i)
        {
            if(!visited.test(i))
            {
                if(cnt1 < 5 - (x + 1))
                {
                    b2 += i;
                    ++cnt1;
                }
                if(cnt2 < 5 - (y + 1))
                {
                    a2 += i;
                    ++cnt2;
                }
            }
        }
        for(int i = 1, cnt1 = 0, cnt2 = 0; i <= 25 && cnt1 < maxx && cnt2 < maxx; ++i)
        {
            if(!visited.test(i))
            {
                if(cnt1 < 5 - (x + 1))
                {
                    b1 += i;
                    ++cnt1;
                }
                if(cnt2 < 5 - (y + 1))
                {
                    a1 += i;
                    ++cnt2;
                }
            }
        }
        L = max({1, c1 - a2, c2 - b2});
        R = min({25, c1 - a1, c2 - b1});
    }
    if(L > 25 || R < 1 || L > R) return;

    for(int i = L; i <= R; ++i)
    {
        if(!visited.test(i))
        {
            visited.set(i);
            sumcol[y] -= i;
            sumrow[x] -= i;
            result[x][y] = i;

            solution(k + 1);

            if(stop) return;
            visited.reset(i);
            sumcol[y] += i;
            sumrow[x] += i;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    for(int i = 0; i < 5; i++) scanf("%d", &sumrow[i]);
    for(int i = 0; i < 5; i++) scanf("%d", &sumcol[i]);

    sort_idx(idxRow, sumrow);
    sort_idx(idxCol, sumcol);

    sort(all(sumrow));
    sort(all(sumcol));

    solution(0);

    return 0;
}