Boring Marathon

2.7

3 votes
Mathematics, Easy-Medium, Probability distribution, Probability distribution
Problem

Chintu was part of the Lolympics committee. He had a day off today, so, Chintu decided to watch the 42 km Marathon Finals with Mintu. They started to feel bored after a few minutes. So, they decided to play a game.

They decided a string of length L, and wrote the same string on their respective papers. The string consisted of only upper case letters. Once both of them had a paper with the same string, they started to pick a character from the mentioned string and match if it was same or not. Once an element of a string was picked, they discarded that from their respective strings.

You've to calculate the expected number of times the character both of them picked is same.

Input:
A single line consisting of a number T denoting the number of test cases.
Next T lines consisting of a string of length L having upper case letters.

Output:
Print the expected value upto six decimal places.

Constraints:
1 <= T <= 10
1 <= L <= 105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first test case, we have the string AB. After picking up the letters, we may any of the two sets of strings
1. {AA,BB} = 2 times we will get the same letter
2. {AB,BA} = 0 times we will get the same letter.
So, answer will be (2 + 0) / 2 = 1.0.
Similarly, for the second test case, answer will be 1.5.

Editor Image

?