Under construction

Still being built. Things may change

Farm Village

Time limit2sMemory limit512 MB

Summary
Each house along a road needs one crop unit and can grow up to two; minimize the total growing cost plus cost of carrying crops between neighbors.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy
Solved
No attempts yet

Problem

There is a village along a road. The village has NN houses, numbered 1 to NN in order along the road. Each house has a field that can grow up to two units of the crop, and each house needs exactly one unit. The total cost of giving every house one unit of the crop is the sum of the carrying costs and the growing costs.

  • Carrying cost: carrying one unit of the crop between house ii and house i+1i+1 costs did_i. The cost is the same in either direction.
  • Growing cost: growing one unit of the crop in the field of house ii costs gig_i.

Compute the minimum total cost of supplying one unit of the crop to every house.

Input

The input is a single test case in the following format.

N
d1 d2 ... dN-1
g1 g2 ... gN

The first line contains an integer NN (2≤N≤200,0002 \le N \le 200{,}000), the number of houses. The second line contains N−1N-1 integers separated by spaces. The ii-th integer did_i (1≤di≤1091 \le d_i \le 10^9, 1≤i≤N−11 \le i \le N-1) is the carrying cost between house ii and house i+1i+1. The third line contains NN integers separated by spaces. The ii-th integer gig_i (1≤gi≤1091 \le g_i \le 10^9, 1≤i≤N1 \le i \le N) is the growing cost of the field of house ii.

Output

Print the minimum cost of supplying one unit of the crop to every house.

Examples3

  1. Example 1

    Input
    2
    3
    1 5
    
    Expected output
    5
    
  2. Example 2

    Input
    3
    100 100
    1 2 3
    
    Expected output
    6
    
  3. Example 3

    Input
    4
    1 2 3
    1 1 100 100
    
    Expected output
    12