Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

Once, after a stressful day, Chef decided to relax and visit a casino near his house to gamble. He feels lucky and he's going to bet almost all of his money.

The game Chef is going to play in the casino consists of tossing a die with $N$ faces twice. There is a number written on each face of the die (these numbers are not necessarily distinct). In order to win, Chef must get the number $A$ on the first toss and the number $B$ on the second toss of the die.

The excited viewers want to know the probability that Chef will win the game. Can you help them find that number? Assume that Chef gets each face of the die with the same probability on each toss and that tosses are mutually independent.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains three space-separated integers $N$, $A$ and $B$.
The second line contains $N$ space-separated integers $x_{1}, x_{2}, \dots, x_{N}$ denoting the numbers written on the faces of the die.

------  Output ------
For each test case, print a single line containing one real number — the probability that Chef will win. Your answer will be considered correct if its absolute error does not exceed $10^{-6}$.

------  Constraints ------
$1 ≤ T ≤ 70$
$1 ≤ N ≤ 10^{4}$
$1 ≤ A ≤ N$
$1 ≤ B ≤ N$
$1 ≤ x_{i} ≤ N$ for each valid $i$

------  Subtasks ------
Subtask #1 (20 points):
$T ≤ 10$
$N ≤ 100$

Subtask #2 (80 points): original constraints

----- Sample Input 1 ------ 
2
5 1 1
1 1 1 1 1
2 1 1
1 2
----- Sample Output 1 ------ 
1.0000000000
0.2500000000

Difficulty: EASY
Tags: Data structures

Mathematics

Probability
Skill types: Data structures

Starter code:

Solutions:
for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	N = list(map(int, input().split()))
	print(N.count(a) * N.count(b) / (n * n))


goals = int(input())
for distractions in range(goals):
	(wife, life, aim) = map(int, input().split())
	List = list(map(int, input().split()))
	knife = List.count(life) / wife
	death = List.count(aim) / wife
	print(knife * death)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	ca = 0
	cb = 0
	for i in range(n):
		if arr[i] == a:
			ca += 1
		if arr[i] == b:
			cb += 1
	print(ca / n * (cb / n))


for _ in range(int(input())):
	(N, A, B) = map(int, input().split())
	List = list(map(int, input().split()))
	k = List.count(A) / N
	j = List.count(B) / N
	final = k * j
	print('%.10f' % final)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = []
	l = list(map(int, input().split()))
	x = l.count(a)
	y = l.count(b)
	print(x * y / n ** 2)


for testcase in range(int(input())):
	(n, a, b) = map(int, input().split(' '))
	n_list = list(map(int, input().split(' ')))
	a_counter = 0
	b_counter = 0
	for i in n_list:
		if i == a:
			a_counter += 1
		if i == b:
			b_counter += 1
	print(a_counter / n * (b_counter / n))


for I in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	i = l.count(a)
	j = l.count(b)
	k = i * j / (n * n)
	print('%.10f' % k)


T = int(input())
for i in range(T):
	(N, A, B) = map(int, input().split())
	X = list(map(int, input().split()))
	Y = X.count(A)
	Z = X.count(B)
	P = Y * Z / (N * N)
	print(P)


t = int(input())
for i in range(t):
	(N, A, B) = map(int, input().split())
	l = list(map(int, input().split()))
	probability = l.count(A) / len(l) * (l.count(B) / len(l))
	print('{:.10f}'.format(probability))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	p = l.count(b) / a
	q = l.count(c) / a
	print(q * p)


for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	num1 = x.count(a)
	num2 = x.count(b)
	ans = num1 / n * (num2 / n)
	print(ans)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	aCount = bCount = 0
	x = list(map(int, input().split()))
	for num in x:
		if num == a:
			aCount += 1
		if num == b:
			bCount += 1
	aProb = aCount / n
	bProb = bCount / n
	print(aProb * bProb)


from array import *
t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	x = 0
	for i in range(n):
		if arr[i] == a:
			x = x + 1
	y = 0
	for i in range(n):
		if arr[i] == b:
			y = y + 1
	print(x * y / (n * n))


def probability(n, L, a, b):
	prob_a = L.count(a) / n
	prob_b = L.count(b) / n
	return prob_a * prob_b
for i in range(int(input())):
	(n, a, b) = input().split()
	(n, a, b) = (int(n), int(a), int(b))
	L = list(map(int, input().split()))
	print(probability(n, L, a, b))


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	(a1, b1) = (0, 0)
	for i in range(n):
		if x[i] == a:
			a1 += 1
		if x[i] == b:
			b1 += 1
	print(a1 / n * (b1 / n))


T = int(input())
for _ in range(T):
	(N, A, B) = map(int, input().split())
	x = list(map(int, input().split()))
	(Ac, Bc) = (x.count(A), x.count(B))
	p = Ac * Bc / (N * N)
	print(p)


for _ in range(int(input())):
	(w, l, a) = [int(i) for i in input().split()]
	L = [int(i) for i in input().split()]
	(k, d) = (L.count(l) / w, L.count(a) / w)
	print(k * d)


for cases in range(int(input())):
	(faces, num1, num2) = map(int, input().split())
	numbers = list(map(int, input().split()))
	probability = numbers.count(num1) / faces * numbers.count(num2) / faces
	print(f'{probability:.10f}')


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	y = x.count(a)
	z = x.count(b)
	k = y * z / (n * n)
	print('%.10f' % k)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	L = list(map(int, input().split()))
	knife = L.count(b) / a
	death = L.count(c) / a
	print(knife * death)


t = int(input())
for i in range(t):
	(N, A, B) = map(int, input().split())
	k = list(map(int, input().split()))
	x = k.count(A) / N
	y = k.count(B) / N
	print(x * y)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	k = l.count(a) / n
	d = l.count(b) / n
	print(k * d)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	print(l.count(a) / n * (l.count(b) / n))


for I in range(int(input())):
	(n1, a1, b1) = map(int, input().split())
	l1 = list(map(int, input().split()))
	i = l1.count(a1)
	j = l1.count(b1)
	k1 = i * j / (n1 * n1)
	print('%.10f' % k1)


for i in range(int(input())):
	(N, A, B) = [int(x) for x in input().split(' ')]
	X = [int(x) for x in input().split(' ')]
	p = 1
	for n in [A, B]:
		i = 0
		if n in X:
			for x in X:
				if x == n:
					i += 1
			p *= i / N
		else:
			p = 0
	print(p)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	counta = 0
	countb = 0
	c = list(map(int, input().split()))
	for j in range(n):
		if c[j] == a:
			counta += 1
		if c[j] == b:
			countb += 1
	print(counta / n * (countb / n))


Test = int(input())
for Cases in range(Test):
	(NumberofFaces, FirstToss, SecondToss) = map(int, input().split())
	DigitsonFaces = map(int, input().split())
	DigitsonFaces = list(DigitsonFaces)
	OccuranceofFirstToss = DigitsonFaces.count(FirstToss)
	OccuranceofSecondToss = DigitsonFaces.count(SecondToss)
	Result = OccuranceofFirstToss * OccuranceofSecondToss / (NumberofFaces * NumberofFaces)
	print('%.10f' % Result)


def prob():
	ca = l.count(a)
	cb = l.count(b)
	p = len(l)
	return ca / p * (cb / p)
n = int(input())
for i in range(n):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	print(prob())


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	l1 = list(map(int, input().split()))
	m1 = l1.count(a)
	m2 = l1.count(b)
	print(str.format('{0:.6f}', m1 / n * m2 / n))


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	x = list(map(int, input().split()))
	y = x.count(b) / a
	z = x.count(c) / a
	print(y * z)


T = int(input())
for i in range(0, T):
	(N, A, B) = input().split()
	(N, A, B) = [int(N), int(A), int(B)]
	ca = 0.0
	cb = 0.0
	x = [int(x) for x in input().split()]
	ca = x.count(A)
	cb = x.count(B)
	pa = ca / N
	pb = cb / N
	pf = pa * pb
	print(pf)


n = int(input())
a = []
b = []
for i in range(n):
	a.append(list(map(int, input().split())))
	b.append(list(map(int, input().split())))
for i in range(n):
	print(b[i].count(a[i][1]) / a[i][0] * (b[i].count(a[i][2]) / a[i][0]))


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	lst = list(map(int, input().split()))
	print(lst.count(a) / n * (lst.count(b) / n))


for i in range(int(input())):
	J = input().split()
	N = J[0]
	A = J[1]
	B = J[2]
	X = input().split()
	p_a = X.count(A) / len(X)
	p_b = X.count(B) / len(X)
	print(p_a * p_b)


for i in range(0, int(input())):
	(x, y, z) = map(int, input().split())
	l = list(map(int, input().split()))
	a = l.count(y) / x
	b = l.count(z) / x
	m = a * b
	print('%.10f' % m)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	probability = x.count(a) / n * (x.count(b) / n)
	print(probability)


for i in range(int(input())):
	(n, a, b) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	x = lst.count(a)
	y = lst.count(b)
	res = x * y / (n * n)
	print('%.10f' % res)


import re
test_cases = int(input())
for _ in range(0, test_cases):
	(N, A, B) = map(int, input().split())
	dice_values = [*map(int, input().split())]
	count_A = dice_values.count(A)
	count_B = dice_values.count(B)
	probability_A = count_A / N
	probability_B = count_B / N
	print(probability_A * probability_B)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	x = l.count(b)
	y = l.count(c)
	k = x * y / (a * a)
	print('%.10f' % k)


T = int(input())
for t in range(T):
	(N, A, B) = map(int, input().split())
	face_list = list(map(int, input().split()))
	freq_A = face_list.count(A)
	freq_B = face_list.count(B)
	prob_win = freq_A * freq_B / (N * N)
	print(prob_win)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	print(x.count(a) * x.count(b) / (n * n))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	d = l.count(b) / a
	e = l.count(c) / a
	print(d * e)


T = int(input())
for t in range(0, T):
	(n, a, b) = map(int, input().split())
	X = list(map(int, input().split()))
	a_in_x = X.count(a) / len(X)
	b_in_x = X.count(b) / len(X)
	prob = a_in_x * b_in_x
	print(prob)


t = int(input())
for _ in range(t):
	(n, a, b) = map(int, input().split())
	faces = list(map(int, input().split()))
	res = 0
	proba = faces.count(a) / n
	probb = faces.count(b) / n
	print(proba * probb)


for test in range(int(input())):
	(n, a, b) = map(int, input().split())
	N = list(map(int, input().split()))
	one = N.count(a) / n
	two = N.count(b) / n
	print(one * two)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	List = list(map(int, input().split()))
	a = List.count(y) / x
	c = List.count(z) / x
	print(a * c)


num = int(input())
for i in range(num):
	(n, a, b) = map(int, input().split())
	face_values = [int(face) for face in input().split()]
	(count_a, count_b) = (face_values.count(a), face_values.count(b))
	prob = count_a * count_b / n ** 2
	print(prob)


nTestCases = int(input())
for i in range(0, nTestCases):
	inputStringLIst = input().split()
	nFaces = int(inputStringLIst[0])
	numberA = int(inputStringLIst[1])
	numberB = int(inputStringLIst[2])
	facesList = []
	facesStringList = input().split()
	for j in facesStringList:
		facesList.append(int(j))
	probabilityA = facesList.count(numberA) / len(facesList)
	probabilityB = facesList.count(numberB) / len(facesList)
	print(probabilityA * probabilityB)


for x in range(int(input())):
	(n, a, b) = map(int, input().split())
	faces = list(map(int, input().split()))
	prob_a = faces.count(a) / n
	prob_b = faces.count(b) / n
	print(prob_a * prob_b)


t = int(input())
for i in range(t):
	(N, A, B) = map(int, input().split())
	X = list(map(int, input().split()))
	cntA = X.count(A)
	cntB = X.count(B)
	print('%.10f' % (cntA * cntB / (N * N)))


T = int(input())
while T:
	(N, A, B) = [int(i) for i in input().split()]
	x = [int(i) for i in input().split()]
	print(x.count(A) / N * x.count(B) / N)
	T -= 1


testCases = int(input())
for i in range(testCases):
	dieSides = input().split(' ')
	dieValues = input().split(' ')
	N = int(dieSides[0])
	A = int(dieSides[1])
	B = int(dieSides[2])
	dieValues = [int(x) for x in dieValues]
	prob1 = dieValues.count(A)
	prob2 = dieValues.count(B)
	finalProb = prob1 * prob2 / (N * N)
	print('%.10f' % finalProb)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	x = []
	x = [int(y) for y in input().split()]
	counta = 0
	countb = 0
	for j in x:
		if j == a:
			counta = counta + 1
		if j == b:
			countb = countb + 1
	proba = counta / n
	probb = countb / n
	print(proba * probb)


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	tempa = l.count(a)
	tempb = l.count(b)
	print(tempa / n * (tempb / n))


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list1 = list(list1)
	k = len(list1)
	count_a = 0
	count_b = 0
	for i in range(n):
		if list1[i] == a:
			count_a += 1
		if list1[i] == b:
			count_b += 1
	print(float(count_a / n) * float(count_b / n))


for _ in range(int(input())):
	(n, a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	pa = x.count(a) / n
	pb = x.count(b) / n
	print(pa * pb)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	p = l.count(a) / n
	k = l.count(b) / n
	l = p * k
	print('%.10f' % l)


for t in range(int(input())):
	(n, a, b) = map(int, input().split())
	newList = list(map(int, input().split()))
	numofa = newList.count(a)
	numofb = newList.count(b)
	print(numofa * numofb / (n * n))


T = int(input())
for distractions in range(T):
	(n, a, b) = map(int, input().split())
	List = list(map(int, input().split()))
	w = List.count(a) / n
	d = List.count(b) / n
	print(w * d)


t = int(input())
for i in range(t):
	(n, a, b) = map(int, input().split())
	r = list(map(int, input().split()))
	z = r.count(a) / n
	z1 = r.count(b) / n
	print(z * z1)