Shobon has decided to use a generative AI to help develop a software project. The project consists of tasks. Each task () has a predetermined implementation workload and complexity .
Shobon can proceed with these tasks in any order. However, he cannot work on more than one task at the same time.
Each task () can be completed in one of the following two ways:
Implement the task manually. Shobon writes the code himself, which takes units of time.
Use the generative AI. To make the AI generate correct code, Shobon explains the current task and all previously completed tasks to the AI. Let be the sum of the complexities of all previously completed tasks. Preparing this explanation takes units of time. The AI then finishes the implementation instantly, so no additional implementation time is required. Thus, completing this task by using the AI takes a total of units of time.
Regardless of which method is used, once task is completed, its complexity is included in future values of when using the generative AI.
Find the minimum total time required to complete all tasks.
输入格式
The input consists of three lines in the following format.
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
In the first line, the number of tasks, , is given (). The second line contains integers, , each between and , inclusive, representing the implementation workloads of the tasks. The third line contains integers, , each between and , inclusive, representing the complexities of the tasks.
输出格式
Output in a line the minimum total time required to complete all tasks.