#P8091. Non-transitive Dice

    ID: 21274 Type: Default 1000ms 256MiB

Non-transitive Dice

Non-transitive Dice

Cows in the barn like to pass the time with a simple dice game. In one version of the game, two 4-sided dice, X and Y, are rolled. The die showing the larger number wins the round. In case of a tie the dice are re-rolled (which may happen several times). We say that die X beats die Y if the probability that X wins is greater than the probability that Y wins. Equivalently, if we denote by \(W(X,Y)\) the number of pairs \((x,y)\) with x from X and y from Y such that \(x>y\), and by \(L(X,Y)\) the number of pairs with \(x<y\), then we say that X beats Y if

[ W(X,Y) > L(X,Y), ]

Consider the following 4-sided dice:

  • Die A has numbers \(4, 5, 6, 7\) on its faces.
  • Die B has numbers \(2, 4, 5, 10\) on its faces.

It turns out that these dice have a rather curious property: A beats B. Your task is to determine whether there exists an assignment of numbers (each an integer between 1 and 10) to the faces of a third 4-sided die C such that the set \(\{A, B, C\}\) is non-transitive. In a non-transitive set the relationships are cyclic; that is, one die beats one of the others and loses to the remaining die. More precisely, you should choose numbers for die C such that:

  • A beats B,
  • B beats C, and
  • C beats A.

Note that if during a roll the two dice show the same number, they are re-rolled indefinitely until a decision is reached.

inputFormat

The input consists of two lines. The first line contains 4 integers representing the numbers on the faces of die A. The second line contains 4 integers representing the numbers on the faces of die B. Each number is between 1 and 10.

It is guaranteed that when comparing dice A and B (using the re-roll rule for ties), die A beats die B, i.e. \(W(A,B) > L(A,B)\).

outputFormat

If there exists an assignment of numbers for die C that makes the set non-transitive (i.e. A beats B, B beats C, and C beats A), output 4 integers (separated by spaces) denoting one valid assignment for die C. Otherwise, output NO.

sample

4 5 6 7
2 4 5 10
1 4 8 9