#include <iostream>
#include <vector>
using namespace std;

// nonogram
int main()
{
    int n;
    cin >> n;
    vector<vector<bool>> grid(n, vector<bool>(n));
    for (int r = 0; r < n; ++r)
    {
        for (int c = 0; c < n; ++c)
        {
            bool b;
            cin >> b;
            grid[r][c] = b;
        }
    }
    // check columns
    for (int c = 0; c < n; ++c)
    {
        bool isEmpty = true;
        int count = 0;
        for (int r = 0; r < n; ++r)
        {
            if (grid[r][c])
            {
                ++count;
                isEmpty = false;
            }
            else if (count > 0)
            {
                cout << count << " ";
                count = 0;
            }
        }
        if (count > 0)
        {
            cout << count << " ";
        }
        else if (isEmpty)
        {
            cout << "0";
        }
        cout << endl;
    }
    // check rows
    for (int r = 0; r < n; ++r)
    {
        bool isEmpty = true;
        int count = 0;
        for (int c = 0; c < n; ++c)
        {
            if (grid[r][c])
            {
                ++count;
                isEmpty = false;
            }
            else if (count > 0)
            {
                cout << count << " ";
                count = 0;
            }
        }
        if (count > 0)
        {
            cout << count << " ";
        }
        else if (isEmpty)
        {
            cout << "0";
        }
        cout << endl;
    }
}