The Logging Company owns many sawmills. However, these sawmills currently require a human operator to function. To decrease wage expenses, the Company has hired you to write a program to replace all the humans at the sawmills.

At the sawmill, there are saws and logs . The task of an operator is to coordinate which saws should saw which logs. Each saw has an energy consumption rate , and each log has a length . Each saw should only saw one log per day, to prevent overheating. The total energy a saw needs to saw a log is its energy consumption rate multiplied by the log's length. To prove that your program can do the operators' jobs better than they can, you want to assign logs to saws such that the total energy used per day is minimized.

#### Input Specification

- The first line will be , the number of saws and logs.
- The second line will contain integers, the energy consumption of each saw, .
- The third line will contain integers, the length of each log, .

#### Output Specification

The first and only line of output should be the minimum total energy used on the day described by the input.

#### Scoring

- For cases worth 20% of the points, .
- For cases worth another 30% of the points, .
- For cases worth another 20% of the points, .
- For cases worth 90% of the points in total, .

#### Sample Input 1

```
5
1 1 1 1 1
13 27 6 20 34
```

#### Sample Output 1

`100`

#### Sample Input 2

```
3
1 4 2
30 20 10
```

#### Sample Output 2

`110`

## Comments

Can't seem to submit my solution, every time I click submit the Execution Results never updates

nvm fixed

The judge was busy with rejudging submissions.

IT says i made too many submissions

This is because we are rejudging submissions made during the contest.

Last one timed out -_-

Dont swear ppl

Try using Collections.sort

Im using Collections.sort, however its still timing out for last test case

You are still using Arrays.sort for something. Also, keep the answer in a long variable.

Im not, Im using collections to sort both lists. Will try using a long now.

Used a long, still nothing :(

In submission 12788, you are using Arrays.sort two times. Change both to Collections.sort.

Jeez, I thought I had Collections this whole time. Woops :P

Collections runs .5 seconds faster than Arrays.

Wowa

Good to know.

The TLE does not report any time past the time limit. All you know is that your program took at least 1 second to run (it may not terminate at all, but in this case it does). It is possible to construct a test case such that Arrays.sort is O(N^2), and indeed, there is such a case in the test data.

Now, I'm getting it wrong :O

The final answer will overflow int; use long.

This comment is hidden due to too much negative feedback. Click here to view it.

110 is correct.