Under construction

Still being built. Things may change

Pollution Solution

Time limit1sMemory limit128 MB

Summary
Compute the area where a half-disk of radius r centered at the origin overlaps a given polygon above the x-axis.
Level

Medium7 of 10

Topics
Geometry
Solved
No attempts yet

Problem

Haebin works at the water pollution control center, monitoring pollutants released into rivers, lakes, and the sea. The task is to measure, as an area, how that pollution affects aquatic ecosystems such as coral reefs and spawning grounds.

The model is as follows. The shoreline is the xx-axis, and the pollution source is at the origin (0,0)(0, 0). The pollution spreads inside a semicircle centered at the origin with radius rr, that is, the half-disk above the shoreline (the region with y≥0y \ge 0). The ecosystem is given as a single simple polygon whose vertices all satisfy y≥0y \ge 0.

Compute the area of the region where the pollution half-disk and the ecosystem polygon overlap.

Input

The first line contains two integers nn and rr (3≤n≤1003 \le n \le 100, 1≤r≤10001 \le r \le 1000), where nn is the number of vertices of the ecosystem polygon and rr is the radius measured from the source.

Each of the next nn lines contains the coordinates xix_i, yiy_i of one polygon vertex, listed in counterclockwise order (−1500≤xi≤1500-1500 \le x_i \le 1500, 0≤yi≤15000 \le y_i \le 1500).

The polygon's edges neither cross nor touch one another, and no vertex lies on the arc of the semicircle (the boundary at radius rr).

Output

Print the area of the part of the ecosystem polygon that lies inside the half-disk (semicircle) of radius rr centered at the source. Round the area to exactly six decimal places.

Examples3

  1. Example 1

    Input
    6 10
    -8 2
    8 2
    8 14
    0 14
    0 6
    -8 14
    
    Expected output
    101.576438
    
  2. Example 2

    Input
    3 1000
    1 1
    3 1
    1 4
    
    Expected output
    3.000000
    
  3. Example 3

    Input
    3 1
    100 100
    200 100
    100 200
    
    Expected output
    0.000000