Porker Champions


Submit solution

Points: 1
Time limit: 5.0s
Python 20.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

Patrick is playing a poker game with dice with some of the pigs from the farm, and seems to have drawn a bit of a crowd.

"Why are they playing poker again? Isn't this competition themed around farming?" one of the onlookers exclaims incredulously.

The pigs on the farm have been acting up recently, destroying farm equipment and trying to escape their pens. Noticing that they have been playing lots of probability games recently, Patrick has decided to challenge them to a game to put them in their place. If Patrick wins, the pigs will obey all of his commands. If the pigs win, they get to be free and escape the farm forever.

Instead of cards, this game consists of five dice, as the pigs brains aren't big enough to comprehend the cards (yet). Initially, five 6-sided dice are rolled. After the roll, you can choose to reroll any subset of the dice. Your final score is based on the 'hand' which is formed by the dice.

  • Five of a kind is worth 50
  • Four of a kind is worth 25
  • Full house (3+2) is worth 15
  • Three of a kind is worth 10
  • Two pair is worth 5
  • One pair is worth 2
  • Anything else is worth 0

Patrick wants to develop a strategy that has a high chance of beating the pigs, who seem to make decisions at random. Given a starting roll, can you calculate Patrick's expected value — who will always reroll the optimal subset in order to maximise expected value — and the pigs' expected value — who will always reroll a uniformly random subset of the dice (i.e., they will select one of the 2^5 subsets of dice to reroll at random including rerolling no dice)?

Input

Each input contains multiple test cases. The first line contains a single integer n (1 \leq n \leq 10^3), the number of test cases in this input.

Each of the next n lines contain five space-separated integers between 1 and 6, the initial roll of your 5 dice for that test case.

Output

Your output should contain n lines, where each line contains two numbers, the first being the expected value of Patrick's optimal rerolling, and the second being the expected value of the pigs' random rerolling. You should round your answer to 3 decimal places.

  • In C++, this can be done with std::cin << std::fixed << std::setprecision(3) << x
  • In Python, this can be done with print(f"{x:3f}")

Example

Input 1
2
1 1 1 2 3
2 3 4 5 6
Output 1
15.972 6.066
4.726 3.247

In the first test case, Patrick should reroll the 2 and 3 to try to form a four or five of a kind with his ones, while the pigs are equally likely to reroll the ones with their random strategy. For the second case, Patrick will reroll everything to try to roll new combinations, while the pigs are equally likely to keep some of them.

Input 2
2
5 5 5 5 2
2 2 2 2 2
Output 2
29.167 9.482
50.000 14.522

In the first case, Patrick will reroll the 2 for a \frac{1}{6} chance of rolling a five of a kind and a \frac{5}{6} chance of keeping the four of a kind. For the second case, Patrick will reroll nothing, leading to a guaranteed five of a kind.


Comments

There are no comments at the moment.