QOJ.ac

QOJ

Límite de tiempo: 4 s Límite de memoria: 256 MB Puntuación total: 100

#11140. Enchanted Pencil

Estadísticas

The organizers of this year's Potyczki Algorytmiczne have clearly run out of ideas for cool problems, but the final must be prepared. Fear not! Piotrek, the owner of the Enchanted Pencil, has come to the rescue.

Piotrek will draw $n$ triangles on a plane one after another – that is, he will trace the perimeter of each one with his Pencil. The Enchanted Pencil appears to draw normally, but it has a unique property: if it visits a point on Piotrek's paper for the second time, that point stops being drawn and disappears from the paper, as if it had never been there. Naturally, if it is visited a third time, it will reappear, on the fourth time it will disappear again, and so on.

Why all this trouble? As we said, we need to give you a task. Calculate the perimeter of the resulting figure, which is the sum of the lengths of all line segments that will be visible on the paper after Piotrek finishes drawing.

Input

The first line of input contains a single integer $n$ ($1 \le n \le 100\,000$), representing the number of triangles.

The next $n$ lines contain the descriptions of the triangles. The $i$-th of these lines contains six integers $x_1, y_1, x_2, y_2, x_3, y_3$, meaning that the $i$-th triangle has vertices at coordinates $(x_1, y_1)$, $(x_2, y_2)$, and $(x_3, y_3)$. Each triangle is non-degenerate – its vertices are not collinear. The coordinates of all points are in the range $[-10^6, 10^6]$.

Output

Output a single real number – the total length of the segments visible on the paper. The answer will be accepted if its relative or absolute error does not exceed $10^{-6}$.

Note: For technical reasons, printing more than 18 digits after the decimal point may result in a "wrong answer" verdict.

Examples

Input 1

2
1 1 3 1 2 3
3 3 4 1 2 1

Output 1

10.9442719100

Input 2

2
0 1 2 1 1 2
1 1 2 0 3 1

Output 2

7.6568542495

Note

Explanation of the examples: In the first test, the result is $2 + 4\sqrt{5} \approx 10.94427190999916$, while in the second it is $2 + 4\sqrt{2} \approx 7.656854249492381$. Both are illustrated in the images below.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.