Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

נתון לכם מצולע פשוט בן $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.