#include <iostream>
#include <cstring>
#include <array>
#include <vector>

using   u32 = unsigned int;

#define hint( msg )

enum    RESULT
{
    win,
    even,
    lose,
    result_count,   hint( "sizer" )
};

struct  TEAM_SCORE
{
    int counts[ result_count ];
};

std::vector< TEAM_SCORE >   results;
std::vector< TEAM_SCORE >   suppose;

//----------------------------------------------------------------------------------------

std::vector< std::pair< int, int > >    matches;

void build_matches( const int team_count )
{
    matches.clear();

    const   int triangular_size = team_count * ( team_count - 1 ) / 2;
    matches.reserve( triangular_size );

    for( int a = 0; a < team_count - 1; ++a )
        for( int b = a + 1; b < team_count; ++b )
            matches.emplace_back( std::make_pair( a, b ) );
}
//----------------------------------------------------------------------------------------

bool possible;

void play_game1( u32 game_index );

inline void test_case1( const u32 game_index, const RESULT result_a, const RESULT result_b )
{
    const u32 team_a = matches[ game_index ].first;
    const u32 team_b = matches[ game_index ].second;

    if( suppose[ team_a ].counts[ result_a ] + 1 <=
        results[ team_a ].counts[ result_a ] &&

        suppose[ team_b ].counts[ result_b ] + 1 <=
        results[ team_b ].counts[ result_b ] )
    {
        suppose[ team_a ].counts[ result_a ]++;
        suppose[ team_b ].counts[ result_b ]++;
        play_game1( game_index + 1 );
        suppose[ team_a ].counts[ result_a ]--;
        suppose[ team_b ].counts[ result_b ]--;
    }
}

void play_game1( u32 game_index )
{
    if( game_index >= matches.size() )
    {
        possible = true;
        return;
    }

    test_case1( game_index, win, lose );
    if( possible ) return;

    test_case1( game_index, lose, win );
    if( possible ) return;

    test_case1( game_index, even, even );
    if( possible ) return;
}
//----------------------------------------------------------------------------------------

#include <setjmp.h>

jmp_buf env;

void play_game2( u32 game_index );

inline void test_case2( const u32 game_index, const RESULT result_a, const RESULT result_b )
{
    const u32 team_a = matches[ game_index ].first;
    const u32 team_b = matches[ game_index ].second;

    if( suppose[ team_a ].counts[ result_a ] + 1 <=
        results[ team_a ].counts[ result_a ] &&

        suppose[ team_b ].counts[ result_b ] + 1 <=
        results[ team_b ].counts[ result_b ] )
    {
        suppose[ team_a ].counts[ result_a ]++;
        suppose[ team_b ].counts[ result_b ]++;
        play_game2( game_index + 1 );
        suppose[ team_a ].counts[ result_a ]--;
        suppose[ team_b ].counts[ result_b ]--;
    }
}

void play_game2( u32 game_index )
{
    if( game_index >= matches.size() )
        longjmp( env, 1 );

    test_case2( game_index, win, lose );
    test_case2( game_index, lose, win );
    test_case2( game_index, even, even );
}
//----------------------------------------------------------------------------------------

using   namespace   std;

constexpr   int team_count      = 6;
constexpr   int problem_count   = 4;

array< array< TEAM_SCORE, team_count >, problem_count > inputs
{ {
    { { { 5, 0, 0 }, { 3, 0, 2 }, { 2, 0, 3 }, { 0, 0, 5 }, { 4, 0, 1 }, { 1, 0, 4 } } },
    { { { 4, 1, 0 }, { 3, 0, 2 }, { 4, 1, 0 }, { 1, 1, 3 }, { 0, 0, 5 }, { 1, 1, 3 } } },
    { { { 5, 0, 0 }, { 4, 0, 1 }, { 2, 2, 1 }, { 2, 0, 3 }, { 1, 0, 4 }, { 0, 0, 5 } } },
    { { { 5, 0, 0 }, { 3, 1, 1 }, { 2, 1, 2 }, { 2, 0, 3 }, { 0, 0, 5 }, { 1, 0, 4 } } },
} };

int main()
{
	build_matches( team_count );
	suppose.resize( team_count );
	
    for( u32 i = 0; i < inputs.size(); ++i )
    {
        std::fill( suppose.begin(), suppose.end(), TEAM_SCORE{ 0, 0, 0 } );
        results.assign( inputs[ i ].begin(), inputs[ i ].end() );
        possible = false;
        play_game1( 0 );
        cout << possible << " ";
    }
    cout << endl;

    for( u32 i = 0; i < inputs.size(); ++i )
    {
        std::fill( suppose.begin(), suppose.end(), TEAM_SCORE{ 0, 0, 0 } );
        results.assign( inputs[ i ].begin(), inputs[ i ].end() );
        int possible = setjmp( env );
        if( !possible )
            play_game2( 0 );
        cout << possible << " ";
    }
    cout << endl;
    
	return  0;
}