PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000136. Thăm đền và miếu (Lazy Faith)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Thăm đền và miếu (Lazy Faith)

Lazy Faith

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are AA shrines at s1<s2<⋯<sAs_1<s_2<\cdots<s_A and BB temples at t1<t2<⋯<tBt_1<t_2<\cdots<t_B on an east-west road. All coordinates are distances in metres from the western end. For each of QQ independent starting locations xix_i, find the shortest total walking distance required to visit at least one shrine and at least one temple, in either order. Additional sites may be passed.

Input

The first line contains A,B,QA,B,Q. The next AA lines contain s1,…,sAs_1,\ldots,s_A, one per line. The following BB lines contain t1,…,tBt_1,\ldots,t_B, one per line. The final QQ lines contain the starting locations x1,…,xQx_1,\ldots,x_Q.

Output

Print QQ lines; line kk is the shortest travel distance for starting point xkx_k.

Subtasks

  • Subtask 1 (20 points): 1≤A≤201\le A\le 20; 1≤B≤201\le B\le 20; 1≤Q≤201\le Q\le 20; 1≤s1<⋯<sA≤10101\le s_1<\cdots<s_A\le 10^{10}; 1≤t1<⋯<tB≤10101\le t_1<\cdots<t_B\le 10^{10}; 1≤xi≤10101\le x_i\le 10^{10} for every 1≤i≤Q1\le i\le Q; all shrine, temple and start coordinates are pairwise distinct.
  • Subtask 2 (30 points): 1≤A≤15001\le A\le 1500; 1≤B≤15001\le B\le 1500; 1≤Q≤15001\le Q\le 1500; 1≤s1<⋯<sA≤10101\le s_1<\cdots<s_A\le 10^{10}; 1≤t1<⋯<tB≤10101\le t_1<\cdots<t_B\le 10^{10}; 1≤xi≤10101\le x_i\le 10^{10} for every 1≤i≤Q1\le i\le Q; all shrine, temple and start coordinates are pairwise distinct.
  • Subtask 3 (50 points): 1≤A≤1000001\le A\le 100000; 1≤B≤1000001\le B\le 100000; 1≤Q≤1000001\le Q\le 100000; 1≤s1<⋯<sA≤10101\le s_1<\cdots<s_A\le 10^{10}; 1≤t1<⋯<tB≤10101\le t_1<\cdots<t_B\le 10^{10}; 1≤xi≤10101\le x_i\le 10^{10} for every 1≤i≤Q1\le i\le Q; all shrine, temple and start coordinates are pairwise distinct.

Examples

Input

2 3 4
100
600
400
900
1000
150
2000
899
799

Output

350
1400
301
399

Explanation

Shrines are at 100,600100,600; temples at 400,900,1000400,900,1000. From 150150, go to 100100 (5050 m), then 400400 (300300 m): 350350. From 20002000, go to 10001000 (10001000 m), then 600600 (400400 m): 14001400. From 899899, visit 900900 (11 m), then 600600 (300300 m): 301301. From 799799, visit 600600 (199199 m), then 400400 (200200 m): 399399. All nearest predecessor/successor choices in both visit orders are considered.