CADYDIST - Candy Distribution


Alice is a teacher that loves her students. As the school year reaches its end, she wants to reward all her students with candies for all their hard work.

Since each of her classes is unique, she decided she’ll give a different kind of candy for each class, and in order to avoid students being mad at others in their class, she wants to make things fair by giving all students in the same class the same kind of candy.

Happily, she went to the candy shop, and fortunately found out that it had N different types of candy, exactly the same number of classes of students she taught!

Looking at the prices and paying close attention to the number of students in each class, Alice noted that she could save some money by assigning the types of candy to certain classes. Because she’s a teacher, her income is not that big and saving money is very important to her, so she asked you to write a program to determine the least amount of money she must spend.

Input

Each test case consists of three lines. The first line contains a positive integer N (1 ≤ N ≤ 100000). The second line contains N integers Ci, the ith integer indicates the number of students in Alice’s i-th class. The third and last line also contains N integers Pi the ith integer indicates the price of the ith type of candy (1 ≤ Ci, Pi  ≤ 100000).

The input ends with a line consisting of a 0, which indicates end of input.

Output

For each test case, output a line containing the least amount of money Alice must spend.

Example

Input:
4
1 1 1 1
2 2 2 2
5
10 80 37 22 109
6 8 8 20 15
0 Output: 8
2120

hide comments
Vaseem Ahmed khan: 2012-07-07 19:29:23

@:D i had taken long long for output value but its giving me WA but same code on making every variable unsigned long long gives AC .

:D: 2012-06-16 10:02:23

The constrains are correct. You are probably having problems since output value and only this value can be long long:
maxN * maxC * maxP = (10^5)^3 = 10^15

Really, be more careful when writing about problem issues. More often than not it's the solvers fault.

Pranshul Agarwal: 2012-06-12 12:01:41

Thnx darky1, secret and
15972125841321

Inspiron: 2012-06-05 11:20:37

hmmmmmmmmmmm

Last edit: 2012-08-28 23:30:40
Darky: 2012-06-04 12:36:05

Use scanf, printf and unsigned long long int even for N

15972125841321: 2012-05-28 13:20:37

@secret ur comment helped ... thnx

LaFolle: 2012-04-20 15:51:07

Same as : http://code.google.com/codejam/contest/32016/dashboard#s=p0"

EDIT : Missing facility for HTML tags :(

Last edit: 2012-04-20 15:52:37
Shekhar: 2012-04-10 05:10:07

Someone plz provide more typical test cases. My code is correct, still getting WA ??

bristy: 2012-03-22 18:11:05

i think Ci & Pi >100000......

Secret: 2012-03-13 20:17:25

got accepted after taking evry variable in unsigned long long int...


Added by:Paulo Costa
Date:2012-01-19
Time limit:0.301s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ITA - Brazilian ICPC Training Camp, Jan-Feb/2012