Card Counting


Submit solution


Points: 1
Time limit: 1.0s
Memory limit: 256M

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

You are playing your lovely PEGI-12 rated game of Balatro, and you need to draw the perfect hand to win the final blind. You will draw exactly five cards from your randomly shuffled deck of cards. The exact contents of the hand don't matter, but you must draw a full house if you want to win.

A full house consists of three cards of one rank and two cards of another rank, in any order. For example, if the ranks of the cards in your hand are A A A 10 10 or J 3 3 J 3, you have a full house, whereas if the ranks of the cards in your hand are 2 2 2 2 7 or 4 4 4 4 4, you do not have a full house.

For a standard deck of cards, with four cards of each rank, the probability that you draw a full house is approximately 0.001440576, or around 1 in 694. However, this might not be a standard deck of cards. What is the probability that you win?

Input

The input consists of two lines.

The first line contains a single integer n (5 \le n \le 1000), representing the number of cards in the deck.

The second line contains n space-separated card ranks (where a card rank is one of A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q and K), representing the ranks of the cards in the deck.

Output

The output should consist of a single decimal in the interval [0,1], representing the probability that you get a full house when drawing the top five cards from the (uniformly randomly) shuffled deck.

Important: Your answer only needs to be correct to within an absolute difference of 10^{-5}. That is, if the correct answer is x and your output is y, then |x-y|<10^{-5}.

Note

You are likely to need to handle large integers and floating point numbers in your solution. If you are using Java, C or C++, it is recommended that you use longs (Java), long longs (C/C++) and doubles (Java/C/C++) respectively to ensure your answer is accurate and does not suffer from integer overflow.

Examples

Input 1
8
A 2 2 2 3 3 3 3
Output 1
0.32142857142857145
Explanation

There are 56 possible hands of cards that can be dealt. Out of them, 6 of them consist of three 2s and two 3s, and 12 of them consist of three 3s and two 2s.

Input 2
6
J 3 J 3 3 J
Output 2
1.0
Explanation

No matter how the cards are dealt, either three Js and two 3s are dealt or three 3s and two Js are dealt.

Input 3
52
A A A A 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 J J J J Q Q Q Q K K K K
Output 3
0.0014405762304921968

Comments

There are no comments at the moment.