This page is still under construction.

Parts of this page are still being built. What you see may change.

Cute Panda

Time limit2sMemory limit512 MB

Summary
Each panda splits its donuts between bin i and bin i+1 (cyclically); find the maximum total donuts the bins can absorb.
Level

Medium7 of 10

Topics
Greedy, Array, Implementation, Math
Solved
No attempts yet

Problem

There are nn pandas numbered from 11 to nn, and the ii-th panda has aia_i donuts. There are also nn bins numbered from 11 to nn, and the ii-th bin can hold up to bib_i donuts. For every ii from 11 to nn, the ii-th panda can distribute his donuts between the ii-th bin and the (i mod n+1)(i \bmod n + 1)-th bin.

Find the maximum number of donuts that can be distributed.

Input

The input contains zero or more test cases, and is terminated by end-of-file. Each test case is given as follows.

The first line contains an integer nn (3≤n≤1063 \le n \le 10^6).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9).

The third line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi≤1090 \le b_i \le 10^9).

The sum of all nn over all test cases does not exceed 10610^6.

Output

For each test case, output one integer: the maximum number of donuts that can be distributed.

Examples1

  1. Example 1

    Input
    5
    8 4 8 3 10
    1 0 4 5 1
    5
    9 4 10 0 4
    3 5 2 2 1
    
    Expected output
    11
    13