Universal Cup Judging System

Universal Cup

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓
统计

أُعطيت مضلعًا بسيطًا ذا $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.