Under construction

Still being built. Things may change

Eerie Shadows

Time limit1sMemory limit1024 MB

Summary
Given a bridge with symmetric pillar pairs and two lamps at one end, compute the area of the bridge ahead that lies in at least one lamp's shadow.
Level

Medium7 of 10

Topics
Geometry, Intervals, Math, Implementation
Solved
No attempts yet

Problem

One night, as you walk home across a bridge, you notice that the shadows from two large lamps at one end of the bridge form an interesting symmetrical pattern on the ground. The two lamps are equally far from the sides of the bridge on both sides.

The bridge has pillars in pairs at irregular sizes and intervals, and every pillar always has an identical pillar on the opposite side. You may assume that the parts of the pillars above ground level are infinitesimally thin and that the bridge is infinitely long.

Figure E.1: A visualisation of the second sample input.

How much of the bridge ahead of you is in the shadow of at least one lamp?

Input

The input consists of:

  • One line containing two integers ww and ll (1≤w≤5001 \le w \le 500, 1≤l≤100001 \le l \le 10000). ww is the distance in centimetres from the middle of the bridge to either side, and ll is the distance from the sides of the bridge to the lamps.
  • One line containing one integer nn (1≤n≤10001 \le n \le 1000), the number of pillar pairs.
  • nn further lines, each containing two integers aa and bb (0≤a≤b≤100000 \le a \le b \le 10000). They give the distances in centimetres from the end of the bridge to the start and end of one pair of pillars. For all ii, bi<ai+1b_i < a_{i+1}.

Output

Output the total area in square centimetres that is shadowed by the pillars. The absolute or relative error of your output must be at most 10−610^{-6}.

Examples2

  1. Example 1

    Input
    1 1
    1
    0 1
    
    Expected output
    5
    
  2. Example 2

    Input
    2 4
    2
    0 2
    3 5
    
    Expected output
    32.7