AlgoUniversity
  • Go Back
Discussion
School Picnic :

Author

Ujjwal Srivastava

Difficulty Level : Medium

Submissions : 1064

Asked In : Uber

Marks :30

: 6 | : 1

Professor X has to solve the perennial problem of the budget for school picnic Each student is identified by a unique Roll Number $$$(r[i])$$$ and a Unique Identification Number$$$(a[i])$$$. The total amount of the trip will be calculated as the sum of the cost of each of the rounds as long as there are at least two students remaining in the class. In a single round:

  • Professor will select two students in his class, let them be $$$p$$$ and $$$q$$$.

  • Choose Unique Identification Number $$$(a[p])$$$ of one and Roll Number$$$(r[q])$$$ of the other. Add the value $$$a[p] \cdot r[q]$$$ to the amount of trip. Or another option is vice versa, $$$a[q] \cdot r[p].$$$

  • Return one (say $$$p$$$) back to the class, while the other (say $$$q$$$) will go and sit in the bus outside or vice versa, i.e., return $$$q$$$ to the class and $$$p$$$ goes and sits in the bus. Note $$$p$$$ and $$$q$$$ are indexes of the students.

In the last round, both students will go to the bus.

The professor needs your help. You need to find the minimum possible amount of the trip, considering all the possible ways in which the student can be selected and organized. Help him out.

As this amount can be very large find its mod with 10^9+7.

Input

  • The first line contains a positive integer $$$n$$$: the number of students.
  • The second line contains a list of $$$n$$$ positive integers $$$a$$$; the $$$i_{th}$$$ of these represents the Unique Identification Number on the $$$i_{th}$$$ student.
  • The third line contains a list of $$$n$$$ positive integers $$$r$$$; the $$$i_{th}$$$ of these represents the Roll number on the $$$i_{th}$$$ student.
Constraints
  • $$$(2 \le n \le 10^3)$$$
  • $$$(1 \le a[i] \le 10^9)$$$
  • $$$(1 \le r[i] \le 10^5)$$$

Output

The minimum possible total that can be attained if students are selected optimally.

Examples

Input
3
23 45 56
11 14 3
Output
204
Input
3
4 1 2
8 3 1
Output
5

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.