Jaccard index

The Jaccard index is a statistic used for comparing the similarity and diversity of two sets. Namely, the Jaccard index J(A,B)J(A,B) of AA and BB is J(A,B)=ABAB.J(A,B) = \frac{\mid A\cap B\mid }{\mid A\cup B\mid }.

For example, the Jaccard index of the sets {1,2,3}\{1,2,3\} and {3,4}\{3,4\} is 0.250.25.

Write a program to compute the Jaccard index of pairs of sets of integers.

Input

The input consists of several cases. Each case starts describes two sets AA and BB. The first set AA starts with its cardinality m0m \geq 0 and then follow its mm integer elements in strictly increasing order. The second set BB starts with its cardinality m0m \geq 0 and then follow its nn integer elements in strictly increasing order. For each case, m+n1m+n\ge1.

Output

For each case in the input, print the Jaccard index of its two sets in a different line with 3 digits of precision.

Hint

Problem information

Author: Guillem Godoy, Jordi Petit

Generation: 2026-01-25T11:33:28.054Z

© Jutge.org, 2006–2026.
https://jutge.org