import java.util.*;

public class Fussball {
    // simply prints all permutation - to see how it works
	private static void printPermutations( Comparable[] c ) {
		System.out.println( Arrays.toString( c ) );
		while ( ( c = nextPermutation( c ) ) != null ) {
			System.out.println( Arrays.toString( c ) );
		}
	}

	// modifies c to next permutation or returns null if such permutation does not exist
	private static Comparable[] nextPermutation( final Comparable[] c ) {
		// 1. finds the largest k, that c[k] < c[k+1]
		int first = getFirst( c );
		if ( first == -1 ) return null; // no greater permutation
		// 2. find last index toSwap, that c[k] < c[toSwap]
		int toSwap = c.length - 1;
		while ( c[ first ].compareTo( c[ toSwap ] ) >= 0 )
			--toSwap;
		// 3. swap elements with indexes first and last
		swap( c, first++, toSwap );
		// 4. reverse sequence from k+1 to n (inclusive) 
		toSwap = c.length - 1;
		while ( first < toSwap )
			swap( c, first++, toSwap-- );
		return c;
	}

	// finds the largest k, that c[k] < c[k+1]
	// if no such k exists (there is not greater permutation), return -1
	private static int getFirst( final Comparable[] c ) {
		for ( int i = c.length - 2; i >= 0; --i )
			if ( c[ i ].compareTo( c[ i + 1 ] ) < 0 )
				return i;
		return -1;
	}

	// swaps two elements (with indexes i and j) in array 
	private static void swap( final Comparable[] c, final int i, final int j ) {
		final Comparable tmp = c[ i ];
		c[ i ] = c[ j ];
		c[ j ] = tmp;
	}

    private static boolean stimmenFanAussagen(Integer[] platzierungen) {
        for (int i = 0; i < 32; i++) {
            boolean result = true;

            if ((i & 0x01) == 0x01)
                result = result && (platzierungen[0] != 2) && (platzierungen[1] == 5);
            else
                result = result && (platzierungen[0] == 2) && (platzierungen[1] != 5);
            if ((i & 0x02) == 0x02)
                result = result && (platzierungen[2] != 2) && (platzierungen[3] == 3);
            else
                result = result && (platzierungen[2] == 2) && (platzierungen[3] != 3);
            if ((i & 0x04) == 0x04)
                result = result && (platzierungen[5] != 1) && (platzierungen[2] == 3);
            else
                result = result && (platzierungen[5] == 1) && (platzierungen[2] != 3);
            if ((i & 0x08) == 0x08)
                result = result && (platzierungen[0] != 3) && (platzierungen[4] == 6);
            else
                result = result && (platzierungen[0] == 3) && (platzierungen[4] != 6);
            if ((i & 0x10) == 0x10)
                result = result && (platzierungen[2] != 3) && (platzierungen[4] == 4);
            else
                result = result && (platzierungen[2] == 3) && (platzierungen[4] != 4);

            if (result) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Integer[] platzierungen = { 1, 2, 3, 4, 5, 6 };
        while ((platzierungen = (Integer [])nextPermutation(platzierungen)) != null) {
            if (stimmenFanAussagen(platzierungen)) {
                System.out.println(Arrays.toString(platzierungen));
            }
        }
    }
}
