AlgoUniversity
  • Go Back
Discussion
Equal :

Author

Shikhar Mehrotra

Difficulty Level : Medium

Submissions : 141

Asked In : Jaguar

Marks :20

: 3 | : 1

You are given 2 arrays $$$a_1,a_2...a_n$$$ and $$$b_1,b_2,...b_n$$$. In each steps you can set $$$a_i$$$ to $$$a_i-b_i$$$ if $$$a_i>=b_i$$$

Determine minimum number of steps to make all $$$a's$$$ equal.

Input

The first line contains $$$1\le n \le 5000$$$.

The second line contains $$$n$$$ space separated integers where $$$i_{th}$$$ integer represents $$$1\le a_i \le 5000$$$.

The third line contains $$$n$$$ space separated integers where $$$i_{th}$$$ integer represents $$$1\le b_i \le 5000$$$.

Output

Print minimum steps required to make all $$$a's$$$ equal . If it is not possible print $$$-1$$$.

Examples

Input
2
5 6
4 3
Output
-1
Input
5
5 7 10 5 15
2 2 1 3 5
Output
8

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.