QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#10298. 公交

統計

There are $L$ bus stops uniformly distributed along a highway, numbered from $1$ to $L$. Initially, there are $n$ passengers waiting for the bus. The $i$-th passenger is waiting at stop $s_i$ and their destination is stop $t_i$. It is guaranteed that $s_i \neq t_i$.

There is exactly one bus operating on this highway, initially located at stop $p$.

If the bus is at stop $i$, it can move to stop $(i-1)$ or $(i+1)$ in one unit of time, provided the stop number is within $[1, L]$. At the initial stop or after moving from one stop to another, the bus will open its doors to pick up all passengers waiting at that stop and drop off all passengers on the bus whose destination is that stop.

Assume the bus has infinite capacity, the bus's movement between stops can be chosen arbitrarily, and passengers boarding or alighting do not consume time. You need to find the minimum number of units of time required for the bus to transport all $n$ passengers to their destinations.

Since no one knows where the bus is initially parked, you also need to solve $q$ queries. Each query provides a different $p$, while the passenger information remains the same. You need to find the answer to the above problem for each query.

Input

The data is read from standard input.

The first line contains a positive integer $id$, representing the subtask number.

  • The first line contains three integers $L, n, q$, representing the number of bus stops, the number of passengers, and the number of queries.
  • The next $n$ lines each contain two integers $s_i, t_i$, describing a passenger.
  • The next line contains $q$ integers $p_1, p_2, \dots, p_q$, describing the value of $p$ for each query.

Output

Output to standard output.

For each test case, output a line containing $q$ integers $a_1, a_2, \dots, a_q$, representing the answers to each query in order.

Examples

Input

1
20 2 3
3 5
10 12
2 6 9

Output

10 12 14

Note

  • In the first query, $p = 2$. The optimal way for the bus to move is to continuously increment the stop number, taking ten units of time to reach $12$.
  • In the second query, $p = 6$. The optimal way for the bus to move is to first spend three units of time to reach $3$, then spend nine units of time to reach $12$.
  • In the third query, $p = 9$. The optimal way for the bus to move is to first spend three units of time to reach $12$, then spend nine units of time to reach $3$, and finally spend two units of time to reach $5$.

Examples

Input

1
10 10 10
7 3
6 5
8 3
10 8
7 1
4 7
7 9
6 2
1 9
10 1
9 2 10 3 1 6 8 4 5 7

Output

18 19 17 20 18 21 19 21 22 20

Subtasks

For all test data:

  • $1 \le L \le 10^{16}$, $1 \le n, q \le 10^{6}$;
  • $\forall 1 \le i \le n, 1 \le s_i, t_i \le L, s_i \neq t_i$;
  • $1 \le p_1, p_2, \dots, p_q \le L$;
  • $\forall 1 \le i \le n, 1 \le j \le q, s_i \neq p_j, t_i \neq p_j$.
Subtask IDScore$n,q \le$Special Property
113$10$A
214$50$None
38$3,000$B
412None
513$10^{6}$B
616C
724None

Special Property A: $L \le 10$.

Special Property B: $\forall 1 \le i \le n, 1 \le j \le q, p_j < s_i$.

Special Property C: $\forall 1 \le i \le n, 1 \le j \le q, p_j \not\in [\min(s_i,t_i), \max(s_i,t_i)]$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.