Maximum Flow

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Bobo has an undirected graph with (2n+2)(2n + 2) vertices conveniently labeled with the following pairs of integers: (0,0),(0,1),,(0,n),(1,0),(1,1),,(1,n)(0, 0), (0, 1), \dots, (0, n), (1, 0), (1, 1), \dots, (1, n). The graph has three classes of edges.

  • The edges of the first class connect vertices (0,i1)(0, i - 1) and (0,i)(0, i) with capacity a_ia\_i for i1,2,,ni \in \\{1, 2, \dots, n\\}.
  • The edges of the second class connect vertices (1,i1)(1, i - 1) and (1,i)(1, i) with capacity b_ib\_i for i1,2,,ni \in \\{1, 2, \dots, n\\}.
  • The edges of the third class connect vertices (0,i12)(0, \lfloor\frac{i - 1}{2} \rfloor) and (1,i2)(1, \lfloor \frac{i}{2}\rfloor) with capacity c_ic\_i for i1,2,,2n+1i \in \\{1, 2, \dots, 2n + 1\\}.

Bobo would like to find the maximum flow from vertex (0,0)(0, 0) to vertex (1,n)(1, n).

입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains an integer nn (1n51051 \leq n \leq 5 \cdot 10^5).

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \dots, a\_n.

The third line contains nn integers b_1,b_2,,b_nb\_1, b\_2, \dots, b\_n.

The fourth line contains (2n+1)(2n + 1) integers c_1,c_2,,c_2n+1c\_1, c\_2, \dots, c\_{2n + 1}.

The constraints are: 1a_i,b_i,c_i1091 \leq a\_i, b\_i, c\_i \leq 10^9.

It is guaranteed that the number of test cases does not exceed 10510^5, and the sum of all nn does not exceed 51055 \cdot 10^5.

출력

For each test case, output an integer which denotes the maximum flow.