This page is still under construction.

Parts of this page are still being built. What you see may change.

Drawing Circles

Time limit5sMemory limit1024 MB

Summary
Given up to 2000 circles drawn in order, each new circle erases the interior of everything already there; find the total length of circumference still visible.
Level

Hard8 of 10

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

Problem

Alice likes to draw circles. Whenever she has some time, she grabs a piece of paper and draws circles on it.

Alice draws circles on a paper with a coordinate system. Each circle is represented by an ordered tuple (x, y, r), where (x, y) is the position of the circle's center and r is the radius. She does not like two circles to cross each other, so she always erases the inside area of each new circle she draws. That is, she erases the interior of each new circle, leaving the pencil line showing the circumference. (Of course, if she overwrites an existing circle then the new pencil line simply hides the old circumference, removing it from view.)

For example (see Figure A.1),

  • if she first draws (0, 0, 1) and then (0, 0, 2), the first circle will be completely erased; or
  • if she first draws (−1, 0, 2) and then (1, 0, 2), then the part of the first circle to the right of the x = 0 axis will be erased.

Figure A.1: Sample inputs. Dotted lines are areas that have been erased.

After drawing a number of circles, she would like to know the total length of all curved line segments that are still visible on the paper.

Input

The first line of input contains an integer N (1 ≤ N ≤ 2000) denoting the number of circles Alice drew. Each of the following N lines contains three space-separated integers xi, yi, and ri (−10 000 ≤ xi, yi ≤ 10 000, 1 ≤ ri ≤ 10 000, i = 1 . . . N) describing the i th circle she drew.

Output

Output the total length of all curved line segments that are visible.

Your answer will be considered correct if its absolute or relative error does not exceed 10−6.

Examples2

  1. Example 1

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

    Input
    2
    -1 0 2
    1 0 2
    
    Expected output
    20.943951