Sleeping schedule P17733


Statement
 

pdf   zip

Darío has a weird sleeping schedule. And I mean really weird. It has gotten so bad that, whenever the National Cybersecurity Agency needs a pseudorandom number for encrypting purposes, they simply call Darío and ask him what time he woke up that morning.

The constant calls are beginning to annoy Darío (how is he supposed to think about math with all these interruptions?), so he has decided he is going to standardize his routine. However, he wants his schedule to satisfy a few restrictions.

To begin with, Darío’s days have hh hours, instead of the usual 2424, which he numbers from 00 to h1h-1. He will choose:

  • a fixed time ww at which to wake up, and

  • a fixed time ss at which to go to sleep.

Every day, he will sleep from ww to ss. In particular, if both times are equal, he will sleep for 0 hours. For example, if h=10h = 10, going to sleep at 7:00 and getting up at 2:00 means that Darío will sleep for 5 hours.

His chosen times must also satisfy the following conditions:

  • Both times must be multiples of an hour (e.g. he can go to sleep at 9:00 or 4:00 but not at 4:23).

  • He must wake up at a time when the dining hall is open (as everyone knows, a good day starts with a good breakfast).

  • He must go to sleep at a time when there is no ICPC training (otherwise, he would never stick to his schedule).

Darío has given you a list with the nn hours in which there is no ICPC training, and the mm hours in which the dining hall is open. He will choose uniformly at random both ww and ss (one independently from the other). Can you compute the average number of hours he will be sleeping per day?

Input

Input consists of multiple cases, only with integer numbers. Each case begins with hh, nn and mm, all between 1 and 10510^5. Follow nn distinct integers a1,,ana_1, \dots, a_n satisfying 0ai<h0 \le a_i < h, indicating the hours with no ICPC training. Follow mm distinct integers b1,,bmb_1, \dots, b_m satisfying 0bi<h0 \le b_i < h, indicating the hours with the dining hall open.

Output

For each case, print with 4 digits after the decimal point the expected number of hours that Darío will be sleeping. The given input cases will have no precission issues.

Public test cases
  • Input

    12 4 3
    0 5 8 7
    11 2 10
    
    24 2 2
    3 5
    5 3
    
    8 1 1
    6
    6
    
    24 11 11
    0 1 2 3 4 5 6 7 8 9 10
    3 4 5 6 7 8 9 10 11 12 13
    

    Output

    5.6667
    6.0000
    0.0000
    8.5537
    
  • Information
    Author
    Xavier Povill
    Language
    English
    Official solutions
    C++
    User solutions
    C++