Universal Cup Judging System

Universal Cup

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓
Statistiques

คุณได้รับรูปหลายเหลี่ยมเชิงเดียว $N$ เหลี่ยมบนระนาบ $xy$ ซึ่งด้านทุกด้านขนานกับแกน $x$ หรือแกน $y$ (กล่าวคือ เป็นรูปหลายเหลี่ยมที่ไม่มีด้านตัดกันเองและไม่มีรู)

มีสถานที่ปราศรัย $M$ แห่งอยู่บนขอบของรูปหลายเหลี่ยมนี้

เมื่ออนุญาตให้เคลื่อนที่ได้เฉพาะตามขอบของรูปหลายเหลี่ยมนี้เท่านั้น จงหาระยะทางรวมในการเดินทางที่น้อยที่สุดที่ต้องใช้เพื่อไปเยือนสถานที่ปราศรัยทั้งหมดครบทุกแห่งละหนึ่งครั้งพอดี

จุดเริ่มต้นและจุดสิ้นสุดของการเคลื่อนที่สามารถเลือกที่ใดก็ได้บนขอบของรูปหลายเหลี่ยม

Input

บรรทัดแรกประกอบด้วยจำนวนจุดยอด $N$ ของรูปหลายเหลี่ยม และจำนวนสถานที่ปราศรัย $M$ ($4 \le N \le 10^5, 1 \le M \le 10^5$)

บรรทัดที่ $(i + 1)$ ประกอบด้วยพิกัด $(x_i, y_i)$ ของจุดยอดที่ $i$ ของรูปหลายเหลี่ยมเชิงเดียว $N$ เหลี่ยม ($1 \le i \le N, |x_i|, |y_i| \le 10^5$) ด้านของรูปหลายเหลี่ยมจะเชื่อมจุดยอดที่ $i$ และจุดยอดที่ $(i + 1)$ กล่าวอีกนัยหนึ่ง จะมีเพียงเงื่อนไขเดียวเท่านั้นที่เป็นจริงระหว่าง $x_i = x_{i+1}$ หรือ $y_i = y_{i+1}$ (จุดยอดที่ $(N + 1)$ แทนจุดยอดที่ $1$) ไม่มีจุดยอดใดอยู่บนด้าน (นั่นคือ ไม่มีจุดยอดใดที่มีมุม $180$ องศา)

บรรทัดที่ $(j + 1 + N)$ ประกอบด้วยพิกัด $(p_j, q_j)$ ของสถานที่ปราศรัยแห่งที่ $j$ ($1 \le j \le M, |p_j|, |q_j| \le 10^5$) จุดเหล่านี้แตกต่างกันทั้งหมดและอยู่บนขอบของรูปหลายเหลี่ยมที่กำหนดให้ (รวมถึงจุดยอดด้วย)

ค่าข้อมูลนำเข้าทั้งหมดเป็นจำนวนเต็ม

Output

พิมพ์คำตอบออกมา

Examples

Input 1

4 3
0 0
3 0
3 2
0 2
0 0
3 0
3 2

Output 1

5

Input 2

6 4
0 0
3 0
3 1
2 1
2 2
0 2
3 0
0 2
2 1
1 2

Output 2

5

Input 3

10 10
-12 -11
-12 9
3 9
3 1
-3 1
-3 -1
8 -1
8 -10
-5 -10
-5 -11
3 1
3 7
7 -1
-3 0
-4 -10
-12 8
-10 -11
-3 9
-12 -10
8 -7

Output 3

74

Note

ในตัวอย่างแรก มีจุดอยู่บนจุดยอดสามจุดของรูปสี่เหลี่ยมมุมฉาก และการไปเยือนตามลำดับแห่งที่ $1$ $(0, 0) \to 2$ $(3, 0) \to 3$ $(3, 2)$ จะให้ระยะทางรวมในการเดินทางที่สั้นที่สุด ซึ่งก็คือ $3 + 2 = 5$

problem_17716_25.png

Figure for Sample Input 1

problem_17716_26.png

Figure for Sample Input 2

problem_17716_24.png

Figure for Sample Input 3

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1525EditorialOpen题解jianglyView

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.