eolymp
bolt
Try our new interface for solving problems
Problems

A Cycle of Points

A Cycle of Points

There are n points on a plane, numbered from 1 to n. They form a directed cycle 12 → ... → n1. You need to perform the following operation several times: given the numbers of two points a and b, remove the part of the cycle starting with the point a and ending with the point b, and return it back in reversed order, so that part will start from b and end with a. Find the length of the final cycle.

Input

The first line contains two numbers n and m (3n, m100000). Next n lines contain two numbers xi and yi - coordinates of i-th point. Next m lines contain two numbers ai and bi - point numbers in i-th operation.

Output

Output the length of the final cycle with two digits after the decimal point.

Explanation

  1. Initial cycle: 123451
  2. After the first operation: 153421(part 512 is replaced with 215)
  3. After the second operation: 124351 (part 5342 is replaced with 2435)
  4. After the third operation: 125341
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 3
0 0
1 0
2 0
2 2
0 2
5 2
5 2
4 5
Output example #1
10.89
Author Alexey Shchepin
Source ACM-ICPC Ukraine 2013, 2nd Stage Ukraine, September 10-12, 2013