atcoder#ABC229F. [ABC229F] Make Bipartite

[ABC229F] Make Bipartite

Score : 500500 points

Problem Statement

Given is an undirected graph with N+1N+1 vertices. The vertices are called Vertex 00, Vertex 11, \ldots, Vertex NN.

For each i=1,2,,Ni=1,2,\ldots,N, the graph has an undirected edge with a weight of AiA_i connecting Vertex 00 and Vertex ii.

Additionally, for each i=1,2,,Ni=1,2,\ldots,N, the graph has an undirected edge with a weight of BiB_i connecting Vertex ii and Vertex i+1i+1. (Here, Vertex N+1N+1 stands for Vertex 11.)

The graph has no edge other than these 2N2N edges above.

Let us delete some of the edges from this graph so that the graph will be bipartite. What is the minimum total weight of the edges that have to be deleted?

Constraints

  • 3N2×1053 \leq N \leq 2 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Bi1091 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

Output

Print the answer.

5
31 4 159 2 65
5 5 5 5 10
16

Deleting the edge connecting Vertices 0,20,2 (weight: 44), the edge connecting Vertices 0,40,4 (weight: 22), and the edge connecting Vertices 1,51,5 (weight: 1010) makes the graph bipartite.

4
100 100 100 1000000000
1 2 3 4
10